Repository navigation
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import clsx from 'clsx'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
|
|
@@ -9,9 +14,9 @@ import { VisuallyHidden } from '../visually-hidden'; | |
| * Internal dependencies | ||
| */ | ||
| import { ALIGNMENT_LABEL } from './utils'; | ||
| import { Cell as CellView, Point } from './styles'; | ||
| import type { AlignmentMatrixControlCellProps } from './types'; | ||
| import type { WordPressComponentProps } from '../context'; | ||
| import styles from './style.module.scss'; | ||
|
|
||
| export default function Cell( { | ||
| id, | ||
|
|
@@ -22,13 +27,19 @@ export default function Cell( { | |
| <Tooltip text={ ALIGNMENT_LABEL[ value ] }> | ||
| <Composite.Item | ||
| id={ id } | ||
| render={ <CellView { ...props } role="gridcell" /> } | ||
| render={ | ||
| <span | ||
| { ...props } | ||
| className={ clsx( styles.cell, props.className ) } | ||
| role="gridcell" | ||
| /> | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The migration has three steps:
|
||
| > | ||
| { /* VoiceOver needs a text content to be rendered within grid cell, | ||
| otherwise it'll announce the content as "blank". So we use a visually | ||
| hidden element instead of aria-label. */ } | ||
| <VisuallyHidden>{ value }</VisuallyHidden> | ||
| <Point role="presentation" /> | ||
| <span className={ styles.point } role="presentation" /> | ||
| </Composite.Item> | ||
| </Tooltip> | ||
| ); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,11 @@ import { useCallback } from '@wordpress/element'; | |
| */ | ||
| import Cell from './cell'; | ||
| import { Composite } from '../composite'; | ||
| import { GridContainer, GridRow } from './styles'; | ||
| import AlignmentMatrixControlIcon from './icon'; | ||
| import { GRID, getItemId, getItemValue } from './utils'; | ||
| import type { WordPressComponentProps } from '../context'; | ||
| import type { AlignmentMatrixControlProps } from './types'; | ||
| import styles from './style.module.scss'; | ||
|
|
||
| function UnforwardedAlignmentMatrixControl( { | ||
| className, | ||
|
|
@@ -49,7 +49,11 @@ function UnforwardedAlignmentMatrixControl( { | |
| [ baseId, onChange ] | ||
| ); | ||
|
|
||
| const classes = clsx( 'component-alignment-matrix-control', className ); | ||
| const classes = clsx( | ||
| 'component-alignment-matrix-control', | ||
| styles.gridContainer, | ||
| className | ||
| ); | ||
|
|
||
| return ( | ||
| <Composite | ||
|
|
@@ -58,18 +62,21 @@ function UnforwardedAlignmentMatrixControl( { | |
| setActiveId={ setActiveId } | ||
| rtl={ isRTL() } | ||
| render={ | ||
| <GridContainer | ||
| <div | ||
| { ...props } | ||
| aria-label={ label } | ||
| className={ classes } | ||
| aria-label={ label } | ||
| id={ baseId } | ||
| role="grid" | ||
| size={ width } | ||
| style={ { width: `${ width }px` } } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sometimes style interpolation forces us to declare a |
||
| /> | ||
| } | ||
| > | ||
| { GRID.map( ( cells, index ) => ( | ||
| <Composite.Row render={ <GridRow role="row" /> } key={ index }> | ||
| <Composite.Row | ||
| render={ <div className={ styles.gridRow } role="row" /> } | ||
| key={ index } | ||
| > | ||
| { cells.map( ( cell ) => ( | ||
| <Cell | ||
| id={ getItemId( baseId, cell ) } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| @use "@wordpress/base-styles/variables" as *; | ||
| @use "../utils/theme-variables" as *; | ||
|
|
||
| /* Grid structure */ | ||
| .gridContainer { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With existing CSS naming conventions, I'd expect this to be called
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, fixing in #73757. |
||
| direction: ltr; | ||
|
|
||
| display: grid; | ||
| grid-template-columns: repeat(3, 1fr); | ||
| grid-template-rows: repeat(3, 1fr); | ||
|
|
||
| box-sizing: border-box; | ||
| aspect-ratio: 1; | ||
|
|
||
| border: 1px solid transparent; | ||
| border-radius: $radius-medium; | ||
| outline: none; | ||
|
|
||
| cursor: pointer; | ||
| } | ||
|
|
||
| .gridRow { | ||
| grid-column: 1 / -1; | ||
|
|
||
| box-sizing: border-box; | ||
| display: grid; | ||
| grid-template-columns: repeat(3, 1fr); | ||
| } | ||
|
|
||
| /* Cell */ | ||
| .cell { | ||
| position: relative; | ||
|
|
||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
|
|
||
| box-sizing: border-box; | ||
| margin: 0; | ||
| padding: 0; | ||
|
|
||
| appearance: none; | ||
| border: none; | ||
| outline: none; | ||
| } | ||
|
|
||
| /* Point */ | ||
| .point { | ||
| display: block; | ||
| contain: strict; | ||
|
|
||
| box-sizing: border-box; | ||
| width: 6px; | ||
| aspect-ratio: 1; | ||
|
|
||
| margin: auto; | ||
|
|
||
| color: $components-color-gray-400; | ||
|
|
||
| /* Use border instead of background color so that the point shows | ||
| in Windows High Contrast Mode */ | ||
| border: 3px solid currentColor; | ||
| } | ||
|
|
||
| /* Highlight active item */ | ||
| .cell[data-active-item] .point { | ||
| color: $components-color-foreground; | ||
| transform: scale(calc(5 / 3)); | ||
| } | ||
|
|
||
| /* Hover styles for non-active items */ | ||
| .cell:not([data-active-item]):hover .point { | ||
| color: $components-color-accent; | ||
| } | ||
|
|
||
| /* Show an outline only when interacting with keyboard */ | ||
| .cell[data-focus-visible] .point { | ||
| outline: 1px solid $components-color-accent; | ||
| outline-offset: 1px; | ||
| } | ||
|
|
||
| @media not (prefers-reduced-motion) { | ||
| .point { | ||
| transition-property: color, transform; | ||
| transition-duration: 120ms; | ||
| transition-timing-function: linear; | ||
| } | ||
| } | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| "types": [ | ||
| "gutenberg-env", | ||
| "gutenberg-test-env", | ||
| "css-modules", | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In order to have types for the |
||
| "jest", | ||
| "@testing-library/jest-dom" | ||
| ] | ||
|
|
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,7 +108,6 @@ module.exports = { | |
| test: /\.scss$/, | ||
| exclude: /\.lazy\.scss$/, | ||
| use: scssLoaders( { isLazy: false } ), | ||
| include: path.resolve( __dirname ), | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing this line enables the The |
||
| }, | ||
| { | ||
| test: /\.lazy\.scss$/, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| declare module '*.module.css' { | ||
| const classes: { [ key: string ]: string }; | ||
| export default classes; | ||
| } | ||
|
|
||
| declare module '*.module.scss' { | ||
| const classes: { [ key: string ]: string }; | ||
| export default classes; | ||
| } |
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
hasFocusBorderprop 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
styledwrapped checks props and forwards them only if they're valid (@emotion/is-prop-valid). That's why this error was detected only now, after removingstyled.