Would be nice to have a className-like helper when you want to dynamically apply classes according to a variant config.
In my case, I'm playing with a basic <Button />component that would have an icon prop that could receive an ReactElement:
<Button size="xs" icon={<XMarkIcon />}>
Default
</Button>
In this case I'd like to apply some size-based variants to the icon as well, something like:
const iconClassNames = variantClassNames({
variants: {
size: {
xs: "w-4 h-4 -ml-0.5 mr-1",
sm: "w-4 h-4 -ml-0.5 mr-2",
md: "w-5 h-5 -ml-1 mr-2",
lg: "w-6 h-6 -ml-1 mr-3",
xl: "w-6 h-6 -ml-1 mr-3",
}
},
defaultVariants: {
size: "md",
},
});
That could be used this way:
<button>
{icon ? cloneElement(icon, {className: iconClassNames(props)}) : null}
{children}
</button>
Do you think this could be useful or would you do it differently (eg. nested styles, etc.)?
Would be nice to have a className-like helper when you want to dynamically apply classes according to a variant config.
In my case, I'm playing with a basic
<Button />component that would have aniconprop that could receive anReactElement:In this case I'd like to apply some size-based variants to the icon as well, something like:
That could be used this way:
Do you think this could be useful or would you do it differently (eg. nested styles, etc.)?