Compound Variants
You can extend your StyleSheets
even more by using compound variants
.
Compound variants are a way of applying additional styles when certain conditions are met.
This approach simplifies the management of complex styling by reducing redundancy and increasing flexibility of your StyleSheets
.
Basic usage
Let’s say you created a base Typography
component with following variants:
What if you’ve received a new requirement where the text should be underlined when isBold
is true
and color
is link
?
This task could be challenging while using features like dynamic functions as you would need to use ifs in your StyleSheet
.
Usage with Compound variants
With compound variants it can be achieved in a more concise way:
Styles from the compoundVariants
array will take precedence over the styles defined in the variants
object.
You can define multiple compoundVariants
in the array to handle different combinations of style properties. This allows for more granular control and customization of your component’s appearance.