API Reference
This content is for Beta. Switch to the latest version for up-to-date documentation.
Builds a cva component
import { cva } from "cva";
const component = cva(options);Parameters
Section titled “Parameters”optionsbase: the base class name (string,string[]or otherclsxvalue)variants: your variants schema. A variant name prefixed with_is internal: hidden from the component’s props type and fromgetSchema, but still settable viadefaultVariantsand matchable incompoundVariantscompoundVariants: variants based on a combination of previously defined variantsdefaultVariants: set default values for previously defined variantscomposes: shallow merge one or more othercvacomponents into this one, as a single component or an array (see Composing Components)
Returns
Section titled “Returns”A cva component function
Concatenates class names (an alias of clsx)
import { cx } from "cva";
const className = cx(classes);Parameters
Section titled “Parameters”classes: array of classes to be concatenated (seeclsxusage)
Returns
Section titled “Returns”string
getSchema
Section titled “getSchema”Extracts a plain-object schema (variant names, possible values, and default values) from a cva component. Use it to generate Storybook controls, documentation, or any other UI that reads a component’s variants without re-declaring them. See Utilities for use cases.
import { cva, getSchema } from "cva";
const button = cva({ base: "button", variants: { intent: { primary: "button--primary", secondary: "button--secondary", }, disabled: { true: "button--disabled", false: "button--enabled", }, }, defaultVariants: { intent: "primary", disabled: false, },});
getSchema(button);// => {// intent: { values: ["primary", "secondary"], defaultValue: "primary" },// disabled: { values: [true, false], defaultValue: false },// }getSchema omits a variant that has no values (e.g. variants: { empty: {} }) and any internal (_-prefixed) variant.
Parameters
Section titled “Parameters”component: a component created by cva (including components composed via composes)
Returns
Section titled “Returns”An object keyed by variant name. Each entry has:
values: a readonly array of the variant’s possible valuesdefaultValue: present only if the variant has adefaultVariantsentry
defineConfig
Section titled “defineConfig”Generate cva and cx functions based on your preferred configuration.
Store in a cva.config.ts file, and import across your project.
import { defineConfig } from "cva";
export const { cva, cx } = defineConfig(options);optionshooksonComplete: returns a concatenated class string of all classes passed tocxorcva.
defineConfig also returns a deprecated compose function for migrating from class-variance-authority; use the composes property on cva instead. See What’s new?.