Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` ([#84706](https://github.com/WordPress/gutenberg/pull/84706))
- `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))
Expand All @@ -18,6 +19,7 @@

### Enhancements

- `Menu`: Use WPDS motion tokens for popup transition durations and slide easing ([#84706](https://github.com/WordPress/gutenberg/pull/84706)).
- `TabPanel`: Add interaction backgrounds to unselected tabs, preserve keyboard focus rings, and size neutral vertical selection lines to the content ([#84572](https://github.com/WordPress/gutenberg/pull/84572)).
- `Popover`: Use the design-system stroke color, border width, radius, and background on the default surface. `Dropdown` and `DropdownMenu` pick this up through `Popover` ([#84574](https://github.com/WordPress/gutenberg/pull/84574)).

Expand Down
37 changes: 26 additions & 11 deletions packages/components/src/menu/checkbox-item.tsx
Original file line number Diff line number Diff line change
@@ -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 );
Expand All @@ -24,34 +32,41 @@ export const CheckboxItem = forwardRef<
);
}
return (
<Styled.CheckboxItem
<Ariakit.MenuItemCheckbox
ref={ ref }
{ ...props }
className={ clsx(
styles.item,
styles[ 'checkbox-item' ],
className
) }
accessibleWhenDisabled
disabled={ disabled }
store={ store }
hideOnClick={ computedHideOnClick }
>
<Ariakit.MenuItemCheck
store={ store }
render={ <Styled.ItemPrefixWrapper /> }
render={
<span className={ styles[ 'item-prefix-wrapper' ] } />
}
// Override some ariakit inline styles
style={ { width: 'auto', height: 'auto' } }
>
<Icon icon={ check } size={ 24 } />
</Ariakit.MenuItemCheck>

<Styled.ItemContentWrapper>
<Styled.ItemChildrenWrapper>
<div className={ styles[ 'item-content-wrapper' ] }>
<div className={ styles[ 'item-children-wrapper' ] }>
{ children }
</Styled.ItemChildrenWrapper>
</div>

{ suffix && (
<Styled.ItemSuffixWrapper>
<span className={ styles[ 'item-suffix-wrapper' ] }>
{ suffix }
</Styled.ItemSuffixWrapper>
</span>
) }
</Styled.ItemContentWrapper>
</Styled.CheckboxItem>
</div>
</Ariakit.MenuItemCheckbox>
);
} );
9 changes: 6 additions & 3 deletions packages/components/src/menu/group-label.tsx
Original file line number Diff line number Diff line change
@@ -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 ) {
Expand All @@ -19,7 +21,7 @@ export const GroupLabel = forwardRef<
}

return (
<Styled.GroupLabel
<Ariakit.MenuGroupLabel
ref={ ref }
render={
// @ts-expect-error The `children` prop is passed
Expand All @@ -32,6 +34,7 @@ export const GroupLabel = forwardRef<
/>
}
{ ...props }
className={ clsx( styles[ 'group-label' ], className ) }
store={ menuContext.store }
/>
);
Expand Down
13 changes: 10 additions & 3 deletions packages/components/src/menu/group.tsx
Original file line number Diff line number Diff line change
@@ -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 ) {
Expand All @@ -17,6 +19,11 @@ export const Group = forwardRef<
}

return (
<Styled.Group ref={ ref } { ...props } store={ menuContext.store } />
<Ariakit.MenuGroup
ref={ ref }
{ ...props }
className={ clsx( styles.group, className ) }
store={ menuContext.store }
/>
);
} );
15 changes: 12 additions & 3 deletions packages/components/src/menu/item-help-text.tsx
Original file line number Diff line number Diff line change
@@ -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 ) {
Expand All @@ -15,5 +17,12 @@ export const ItemHelpText = forwardRef<
);
}

return <Styled.ItemHelpText numberOfLines={ 2 } ref={ ref } { ...props } />;
return (
<Truncate
numberOfLines={ 2 }
ref={ ref }
{ ...props }
className={ clsx( styles[ 'item-help-text' ], className ) }
/>
);
} );
15 changes: 12 additions & 3 deletions packages/components/src/menu/item-label.tsx
Original file line number Diff line number Diff line change
@@ -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 ) {
Expand All @@ -15,5 +17,12 @@ export const ItemLabel = forwardRef<
);
}

return <Styled.ItemLabel numberOfLines={ 1 } ref={ ref } { ...props } />;
return (
<Truncate
numberOfLines={ 1 }
ref={ ref }
{ ...props }
className={ clsx( styles[ 'item-label' ], className ) }
/>
);
} );
26 changes: 16 additions & 10 deletions packages/components/src/menu/item.tsx
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -10,6 +12,7 @@ export const Item = forwardRef<
WordPressComponentProps< ItemProps, 'div', false >
>( function UnforwardedItem(
{
className,
prefix,
suffix,
children,
Expand Down Expand Up @@ -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 (
<Styled.Item
<Ariakit.MenuItem
ref={ ref }
{ ...props }
className={ clsx( styles.item, className ) }
accessibleWhenDisabled
disabled={ disabled }
store={ computedStore }
hideOnClick={ computedHideOnClick }
>
<Styled.ItemPrefixWrapper>{ prefix }</Styled.ItemPrefixWrapper>
<span className={ styles[ 'item-prefix-wrapper' ] }>
{ prefix }
</span>

<Styled.ItemContentWrapper>
<Styled.ItemChildrenWrapper>
<div className={ styles[ 'item-content-wrapper' ] }>
<div className={ styles[ 'item-children-wrapper' ] }>
{ children }
</Styled.ItemChildrenWrapper>
</div>

{ suffix && (
<Styled.ItemSuffixWrapper>
<span className={ styles[ 'item-suffix-wrapper' ] }>
{ suffix }
</Styled.ItemSuffixWrapper>
</span>
) }
</Styled.ItemContentWrapper>
</Styled.Item>
</div>
</Ariakit.MenuItem>
);
} );
21 changes: 15 additions & 6 deletions packages/components/src/menu/popover.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx';
import * as Ariakit from '@ariakit/react';
import {
useContext,
Expand All @@ -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<
Expand Down Expand Up @@ -61,19 +62,27 @@ export const Popover = forwardRef<

const renderMenu = useCallback(
( htmlProps: React.ComponentPropsWithRef< 'div' > ) => (
<Styled.MenuMotionRoot>
<Styled.MenuSurface
<div className={ styles[ 'menu-motion-root' ] }>
<div
{ ...htmlProps }
variant={ menuContext.variant }
className={ clsx(
styles[ 'menu-surface' ],
htmlProps.className,
{
[ styles[ 'is-toolbar' ] ]:
menuContext.variant === 'toolbar',
}
) }
/>
</Styled.MenuMotionRoot>
</div>
),
[ menuContext.variant ]
);

return (
<Styled.Menu
<Ariakit.Menu
{ ...otherProps }
className={ clsx( styles.menu, otherProps.className ) }
ref={ ref }
modal={ modal }
store={ menuContext.store }
Expand Down
Loading
Loading