-
I'm trying to add custom variants to existing components and I was somewhat able to do this using tailwind-variants but there's some issues with it. I was wondering what the recommended approach to extending or customizing components is? Here's an example of what seems to work using the Card component:
Although this works, it's still a bit hacky because extending with the Card component instead of card tailwind-variants object I end up losing context for the rest of the props available to the Card component. When I try extending the card style object from theme, I get problems trying to pass the new cardStyles object to base, probably because it expects a string, not a function. Same issue trying to use className.
I tried looking for something in the docs that could help, found this page: https://nextui.org/docs/customization/custom-variants#creating-new-variants-for-slots-components But it seems you're only able to modify existing variants (i.e. adding a new color inside colors) but it's not possible to create new variants like (size or color for Card for example) using extendVariants. So I'm wondering what is the recommended approach to customizing existing components. Is using the useCard hook the only option at this point? Would really appreciate some direction here, hopefully this can start a productive discussion at least if not a direct answer. Thanks for your time! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I figured it out - the issue was that Card is a slot component and there's a different pattern to passing extended styles to slot components. Here's how it should be done:
You can read this for more info: https://www.tailwind-variants.org/docs/composing-components#extending-components-with-slots Closing this since the issue is solved. |
Beta Was this translation helpful? Give feedback.
I figured it out - the issue was that Card is a slot component and there's a different pattern to passing extended styles to slot components. Here's how it should be done:
You can read this for more info: https://www.tailwind-variants.org/docs/composing-compon…