-
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 postcss plugin #2092
Conversation
# Conflicts: # packages/documentation/src/stories/components/choice-card/choice-card.ts
|
|
||
module.exports = () => { | ||
return { | ||
plugins: [postcssPseudoClasses], |
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 wasn't able to change the Vite config to use this plugin like vitejs/vite#8693
Preview environment ready: https://preview-2092--swisspost-design-system-next.netlify.app |
/** | ||
* PostCSS plugin to automatically add in companion classes where pseudo-selectors are used. | ||
* This allows you to add the class name to force the styling of a pseudo-selector, which can be really helpful for testing or being able to concretely reach all style states. | ||
* @param {array} [options.blacklist] - Define elements to be ignored | ||
* @param {array} [options.restrictTo] - Create classes for a restricted list of selectors. e.g. [':nth-child', 'hover'] | ||
* @param {boolean} [options.allCombinations=false] - When enabled output with all combinations of pseudo styles/pseudo classes. | ||
* @param {boolean} [options.preserveBeforeAfter=true] - When enabled output does not generate pseudo classes for `:before` and `:after`. | ||
* @param {string} [options.prefix='\\:'] - Define the pseudo-class class prefix. Default: ':' so the class name will be ':hover' for example. | ||
* @author giuseppeg <https://github.com/giuseppeg> | ||
* @author philippone <https://github.com/philippone> | ||
* @author michaeldfoley <https://github.com/michaeldfoley> | ||
* @see {@link https://github.com/giuseppeg/postcss-pseudo-classes} | ||
* @returns {{postcssPlugin: string, Once(*): void}} | ||
*/ |
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.
Ideally, we should publish it as new package perhaps?
<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> | ||
`, | ||
)} |
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.
After #2133, we should add pseudo-class |
# Conflicts: # packages/documentation/src/stories/components/checkbox/checkbox.stories.ts # packages/documentation/src/stories/components/radio/radio.snapshot.stories.ts # packages/documentation/src/stories/components/radio/radio.stories.ts # packages/documentation/src/stories/components/table/table.snapshot.stories.ts
# Conflicts: # packages/documentation/src/stories/components/badge/badge.stories.ts # packages/documentation/src/stories/components/card/card.snapshot.stories.ts # packages/documentation/src/stories/components/card/card.stories.ts # packages/documentation/src/stories/components/select/select.stories.ts # packages/documentation/src/stories/components/switch/switch.stories.ts # packages/documentation/src/stories/components/toast/toast.stories.ts
# Conflicts: # packages/documentation/src/stories/components/select/select.stories.ts
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
Button-group snapshots have been added. @alizedebray you can review |
What
Use
postcss-pseudo-classes
plugin to simulate pseudo-class likehover
,focus
, etc. This plugin rewrite the associated stylesheet and tries to replace the defined pseudo-class with a class using the following naming template:${pseudoClassName}
.Limitations
Misc
Snapshots that haven't been changed because they don't have a snapshot file currently: