Repository navigation
Components: Migrate ItemGroup to SCSS module #80797
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 6 commits
3fbb28d
15be7a5
51006ce
32147aa
6417712
3e9510e
15958e2
a39a6b0
8884f99
02c59e6
c177b21
ce69c1b
a6132b6
4bd0942
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,15 +1,9 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import clsx from 'clsx'; | ||
|
|
||
| import type { WordPressComponentProps } from '../../context'; | ||
| import { useContextSystem } from '../../context'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import * as styles from '../styles'; | ||
| import { useCx } from '../../utils/hooks/use-cx'; | ||
| import type { ItemGroupProps } from '../types'; | ||
| import styles from '../style.module.scss'; | ||
|
|
||
| export function useItemGroup( | ||
| props: WordPressComponentProps< ItemGroupProps, 'div' > | ||
|
|
@@ -23,12 +17,12 @@ export function useItemGroup( | |
| ...otherProps | ||
| } = useContextSystem( props, 'ItemGroup' ); | ||
|
|
||
| const cx = useCx(); | ||
|
|
||
| const classes = cx( | ||
| isBordered && styles.bordered, | ||
| isSeparated && styles.separated, | ||
| isRounded && styles.rounded, | ||
| const classes = clsx( | ||
| { | ||
| [ styles.bordered ]: isBordered, | ||
| [ styles.separated ]: isSeparated, | ||
| [ styles.rounded ]: isRounded, | ||
| }, | ||
|
Comment on lines
+20
to
+26
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. These are also modifier classes. I'd probably add a |
||
| className | ||
| ); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,16 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { useMemo } from '@wordpress/element'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import clsx from 'clsx'; | ||
|
|
||
| import type { WordPressComponentProps } from '../../context'; | ||
| import { useContextSystem } from '../../context'; | ||
| import * as styles from '../styles'; | ||
| import { useItemGroupContext } from '../context'; | ||
| import { useCx } from '../../utils/hooks/use-cx'; | ||
| import type { ItemProps } from '../types'; | ||
| import styles from '../style.module.scss'; | ||
|
|
||
| const sizeClassName = { | ||
| small: styles[ 'size-small' ], | ||
| medium: styles[ 'size-medium' ], | ||
| large: styles[ 'size-large' ], | ||
| }; | ||
|
|
||
| export function useItem( props: WordPressComponentProps< ItemProps, 'div' > ) { | ||
| const { | ||
|
|
@@ -29,22 +28,16 @@ export function useItem( props: WordPressComponentProps< ItemProps, 'div' > ) { | |
|
|
||
| const as = asProp || ( typeof onClick !== 'undefined' ? 'button' : 'div' ); | ||
|
|
||
| const cx = useCx(); | ||
|
|
||
| const classes = useMemo( | ||
| () => | ||
| cx( | ||
| ( as === 'button' || as === 'a' ) && | ||
| styles.unstyledButton( as ), | ||
| styles.itemSizes[ size ] || styles.itemSizes.medium, | ||
| styles.item, | ||
| spacedAround && styles.spacedAround, | ||
| className | ||
| ), | ||
| [ as, className, cx, size, spacedAround ] | ||
| const classes = clsx( | ||
| as === 'button' && styles[ 'unstyled-button' ], | ||
| as === 'a' && styles[ 'unstyled-link' ], | ||
| sizeClassName[ size ] || sizeClassName.medium, | ||
| styles.item, | ||
| spacedAround && styles[ 'spaced-around' ], | ||
|
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. These seem to be modifier classes of |
||
| className | ||
| ); | ||
|
|
||
| const wrapperClassName = cx( styles.itemWrapper ); | ||
| const wrapperClassName = styles[ 'item-wrapper' ]; | ||
|
|
||
| return { | ||
| as, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| @use "../utils/theme-variables" as *; | ||
|
|
||
| // Matches CONFIG.radiusSmall — not --wpds-border-radius-xs (1px). | ||
| $border-radius: 2px; | ||
|
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. Why not use |
||
|
|
||
| // Matches CONFIG.surfaceBorderColor — not the WPDS stroke token (#dbdbdb). | ||
| $surface-border-color: rgba(0, 0, 0, 0.1); | ||
|
|
||
| $base-font-height: calc(13px * 1.4); | ||
| $padding-y: calc((36px - #{$base-font-height} - 2px) / 2); | ||
| $padding-y-small: calc((calc(36px * 0.8) - #{$base-font-height} - 2px) / 2); | ||
| $padding-y-large: calc((calc(36px * 1.2) - #{$base-font-height} - 2px) / 2); | ||
|
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. Can we have a |
||
|
|
||
| .unstyled-button, | ||
| .unstyled-link { | ||
| font-size: 13px; | ||
| font-family: inherit; | ||
| appearance: none; | ||
| border: 1px solid transparent; | ||
| cursor: var(--wpds-cursor-control); | ||
| background: none; | ||
| text-align: start; | ||
|
|
||
| svg, | ||
| path { | ||
| fill: currentColor; | ||
| } | ||
|
|
||
| &:hover { | ||
| color: $components-color-accent; | ||
| } | ||
|
|
||
| &:focus { | ||
| box-shadow: none; | ||
| outline: none; | ||
| } | ||
|
|
||
| &:focus-visible { | ||
| box-shadow: 0 0 0 var(--wp-admin-border-width-focus) $components-color-accent; | ||
| // Windows high contrast mode. | ||
| outline: 2px solid transparent; | ||
| outline-offset: 0; | ||
| } | ||
| } | ||
|
|
||
| .unstyled-link { | ||
| text-decoration: none; | ||
| } | ||
|
|
||
| .item-wrapper { | ||
| width: 100%; | ||
| display: block; | ||
| } | ||
|
|
||
| .item { | ||
| box-sizing: border-box; | ||
| width: 100%; | ||
| display: block; | ||
| margin: 0; | ||
| color: inherit; | ||
| } | ||
|
|
||
| .bordered { | ||
| border: 1px solid $surface-border-color; | ||
| } | ||
|
|
||
| .separated { | ||
| > *:not(marquee) > * { | ||
| border-bottom: 1px solid $surface-border-color; | ||
| } | ||
|
|
||
| > *:last-of-type > * { | ||
| /* stylelint-disable-next-line plugin/use-logical-properties-and-values -- Preserve Emotion physical border-bottom-color. */ | ||
| border-bottom-color: transparent; | ||
|
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. There's no reason to preserve these. Please fix to logical. |
||
| } | ||
| } | ||
|
|
||
| .spaced-around { | ||
| border-radius: $border-radius; | ||
| } | ||
|
|
||
| .rounded { | ||
| border-radius: $border-radius; | ||
|
|
||
| > *:first-of-type > * { | ||
| /* stylelint-disable-next-line plugin/use-logical-properties-and-values -- Preserve Emotion physical radius corners. */ | ||
| border-top-left-radius: $border-radius; | ||
| /* stylelint-disable-next-line plugin/use-logical-properties-and-values -- Preserve Emotion physical radius corners. */ | ||
| border-top-right-radius: $border-radius; | ||
| } | ||
|
|
||
| > *:last-of-type > * { | ||
| /* stylelint-disable-next-line plugin/use-logical-properties-and-values -- Preserve Emotion physical radius corners. */ | ||
| border-bottom-left-radius: $border-radius; | ||
| /* stylelint-disable-next-line plugin/use-logical-properties-and-values -- Preserve Emotion physical radius corners. */ | ||
| border-bottom-right-radius: $border-radius; | ||
| } | ||
| } | ||
|
|
||
| .size-small { | ||
| padding: $padding-y-small 8px; | ||
| } | ||
|
|
||
| .size-medium { | ||
| padding: $padding-y 12px; | ||
| } | ||
|
|
||
| .size-large { | ||
| // Matches CONFIG.controlPaddingXLarge (`12 * 1.3334`). | ||
| padding: $padding-y-large 16.0008px; | ||
| } | ||
This file was deleted.
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 also needs to be in the breaking change section, like the other PR. Anything that replaces a
cxcall.