You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Support passing arrays of styles to `style` and `styleVariants`
6
+
7
+
Multiple styles can now be composed into a single rule by providing an array of styles.
8
+
9
+
```ts
10
+
import { style } from'@vanilla-extract/css';
11
+
12
+
const base =style({ padding: 12 });
13
+
14
+
exportconst primary =style([
15
+
base,
16
+
{ background: 'blue' }
17
+
]);
18
+
19
+
exportconst secondary =style([
20
+
base,
21
+
{ background: 'aqua' }
22
+
]);
23
+
```
24
+
25
+
When composed styles are used in selectors, they are assigned an additional class if required so they can be uniquely identified. When selectors are processed internally, the composed classes are removed, only leaving behind the unique identifier classes. This allows you to treat them as if they were a single class within vanilla-extract selectors.
This feature is a replacement for the standalone `composeStyles` function which is now marked as deprecated. You can use `style` with an array as a drop-in replacement.
> 💡 To improve maintainability, each `style` block can only target a single element. To enforce this, all selectors must target the `&` character which is a reference to the current element. For example, `'&:hover:not(:active)'` is considered valid, while `'& > a'` and ``[`& ${childClass}`]`` are not.
396
+
> 💡 To improve maintainability, each style block can only target a single element. To enforce this, all selectors must target the “&” character which is a reference to the current element.
397
397
>
398
-
>If you want to target another scoped class then it should be defined within the `style` block of that class instead. For example,``[`& ${childClass}`]`` is invalid since it targets `${childClass}`, so it should instead be defined in the `style` block for `childClass`.
398
+
>For example, `'&:hover:not(:active)'` and `` [`${parentClass} &`] `` are considered valid, while `'& a[href]'` and``[`& ${childClass}`]`` are not.
399
399
>
400
-
>If you want to globally target child nodes within the current element (e.g. `'& > a'`), you should use [`globalStyle`](#globalstyle) instead.
400
+
> If you want to target another scoped class then it should be defined within the style block of that class instead.
401
+
>
402
+
> For example, `` [`& ${childClass}`] `` is invalid since it doesn’t target “&”, so it should instead be defined in the style block for `childClass`.
403
+
>
404
+
> If you want to globally target child nodes within the current element (e.g. `'& a[href]'`), you should use [`globalStyle`](#globalstyle) instead.
405
+
406
+
Multiple styles can be composed into a single rule by providing an array of styles.
407
+
408
+
```ts
409
+
import { style } from'@vanilla-extract/css';
410
+
411
+
const base =style({ padding: 12 });
412
+
413
+
exportconst primary =style([
414
+
base,
415
+
{ background: 'blue' }
416
+
]);
417
+
418
+
exportconst secondary =style([
419
+
base,
420
+
{ background: 'aqua' }
421
+
]);
422
+
```
423
+
424
+
When composed styles are used in selectors, they are assigned an additional class if required so they can be uniquely identified. When selectors are processed internally, the composed classes are removed, only leaving behind the unique identifier classes. This allows you to treat them as if they were a single class within vanilla-extract selectors.
> 💡 Styles can also be provided in shallow and deeply nested arrays, similar to [classnames.](https://github.com/JedWatson/classnames)
481
-
482
-
When style compositions are used in selectors, they are assigned an additional class so they can be uniquely identified. When selectors are processed internally, the composed classes are removed, only leaving behind the unique identifier classes. This allows you to treat them as if they were a single class within vanilla-extract selectors.
0 commit comments