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(documentation): Add pseudo-class to snapshots with storybook-addon-pseudo-states plugin #2076

Closed
wants to merge 2 commits into from

Conversation

imagoiq
Copy link
Contributor

@imagoiq imagoiq commented Oct 16, 2023

What

Use storybook-addon-pseudo-states plugin to simulate pseudo-class like hover, focus, etc. This plugin rewrite the associated stylesheet and try to replace the defined pseudo-class with a class using the following naming template .pseudo-${pseudoClassName}.

Limitation

Misc

  • Topic-teaser uses default browser focus-rules, so we can't simulate, and it's invisible in snapshot
  • Components without snapshot: textarea, tooltip, button-group

@imagoiq imagoiq self-assigned this Oct 16, 2023
@changeset-bot
Copy link

changeset-bot bot commented Oct 16, 2023

⚠️ No Changeset found

Latest commit: ce6190f

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

Comment on lines -13 to +55
const combinations = [
...COMBINATIONS,
{
label: `Label - no Placeholder`,
placeholder: null,
},
{
label: `Label - with Value`,
value: 'Lorem Ipsum',
},
];
return html`
<div class="d-flex flex-wrap align-items-start gap-regular">
${['bg-white', 'bg-dark'].map(
bg => html`
<div class="${bg} d-flex gap-3 flex-column p-3">
<h3>Sizes</h3>
${getCombinations('size', context.argTypes.size.options, combinations)
.filter(
(args: Args) =>
!args.value ||
(args.value &&
(context.args.type === 'text' || context.args.type === 'password')),
)
.map(
(args: Args) =>
html`
<div>
${args.title !== undefined && args.title
? html`
<h4>
${Object.entries(context.argTypes.size.control.labels)
.filter(([key, value]) => key === args.size)
.map(s => s[1])}
</h4>
`
: ''}
<div>${meta.render?.({ ...context.args, ...args }, context)}</div>
</div>
`,
)}
${context.argTypes.size.options.map((size: string) => {
const variants = bombArgs({
combinations: COMBINATIONS,
size: [size],
pseudoClass: ['null', 'focus'],
})
.map(extractCombinationsArgs)
.filter(
(args: Args) =>
!args.value ||
(args.value &&
(context.args.type === 'text' || context.args.type === 'password')),
)
.map(args => renderVariant(args, context));

return html`
<section>
<h4>${context.argTypes.size.control.labels[size]}</h4>
<div class="d-flex gap-3 flex-column">${variants}</div>
</section>
`;
})}
<h3>Floating Label</h3>
${getCombinations('floatingLabel', [true], combinations)
${bombArgs({
combinations: COMBINATIONS,
floatingLabel: [true],
pseudoClass: ['null', 'focus'],
})
.map(extractCombinationsArgs)
.filter(
(args: Args) =>
!args.value ||
(args.value &&
(context.args.type === 'text' || context.args.type === 'password')),
)
.map(
(args: Args) =>
html`
<div>${meta.render?.({ ...context.args, ...args }, context)}</div>
`,
)}
.map(args => renderVariant(args, context))}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I refactored this part to use bombArgs instead of a custom function. So #2001 will be easier.

@imagoiq imagoiq linked an issue Oct 16, 2023 that may be closed by this pull request
@swisspost-bot
Copy link
Contributor

swisspost-bot commented Oct 16, 2023

Preview environment ready: https://preview-2076--swisspost-design-system-next.netlify.app

@sonarcloud
Copy link

sonarcloud bot commented Oct 16, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@imagoiq imagoiq added the on hold Wait for something to be done, before continue working on this Issue label Oct 16, 2023
@imagoiq imagoiq marked this pull request as draft October 16, 2023 12:04
@imagoiq imagoiq removed the request for review from gfellerph October 16, 2023 12:04
@imagoiq imagoiq changed the title feat(documentation): Add pseudo-class to snapshots feat(documentation): Add pseudo-class to snapshots with storybook-addon-pseudo-states plugin Oct 17, 2023
@imagoiq imagoiq closed this Oct 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold Wait for something to be done, before continue working on this Issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stories: Check out pseudo states plugin
2 participants