-
Hello! I am wondering is the best way how to reuse variants from one component in another one. Let's say I have a Text component and I would love to reuse some specific variant in a Badge component. export const Text = styled('span', {
variants: {
type: {
title: {
// title css
},
label: {
// label css
},
}
}
})
export const Badge = styled('span', {
// badge css
// label css
}) I came with two possible solutions:
Both work well, but feel wrong. Is there any other way, how to achieve this behavior? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Might not be exactly what you're looking for, but the const linkCSS = css({
variants: {
isExternal: { /* ... */ }
}
})
() => <Button className={linkCSS({ isExternal: true })} /> |
Beta Was this translation helpful? Give feedback.
-
Hey! This restriction is by design. We've done that so compositions can happen at the markup layer. The solution you came up is exactly what I'd do. In fact, it's exactly what we do at Modulz! 🎉 |
Beta Was this translation helpful? Give feedback.
-
@peduarte might correct me, but I feel like this is a great use case for export const Text = styled('span', {
variants: {
type: {
title: {
// title css
},
label: {
// label css
},
}
}
})
export const Badge = styled(Text, {
// Inherits variants from `Text`
}) You can see a more complex (but still real-world) example in issue #675, which is very much related. |
Beta Was this translation helpful? Give feedback.
Hey! This restriction is by design. We've done that so compositions can happen at the markup layer.
The solution you came up is exactly what I'd do. In fact, it's exactly what we do at Modulz! 🎉