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

Add 'grid' variant to BlockPatternsList #66550

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Draft
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
89 changes: 69 additions & 20 deletions packages/block-editor/src/components/block-patterns-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import InserterDraggableBlocks from '../inserter-draggable-blocks';
import BlockPatternsPaging from '../block-patterns-paging';
import { INSERTER_PATTERN_TYPES } from '../inserter/block-patterns-tab/utils';

function chunk( array, size ) {
const chunks = [];
for ( let i = 0, j = array.length; i < j; i += size ) {
chunks.push( array.slice( i, i + size ) );
}
return chunks;
}

const WithToolTip = ( { showTooltip, title, children } ) => {
if ( showTooltip ) {
return <Tooltip text={ title }>{ children }</Tooltip>;
Expand Down Expand Up @@ -196,6 +204,7 @@ function BlockPatternsList(
showTitle = true,
showTitlesAsTooltip,
pagingProps,
variant,
},
ref
) {
Expand All @@ -211,34 +220,74 @@ function BlockPatternsList(
setActiveCompositeId( firstCompositeItemId );
}, [ shownPatterns, blockPatterns ] );

const isGridVariant = variant === 'grid';
return (
<Composite
orientation={ orientation }
activeId={ activeCompositeId }
setActiveId={ setActiveCompositeId }
role="listbox"
className="block-editor-block-patterns-list"
role={ isGridVariant ? 'grid' : 'listbox' }
className={ clsx( 'block-editor-block-patterns-list', {
[ `is-variant-${ variant }` ]: !! variant,
} ) }
aria-label={ label }
ref={ ref }
>
{ blockPatterns.map( ( pattern ) => {
const isShown = shownPatterns.includes( pattern );
return isShown ? (
<BlockPattern
key={ pattern.name }
id={ pattern.name }
pattern={ pattern }
onClick={ onClickPattern }
onHover={ onHover }
isDraggable={ isDraggable }
showTitle={ showTitle }
showTooltip={ showTitlesAsTooltip }
category={ category }
/>
) : (
<BlockPatternPlaceholder key={ pattern.name } />
);
} ) }
{ isGridVariant
? // The number of columns might need to be dynamic..
chunk( blockPatterns, 2 ).map( ( row, i ) => (
<Composite.Row
key={ i }
role="row"
className="block-editor-block-patterns-list__grid-row"
style={ {
gridTemplateColumns: '1fr 1fr',
} }
>
{ row.map( ( pattern ) => (
<Composite.Item
role="gridcell"
key={ pattern.name }
render={
shownPatterns.includes( pattern ) ? (
<BlockPattern
id={ pattern.name }
pattern={ pattern }
onClick={ onClickPattern }
onHover={ onHover }
isDraggable={ isDraggable }
showTitle={ showTitle }
showTooltip={
showTitlesAsTooltip
}
category={ category }
/>
) : (
<BlockPatternPlaceholder />
)
}
/>
) ) }
</Composite.Row>
) )
: blockPatterns.map( ( pattern ) => {
const isShown = shownPatterns.includes( pattern );
return isShown ? (
<BlockPattern
key={ pattern.name }
id={ pattern.name }
pattern={ pattern }
onClick={ onClickPattern }
onHover={ onHover }
isDraggable={ isDraggable }
showTitle={ showTitle }
showTooltip={ showTitlesAsTooltip }
category={ category }
/>
) : (
<BlockPatternPlaceholder key={ pattern.name } />
);
} ) }
{ pagingProps && <BlockPatternsPaging { ...pagingProps } /> }
</Composite>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,24 @@
}
}
}

.block-editor-block-patterns-list {
&.is-variant-grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: $grid-unit-15;
.block-editor-block-patterns-list__list-item {
margin-bottom: 0;
}
.block-editor-inserter__media-list__list-item {
min-height: 100px;
}

.block-editor-block-patterns-list__grid-row {
grid-column: 1 / -1;
box-sizing: border-box;
display: grid;
grid-gap: $grid-unit-15;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default function ChangeDesign( { clientId } ) {
blockPatterns={ sameCategoryPatternsWithSingleWrapper }
onClickPattern={ onClickPattern }
showTitle={ false }
variant="grid"
/>
</DropdownContentWrapper>
) }
Expand Down
12 changes: 1 addition & 11 deletions packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,8 @@
}
}

// TODO: check about the below styles..
.block-editor-block-toolbar-change-design-content-wrapper {
padding: $grid-unit-15;
width: 320px;
.block-editor-block-patterns-list {
display: grid;
grid-template-columns: 1fr 1fr;
grid-gap: $grid-unit-15;
.block-editor-block-patterns-list__list-item {
margin-bottom: 0;
}
.block-editor-inserter__media-list__list-item {
min-height: 100px;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
*/
import { useState, useMemo } from '@wordpress/element';
import { useDispatch } from '@wordpress/data';
import { Modal, SearchControl } from '@wordpress/components';
import {
Modal,
SearchControl,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { useAsyncList } from '@wordpress/compose';
import {
BlockContextProvider,
Expand Down Expand Up @@ -64,7 +68,7 @@ export default function PatternSelectionModal( {
onRequestClose={ () => setIsPatternSelectionModalOpen( false ) }
isFullScreen
>
<div className="block-library-query-pattern__selection-content">
<VStack spacing={ 0 }>
<div className="block-library-query-pattern__selection-search">
<SearchControl
__nextHasNoMarginBottom
Expand All @@ -79,9 +83,10 @@ export default function PatternSelectionModal( {
blockPatterns={ filteredBlockPatterns }
shownPatterns={ shownBlockPatterns }
onClickPattern={ onBlockPatternSelect }
variant="grid"
/>
</BlockContextProvider>
</div>
</VStack>
</Modal>
);
}
27 changes: 0 additions & 27 deletions packages/block-library/src/query/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,7 @@
padding: 0 $grid-unit-20 $grid-unit-20 52px;
}

.block-library-query__pattern-selection-content .block-editor-block-patterns-list {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
grid-gap: $grid-unit-10;

.block-editor-block-patterns-list__list-item {
margin-bottom: 0;
.block-editor-block-preview__container {
max-height: 250px;
}
}
}

.block-library-query-pattern__selection-modal {

.block-editor-block-patterns-list {
column-count: 2;
column-gap: $grid-unit-30;

@include break-wide() {
column-count: 3;
}

.block-editor-block-patterns-list__list-item {
break-inside: avoid-column;
}
}

.block-library-query-pattern__selection-search {
background: $white;
position: sticky;
Expand Down
Loading