Support defining variants as functions for easier extending #2309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds support for configuring variants as functions to make it easier to add variants without respecifying the entire list.
Variant functions are invoked with an object that can be destructured into three helper functions:
variants
, which can be called likevariants('padding')
to get the list of variants for that keybefore
, which can be called likebefore(['hover'])
to add some variants before the existing variants,before(['hover'], 'focus')
to add some variants before a specific existing variant, orbefore(['hover'], 'focus', ['responsive', 'focus'])
to add variants before a specific variant to an explicit list, instead of automatically adding it to the list matching the current keyafter
, which can be called likeafter(['hover'])
to add some variants after the existing variants,after(['hover'], 'focus')
to add some variants after a specific existing variant, orafter(['hover'], 'focus', ['responsive', 'focus'])
to add variants after a specific variant to an explicit list, instead of automatically adding it to the list matching the current keywithout
, which can be called likewithout(['hover'])
to disable a variant that's enabled by default, orwithout(['hover'], ['responsive', 'hover', 'focus])
to remove that variant from a list that is passed in rather than assuming the current contextIn practice it looks like this:
Using the last parameter of each helper lets you compose these together, to do stuff like: