An extended version of cva, making it more type-safe, and adding a few features and which were missing from the original
const button = cva({
variants: {
intent: {
primary: "bg-blue-500",
secondary: "bg-white",
},
disabled: {
true: "opacity-50",
false: "opacity-100",
},
},
});
button.variants; // { intent: ["primary", "secondary"], disabled: [true, false] }
typeof button.variants;
// ^?
// {
// "intent": ReadonlyArray<'primary' | 'secondary'>,
// "disabled": readonly boolean[]
// }
//const button = cva({
variants: {
intent: {
primary: "bg-blue-500",
secondary: "bg-white",
},
},
});
button(); // Error: Missing required variant: intent
const optionalIntent = cva({
variants: {
intent: {
primary: "bg-blue-500",
secondary: "bg-white",
},
},
defaultVariants: {
intent: "primary",
},
});
optionalIntent(); // No errorconst button = cva({
variants: {
intent: {
primary: "bg-blue-500",
secondary: "bg-white",
},
$private: {
true: "private",
},
},
});
button({ $private: true }); // Error: Variant $private is not exposed
button.variants; // { intent: ["primary", "secondary"] }
typeof button.variants;
// ^?
// {
// "intent": ReadonlyArray<'primary' | 'secondary'>
// }
//Class Variance Authority - Extended
Visit cva.style to get started.
