Better ways of overriding styles using typescript? #194
Closed
JHunnicutt
started this conversation in
General
Replies: 1 comment 1 reply
-
@JHunnicutt Did you try this? <button
className={button({...props, className})}
{...spreadProps}
>
{props.children}
</button> |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
I'm refactoring a button component to take additional classes that extend or override the existing classes from the
tv()
function. I've read the docs on overriding classes, but it's not evident to me how to combine that the model of constructing a component with TypeScript, as passingclassName
as an additional argument results in an error.After some tinkering, I worked out a solution using the simple
cn()
function that relies on clsx and twMerge which comes with Shadcn/ui, and I thought that others may benefit from this solution.This provides the exact functionality that I was hoping to implement. I'm not sure if there's a different way to handle this situation using the tools extended by TypeScript and Tailwind Variants, and I'd love to receive correction here if so. However, if you're struggling with setting up a type safe component to take some overriding classes, this workaround might be the trick you need.
Beta Was this translation helpful? Give feedback.
All reactions