-
Notifications
You must be signed in to change notification settings - Fork 4.6k
AlignmentMatrixControl: migrate Emotion to style.module #73714
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
Conversation
| className={ clsx( styles.cell, props.className ) } | ||
| role="gridcell" | ||
| /> | ||
| } |
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.
The migration has three steps:
- remove the
style.tsfile that defines several components as styled elements (divorspan) - redefine the styles as regular CSS in the
style.module.cssfile - replace usages of the styled elements with plain
divs andspans with a class name imported from the CSS module
| id={ baseId } | ||
| role="grid" | ||
| size={ width } | ||
| style={ { width: `${ width }px` } } |
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.
Sometimes style interpolation forces us to declare a style attribute.
| aspect-ratio: 1; | ||
|
|
||
| border: 1px solid transparent; | ||
| border-radius: 4px; /* CONFIG.radiusMedium */ |
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.
This should be replaced with a design token variable or something similar.
|
|
||
| /* Hover styles for non-active items */ | ||
| .cell:not([data-active-item]):hover .point { | ||
| color: var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9)); |
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.
This CSS variable is the literal value of the COLORS.theme.accent constant. Stylelint issues a warning about it:
To support component theming and ensure proper fallbacks, use Sass variables from packages/components/src/utils/theme-variables.scss instead.
Using the SASS variables is a bad advice here, but how does the good advice look like? To start using the design system token variables in the component?
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.
Hmm. I think we can only start using DS tokens if the @wordpress/components stylesheet ships with fallbacks for every token used.
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.
A simpler way would be to convert these Sass vars to CSS variables and stick them in the @wordpress/components stylesheet so they can be used without Sass. This would be preferable if we know we're not going to attempt full theming support for legacy components… (undecided?)
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.
Yet another way that would be a quick unblock for the transition period is to support Sass in CSS modules, for @wordpress/components at least.
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.
quick unblock for the transition period is to support Sass in CSS modules
Turns out that *.module.scss works almost out of the box, with just one-line change in the Storybook config. So this PR now uses a style.module.scss with variables like $components-color-accent.
I believe the PR is ready to ship now 🙂
| "types": [ | ||
| "gutenberg-env", | ||
| "gutenberg-test-env", | ||
| "css-modules", |
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.
In order to have types for the style.module.css everywhere, I moved the declare module *.module.css TypeScript definition to the global typings folder. This makes it available for the entire Gutenberg repo.
|
|
||
| export const GridContainer = styled.div< { | ||
| size?: AlignmentMatrixControlProps[ 'width' ]; | ||
| disablePointerEvents?: AlignmentMatrixControlIconProps[ 'disablePointerEvents' ]; |
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.
It turns out that the disablePointerEvents prop is never used on the GridContainer component. Then only way how it could be received is as a prop of the parent component (AlignmentMatrixControlProps) but the parent component doesn't have this prop at all. Only the icon component (AlignmentMatrixControlIcon) has it.
It's a welcome simplification of the styles.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +650 B (+0.03%) Total Size: 2.58 MB
ℹ️ View Unchanged
|
332a1ba to
496d472
Compare
| } } | ||
| renderContent={ () => ( | ||
| <AlignmentMatrixControl | ||
| hasFocusBorder={ false } |
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.
This hasFocusBorder prop doesn't exist on the component and it's also not a valid prop of the native HTML element. It started triggering a React warning.
Emotion's styled wrapped checks props and forwards them only if they're valid (@emotion/is-prop-valid). That's why this error was detected only now, after removing styled.
6c4ddc9 to
d18a1f9
Compare
| test: /\.scss$/, | ||
| exclude: /\.lazy\.scss$/, | ||
| use: scssLoaders( { isLazy: false } ), | ||
| include: path.resolve( __dirname ), |
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.
Removing this line enables the *.scss loader also for files in packages/components. Then the Storybook build can compile the style.module.scss files there.
The path.resolve( __dirname ) value is the /storybook folder, so *.scss files outside it were not processed.
youknowriad
left a comment
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.
This is looking great to me. Also the code of the component feels a lot simpler (less indirection).
52720c0 to
96f2b95
Compare
|
Flaky tests detected in 96f2b95. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/19929141389
|
| @use "../utils/theme-variables" as *; | ||
|
|
||
| /* Grid structure */ | ||
| .gridContainer { |
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.
With existing CSS naming conventions, I'd expect this to be called .grid-container, even if that makes the JavaScript reference a little more verbose by having to use bracket notation for referencing the property.
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.
Good point, fixing in #73757.
Migrates the
AlignmentMatrixControlstyles from Emotion to astyle.module.cssfile. If we managed to do this for all 35 Emotion components, we could remove Emotion completely, including our build process which now must run Babel just for the@emotion/babel-pluginand nothing else.There are still some open questions on this PR, see the review comments. If we sort them out, we can write a more precise prompt that could do the entire migration very quickly.