Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storybook): add a shared decorator for group rendering and static color settings #2420

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

castastrophe
Copy link
Collaborator

@castastrophe castastrophe commented Jan 11, 2024

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 in preview.js) have been pulled into the types folder as args and global respectively. There is also a set of shared properties available in the states.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:

  • Express assets no longer need to be imported into Template iles
  • The globals spread operator no longer needs to be passed between stories; these properties now persist in the global scope and will inherit
    • One minor exception to this seems to be Icon. We must pass the scale property down to the Icon because it throws a React Hook error when we try to fetch the value of scale in the Icon template.
  • Any linting errors that could be fixed were fixed in this PR (namely duplicate properties, unused variables, whitespace, and converting single to double quotes)
  • Removed boilerplate comments still in the files from the template

Four 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.:

customStorybookStyles: {
  padding: undefined,
}

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

  • Accordion: overrides padding settings to 0

Note: All values set by this decorator should appear as inline-styles assigned to the #root-inner element.

To-do list

  • I have read the contribution guidelines.
  • I have updated relevant storybook stories and templates.
  • If my change impacts other components, I have tested to make sure they don't break.
  • If my change impacts documentation, I have updated the documentation accordingly.
  • ✨ This pull request is ready to merge. ✨

@castastrophe
Copy link
Collaborator Author

@mdt2 Not 100% why PR #2398 closed and wouldn't re-open except that since I pulled some items out, maybe since one of them merged first it triggered a connection in git. All that to say, I re-opened this PR for review.

Copy link
Contributor

github-actions bot commented Jan 11, 2024

File metrics

Summary

Total size: 4.42 MB*
Total change (Δ): ⬆ 0.13 KB (0.00%)

Table reports on changes to a package's main file. Other changes can be found in the collapsed Details section below.

Package Size Δ
fieldgroup 1.70 KB ⬆ 0.04 KB

Details

fieldgroup

File Head Base Δ
index-base.css 1.70 KB 1.65 KB ⬆ 0.04 KB (2.48%)
index-vars.css 1.70 KB 1.65 KB ⬆ 0.04 KB (2.48%)
index.css 1.70 KB 1.65 KB ⬆ 0.04 KB (2.48%)
metadata.json 0.88 KB 0.88 KB -
* Size determined by adding together the size of the main file for all packages in the library.
* Results are not gzipped or minified.
* An ASCII character in UTF-8 is 8 bits or 1 byte.

@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 4 times, most recently from b5c1eeb to 71f0e56 Compare January 12, 2024 20:17
Copy link
Contributor

github-actions bot commented Jan 12, 2024

🚀 Deployed on https://pr-2420--spectrum-css.netlify.app

@castastrophe castastrophe added run_vrt For use on PRs looking to kick off VRT size-3 M ~18-30hrs; moderate effort or complexity, several work days needed. labels Jan 16, 2024
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 9 times, most recently from 482f50f to 3a8f133 Compare January 16, 2024 21:27
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 8 times, most recently from f6b0405 to 65a7704 Compare January 18, 2024 17:52
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 8 times, most recently from e4eafe6 to b952ad5 Compare May 8, 2024 20:59
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 19 times, most recently from aaa20f4 to 2ba1ae3 Compare May 15, 2024 17:57
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch from 2ba1ae3 to 52b8560 Compare May 20, 2024 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run_vrt For use on PRs looking to kick off VRT size-3 M ~18-30hrs; moderate effort or complexity, several work days needed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants