Skip to content

postcss-custom-media : update docs #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions plugins/postcss-custom-media/.tape.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ postcssTape(plugin)({
preserve: true
}
},
'examples/true': {
message: 'minimal example with "true"',
},
'examples/false': {
message: 'minimal example with "false"',
},
'examples/complex': {
message: 'minimal example complex queries',
},
'nesting': {
message: 'works when nested'
},
Expand Down
75 changes: 75 additions & 0 deletions plugins/postcss-custom-media/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,81 @@
}
```

## `true` and `false`

With `@custom-media` you can use the constants `true` and `false`.
These are especially handy when debugging.

If you are unsure how your page is affected when a certain media query matches or not you can use these, to quickly toggle the results.
This plugin downgrades these queries to something that works in all browsers.

Quickly check the result as if the query matches:

```pcss
@custom-media --small-viewport true;

@media (--small-viewport) {
/* styles for small viewport */
}

/* becomes */

@media (max-color:2147477350) {
/* styles for small viewport */
}
```

Quickly check the result as if the query does not match:

```pcss
@custom-media --small-viewport false;

@media (--small-viewport) {
/* styles for small viewport */
}

/* becomes */

@media (color:2147477350) {
/* styles for small viewport */
}
```

## logical evaluation of complex media queries

It is impossible to accurately and correctly resolve complex `@custom-media` queries
as these depend on the browser the queries will eventually run in.

_Some of these queries will have only one possible outcome but we have to account for all possible queries in this plugin._

⚠️ When handling complex media queries you will see that your CSS is doubled for each level of complexity.<br>
GZIP works great to de-dupe this but having a lot of complex media queries will have a performance impact.

An example of a very complex (and artificial) use-case :

```pcss

@custom-media --a-complex-query tty and (min-width: 300px);

@media not screen and ((not (--a-complex-query)) or (color)) {
/* Your CSS */
}

/* becomes */


@media tty and (min-width: 300px) {
@media not screen and ((not (max-color:2147477350)) or (color)) {
/* Your CSS */
}
}
@media not tty and (min-width: 300px) {
@media not screen and ((not (color:2147477350)) or (color)) {
/* Your CSS */
}
}
```

## Usage

Add [PostCSS Custom Media] to your project:
Expand Down
48 changes: 48 additions & 0 deletions plugins/postcss-custom-media/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,54 @@
<example.expect.css>
```

## `true` and `false`

With `@custom-media` you can use the constants `true` and `false`.
These are especially handy when debugging.

If you are unsure how your page is affected when a certain media query matches or not you can use these, to quickly toggle the results.
This plugin downgrades these queries to something that works in all browsers.

Quickly check the result as if the query matches:

```pcss
<true.css>

/* becomes */

<true.expect.css>
```

Quickly check the result as if the query does not match:

```pcss
<false.css>

/* becomes */

<false.expect.css>
```

## logical evaluation of complex media queries

It is impossible to accurately and correctly resolve complex `@custom-media` queries
as these depend on the browser the queries will eventually run in.

_Some of these queries will have only one possible outcome but we have to account for all possible queries in this plugin._

⚠️ When handling complex media queries you will see that your CSS is doubled for each level of complexity.<br>
GZIP works great to de-dupe this but having a lot of complex media queries will have a performance impact.

An example of a very complex (and artificial) use-case :

```pcss
<complex.css>

/* becomes */

<complex.expect.css>
```

<usage>

<envSupport>
Expand Down
6 changes: 6 additions & 0 deletions plugins/postcss-custom-media/test/examples/complex.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@custom-media --a-complex-query tty and (min-width: 300px);

@media not screen and ((not (--a-complex-query)) or (color)) {
/* Your CSS */
}
11 changes: 11 additions & 0 deletions plugins/postcss-custom-media/test/examples/complex.expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

@media tty and (min-width: 300px) {
@media not screen and ((not (max-color:2147477350)) or (color)) {
/* Your CSS */
}
}
@media not tty and (min-width: 300px) {
@media not screen and ((not (color:2147477350)) or (color)) {
/* Your CSS */
}
}
5 changes: 5 additions & 0 deletions plugins/postcss-custom-media/test/examples/false.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@custom-media --small-viewport false;

@media (--small-viewport) {
/* styles for small viewport */
}
3 changes: 3 additions & 0 deletions plugins/postcss-custom-media/test/examples/false.expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@media (color:2147477350) {
/* styles for small viewport */
}
5 changes: 5 additions & 0 deletions plugins/postcss-custom-media/test/examples/true.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@custom-media --small-viewport true;

@media (--small-viewport) {
/* styles for small viewport */
}
3 changes: 3 additions & 0 deletions plugins/postcss-custom-media/test/examples/true.expect.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@media (max-color:2147477350) {
/* styles for small viewport */
}