-
Notifications
You must be signed in to change notification settings - Fork 291
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sprinkles condition not overidden #1469
Comments
You're using a darker colour for hover than for pressed, so when both are applied, the darker colour wins because it's generated later in the stylesheet. This is because of the order sprinkles generates classnames, which is in the order the tokens are provided. So the reason it works with a red colour is because the red tokens are defined after the indigo tokens. Using a regular style with You could try a combination of sprinkles and regular selectors if you want to maximise sprinkles usage. The this only works because you happen to be using the same background and border colour: style:
[
sprinkles({
background: {
dark: "indigo6",
},
color: "white",
borderColor: {
dark: "indigo6",
},
}),
{
selectors: {
[DATA_HOVERED]: {
background: colors.indigo8,
borderColor: colors.indigo8,
},
[DATA_PRESSED]: {
background: colors.indigo7,
borderColor: colors.indigo7,
},
},
},
], Specificity issues are quite common with recipes and sprinkles, and there are existing discussions around their interoperability. I don't think we've put in explicit effort to make them work better together. I wonder if simply iterating over sprinkles properties different would address this? |
Thanks for your reply @askoufis, now it's clear why using sprinkles like that create some strange behaviors. Your solution could works but using that approach we mix simple styles with sprinkles and honestly add some complexity while reading and mantaining styles. After some testing, I think using something like this seems much cleaner and readable, but yes is longer than previous. {
variants: {
variant: "filled",
color: "indigo",
},
style: style({
"@media": {
"(prefers-color-scheme: dark)": {
color: vars.colors.white,
background: vars.colors.indigo9,
borderColor: vars.colors.indigo9,
selectors: {
[DATA_HOVERED]: {
background: vars.colors.indigo8,
borderColor: vars.colors.indigo8,
},
[DATA_PRESSED]: {
background: vars.colors.indigo7,
borderColor: vars.colors.indigo7,
},
},
},
"(prefers-color-scheme: light)": {
color: vars.colors.white,
background: vars.colors.indigo9,
borderColor: vars.colors.indigo9,
selectors: {
[DATA_HOVERED]: {
background: vars.colors.indigo8,
borderColor: vars.colors.indigo8,
},
[DATA_PRESSED]: {
background: vars.colors.indigo7,
borderColor: vars.colors.indigo7,
},
},
},
},
}),
} Depending on the project needs (for example the application has a theme toggle) we could adopt another solution, not handling different media using What do you think about the solution above compared to different theme class with tokens value for light and dark mode? |
Your solution would work, and is very flexible, but it is quite verbose. Leaning in to CSS variables more could help. Using semantic vars instead of putting your entire color palette inside vars would mean you could define two themes at build time, one for dark and one for light. For example, these themes would each set This separates your palette from your semantic tokens, and allows you to swap to darkmode by just changing a single classname, rather than defining a media query for every style. |
Describe the bug
Basically my sprinkles defines color conditions for light, dark mode and for both also define states: lightHover, darkHover etc..
Inside my button I used data attributes to style element based on values that came from react-aria
useButton
hook, and each compound variant style key is result of calling sprinkles function.These class are generated in this order in dev mode:
Button__pwy3ag3
--> base button stylesprinkles_background_indigo6_dark__28ssfrzv
--> base button backgroundsprinkles_background_indigo8_darkHover__28ssfr10o
--> base button background on hoversprinkles_background_indigo7_darkPressed__28ssfr10e
--> base button on presssprinkles_color_white_dark__28ssfrjj
--> base button text colorsprinkles_borderColor_indigo6_dark__28ssfr1d3
--> base button border colorsprinkles_borderColor_indigo8_darkHover__28ssfr1dw
--> base button border color on hoversprinkles_borderColor_indigo7_darkPressed__28ssfr1dm
--> base button border on pressedThis is what happen
Is using sprinkles like that a bad way?
EDIT: I tried to assign a complete different color like
red
and seems working with sprinkles function, but I have no idea why in this case works.Reproduction
https://codesandbox.io/p/sandbox/vanilla-extract-specificity-8g2m3r
System Info
Used Package Manager
pnpm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: