defaultVariant styles inherited in other variants
See original GitHub issueif i add some buttons variants to my theme and declare one of these as the defaultVariant for my Button component, styles from the defaultVariant must be manually reset or overridden in my other variant options.
for example, take the following excerpt from my theme object:
buttons: {
medium: {
borderRadius: "$xlarge",
py: 14,
px: "$8",
},
circle: {
borderRadius: "$rounded",
alignItems: "center",
justifyContent: "center",
width: 40,
height: 40,
},
},
with the following component definition:
const Button = styled(Pressable, {
themeKey: "buttons",
defaultVariant: "medium",
})({
alignSelf: "center",
});
when rendering <Button variant={'circle'} /> it will have the py and px padding from the medium variant. i have to add px: 0, py: 0 to my circle variant to prevent this.
i didn’t expect it to inherit this way. it seems like it could be a bug because if i do not set a defaultVariant then no inheriting occurs. let me know if my expectations are misplaced here tho.
Issue Analytics
- State:
- Created a year ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Should base rules override inherited base variants? · Issue #629
One way to get around this, is by extending the color variant in RedBox and overriding the defaultVariant there. But seems like a...
Read more >Variants - Stitches.dev
In the case of needing to set styles of a variant, based on a combination of other variants, you can use the compoundVariants...
Read more >Create interactive components with variants - Figma Help Center
Variant properties are a type of component property specific to variants and component sets. You can add as many properties and values as...
Read more >font-variant - CSS: Cascading Style Sheets - MDN Web Docs
The font-variant CSS shorthand property allows you to set all the font variants for a font.
Read more >Variants - Styled System
Use the variant API to apply complex styles to a component based on a single prop. This can be a handy way to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

i was also unsure about declaring styles in theme at first as I am used to stitches where variants are declared as part of the component, however, your approach has opened my eyes somewhat in that it could allow designers to more easily have control over visual styles. the components themselves could handle functional styles only.
i’ve been trialing going all in on this approach and enjoying it thus far!
this would be super helpful and would suit my use-case perfectly 🙏
thanks for the issue! i see, you’re expecting
variant || defaultVariant. i’ll look into this for you and see what’s up.