feat(storybook): add a shared decorator for group rendering and static color settings #2420
+2,675
−3,216
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.
Description
As we expand the decorators available for use, a more organized decorators folder becomes essential to maintain and update decorators independently of each other. I've moved all decorators into their own distinct files and imported them all into a single entry point:
decorators/index.js
.Additionally, the properties available to all components (argTypes defined in
preview.js
) and global controls (globalTypes inpreview.js
) have been pulled into thetypes
folder as args and global respectively. There is also a set of shared properties available in thestates.js
file to be imported into a component's story so that they don't have to continue to be redefined.All storybook assets have been updated to reflect a few global changes:
globals
spread operator no longer needs to be passed between stories; these properties now persist in the global scope and will inheritFour new decorators have been added:
Preview styles decorator
Many storybook stories require adding layout and/or padding in order to view variants together or snapshot focus states. The goal of this PR is to unify this effort in a shared decorator that can be customized using a new
customStorybookStyles
object that is leveraged in a story's args settings.Any settings added by the story will override these values. You can unset a value completely using
undefined
, i.e.:Sizing decorator
This decorator is based on the preview sizing wrapper decorator that was unused. It displays all sizes of a provided story with labels but only in the testing preview state. It automatically pulls the size properties from a component's argTypes.
Variants decorator
This decorator renders (in testing preview mode only) any argType listed with a category of "Variant".
States decorator
This decorator renders (in testing preview mode only) any argType listed with a category of "State".
How and where has this been tested?
Please tag yourself on the tests you've marked complete to confirm the tests have been run by someone other than the author.
Validation steps
Note: All values set by this decorator should appear as inline-styles assigned to the #root-inner element.
To-do list