/** * WordPress dependencies */ import { cloneBlock } from '@safe-wordpress/blocks'; import { VisuallyHidden } from '@safe-wordpress/components'; import { useInstanceId } from '@safe-wordpress/compose'; import { _x } from '@safe-wordpress/i18n'; import { BlockPreview } from '@safe-wordpress/block-editor'; import type { BlockInstance } from '@safe-wordpress/blocks'; /** * External dependencies */ import { map } from 'lodash'; import type { PopupPattern } from '@nelio/popups/types'; /** * Component adapted from Gutenberg codebase. Use the Gutenberg one instead * when it is exported publicly. * See https://github.com/WordPress/gutenberg/pull/42148 */ type BlockPatternType = { readonly pattern: PopupPattern; readonly onClick: ( pattern: PopupPattern, blocks: ReadonlyArray< BlockInstance > ) => void; }; const BlockPattern = ( { pattern, onClick, }: BlockPatternType ): JSX.Element => { const { blocks, viewportWidth } = pattern; const instanceId = useInstanceId( BlockPattern ); const descriptionId = `block-editor-block-patterns-list__item-description-${ instanceId }`; return (
onClick( pattern, blocks ) } onKeyUp={ ( event ) => { if ( 'Enter' === event.key ) { onClick( pattern, blocks ); } } } tabIndex={ -1 } > cloneBlock( block ) ) } viewportWidth={ viewportWidth } />
{ pattern.title }
{ !! pattern.description && ( { pattern.description } ) }
); }; type BlockPatternListType = { readonly blockPatterns: ReadonlyArray< PopupPattern >; readonly onClickPattern: ( pattern: PopupPattern, blocks: ReadonlyArray< BlockInstance > ) => void; }; const BlockPatternList = ( { blockPatterns, onClickPattern, }: BlockPatternListType ): JSX.Element => { return (
{ blockPatterns.map( ( pattern ) => { return ( ); } ) }
); }; export default BlockPatternList;