Skip to content

Commit d27d15b

Browse files
pascalduezMoOx
authored andcommitted
Added: @apply support (MoOx#291)
Closes MoOx#203
1 parent 4aa517d commit d27d15b

File tree

7 files changed

+61
-3
lines changed

7 files changed

+61
-3
lines changed

docs/content/features.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ depending on your browser scope) using
1818
**[autoprefixer](https://github.com/postcss/autoprefixer)**).
1919

2020

21-
## custom properties & `var()`
21+
## custom properties & `var()`
2222

2323
The current transformation for custom properties aims to provide a
2424
future-proof way of using a **limited subset (to top-level `:root` selector)**
@@ -42,6 +42,30 @@ might happen).
4242
|
4343
[Plugin documentation](https://github.com/postcss/postcss-custom-properties)
4444

45+
## custom properties set & `@apply`
46+
47+
Allows you to store a set of properties in a named variable, then reference them
48+
in other style rules.
49+
50+
```css
51+
:root {
52+
--danger-theme: {
53+
color: white;
54+
background-color: red;
55+
};
56+
}
57+
58+
.danger {
59+
@apply --danger-theme;
60+
}
61+
```
62+
63+
(The same DOM restrictions as the custom properties plugin apply).
64+
65+
[Specification](https://tabatkins.github.io/specs/css-apply-rule)
66+
|
67+
[Plugin documentation](https://github.com/pascalduez/postcss-apply)
68+
4569
## reduced `calc()`
4670

4771
Allows you to use safely calc with custom properties by optimizing previously

docs/content/index.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ title: cssnext - Use tomorrow’s CSS syntax, today.
5151
<a href="/features/#automatic-vendor-prefixes">automatic vendor prefixes</a>
5252
</li>
5353
<li class="r-Grid-cell r-minS--1of2">
54-
<a href="/features/#custom-properties-var">custom properties & <code>var()</code></a>
54+
<a href="/features/#custom-properties-var">custom properties &amp; <code>var()</code></a>
55+
</li>
56+
<li class="r-Grid-cell r-minS--1of2">
57+
<a href="/features/#custom-properties-set-apply">custom properties set &amp; <code>@apply</code></a>
5558
</li>
5659
<li class="r-Grid-cell r-minS--1of2">
5760
<a href="/features/#reduced-calc">reduced <code>calc()</code></a>

docs/content/playground.html

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
--highlightColor: hwb(190, 35%, 20%);
1717
}
1818

19+
/* custom properties set & @apply rule */
20+
:root {
21+
--centered: {
22+
display: flex;
23+
align-items: center;
24+
justify-content: center;
25+
};
26+
}
27+
28+
.centered {
29+
@apply --centered;
30+
}
31+
1932
/* custom media queries */
2033
@custom-media --viewport-medium (width <= 50rem);
2134

@@ -65,7 +78,7 @@
6578

6679
/* overflow-wrap fallback */
6780
body {
68-
overflow-wrap: break-word;
81+
overflow-wrap: break-word;
6982
}
7083

7184
</textarea>

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"pixrem": "^3.0.0",
2828
"pleeease-filters": "^3.0.0",
2929
"postcss": "^5.0.4",
30+
"postcss-apply": "^0.3.0",
3031
"postcss-calc": "^5.0.0",
3132
"postcss-color-function": "^2.0.0",
3233
"postcss-color-gray": "^3.0.0",
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
:root {
2+
--foo-set: {
3+
color: tomato;
4+
content: 'foo';
5+
};
6+
}
7+
8+
.foo {
9+
@apply --foo-set;
10+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.foo {
2+
color: tomato;
3+
content: 'foo';
4+
}

src/features.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ export default {
99
// https://npmjs.com/package/postcss-custom-properties
1010
customProperties: (options) => require("postcss-custom-properties")(options),
1111

12+
// https://npmjs.com/package/postcss-apply
13+
applyRule: (options) => require("postcss-apply")(options),
14+
1215
// https://npmjs.com/package/postcss-calc
1316
calc: (options) => require("postcss-calc")(options),
1417

0 commit comments

Comments
 (0)