Reuse styles in selectors #726
Unanswered
pradeeproark
asked this question in
Q&A
Replies: 3 comments 5 replies
-
I would probably just use e.g. export const dropShadow = {
boxShadow: '5px 10px #888888'
} as const;
export const cardStyle = style({
selectors: {
'&:hover': dropShadow
}
}); |
Beta Was this translation helpful? Give feedback.
4 replies
-
I toyed with a solution to this the other day, something like this: import { style as _style, ComplexStyleRule } from '@vanilla-extract/css';
function style<Rule extends ComplexStyleRule>(
rule: Rule,
debugId?: string
): [string, Rule] {
return [_style(rule, debugId), rule];
}
export const [dropShadow, dropShadowRule] = style({
boxShadow: '5px 10px #888888',
});
export const [cardStyle] = style({
selectors: {
'&:hover': dropShadowRule,
},
}); This way you get auto-complete in the style rules, but you could pass other properties as the rule only has to extend |
Beta Was this translation helpful? Give feedback.
1 reply
-
still no solution for this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, is it possible to have an API that allows reusing existing style definitions in other style's selectors
Example try to reuse the dropShadowStyle in the hover selector in card style:
One workaround that I did is if we type dropShadow as CSSPropertiesWithVars then it can be used for the hover selector
But dropShadow by itself cannot be used a style.
Beta Was this translation helpful? Give feedback.
All reactions