cva
cva builds a component function. Call it with a config object describing base classes, variants, compound variants, and default variants. It returns a function that accepts variant props and an optional class or className, and returns a resolved class string.
Signature
Parameters
Base classes that are applied to every instance of the component, regardless of which variants are active. Accepts any value supported by
clsx: a string, an array of strings, an object with boolean values, null, undefined, or boolean.A map of variant groups. Each key is a variant name; its value is a map of variant option names to class values.String variant keys that spell
"true" or "false" are automatically widened to the boolean type in the returned function’s props.An array of rules that apply additional classes when a specific combination of variants is active. Each entry is a partial variant condition object plus a
class or className property.The condition matches when all specified variant keys equal the given values. A value can also be an array, in which case the condition matches when the active variant is any of the listed values.Default values for variant keys. Applied when the caller does not pass a value for a given variant.
Return value
cva returns a component function. The component function accepts an optional props object:
string of concatenated class names.
Complete example
components/button.ts
The
cva package uses a single config-object signature. If you are migrating from the legacy class-variance-authority package, which used cva(base, options), see the migration guide.