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 #2398

Closed
wants to merge 0 commits into from

Conversation

castastrophe
Copy link
Collaborator

@castastrophe castastrophe commented Jan 2, 2024

Description

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.

The default storybook styles applied by the decorator are:

const customStorybookStyles = {
  /** @todo: do we really want flex as our default display type? does this make development harder b/c we have to consider how it impacts a component or is it helpful so we can stack components in a view easily? */
  display: "flex",
  // automatically set the background color for static color settings
  backgroundColor: staticColor === "white" ? "rgb(15, 121, 125)" : staticColor === "black" ? "rgb(181, 209, 211)" : undefined,
  // Gap is only supported for flex and grid so we don't need to set it for other display types
  gap: customStyles.gap ?? (!customStyles.display || customStyles.display && ["flex", "grid"].some(d => customStyles.display.endsWith(d))) ? "10px" : undefined,
  padding: customStyles.padding ?? (customStyles.display && ["flex", "grid", "contents"].every(d => !customStyles.display.endsWith(d))) ? "10px 0" : undefined,
  ...customStyles,
};

Any settings added by the story will override these values. You can unset a value completely using undefined, i.e.:

customStorybookStyles: {
  display: undefined,
}

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
  • Action bar: overrides display to use "contents" (instead of flex)
  • Alert banner: sets flex-direction to "column" (instead of default value of row)
  • Checkbox:
    • flex-direction: column
    • gap is unset (should not appear in stylesheet)
    • padding: 1rem
  • Opacity checkerboard: inline & block size is 100px
  • Radio: flex-direction is "column" and align-items is "flex-start" (instead of default of stretch)
  • Stepper: flex-direction is "column" and align-items is "flex-start"
  • All other components should default to:
    • display: flex
    • background-color: transparent (unless static-white or static-black settings are active)
    • gap: 1rem

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.
  • I have tested these changes in Windows High Contrast mode.
  • 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 castastrophe force-pushed the feat-storybook-decorator-alignment branch from 6887118 to e536999 Compare January 2, 2024 18:07
Copy link
Contributor

github-actions bot commented Jan 2, 2024

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

Copy link
Contributor

github-actions bot commented Jan 2, 2024

File metrics

Summary

Total size: 3.92 MB*

🎉 No changes detected in any packages

* 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 from e536999 to 9b051ff Compare January 2, 2024 18:26
@castastrophe castastrophe changed the title feat(storybook): add a shared decorator for focus-state and static color settings feat(storybook): add a shared decorator for group rendering and static color settings Jan 2, 2024
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 2 times, most recently from 508fb2b to 2350e5c Compare January 2, 2024 20:06
@castastrophe castastrophe added the run_vrt For use on PRs looking to kick off VRT label Jan 2, 2024
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 7 times, most recently from 400e282 to 7b32a94 Compare January 4, 2024 00:54
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 6 times, most recently from 246513e to d397535 Compare January 4, 2024 16:08
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 3 times, most recently from 5eea5f5 to 8a4cb1b Compare January 4, 2024 18:02
tasks/mod-extractor.js Outdated Show resolved Hide resolved
@castastrophe castastrophe self-assigned this Jan 5, 2024
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 15 times, most recently from bdecdc6 to aeb087b Compare January 5, 2024 21:07
@castastrophe castastrophe force-pushed the feat-storybook-decorator-alignment branch 4 times, most recently from fa503fa to 0887029 Compare January 8, 2024 16:41
Copy link
Collaborator

@mdt2 mdt2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Continuing review on this one! Here's a few more comments. Also, once I've clicked on a static color story, I'm seeing that background color persist after I click away to a different, non-static-color story. 🤔

components/coachmark/stories/coachmark.stories.js Outdated Show resolved Hide resolved
</div>
<div class="spectrum-CoachMark-content">
Pixel brushes use pixels to create brush strokes, just like in other design and drawing tools. Start drawing, and zoom in to see the pixels in each stroke.
</div>
<div class="${rootClass}-footer">
${hasPagination ? html`<div class="spectrum-CoachMark-step"><bdo dir="ltr">2 of 8</bdo></div>` : ''}
${when(hasPagination, () => html`<div class="spectrum-CoachMark-step"><bdo dir="ltr">2 of 8</bdo></div>`)}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dig this refactoring with when that you're doing throughout this PR 👍

components/menu/stories/menu.stories.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@mdt2 mdt2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I've officially looked at all the code changes 🎉 Between my reviews, it looks like there's a few things to be addressed, so let me know when you need a re-review from me.

@@ -4,9 +4,9 @@ import { ifDefined } from "lit/directives/if-defined.js";
import { styleMap } from "lit/directives/style-map.js";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the visual differences I was seeing in ActionMenu are probably due to these changes in popover. This has been a notoriously tricky one. Recently I did some work to address an issue with Storybook not having the correct offset which seems to be reverted with this refactor (though I agree a refactor is a good idea for this component). And we had so much trouble with nested popovers that we chose to show them statically. Hopefully you can find a way to use this refactored code and still have the offset reflect the spec.

popover-difference

},
trigger: (passthroughs) => ActionButton({
label: "Hop on pop(over) 2",
label: "Grand-pop(over)",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha excellent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A request to add a feature to a component ready-for-review run_vrt For use on PRs looking to kick off VRT size-3 M ~18-30hrs; moderate effort or complexity, several work days needed. storybook
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants