Skip to main content

API reference

sxv(config)​

Creates a typed recipe. The call is transformed at build time by the Babel plugin into static StyleX styles.

Configuration​

PropertyRequiredDescription
baseNoStyle applied to every recipe call.
variantsNoNamed groups and their possible values.
defaultVariantsNoValues used when a prop is omitted.
compoundVariantsNoExtra styles activated by matching multiple values.
slotsNoNamed style maps for multi-element components.
compoundSlotsNoConditional styles applied to one or more slots.

All style objects must be static StyleX-compatible objects. See limitations for unsupported dynamic patterns.

Call-site overrides​

Every recipe and slot accepts className and style in addition to its variant props. Generated StyleX props are merged with these values at the call site:

button({
tone: "primary",
className: "custom-button",
style: { boxShadow: "0 0 0 2px blue" },
});

For slots, pass overrides to the individual slot function:

const cardStyles = card({ tone: "accent" });
cardStyles.title({ className: "custom-title" });

See overriding, extend, and slots for complete examples.

VariantProps<typeof recipe>​

Extracts the variant props accepted by a recipe for use in component APIs:

type ButtonProps = VariantProps<typeof button> & {
children: React.ReactNode;
};

The extracted type includes className and style, which are merged with the StyleX result when supplied.

Return value​

Calling a recipe returns the object produced by stylex.props. It can be spread directly on an element:

<button {...button({ tone: "primary" })}>Save</button>