Variants
View Source
Describe how component trees are styled throughout different states.
This component is responsible for turning variants on/off. Any prop passed to this component is considered the key for a variant and will be activated when true
.
Box and Text primitive components, as well as any layout components, may pass a variants
prop that describes styles at various points in time. When the respective key is activated in VariantProvider
, the styles will be applied or overridden in the order they are written.
focus
, hover
, and active
are reserved variant keys that will generate the respective pseudo state CSS. These may also be activated programatically by using VariantProvider
.
Variants work similar to CSS in that they will cascade down and any child can define the styling that will be applied when the respective variant is activated in the closest parent VariantProvider
.
In a simple example we can model compact and hover states for a UI screen:
Normal
Heading
Model behavior throughout a tree of components.
I'm pink on hover.
Compact
Heading
Model behavior throughout a tree of components.
I'm pink on hover.
Compact & Hover
Heading
Model behavior throughout a tree of components.
I'm pink on hover.