-
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.
Answered by
joe-bell
Dec 13, 2023
Replies: 2 comments 13 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.
1 reply
-
It's on my todo list for 1.0! Thanks for sharing your solution 🙏 |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I’m interested, I’m just personally at capacity right now — introducing new features like this requires a lot of time to think and strategise
As much as I love this project and want to push it forwards, is not my number one priority 🙏🏼