From 9ab9a5bd8259fce04200e57d04b4607b4c224e1f Mon Sep 17 00:00:00 2001 From: Marco Ciampini Date: Wed, 14 Oct 2026 16:24:12 +0200 Subject: [PATCH 1/6] Menu: Migrate Emotion styles to SCSS Modules --- packages/components/CHANGELOG.md | 1 + .../components/src/menu/checkbox-item.tsx | 37 +- packages/components/src/menu/group-label.tsx | 9 +- packages/components/src/menu/group.tsx | 13 +- .../components/src/menu/item-help-text.tsx | 15 +- packages/components/src/menu/item-label.tsx | 15 +- packages/components/src/menu/item.tsx | 26 +- packages/components/src/menu/popover.tsx | 21 +- packages/components/src/menu/radio-item.tsx | 33 +- packages/components/src/menu/separator.tsx | 12 +- .../components/src/menu/style.module.scss | 296 ++++++++++++++ packages/components/src/menu/styles.ts | 362 ------------------ .../src/menu/submenu-trigger-item.tsx | 11 +- .../components/src/utils/dropdown-motion.ts | 24 +- packages/components/src/utils/style-mixins.ts | 2 +- tools/eslint/suppressions.json | 5 - 16 files changed, 435 insertions(+), 447 deletions(-) create mode 100644 packages/components/src/menu/style.module.scss delete mode 100644 packages/components/src/menu/styles.ts diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 04d2faea6d23ee..f6f8cfa58222c8 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -5,6 +5,7 @@ ### Breaking Changes - Components that compose Emotion style fragments with `cx()` should pass source-order-dependent fragments in a single `css()` call. Passing separate fragments can change override order after the following components stopped rendering styles through Emotion: + - `Menu` - `Navigator` ([#84565](https://github.com/WordPress/gutenberg/pull/84565)) - `UnitControl` ([#84561](https://github.com/WordPress/gutenberg/pull/84561)) - `RangeControl` ([#84562](https://github.com/WordPress/gutenberg/pull/84562)) diff --git a/packages/components/src/menu/checkbox-item.tsx b/packages/components/src/menu/checkbox-item.tsx index 7eb43e832d3d60..c67df95416181c 100644 --- a/packages/components/src/menu/checkbox-item.tsx +++ b/packages/components/src/menu/checkbox-item.tsx @@ -1,17 +1,25 @@ +import clsx from 'clsx'; import * as Ariakit from '@ariakit/react'; import { forwardRef, useContext } from '@wordpress/element'; import { Icon, check } from '@wordpress/icons'; import type { WordPressComponentProps } from '../context'; import { Context } from './context'; import type { CheckboxItemProps } from './types'; -import * as Styled from './styles'; +import styles from './style.module.scss'; import { useMenuItemHideOnClick } from './use-menu-item-hide-on-click'; export const CheckboxItem = forwardRef< HTMLDivElement, WordPressComponentProps< CheckboxItemProps, 'div', false > >( function UnforwardedCheckboxItem( - { suffix, children, disabled = false, hideOnClick = false, ...props }, + { + className, + suffix, + children, + disabled = false, + hideOnClick = false, + ...props + }, ref ) { const menuContext = useContext( Context ); @@ -24,9 +32,14 @@ export const CheckboxItem = forwardRef< ); } return ( - } + render={ + + } // Override some ariakit inline styles style={ { width: 'auto', height: 'auto' } } > - - +
+
{ children } - +
{ suffix && ( - + { suffix } - + ) } - - +
+ ); } ); diff --git a/packages/components/src/menu/group-label.tsx b/packages/components/src/menu/group-label.tsx index b0406eb4ea4d5b..e72a24fb362abe 100644 --- a/packages/components/src/menu/group-label.tsx +++ b/packages/components/src/menu/group-label.tsx @@ -1,15 +1,17 @@ +import clsx from 'clsx'; +import * as Ariakit from '@ariakit/react'; import { forwardRef, useContext } from '@wordpress/element'; import type { WordPressComponentProps } from '../context'; import { Context } from './context'; import { Text } from '../text'; import { CONFIG } from '../utils'; import type { GroupLabelProps } from './types'; -import * as Styled from './styles'; +import styles from './style.module.scss'; export const GroupLabel = forwardRef< HTMLDivElement, WordPressComponentProps< GroupLabelProps, 'div', false > ->( function Group( props, ref ) { +>( function Group( { className, ...props }, ref ) { const menuContext = useContext( Context ); if ( ! menuContext?.store ) { @@ -19,7 +21,7 @@ export const GroupLabel = forwardRef< } return ( - } { ...props } + className={ clsx( styles[ 'group-label' ], className ) } store={ menuContext.store } /> ); diff --git a/packages/components/src/menu/group.tsx b/packages/components/src/menu/group.tsx index 5d9e91e213ec03..26fd1dd0ddecfb 100644 --- a/packages/components/src/menu/group.tsx +++ b/packages/components/src/menu/group.tsx @@ -1,13 +1,15 @@ +import clsx from 'clsx'; +import * as Ariakit from '@ariakit/react'; import { forwardRef, useContext } from '@wordpress/element'; import type { WordPressComponentProps } from '../context'; import { Context } from './context'; import type { GroupProps } from './types'; -import * as Styled from './styles'; +import styles from './style.module.scss'; export const Group = forwardRef< HTMLDivElement, WordPressComponentProps< GroupProps, 'div', false > ->( function UnforwardedGroup( props, ref ) { +>( function UnforwardedGroup( { className, ...props }, ref ) { const menuContext = useContext( Context ); if ( ! menuContext?.store ) { @@ -17,6 +19,11 @@ export const Group = forwardRef< } return ( - + ); } ); diff --git a/packages/components/src/menu/item-help-text.tsx b/packages/components/src/menu/item-help-text.tsx index 1cb596c0704d8c..03e8ecc9c316f5 100644 --- a/packages/components/src/menu/item-help-text.tsx +++ b/packages/components/src/menu/item-help-text.tsx @@ -1,12 +1,14 @@ +import clsx from 'clsx'; import { forwardRef, useContext } from '@wordpress/element'; import type { WordPressComponentProps } from '../context'; import { Context } from './context'; -import * as Styled from './styles'; +import { Truncate } from '../truncate'; +import styles from './style.module.scss'; export const ItemHelpText = forwardRef< HTMLSpanElement, WordPressComponentProps< { children: React.ReactNode }, 'span', true > ->( function UnforwardedItemHelpText( props, ref ) { +>( function UnforwardedItemHelpText( { className, ...props }, ref ) { const menuContext = useContext( Context ); if ( ! menuContext?.store ) { @@ -15,5 +17,12 @@ export const ItemHelpText = forwardRef< ); } - return ; + return ( + + ); } ); diff --git a/packages/components/src/menu/item-label.tsx b/packages/components/src/menu/item-label.tsx index ab01bac3a68921..7e2eb7cfa0e1f7 100644 --- a/packages/components/src/menu/item-label.tsx +++ b/packages/components/src/menu/item-label.tsx @@ -1,12 +1,14 @@ +import clsx from 'clsx'; import { forwardRef, useContext } from '@wordpress/element'; import type { WordPressComponentProps } from '../context'; import { Context } from './context'; -import * as Styled from './styles'; +import { Truncate } from '../truncate'; +import styles from './style.module.scss'; export const ItemLabel = forwardRef< HTMLSpanElement, WordPressComponentProps< { children: React.ReactNode }, 'span', true > ->( function UnforwardedItemLabel( props, ref ) { +>( function UnforwardedItemLabel( { className, ...props }, ref ) { const menuContext = useContext( Context ); if ( ! menuContext?.store ) { @@ -15,5 +17,12 @@ export const ItemLabel = forwardRef< ); } - return ; + return ( + + ); } ); diff --git a/packages/components/src/menu/item.tsx b/packages/components/src/menu/item.tsx index 9dd3ce2f5295a8..99a716997c7e79 100644 --- a/packages/components/src/menu/item.tsx +++ b/packages/components/src/menu/item.tsx @@ -1,7 +1,9 @@ +import clsx from 'clsx'; +import * as Ariakit from '@ariakit/react'; import { forwardRef, useContext } from '@wordpress/element'; import type { WordPressComponentProps } from '../context'; import type { ItemProps } from './types'; -import * as Styled from './styles'; +import styles from './style.module.scss'; import { Context } from './context'; import { useMenuItemHideOnClick } from './use-menu-item-hide-on-click'; @@ -10,6 +12,7 @@ export const Item = forwardRef< WordPressComponentProps< ItemProps, 'div', false > >( function UnforwardedItem( { + className, prefix, suffix, children, @@ -38,27 +41,30 @@ export const Item = forwardRef< // `Menu.SubmenuTriggerItem`), the context store wouldn't be correct. This is // why the component accepts a `store` prop to override the context store. return ( - - { prefix } + + { prefix } + - - +
+
{ children } - +
{ suffix && ( - + { suffix } - + ) } - - +
+ ); } ); diff --git a/packages/components/src/menu/popover.tsx b/packages/components/src/menu/popover.tsx index ca14b62c1a2237..390c2cef5c889e 100644 --- a/packages/components/src/menu/popover.tsx +++ b/packages/components/src/menu/popover.tsx @@ -1,3 +1,4 @@ +import clsx from 'clsx'; import * as Ariakit from '@ariakit/react'; import { useContext, @@ -7,7 +8,7 @@ import { } from '@wordpress/element'; import type { WordPressComponentProps } from '../context'; import type { PopoverProps } from './types'; -import * as Styled from './styles'; +import styles from './style.module.scss'; import { Context } from './context'; export const Popover = forwardRef< @@ -61,19 +62,27 @@ export const Popover = forwardRef< const renderMenu = useCallback( ( htmlProps: React.ComponentPropsWithRef< 'div' > ) => ( - - +
- +
), [ menuContext.variant ] ); return ( - >( function UnforwardedRadioItem( - { suffix, children, disabled = false, hideOnClick = false, ...props }, + { + className, + suffix, + children, + disabled = false, + hideOnClick = false, + ...props + }, ref ) { const menuContext = useContext( Context ); @@ -31,9 +39,10 @@ export const RadioItem = forwardRef< ); } return ( - } + render={ + + } // Override some ariakit inline styles style={ { width: 'auto', height: 'auto' } } > - - +
+
{ children } - +
{ suffix && ( - + { suffix } - + ) } - - +
+ ); } ); diff --git a/packages/components/src/menu/separator.tsx b/packages/components/src/menu/separator.tsx index f5e3fd1b08f95f..71937ecabab758 100644 --- a/packages/components/src/menu/separator.tsx +++ b/packages/components/src/menu/separator.tsx @@ -1,13 +1,15 @@ +import clsx from 'clsx'; +import * as Ariakit from '@ariakit/react'; import { forwardRef, useContext } from '@wordpress/element'; import type { WordPressComponentProps } from '../context'; import { Context } from './context'; import type { SeparatorProps } from './types'; -import * as Styled from './styles'; +import styles from './style.module.scss'; export const Separator = forwardRef< HTMLHRElement, WordPressComponentProps< SeparatorProps, 'hr', false > ->( function UnforwardedSeparator( props, ref ) { +>( function UnforwardedSeparator( { className, ...props }, ref ) { const menuContext = useContext( Context ); if ( ! menuContext?.store ) { @@ -17,11 +19,13 @@ export const Separator = forwardRef< } return ( - ); } ); diff --git a/packages/components/src/menu/style.module.scss b/packages/components/src/menu/style.module.scss new file mode 100644 index 00000000000000..afdbfa32a38c6b --- /dev/null +++ b/packages/components/src/menu/style.module.scss @@ -0,0 +1,296 @@ +@use "@wordpress/base-styles/variables" as *; +@use "@wordpress/base-styles/z-index" as *; +@use "../utils/theme-variables" as *; + +.menu { + position: relative; + z-index: z-index(".components-popover"); + + /* Only visible in Windows High Contrast mode */ + outline: 2px solid transparent !important; +} + +.menu-surface { + display: grid; + grid-template-columns: minmax(0, max-content) 1fr; + grid-template-rows: auto; + + box-sizing: border-box; + min-width: 160px; + max-width: 320px; + max-height: var(--popover-available-height); + + padding: $grid-unit-05; + + overscroll-behavior: contain; + overflow: auto; + + background-color: $components-color-background; + border-radius: $radius-medium; + box-shadow: 0 0 0 $border-width $components-color-gray-300, $elevation-medium; + + &:where(.is-toolbar) { + box-shadow: 0 0 0 $border-width $components-color-foreground; + } +} + +.menu-motion-root { + // Keep motion values in sync with ../utils/dropdown-motion.ts. + @media not ( prefers-reduced-motion ) { + transition-property: transform, opacity; + transition-duration: + 200ms, + 100ms; + transition-timing-function: + cubic-bezier(0.25, 0, 0, 1), + linear; + will-change: transform, opacity; + + &:not(:has(> .menu-surface[data-submenu])) { + /* Regardless of the side, fade in and out. */ + opacity: 0; + &:has(> .menu-surface[data-enter]) { + opacity: 1; + } + + /* Slide in the direction the menu is opening. */ + &:has(> .menu-surface[data-side="bottom"]) { + transform: translateY(-4px); + } + &:has(> .menu-surface[data-side="top"]) { + transform: translateY(4px); + } + &:has(> .menu-surface[data-side="left"]) { + transform: translateX(4px); + } + &:has(> .menu-surface[data-side="right"]) { + transform: translateX(-4px); + } + &:has(> .menu-surface[data-enter][data-side="bottom"]), + &:has(> .menu-surface[data-enter][data-side="top"]) { + transform: translateY(0); + } + &:has(> .menu-surface[data-enter][data-side="left"]), + &:has(> .menu-surface[data-enter][data-side="right"]) { + transform: translateX(0); + } + } + } +} + +.item { + all: unset; + cursor: var(--wpds-cursor-control); + + position: relative; + min-height: 32px; + box-sizing: border-box; + + /* Occupy the width of all grid columns (ie. full width) */ + grid-column: 1 / -1; + + display: grid; + grid-template-columns: minmax(0, max-content) 1fr; + align-items: center; + + @supports ( grid-template-columns: subgrid ) { + /* + * Define a grid layout which inherits the same columns configuration + * from the parent layout (ie. subgrid). This allows the menu + * to synchronize the indentation of all its items. + */ + grid-template-columns: subgrid; + } + + font-size: $default-font-size; + font-family: inherit; + font-weight: 400; + line-height: 20px; + + color: $components-color-foreground; + border-radius: $radius-small; + + padding-block: $grid-unit-05; + padding-inline: $grid-unit-15; + + /* + * Make sure that, when an item is scrolled into view (eg. while using the + * keyboard to move focus), the whole item comes into view + */ + scroll-margin: $grid-unit-05; + + user-select: none; + outline: none; + + &[aria-disabled="true"] { + color: var(--wpds-color-foreground-interactive-neutral-disabled); + } + + /* Active item (including hover) */ + &[data-active-item]:not([data-focus-visible]):not( + [aria-disabled="true"] + ) { + background-color: $components-color-accent; + color: $components-color-accent-inverted; + } + + /* Keyboard focus (focus-visible) */ + &[data-focus-visible] { + box-shadow: 0 0 0 1.5px $components-color-accent; + + /* Only visible in Windows High Contrast mode */ + outline: 2px solid transparent; + } + + /* When the item is the trigger of an open submenu */ + .menu:not(:focus) &:not(:focus)[aria-expanded="true"] { + background-color: $components-color-gray-100; + color: $components-color-foreground; + } + + svg { + fill: currentColor; + } +} + +.item-prefix-wrapper { + /* Always occupy the first column, even when auto-collapsing */ + grid-column: 1; + + /* + * Even when the item is not checked, occupy the same screen space to avoid + * the space collapside when no items are checked. + */ + .checkbox-item > &, + .radio-item > & { + /* Same width as the check icons */ + min-width: 24px; + } + + .checkbox-item > &, + .radio-item > &, + &:not(:empty) { + margin-inline-end: 8px; + } + + display: flex; + align-items: center; + justify-content: center; + + color: $components-color-gray-700; + + /* + * When the parent menu item is active, except when it's a non-focused/hovered + * submenu trigger (in that case, color should not be inherited) + */ + [data-active-item]:not([data-focus-visible]) > &, + [aria-disabled="true"] > & { + color: inherit; + } +} + +.item-content-wrapper { + /* + * Always occupy the second column, since the first column + * is taken by the prefix wrapper (when displayed). + */ + grid-column: 2; + + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; + + pointer-events: none; +} + +.item-children-wrapper { + flex: 1; + + display: inline-flex; + flex-direction: column; + gap: 4px; +} + +.item-suffix-wrapper { + flex: 0 1 fit-content; + min-width: 0; + width: fit-content; + + display: flex; + align-items: center; + justify-content: center; + gap: 12px; + + color: $components-color-gray-700; + + /* + * When the parent menu item is active, except when it's a non-focused/hovered + * submenu trigger (in that case, color should not be inherited) + */ + [data-active-item]:not([data-focus-visible]) *:not(.menu) &, + [aria-disabled="true"] *:not(.menu) & { + color: inherit; + } +} + +.group { + /* Ignore this element when calculating the layout. Useful for subgrid */ + display: contents; +} + +.group-label { + /* Occupy the width of all grid columns (ie. full width) */ + grid-column: 1 / -1; + + padding-block-start: 12px; + padding-block-end: 8px; + padding-inline: $grid-unit-15; +} + +.separator { + /* Occupy the width of all grid columns (ie. full width) */ + grid-column: 1 / -1; + + border: none; + height: $border-width; + background-color: $components-color-gray-200; + /* Align with menu items' content */ + margin-block: 8px; + margin-inline: $grid-unit-15; + + /* Only visible in Windows High Contrast mode */ + outline: 2px solid transparent; + + &:where(.is-toolbar) { + background-color: $components-color-foreground; + } +} + +.submenu-chevron-icon { + width: 6px; + transform: scaleX(1); + + &:where(.is-rtl) { + transform: scaleX(-1); + } +} + +.item-label { + font-size: $default-font-size; + line-height: 20px; + color: inherit; +} + +.item-help-text { + font-size: $helptext-font-size; + line-height: 16px; + color: $components-color-gray-700; + overflow-wrap: anywhere; + + [data-active-item]:not([data-focus-visible]) *:not(.menu) &, + [aria-disabled="true"] *:not(.menu) & { + color: inherit; + } +} + diff --git a/packages/components/src/menu/styles.ts b/packages/components/src/menu/styles.ts deleted file mode 100644 index ebd2a2346b30d5..00000000000000 --- a/packages/components/src/menu/styles.ts +++ /dev/null @@ -1,362 +0,0 @@ -import * as Ariakit from '@ariakit/react'; -import { css } from '@emotion/react'; -import styled from '@emotion/styled'; -import { COLORS, font, rtl, CONFIG, DROPDOWN_MOTION_CSS } from '../utils'; -import { space } from '../utils/space'; -import Icon from '../icon'; -import { Truncate } from '../truncate'; -import type { ContextProps } from './types'; - -const CONTENT_WRAPPER_PADDING = space( 1 ); -const ITEM_PADDING_BLOCK = space( 1 ); -const ITEM_PADDING_INLINE = space( 3 ); - -// TODO: -// - border color and divider color are different from COLORS.theme variables -// - lighter text color is not defined in COLORS.theme, should it be? -// - lighter background color is not defined in COLORS.theme, should it be? -// TODO: should use the `stroke-surface-neutral` WPDS token when refactored to SCSS modules -const DEFAULT_BORDER_COLOR = COLORS.theme.gray[ 300 ]; -// TODO: should use the `stroke-surface-neutral-weak` WPDS token when refactored to SCSS modules -const DIVIDER_COLOR = COLORS.theme.gray[ 200 ]; -const LIGHTER_TEXT_COLOR = COLORS.theme.gray[ 700 ]; -const LIGHT_BACKGROUND_COLOR = COLORS.theme.gray[ 100 ]; -const TOOLBAR_VARIANT_BORDER_COLOR = COLORS.theme.foreground; -const DEFAULT_BOX_SHADOW = `0 0 0 ${ CONFIG.borderWidth } ${ DEFAULT_BORDER_COLOR }, ${ CONFIG.elevationMedium }`; -const TOOLBAR_VARIANT_BOX_SHADOW = `0 0 0 ${ CONFIG.borderWidth } ${ TOOLBAR_VARIANT_BORDER_COLOR }`; - -const GRID_TEMPLATE_COLS = 'minmax( 0, max-content ) 1fr'; - -export const Menu = styled( Ariakit.Menu )` - position: relative; - /* Same as popover component */ - /* TODO: is there a way to read the sass variable? */ - z-index: 1000000; - - /* Only visible in Windows High Contrast mode */ - outline: 2px solid transparent !important; -`; - -export const MenuSurface = styled.div< Pick< ContextProps, 'variant' > >` - display: grid; - grid-template-columns: ${ GRID_TEMPLATE_COLS }; - grid-template-rows: auto; - - box-sizing: border-box; - min-width: 160px; - max-width: 320px; - max-height: var( --popover-available-height ); - - padding: ${ CONTENT_WRAPPER_PADDING }; - - overscroll-behavior: contain; - overflow: auto; - - background-color: ${ COLORS.ui.background }; - border-radius: ${ CONFIG.radiusMedium }; - ${ ( props ) => css` - box-shadow: ${ - props.variant === 'toolbar' - ? TOOLBAR_VARIANT_BOX_SHADOW - : DEFAULT_BOX_SHADOW - }; - ` } -`; - -/** - * Outer wrapper for menu motion. `Menu.Popover` uses Ariakit’s `render` prop so - * this element wraps the inner surface that receives all merged menu props - * (ref, role, `data-*`, children). Transitions mirror the pre-refactor `Menu` - * styles from `trunk`, driven by `data-enter` / `data-side` on the inner - * surface via `:has(> …)`. - */ -export const MenuMotionRoot = styled.div` - @media not ( prefers-reduced-motion ) { - transition-property: transform, opacity; - transition-duration: - ${ DROPDOWN_MOTION_CSS.SLIDE_DURATION }, - ${ DROPDOWN_MOTION_CSS.FADE_DURATION }; - transition-timing-function: - ${ DROPDOWN_MOTION_CSS.SLIDE_EASING }, - ${ DROPDOWN_MOTION_CSS.FADE_EASING }; - will-change: transform, opacity; - - &:not( :has( > ${ MenuSurface }[data-submenu] ) ) { - /* Regardless of the side, fade in and out. */ - opacity: 0; - &:has( > ${ MenuSurface }[data-enter] ) { - opacity: 1; - } - - /* Slide in the direction the menu is opening. */ - &:has( > ${ MenuSurface }[data-side='bottom'] ) { - transform: translateY( - -${ DROPDOWN_MOTION_CSS.SLIDE_DISTANCE } - ); - } - &:has( > ${ MenuSurface }[data-side='top'] ) { - transform: translateY( - ${ DROPDOWN_MOTION_CSS.SLIDE_DISTANCE } - ); - } - &:has( > ${ MenuSurface }[data-side='left'] ) { - transform: translateX( - ${ DROPDOWN_MOTION_CSS.SLIDE_DISTANCE } - ); - } - &:has( > ${ MenuSurface }[data-side='right'] ) { - transform: translateX( - -${ DROPDOWN_MOTION_CSS.SLIDE_DISTANCE } - ); - } - &:has( > ${ MenuSurface }[data-enter][data-side='bottom'] ), - &:has( > ${ MenuSurface }[data-enter][data-side='top'] ) { - transform: translateY( 0 ); - } - &:has( > ${ MenuSurface }[data-enter][data-side='left'] ), - &:has( > ${ MenuSurface }[data-enter][data-side='right'] ) { - transform: translateX( 0 ); - } - } - } -`; - -const baseItem = css` - all: unset; - cursor: pointer; - - position: relative; - min-height: ${ space( 8 ) }; - box-sizing: border-box; - - /* Occupy the width of all grid columns (ie. full width) */ - grid-column: 1 / -1; - - display: grid; - grid-template-columns: ${ GRID_TEMPLATE_COLS }; - align-items: center; - - @supports ( grid-template-columns: subgrid ) { - /* - * Define a grid layout which inherits the same columns configuration - * from the parent layout (ie. subgrid). This allows the menu - * to synchronize the indentation of all its items. - */ - grid-template-columns: subgrid; - } - - font-size: ${ font( 'default.fontSize' ) }; - font-family: inherit; - font-weight: normal; - line-height: 20px; - - color: ${ COLORS.theme.foreground }; - border-radius: ${ CONFIG.radiusSmall }; - - padding-block: ${ ITEM_PADDING_BLOCK }; - padding-inline: ${ ITEM_PADDING_INLINE }; - - /* - * Make sure that, when an item is scrolled into view (eg. while using the - * keyboard to move focus), the whole item comes into view - */ - scroll-margin: ${ CONTENT_WRAPPER_PADDING }; - - user-select: none; - outline: none; - - &[aria-disabled='true'] { - color: ${ COLORS.ui.textDisabled }; - } - - /* Active item (including hover) */ - &[data-active-item]:not( [data-focus-visible] ):not( - [aria-disabled='true'] - ) { - background-color: ${ COLORS.theme.accent }; - color: ${ COLORS.theme.accentInverted }; - } - - /* Keyboard focus (focus-visible) */ - &[data-focus-visible] { - box-shadow: 0 0 0 1.5px ${ COLORS.theme.accent }; - - /* Only visible in Windows High Contrast mode */ - outline: 2px solid transparent; - } - - /* Active (ie. pressed, mouse down) */ - &:active, - &[data-active] { - /* TODO: should there be a visual active state? */ - } - - /* When the item is the trigger of an open submenu */ - ${ Menu }:not(:focus) &:not(:focus)[aria-expanded="true"] { - background-color: ${ LIGHT_BACKGROUND_COLOR }; - color: ${ COLORS.theme.foreground }; - } - - svg { - fill: currentColor; - } -`; - -export const Item = styled( Ariakit.MenuItem )` - ${ baseItem }; -`; - -export const CheckboxItem = styled( Ariakit.MenuItemCheckbox )` - ${ baseItem }; -`; - -export const RadioItem = styled( Ariakit.MenuItemRadio )` - ${ baseItem }; -`; - -export const ItemPrefixWrapper = styled.span` - /* Always occupy the first column, even when auto-collapsing */ - grid-column: 1; - - /* - * Even when the item is not checked, occupy the same screen space to avoid - * the space collapside when no items are checked. - */ - ${ CheckboxItem } > &, - ${ RadioItem } > & { - /* Same width as the check icons */ - min-width: ${ space( 6 ) }; - } - - ${ CheckboxItem } > &, - ${ RadioItem } > &, - &:not( :empty ) { - margin-inline-end: ${ space( 2 ) }; - } - - display: flex; - align-items: center; - justify-content: center; - - color: ${ LIGHTER_TEXT_COLOR }; - - /* - * When the parent menu item is active, except when it's a non-focused/hovered - * submenu trigger (in that case, color should not be inherited) - */ - [data-active-item]:not( [data-focus-visible] ) > &, - /* When the parent menu item is disabled */ - [aria-disabled='true'] > & { - color: inherit; - } -`; - -export const ItemContentWrapper = styled.div` - /* - * Always occupy the second column, since the first column - * is taken by the prefix wrapper (when displayed). - */ - grid-column: 2; - - display: flex; - align-items: center; - justify-content: space-between; - gap: ${ space( 3 ) }; - - pointer-events: none; -`; - -export const ItemChildrenWrapper = styled.div` - flex: 1; - - display: inline-flex; - flex-direction: column; - gap: ${ space( 1 ) }; -`; - -export const ItemSuffixWrapper = styled.span` - flex: 0 1 fit-content; - min-width: 0; - width: fit-content; - - display: flex; - align-items: center; - justify-content: center; - gap: ${ space( 3 ) }; - - color: ${ LIGHTER_TEXT_COLOR }; - - /* - * When the parent menu item is active, except when it's a non-focused/hovered - * submenu trigger (in that case, color should not be inherited) - */ - [data-active-item]:not( [data-focus-visible] ) *:not(${ Menu }) &, - /* When the parent menu item is disabled */ - [aria-disabled='true'] *:not(${ Menu }) & { - color: inherit; - } -`; - -export const Group = styled( Ariakit.MenuGroup )` - /* Ignore this element when calculating the layout. Useful for subgrid */ - display: contents; -`; - -export const GroupLabel = styled( Ariakit.MenuGroupLabel )` - /* Occupy the width of all grid columns (ie. full width) */ - grid-column: 1 / -1; - - padding-block-start: ${ space( 3 ) }; - padding-block-end: ${ space( 2 ) }; - padding-inline: ${ ITEM_PADDING_INLINE }; -`; - -export const Separator = styled( Ariakit.MenuSeparator )< - Pick< ContextProps, 'variant' > ->` - /* Occupy the width of all grid columns (ie. full width) */ - grid-column: 1 / -1; - - border: none; - height: ${ CONFIG.borderWidth }; - background-color: ${ ( props ) => - props.variant === 'toolbar' - ? TOOLBAR_VARIANT_BORDER_COLOR - : DIVIDER_COLOR }; - /* Align with menu items' content */ - margin-block: ${ space( 2 ) }; - margin-inline: ${ ITEM_PADDING_INLINE }; - - /* Only visible in Windows High Contrast mode */ - outline: 2px solid transparent; -`; - -export const SubmenuChevronIcon = styled( Icon )` - width: ${ space( 1.5 ) }; - ${ rtl( - { - transform: `scaleX(1)`, - }, - { - transform: `scaleX(-1)`, - } - ) }; -`; - -export const ItemLabel = styled( Truncate )` - font-size: ${ font( 'default.fontSize' ) }; - line-height: 20px; - color: inherit; -`; - -export const ItemHelpText = styled( Truncate )` - font-size: ${ font( 'helpText.fontSize' ) }; - line-height: 16px; - color: ${ LIGHTER_TEXT_COLOR }; - overflow-wrap: anywhere; - - [data-active-item]:not( [data-focus-visible] ) *:not( ${ Menu } ) &, - [aria-disabled='true'] *:not( ${ Menu } ) & { - color: inherit; - } -`; diff --git a/packages/components/src/menu/submenu-trigger-item.tsx b/packages/components/src/menu/submenu-trigger-item.tsx index f49eb6a76dc6e4..4c7e36183100df 100644 --- a/packages/components/src/menu/submenu-trigger-item.tsx +++ b/packages/components/src/menu/submenu-trigger-item.tsx @@ -1,11 +1,14 @@ +import clsx from 'clsx'; import * as Ariakit from '@ariakit/react'; import { forwardRef, useContext } from '@wordpress/element'; import { chevronRightSmall } from '@wordpress/icons'; +import { isRTL } from '@wordpress/i18n'; import type { WordPressComponentProps } from '../context'; import type { ItemProps } from './types'; import { Context } from './context'; import { Item } from './item'; -import * as Styled from './styles'; +import Icon from '../icon'; +import styles from './style.module.scss'; export const SubmenuTriggerItem = forwardRef< HTMLDivElement, @@ -35,7 +38,11 @@ export const SubmenuTriggerItem = forwardRef< suffix={ <> { suffix } -