-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
|
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))} |
There was a problem hiding this comment.
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.
Preview environment ready: https://preview-2076--swisspost-design-system-next.netlify.app |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
What
Use
storybook-addon-pseudo-states
plugin to simulate pseudo-class likehover
,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
@media (prefers-reduced-motion: no-preference)
usage.::-moz-range-thumb
or::-webkit-slider-thumb
. This can be fixed by adding them here: https://github.com/chromaui/storybook-addon-pseudo-states/blob/07abc1bb39ee4f3377955b23860c275de12b872f/src/constants.js#L6Misc