Skip to content
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

Migrating PatternTransformationsMenu #56122

Merged
Merged
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
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
Loading