Skip to content

Experimenting with single AllVariants story for all pseudo states #2511

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

Closed
wants to merge 58 commits into from

Conversation

beaesguerra
Copy link
Member

@beaesguerra beaesguerra commented Mar 21, 2025

Summary:

Explore how we could combine different variants, states, rtl, and zoom altogether.

Context: #2508 (comment)

Looking for feedback around:

  • Do we want to combine all the pseudo states into one story?
  • Do we want to include rtl for all the pseudo states?
  • What about the approach for zoom?
  • Is it managable to review visual changes in Chromatic with these larger stories?
  • Anything else you can think of!

Issue: WB-XXXX

Test plan:

…er. Since it's put on the li, it won't conflict with the focus outline box shadow later on
@beaesguerra beaesguerra self-assigned this Mar 21, 2025
Copy link

changeset-bot bot commented Mar 21, 2025

⚠️ No Changeset found

Latest commit: 6932345

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

… is because we swap out the rows since the children props for NavTabItem changes"

This reverts commit 9e0f300.
Copy link
Contributor

github-actions bot commented Mar 21, 2025

Size Change: 0 B

Total Size: 100 kB

ℹ️ View Unchanged
Filename Size
packages/wonder-blocks-accordion/dist/es/index.js 3.54 kB
packages/wonder-blocks-banner/dist/es/index.js 1.55 kB
packages/wonder-blocks-birthday-picker/dist/es/index.js 1.88 kB
packages/wonder-blocks-breadcrumbs/dist/es/index.js 886 B
packages/wonder-blocks-button/dist/es/index.js 4.34 kB
packages/wonder-blocks-cell/dist/es/index.js 2.35 kB
packages/wonder-blocks-clickable/dist/es/index.js 3.07 kB
packages/wonder-blocks-core/dist/es/index.js 2.85 kB
packages/wonder-blocks-data/dist/es/index.js 6.25 kB
packages/wonder-blocks-dropdown/dist/es/index.js 19.5 kB
packages/wonder-blocks-form/dist/es/index.js 6.04 kB
packages/wonder-blocks-grid/dist/es/index.js 1.36 kB
packages/wonder-blocks-icon-button/dist/es/index.js 3.15 kB
packages/wonder-blocks-icon/dist/es/index.js 873 B
packages/wonder-blocks-labeled-field/dist/es/index.js 1.22 kB
packages/wonder-blocks-layout/dist/es/index.js 1.82 kB
packages/wonder-blocks-link/dist/es/index.js 2.04 kB
packages/wonder-blocks-modal/dist/es/index.js 5.5 kB
packages/wonder-blocks-pill/dist/es/index.js 1.49 kB
packages/wonder-blocks-popover/dist/es/index.js 4.92 kB
packages/wonder-blocks-progress-spinner/dist/es/index.js 1.52 kB
packages/wonder-blocks-search-field/dist/es/index.js 1.32 kB
packages/wonder-blocks-switch/dist/es/index.js 2.02 kB
packages/wonder-blocks-tabs/dist/es/index.js 1.24 kB
packages/wonder-blocks-testing-core/dist/es/index.js 3.91 kB
packages/wonder-blocks-testing/dist/es/index.js 1.07 kB
packages/wonder-blocks-theming/dist/es/index.js 679 B
packages/wonder-blocks-timing/dist/es/index.js 1.79 kB
packages/wonder-blocks-tokens/dist/es/index.js 2.7 kB
packages/wonder-blocks-toolbar/dist/es/index.js 923 B
packages/wonder-blocks-tooltip/dist/es/index.js 7.01 kB
packages/wonder-blocks-typography/dist/es/index.js 1.23 kB

compressed-size-action

Copy link
Contributor

github-actions bot commented Mar 21, 2025

A new build was pushed to Chromatic! 🚀

https://5e1bf4b385e3fb0020b7073c-gcfobwydcu.chromatic.com/

Chromatic results:

Metric Total
Captured snapshots 400
Tests with visual changes 6
Total stories 588
Inherited (not captured) snapshots [TurboSnap] 0
Tests on the build 400

/**
* The states to render.
*/
states?: State[];
Copy link
Member Author

Choose a reason for hiding this comment

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

Making it optional to configure the states to support in case there are other states to configure outside of base, hover, focus, press, and hover+focus

* The children as a function that receives the state props used to render
* each variant of the component.
*/
children: (props: any, name: string, isRtl?: boolean) => React.ReactNode;
Copy link
Member Author

Choose a reason for hiding this comment

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

Same as children prop from AllVariants, except we include isRtl to we could choose to toggle labels for the children

@@ -93,3 +98,20 @@ const styles = StyleSheet.create({
gap: spacing.medium_16,
},
});

export const StickerSheet: Story = {
Copy link
Member Author

Choose a reason for hiding this comment

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

This shows a straightforward example of using AllVariantsStates and changing the label based on the isRtl arg

{
name: "Default",
props: {
children: (label: string) => <Link href="#link">{label}</Link>,
Copy link
Member Author

Choose a reason for hiding this comment

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

Refactored the rows so that the label for the link is flexible for the cells. We make children a function instead so we can pass in the label based on if it's in rtl mode

Comment on lines +185 to +186
// showRtl=false because we have a separate story for rtl with rtlRows
<AllVariantsStates rows={rows} columns={columns} showRtl={false}>
Copy link
Member Author

Choose a reason for hiding this comment

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

NavigationTabs is a bit different in that the variety in the examples is based on the props of the children components, rather than the props of NavigationTabs. It also renders multiple NavigationTabItems as children.

To simplify things, we have rows and rtlRows, which has rtl labels instead. Instead of letting AllVariantsStates render the rtl cells, we create a separate story with the rtlRows instead. We can also use the global direction to configure it to be in rtl mode.

Let me know if you have any ideas on how to address this! Or if you have thoughts on this in general.

@beaesguerra beaesguerra changed the base branch from nav-tabs-style to feature/tabs March 25, 2025 15:19
An error occurred while trying to automatically change base from nav-tabs-style to feature/tabs March 25, 2025 15:19
Base automatically changed from feature/tabs to main March 25, 2025 18:08
Copy link
Member

@jandrade jandrade left a comment

Choose a reason for hiding this comment

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

This is a super interesting experiment! thanks for looking into this 🫶

Do we want to combine all the pseudo states into one story?
Is it managable to review visual changes in Chromatic with these larger stories?

I'm seeing that in some cases there's a lot of information in the snapshot, so I'm not sure if that would make it harder to review and/or find small changes. How do you feel about that?

Do we want to include rtl for all the pseudo states?

IMO yes! we should include rtl as a first-class citizen in our visual regression tests.

What about the approach for zoom?

Where you able to fix the viewport issue?

type State = {name: string; id: string};

export const commonStates = {
base: {name: "Base", id: "base"},
Copy link
Member

Choose a reason for hiding this comment

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

thought: How do you feel about changing this to Rest to be consistent on how Design uses these states in Figma? Would love to hear your thoughts on why base could apply better here (if that's the case).

Copy link
Member Author

Choose a reason for hiding this comment

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

Rest makes sense! Will update :)

Comment on lines +39 to +49
export const defaultPseudoStates = {
hover: [
`#${commonStates.hover.id} *`,
`#${commonStates.hoverAndFocus.id} *`,
],
focusVisible: [
`#${commonStates.focus.id} *`,
`#${commonStates.hoverAndFocus.id} *`,
],
active: [`#${commonStates.press.id} *`],
};
Copy link
Member

Choose a reason for hiding this comment

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

praise: Ohh this is neat! Very smart solution :). this is using this feature right? https://github.com/chromaui/storybook-addon-pseudo-states?tab=readme-ov-file#targeting-specific-elements

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes! Then we can target specific sections with the selector styles 😄

@beaesguerra
Copy link
Member Author

@jandrade

I'm seeing that in some cases there's a lot of information in the snapshot, so I'm not sure if that would make it harder to review and/or find small changes. How do you feel about that?

I find when there are many small changes in the same snapshot, it takes longer for me to review all the details (that might just be because we're making more changes right now to support polaris!). With that said, this set up with all the states doesn't account for different themes yet! Would we want it to? Or are we still exploring using modes?

Thinking about themes, it might be easier to see all the states for one theme in one snapshot. So each component would have a stickersheet for each theme.

Let me know what you think! If we want to combine the states into one story, I'll clean up this branch and open a separate PR for it!

What about the approach for zoom?

Where you able to fix the viewport issue?

I reached out to Chromatic and they suggested adding a delay. That didn't fix things so they escalated it to their engineers and will follow up!

jandrade added a commit that referenced this pull request Apr 11, 2025
…es in the same snapshot (#2550)

## Summary:

Builds based on the experiment introduced in #2511 to add a `StateSheet` component to
Storybook. This component will be used to test snapshots similar to the Figma
Handshake file.

The StateSheet component will allow us to create a visual representation of the
different states of our components, making it easier to test them while taking
less snapshots.

This change will also allow us to use this in combination of Chromatic modes in
the near future to test combinations like `responsive`, `theming`, `rtl`, etc.

Issue: "none"

## Test plan:

Verify that the `IconButton - All variants` chromatic snapshot looks similar to
the Handshake file.

<img width="1354" alt="Screenshot 2025-04-11 at 12 39 37 PM" src="https://github.com/user-attachments/assets/74997401-34d3-4f4e-92e3-d0d492f6500b" />

Author: jandrade

Reviewers: beaesguerra, jandrade

Required Reviewers:

Approved By: beaesguerra

Checks: ✅ 10 checks were successful, ⌛ 1 check is pending, ⏭️  2 checks have been skipped

Pull Request URL: #2550
@beaesguerra
Copy link
Member Author

Closing since this has been iterated on in #2550 !

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (dcd7532) to head (e79d9ce).
Report is 57 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@     Coverage Diff      @@
##   main   #2511   +/-   ##
============================
============================

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update dcd7532...e79d9ce. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants