Skip to content

Commit

Permalink
Migrating PatternTransformationsMenu (WordPress#56122)
Browse files Browse the repository at this point in the history
Migrating `PatternTransformationsMenu` to use new `Composite` implementation

 - Removes `__unstableComposite` imports from `@wordpress/components`
 - Adds private `Composite*` exports from `@wordpress/components`
 - Refactors `BlockPatternsList` and `BlockPattern` to use updated `Composite` components
  • Loading branch information
Andrew Hayward authored Nov 15, 2023
1 parent e131e6e commit 397320e
Showing 1 changed file with 20 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,21 @@ import {
MenuItem,
Popover,
VisuallyHidden,
__unstableComposite as Composite,
__unstableUseCompositeState as useCompositeState,
__unstableCompositeItem as CompositeItem,
privateApis as componentsPrivateApis,
} from '@wordpress/components';

/**
* Internal dependencies
*/
import BlockPreview from '../block-preview';
import useTransformedPatterns from './use-transformed-patterns';
import { unlock } from '../../lock-unlock';

const {
CompositeV2: Composite,
CompositeItemV2: CompositeItem,
useCompositeStoreV2: useCompositeStore,
} = unlock( componentsPrivateApis );

function PatternTransformationsMenu( {
blocks,
Expand Down Expand Up @@ -73,10 +78,10 @@ function PreviewPatternsPopover( { patterns, onSelect } ) {
}

function BlockPatternsList( { patterns, onSelect } ) {
const composite = useCompositeState();
const composite = useCompositeStore();
return (
<Composite
{ ...composite }
store={ composite }
role="listbox"
className="block-editor-block-switcher__preview-patterns-container"
aria-label={ __( 'Patterns list' ) }
Expand All @@ -86,14 +91,13 @@ function BlockPatternsList( { patterns, onSelect } ) {
key={ pattern.name }
pattern={ pattern }
onSelect={ onSelect }
composite={ composite }
/>
) ) }
</Composite>
);
}

function BlockPattern( { pattern, onSelect, composite } ) {
function BlockPattern( { pattern, onSelect } ) {
// TODO check pattern/preview width...
const baseClassName =
'block-editor-block-switcher__preview-patterns-container';
Expand All @@ -104,14 +108,16 @@ function BlockPattern( { pattern, onSelect, composite } ) {
return (
<div className={ `${ baseClassName }-list__list-item` }>
<CompositeItem
role="option"
as="div"
{ ...composite }
aria-label={ pattern.title }
aria-describedby={
pattern.description ? descriptionId : undefined
render={
<div
role="option"
aria-label={ pattern.title }
aria-describedby={
pattern.description ? descriptionId : undefined
}
className={ `${ baseClassName }-list__item` }
/>
}
className={ `${ baseClassName }-list__item` }
onClick={ () => onSelect( pattern.transformedBlocks ) }
>
<BlockPreview
Expand Down

0 comments on commit 397320e

Please sign in to comment.