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
For `@keyframes` rules, a `@-webkit-keyframes` block is automatically created with auto-prefixed property names.
382
382
383
-
#### Mixins and `@extend`
383
+
#### Mixins and `@coposes`
384
384
385
-
Mixins and `@extend` make `j2c` sheets composable. Both techniques can be combined.
385
+
Mixins and `@composes` make `j2c` sheets composable. Both techniques can be combined.
386
386
387
387
##### Mixins and source objects composition
388
388
389
389
For mixins, arrays works the same way at the selector level as they do at the property/value one. You can therefore use the [method described in the "inline" section](#mixins) to create mixins, that can return either at-rules, selectors, properties or a mix thereof.
390
390
391
-
##### `@extend`
391
+
##### `@composes`
392
392
393
-
`j2c` also supports a SASS-like `@extend`, more powerful in some regards, but more limited in others.
393
+
`j2c` also supports `@composes`, which works a bit like the SASS`@extend`, more powerful in some regards, but more limited in others.
394
394
395
395
The limitation is that it can only deal with classes. Specifically:
396
396
397
397
```JS
398
-
namespace =j2c.sheet({
399
-
'.red': {color:'#f00'}
400
-
})
401
-
402
-
sheet =j2c.sheet(namespace, {
398
+
sheet =j2c.sheet({
399
+
'.red': {
400
+
color:'#f00'
401
+
},
403
402
'.great': {
404
403
fontSize:'3em'
405
404
},
406
-
'.greatRed': {
407
-
'@extend': ['.great', '.red'] // you can also pass a single class
405
+
// `scarlet` here is the target of the composition, `great` and `red` are the sources.
406
+
'.scarlet': {
407
+
'@composes': ['.great', '.red'] // you can also pass a single class
408
408
}
409
409
})
410
410
```
411
411
412
-
`sheet.greatRed` is now defined as `'great_j2c... red_j2c... greatRed_j2c...'` (class names truncated for readability).
412
+
`sheet.scarlet` is now defined as `'great__j2c-xxx red__j2c-xxx scarlet__j2c-xxx'` (class names truncated for readability).
413
413
414
414
The extra power comes from the fact that you can inherit from arbitrary classes, not just j2c-defined ones:
415
415
416
416
```JS
417
417
sheet =j2c.sheet(namespace, {
418
418
'.myButton': {
419
-
'@extend':':global(.button)', // coming, say, form Bootstrap
419
+
'@composes':':global(.button)', // coming, say, form Bootstrap
420
420
color:theme.highlight
421
421
}
422
422
})
423
423
```
424
424
425
425
Here, `sheet.myButton` is `'button myButton_j2c...'`.
426
426
427
-
While `@extend` can import from arbitrary classes, it only imports into local ones.
428
-
429
-
`@extend` works fine with nested selectors. If there are more than one class in a selector, `@extend` applies to the last (right-most) one.
430
-
431
-
###### Invalid uses
427
+
While the `@composes` sources can be arbitrary classes, the target must be a local one. It will not work in global context.
432
428
433
-
If the last or only selector is a `:global(.klass)`, in `@global` context, or in the absence of a class in the selector, `@extend` is turned into a `at-extend` property and inserted as-is in the sheet.
429
+
`@composes` doesn't support nested selectors, and doesn't work in conditional at rules. Its target must lie at the first nesting level.
0 commit comments