-
Doing some early exploration of enabling display-p3 color. A preferable approach is setting custom properties based on a supports rule. https://webkit.org/blog/10042/wide-gamut-color-in-css-with-display-p3/ /* sRGB color. */
:root {
--bright-green: rgb(0, 255, 0);
}
/* Display-P3 color, when supported. */
@supports (color: color(display-p3 1 1 1)) {
:root {
--bright-green: color(display-p3 0 1 0);
}
}
header {
color: var(--bright-green);
} So wondering if there's a way of using globalCss to achieve something similar either through local scopes or some how toggling between multiple themes (base theme and display-p3 theme). const globalStyles = stitchesConfig.globalCss({
'@supports (color: color(display-p3 1 1 1))': {
':root': {
???
}
}
})
// or
const displayP3Theme = stitchesConfig.createTheme('dispaly-p3', {
'$red': 'color(display-p3 0 1 0)'
})
// check for support and swap theme |
Beta Was this translation helpful? Give feedback.
Answered by
peduarte
Oct 1, 2021
Replies: 1 comment 2 replies
-
Hey, how about this: import { createStitches } from "@stitches/react";
/**
* What's happening:
* 1. We define a `brightGreen` token with the "normal green"
* 2. This token will be created as a CSS Custom Property: `colors-brightGreen`
* 3. We then use the `globalCss` function to override the CSS Custom Property under a `@supports` rule
* The reason for doing it this way is so you still get the token suggestion!
*/
const { styled, globalCss } = createStitches({
theme: {
colors: {
// Define token (normal green)
brightGreen: "rgb(0, 255, 0)"
}
}
});
const globalStyles = globalCss({
// Target the `:root`
":root": {
// Check for support
"@supports (color: color(display-p3 1 1 1))": {
// Override token
"--colors-brightGreen": "color(display-p3 0 1 0)"
}
}
});
const Box = styled("div", {
// Then use it!
backgroundColor: "$brightGreen",
padding: 50
}); Demo: https://codesandbox.io/s/awesome-swirles-9gn0c?file=/src/App.tsx |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
derekr
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, how about this: