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 postcss plugin #2092

Closed
wants to merge 19 commits into from

Conversation

imagoiq
Copy link
Contributor

@imagoiq imagoiq commented Oct 18, 2023

What

Use postcss-pseudo-classes plugin to simulate pseudo-class like hover, 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:

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

changeset-bot bot commented Oct 18, 2023

⚠️ No Changeset found

Latest commit: 200addf

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


module.exports = () => {
return {
plugins: [postcssPseudoClasses],
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 wasn't able to change the Vite config to use this plugin like vitejs/vite#8693

packages/documentation/postcss-pseudo-classes.js Dismissed Show dismissed Hide dismissed
packages/documentation/postcss-pseudo-classes.js Dismissed Show dismissed Hide dismissed
packages/documentation/postcss-pseudo-classes.js Dismissed Show dismissed Hide dismissed
packages/documentation/postcss-pseudo-classes.js Dismissed Show dismissed Hide dismissed
@swisspost-bot
Copy link
Contributor

swisspost-bot commented Oct 18, 2023

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

Comment on lines +1 to +14
/**
* 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}}
*/
Copy link
Contributor Author

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?

Comment on lines 19 to -53
<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>
`,
)}
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 marked this pull request as ready for review October 18, 2023 15:48
@imagoiq
Copy link
Contributor Author

imagoiq commented Oct 25, 2023

After #2133, we should add pseudo-class

@imagoiq imagoiq added the on hold Wait for something to be done, before continue working on this Issue label Oct 25, 2023
# 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
Copy link

sonarcloud bot commented Nov 6, 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 2 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@imagoiq imagoiq removed the on hold Wait for something to be done, before continue working on this Issue label Nov 6, 2023
@imagoiq
Copy link
Contributor Author

imagoiq commented Nov 6, 2023

Button-group snapshots have been added. @alizedebray you can review

@imagoiq imagoiq closed this Nov 9, 2023
@imagoiq imagoiq deleted the feat/1051-snapshot-pseudo-class-v2 branch February 15, 2024 12:56
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.

Stories: Check out pseudo states plugin
2 participants