-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,576 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
'@vanilla-extract/css': minor | ||
--- | ||
|
||
Add support for [cascade layers, i.e. `@layer`][cascade layers]. | ||
|
||
Create a scoped [layer] to avoid naming collisions, or with an explicit name using [globalLayer]. Styles can then be assigned to layers using the `@layer` key within your style definition. | ||
|
||
```tsx | ||
// layers.css.ts | ||
import { layer } from '@vanilla-extract/css'; | ||
|
||
export const reset = layer('reset'); | ||
export const framework = layer('framework'); | ||
export const typography = layer('typography'); | ||
|
||
// typography.css.ts | ||
import { style } from '@vanilla-extract/css'; | ||
import { typography } from './layers.css'; | ||
|
||
export const standard = style({ | ||
'@layer': { | ||
[typography]: { | ||
fontSize: '1rem' | ||
} | ||
} | ||
}); | ||
``` | ||
[cascade layers]: https://developer.mozilla.org/en-US/docs/Web/CSS/@layer | ||
[layer]: https://vanilla-extract.style/documentation/api/layer | ||
[globalLayer]: https://vanilla-extract.style/documentation/global-api/global-layer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Layers</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="./src/index.ts"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"name": "@fixtures/layers", | ||
"version": "0.0.1", | ||
"main": "src/index.ts", | ||
"author": "SEEK", | ||
"private": true, | ||
"dependencies": { | ||
"@vanilla-extract/css": "1.10.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { link, pink } from './styles.css'; | ||
|
||
const html = String.raw; | ||
|
||
document.body.innerHTML = html` | ||
<main> | ||
<p> | ||
<a href="#">This link</a> should be <b>red</b> on mobile, green on | ||
desktop. | ||
</p> | ||
<p> | ||
<a href="#" class=${link}>This link with class of <code>link</code></a> | ||
should be <b>blue</b> on mobile, green on desktop. | ||
</p> | ||
<p> | ||
<a href="#" class=${pink}>This link with class of <code>pink</code></a> | ||
should be <b>pink</b> on mobile, green on desktop. | ||
</p> | ||
</main> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { style, globalStyle, layer, globalLayer } from '@vanilla-extract/css'; | ||
|
||
/* | ||
The resulting layer order: | ||
1. lib | ||
2. base | ||
3. typography (when above 600px) | ||
4. utilities | ||
5. typography (when below 600px) | ||
This will make links red/blue/pink when below 600px and green when above 600px. | ||
*/ | ||
|
||
const typography = 'typography'; // this layer is defined conditionally | ||
|
||
const lib = globalLayer('lib'); | ||
const base = layer({ parent: lib }); | ||
|
||
globalStyle('a', { | ||
'@media': { | ||
'screen and (min-width: 600px)': { | ||
'@layer': { | ||
[typography]: { | ||
color: 'green', // styles *all* links | ||
fontSize: '1.5rem', | ||
}, | ||
}, | ||
}, | ||
}, | ||
'@layer': { | ||
[base]: { | ||
fontWeight: 800, | ||
color: 'red', | ||
}, | ||
}, | ||
}); | ||
|
||
export const link = style({ | ||
'@layer': { | ||
[base]: { | ||
color: 'blue', | ||
}, | ||
}, | ||
}); | ||
|
||
const utilities = layer({ parent: lib }); | ||
|
||
export const pink = style({ | ||
'@layer': { | ||
[utilities]: { | ||
color: 'hotpink', // styles *all* .pink's | ||
}, | ||
}, | ||
}); | ||
|
||
globalLayer(typography); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.