class-recipe exports
Every export is documented with TSDoc, so your editor shows the full reference, including the types of each config and its props.
Functions
Section titled “Functions”| Export | Signature | Description | See |
|---|---|---|---|
cx |
(...inputs: ClassArray) => string |
Joins class names, skipping falsy values. Compatible with clsx. |
cx |
cva |
(config: RecipeConfig) => Recipe |
Creates a recipe that returns the class name of one element. | cva |
sva |
(config: SlotRecipeConfig) => SlotRecipe |
Creates a slot recipe that returns the class names of several slots. | sva |
createRecipe |
Same as cva |
The same function as cva, under a longer name. |
cva |
createSlotRecipe |
Same as sva |
The same function as sva, under a longer name. |
sva |
createRecipes |
(options?: RecipesOptions) => Recipes |
Returns cx and the recipe creators with a custom join or cache. |
createRecipes |
cva and sva are generic: they infer the type parameters of the config
and of the recipe from the config you pass.
Types for components
Section titled “Types for components”| Export | Type parameters | Description | See |
|---|---|---|---|
VariantsOf |
<Recipe> |
The variants a recipe or slot recipe accepts, without className or classNames. |
Typing recipes |
PropsOf |
<Recipe> |
The props a recipe or slot recipe accepts: its variants, and className or classNames. |
Typing recipes |
SlotClasses |
<Slot> |
Classes for some of a slot recipe’s slots, keyed by slot name. Types a classNames prop. |
Building components |
SlotClassNames |
<Slot> |
The class name of every slot, keyed by slot name, as a slot recipe returns it. | sva |
ClassValue |
None | A value that cx turns into class names. |
cx |
ClassArray |
None | A list of class values, which may be nested. | cx |
ClassDictionary |
None | An object whose keys are class names, each included when its value is truthy. | cx |
Types of recipes and configs
Section titled “Types of recipes and configs”| Export | Type parameters | Description | See |
|---|---|---|---|
Recipe |
<Props, Composition> |
A function that returns the class name for a selection, with variantKeys, variantOptions, and defaultVariants. |
cva |
RecipeConfig |
<Variants, DefaultedName, Composed> |
The config of a recipe made by cva. |
cva |
RecipeProps |
<Variants, DefaultedName> |
The props a recipe accepts: its variants and className. Takes the parts of a config, not a recipe. |
Typing recipes |
RecipeVariants |
None | The variants of a recipe’s config, with any names: for each variant name, the classes of each option. | Typing recipes |
CompoundVariant |
<Variants> |
A compound variant of a recipe: { variants, className }. |
cva |
CreateRecipe |
None | The type of cva and createRecipe. |
cva |
SlotRecipe |
<Slot, Props, Composition> |
A function that returns the class name of every slot for a selection, with its variants listed as a Recipe lists them. |
sva |
SlotRecipeConfig |
<Slot, Variants, DefaultedName, Composed> |
The config of a slot recipe made by sva. |
sva |
SlotRecipeProps |
<Slot, Variants, DefaultedName> |
The props a slot recipe accepts: its variants and classNames. Takes the parts of a config, not a recipe. |
Typing recipes |
SlotRecipeVariants |
None | The variants of a slot recipe’s config, with any names: for each variant name, the classes of each slot for each option. | Typing recipes |
SlotCompoundVariant |
<Slot, Variants> |
A compound variant of a slot recipe: { variants, classNames }. |
sva |
CreateSlotRecipe |
None | The type of sva and createSlotRecipe. |
sva |
RecipeOf |
<Config, Composed> |
The type of the recipe that cva returns for a config declared as const. Annotates an exported recipe. |
Exporting recipes |
SlotRecipeOf |
<Config, Composed> |
The type of the slot recipe that sva returns for a config declared as const. Annotates an exported slot recipe. |
Exporting recipes |
Recipes |
None | The functions that createRecipes returns, all sharing one join and cache setting. |
createRecipes |
RecipesOptions |
None | The options of createRecipes. |
createRecipes |
ClassJoin |
None | (...classNames: readonly string[]) => string: combines class strings into the class name, such as cx or twMerge. |
createRecipes |
In these type parameters, Variants is the type of a config’s
variants, DefaultedName the names of the variants that have a default,
Slot the names of the slots, Props the props a recipe accepts,
Composed the types of the recipes in composes, and Config the type
of a config. Composition is what a recipe passes on to the recipes that
compose it; it exists in the types only.
Types shared with the engine
Section titled “Types shared with the engine”These types come from @lynstack/recipe, which class-recipe re-exports
so that you need not install it. RecipeComposition is part of the type
of every recipe, so a module that emits declarations names it through
class-recipe. ComposedVariants, ComposableKindRecipe, and
ComposableKindSlotRecipe type a function whose configs compose recipes
(see
When the configs compose recipes).
| Export | Type parameters | Description |
|---|---|---|
VariantSelection |
<Variants, DefaultedName> |
The variants a selection names, with the optional ones marked optional. |
VariantOption |
<Options> |
The values accepted for one variant: its option names, and numbers or booleans for them. |
DefaultVariants |
<Variants, DefaultedName> |
The option each defaulted variant uses when a selection leaves it out. |
CompoundCondition |
<Variants> |
The condition of a compound variant: the options it matches for each variant it names. |
RecipeFunction |
<Props, Result> |
A function that takes a selection, whose argument is optional when every variant is. |
RecipeComposition |
<Variants, DefaultedName, Value, Slots> |
What a recipe passes on to the recipes that compose it, in its type only. |
ComposedSlot |
<Composed, Slot> |
The slots of a slot recipe that composes others: theirs, then its own. |
ComposedVariants |
<Composed, Variants> |
The variants of a config together with those of the recipes it composes. |
ComposableKindRecipe |
<Value> |
Any recipe that composes accepts; use ComposableKindRecipe<string>. |
ComposableKindSlotRecipe |
<Value> |
Any slot recipe that a slot recipe’s composes accepts; use ComposableKindSlotRecipe<string>. |
The recipes of class-recipe are built on
@lynstack/recipe. Use it to create recipes for values
other than class names, such as style objects.