-
E.g. I have export const buttonVariants = cva(['your', 'base', 'classes'], {
variants: {
color: {
primary: 'bg-primary-600 hover:bg-primary-500 text-white',
dark: 'bg-gray-800 hover:bg-gray-700 text-white',
light: 'bg-gray-200 hover:bg-gray-300 text-gray-800',
danger: 'bg-red-600 hover:bg-red-500 text-white',
gray: 'bg-gray-600 hover:bg-gray-500 text-white',
info: 'bg-blue-600 hover:bg-blue-500 text-white',
purple: 'bg-purple-600 hover:bg-purple-500 text-white',
success: 'bg-green-600 hover:bg-green-500 text-white',
warning: 'bg-yellow-600 hover:bg-yellow-500 text-white',
},
size: {
xs: 'px-2 py-1',
sm: 'px-2 py-1',
md: 'px-2.5 py-1.5',
lg: 'px-3 py-2',
xl: 'px-4 py-2',
},
},
defaultVariants: {
color: 'primary',
size: 'md',
},
}) And I want to create a storybook with all options without copypasting them. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 19 replies
-
Ended up writing my own import { ClassValue, ClassProp, StringToBoolean } from 'class-variance-authority/dist/types'
import { ConfigSchema, ConfigVariants, Config, cva } from 'class-variance-authority'
type TcvaProps<T> = T extends ConfigSchema ? ConfigVariants<T> & ClassProp : ClassProp
type TcvaReturnFunction<T extends ConfigSchema> = {
(props?: TcvaProps<T> | undefined): string
} & {
[K in keyof T]: T[K]
}
export declare type TCVA = <T extends ConfigSchema>(
base?: ClassValue,
config?: Config<T> | undefined
) => TcvaReturnFunction<T>
export const tcva = <T extends ConfigSchema>(base: ClassValue, config: Config<T>) => {
const variantsFn: TcvaReturnFunction<T> = cva(base, config) as TcvaReturnFunction<T>
for (const variant of Object.keys(config.variants!)) {
;(variantsFn as any)[variant] = config.variants![variant]
}
return variantsFn
} |
Beta Was this translation helpful? Give feedback.
-
It's on my todo list for 1.0! Thanks for sharing your solution 🙏 |
Beta Was this translation helpful? Give feedback.
-
Also came across a need for similar functionality (getting a config or variants). I am looking forward to the update with the addition of a feature adding this functionality. Thanks more for a great tool! |
Beta Was this translation helpful? Give feedback.
-
This would be a killer feature since it would ensure all our stories are automatically in sync with the variants we define |
Beta Was this translation helpful? Give feedback.
-
I've published a fork of this package that adds support for this, as well as a couple of other things we've needed using |
Beta Was this translation helpful? Give feedback.
-
Tackling in #333! |
Beta Was this translation helpful? Give feedback.
Tackling in #333!