-
-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Variant Typings Don't Respect Composing #144
Comments
Also, with the following Toggle: const Toggle = classed('div', Button, {
defaultVariants: {
size: 'sm',
variant: 'ghost',
},
variants: {
size: {
sm: '',
},
variant: {
ghost: '',
},
},
}) I can't use Toggle({
variant: 'default' // ERROR, only `'ghost' | undefined`
}) However, maybe it's even good, because we can limit variant set for the extended component. |
And the most unavoidable: Providing Tailwind classes to the extended component overrides the base ones: const Button = classed('button', {
defaultVariants: {
variant: 'default',
},
variants: {
variant: {
default: '1 2 3',
},
},
})
const Toggle = classed(TogglePrimitive, Button, {
variants: {
variant: {
default: '4 5'
},
},
})
expect(
Toggle().className
).toEqual(
'1 2 3 4 5' // actual: 4 5
) |
I'm trying to use this in the same way and am running into the same issues here. |
This is intended behavor |
This should not error, you are correct. The rest is intended |
Got a fix locally, will see to it tomorrow |
Thus, there's no way to actually extend components with additional classes. If we had the proposed extension, we would be able to remove (reset to initial) some of the base classes:
However, now we can only overwrite. |
Yes there is. We have the {
base: "base classes",
variants: {
...
}
},
{
base: "base 2"
} This is extendable and combined with |
Allows any string KV pair in defaultVariants fixes: #144
Yes, but the same doesn't apply with the variants. Look at this comment. So, the bases are merged but the variants aren't. |
I see. I will likely add this as a flag in V2 release. export const { classed } = createClassed({ merger: twMerge, mergeVariants: true }); The reason is that some, including me, rely on variants being able to completely override. |
Describe the bug
User Story:
small
andghost
by default.defaultVariant#size
since thevariants
prop doesn't havesize
. However, I should be able to do this since the "composable" Button has it.To Reproduce
Copy these two components into your project (it would be great to have a StackBlitz template).
Expected behavior
The error should not appear.
Environment? (please complete the following information):
The text was updated successfully, but these errors were encountered: