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
1 change: 1 addition & 0 deletions packages/block-editor/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Enhancements

- Patterns explorer: Refactor the category sidebar to use `Tabs` ([#81807](https://github.com/WordPress/gutenberg/pull/81807)).
- Show separate horizontal and vertical block spacing controls in the block inspector only for Flex and Grid layouts, while retaining axial gap support in Global Styles. Responsive Grid column calculations use the horizontal gap, while Flow and Constrained layouts use the vertical gap when receiving an axial value ([#81476](https://github.com/WordPress/gutenberg/pull/81476)).

### Bug Fixes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Modal } from '@wordpress/components';
import { Tabs } from '@wordpress/ui';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import PatternExplorerSidebar from './pattern-explorer-sidebar';
Expand All @@ -14,22 +15,34 @@ function PatternsExplorer( { initialCategory, rootClientId, onModalClose } ) {
const patternCategories = usePatternCategories( rootClientId );

return (
<div className="block-editor-block-patterns-explorer">
<Tabs.Root
className="block-editor-block-patterns-explorer"
orientation="vertical"
value={ selectedCategory }
onValueChange={ setSelectedCategory }
>
<PatternExplorerSidebar
selectedCategory={ selectedCategory }
patternCategories={ patternCategories }
onClickCategory={ setSelectedCategory }
searchValue={ searchValue }
setSearchValue={ setSearchValue }
/>
<PatternList
searchValue={ searchValue }
selectedCategory={ selectedCategory }
patternCategories={ patternCategories }
rootClientId={ rootClientId }
onModalClose={ onModalClose }
/>
</div>
{ patternCategories.map( ( { name } ) => (
<Tabs.Panel
key={ name }
value={ name }
tabIndex={ -1 }
className="block-editor-block-patterns-explorer__panel"
>
<PatternList
searchValue={ searchValue }
selectedCategory={ name }
patternCategories={ patternCategories }
rootClientId={ rootClientId }
onModalClose={ onModalClose }
/>
</Tabs.Panel>
) ) }
</Tabs.Root>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,32 @@
import { Button, SearchControl } from '@wordpress/components';
import { SearchControl } from '@wordpress/components';
import { Stack, Tabs } from '@wordpress/ui';
import { __ } from '@wordpress/i18n';

function PatternCategoriesList( {
selectedCategory,
function PatternExplorerSidebar( {
patternCategories,
onClickCategory,
searchValue,
setSearchValue,
} ) {
const baseClassName = 'block-editor-block-patterns-explorer__sidebar';
return (
<div className={ `${ baseClassName }__categories-list` }>
{ patternCategories.map( ( { name, label } ) => {
return (
<Button
__next40pxDefaultSize
key={ name }
label={ label }
className={ `${ baseClassName }__categories-list__item` }
isPressed={ selectedCategory === name }
onClick={ () => {
onClickCategory( name );
} }
>
{ label }
</Button>
);
} ) }
</div>
);
}

function PatternsExplorerSearch( { searchValue, setSearchValue } ) {
const baseClassName = 'block-editor-block-patterns-explorer__search';
return (
<div className={ baseClassName }>
<Stack
direction="column"
gap="lg"
className="block-editor-block-patterns-explorer__sidebar"
>
<SearchControl
onChange={ setSearchValue }
value={ searchValue }
label={ __( 'Search' ) }
placeholder={ __( 'Search' ) }
/>
</div>
);
}

function PatternExplorerSidebar( {
selectedCategory,
patternCategories,
onClickCategory,
searchValue,
setSearchValue,
} ) {
const baseClassName = 'block-editor-block-patterns-explorer__sidebar';
return (
<div className={ baseClassName }>
<PatternsExplorerSearch
searchValue={ searchValue }
setSearchValue={ setSearchValue }
/>
{ ! searchValue && (
<PatternCategoriesList
selectedCategory={ selectedCategory }
patternCategories={ patternCategories }
onClickCategory={ onClickCategory }
/>
) }
</div>
<Tabs.List>
{ patternCategories.map( ( { name, label } ) => (
<Tabs.Tab key={ name } value={ name }>
{ label }
</Tabs.Tab>
) ) }
</Tabs.List>
</Stack>
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useMemo, useEffect, useRef, useState } from '@wordpress/element';
import { _n, sprintf } from '@wordpress/i18n';
import { __, _n, sprintf } from '@wordpress/i18n';
import { useDebounce } from '@wordpress/compose';
import { __experimentalHeading as Heading } from '@wordpress/components';
import { Text } from '@wordpress/ui';
import { speak } from '@wordpress/a11y';
import BlockPatternsList from '../../block-patterns-list';
import useInsertionPoint from '../hooks/use-insertion-point';
import usePatternsState from '../hooks/use-patterns-state';
import InserterListbox from '../../inserter-listbox';
import { searchItems } from '../search-items';
import BlockPatternsPaging from '../../block-patterns-paging';
import usePatternsPaging from '../hooks/use-patterns-paging';
Expand All @@ -17,30 +16,6 @@ import {
starterPatternsCategory,
} from '../block-patterns-tab/utils';

function PatternsListHeader( { filterValue, filteredBlockPatternsLength } ) {
if ( ! filterValue ) {
return null;
}

return (
<Heading
level={ 2 }
lineHeight="48px"
className="block-editor-block-patterns-explorer__search-results-count"
>
{ sprintf(
/* translators: %d: number of patterns. */
_n(
'%d pattern found',
'%d patterns found',
filteredBlockPatternsLength
),
filteredBlockPatternsLength
) }
</Heading>
);
}

function PatternList( {
searchValue,
selectedCategory,
Expand Down Expand Up @@ -143,26 +118,26 @@ function PatternList( {
className="block-editor-block-patterns-explorer__list"
ref={ container }
>
<PatternsListHeader
filterValue={ searchValue }
filteredBlockPatternsLength={ filteredBlockPatterns.length }
/>

<InserterListbox>
{ hasItems && (
<>
<BlockPatternsList
blockPatterns={ pagingProps.categoryPatterns }
onClickPattern={ ( pattern, blocks ) => {
onClickPattern( pattern, blocks );
onModalClose();
} }
isDraggable={ false }
/>
<BlockPatternsPaging { ...pagingProps } />
</>
) }
</InserterListbox>
{ hasItems ? (
<>
<BlockPatternsList
blockPatterns={ pagingProps.categoryPatterns }
onClickPattern={ ( pattern, blocks ) => {
onClickPattern( pattern, blocks );
onModalClose();
} }
isDraggable={ false }
/>
<BlockPatternsPaging { ...pagingProps } />
</>
) : (
<Text
render={ <p /> }
className="block-editor-block-patterns-explorer__no-results"
>
{ __( 'No results found.' ) }
</Text>
) }
</div>
);
}
Expand Down
80 changes: 38 additions & 42 deletions packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -392,66 +392,62 @@ $block-inserter-tabs-height: 44px;
}
}

.block-editor-block-patterns-explorer {
&__sidebar {
.block-editor-block-patterns-explorer__sidebar {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nesting CSS selectors like &__element is generally not recommended in Gutenberg, so I have expanded it here.

padding-bottom: $grid-unit-30;

@include break-medium() {
position: absolute;
top: $header-height + $grid-unit-10;
left: 0;
bottom: 0;
width: $sidebar-width;
padding: $grid-unit-30 $grid-unit-30 $grid-unit-30;
padding: $grid-unit-30;
overflow-x: visible;
overflow-y: auto;

&__categories-list__item {
display: block;
width: 100%;
height: 48px;
text-align: left;
}
}
}

&__search {
margin-bottom: $grid-unit-40;
.block-editor-block-patterns-explorer__panel {
@include break-medium() {
margin-inline-start: $sidebar-width;
}
}

&__search-results-count {
padding-bottom: $grid-unit-40;
}
.block-editor-block-patterns-explorer__no-results {
padding: $grid-unit-40;
text-align: center;
}

&__list {
margin-left: $sidebar-width;
padding: $grid-unit-30 0 $grid-unit-40;
.block-editor-patterns__sync-status-filter {
.components-input-control__container {
width: 380px;
}
}
.block-editor-block-patterns-explorer__list {
padding: $grid-unit-30 0 $grid-unit-40;

.block-editor-patterns__sync-status-filter .components-input-control__container {
width: 380px;
}
}

.block-editor-block-patterns-list {
display: grid;
grid-gap: $grid-unit-40;
grid-template-columns: repeat(1, 1fr);
margin-bottom: $grid-unit-20;
.block-editor-block-patterns-explorer .block-editor-block-patterns-list {
display: grid;
grid-gap: $grid-unit-40;
grid-template-columns: repeat(1, 1fr);
margin-bottom: $grid-unit-20;

@include break-xlarge() {
grid-template-columns: repeat(2, 1fr);
}
@include break-xlarge() {
grid-template-columns: repeat(2, 1fr);
}

@include break-huge() {
grid-template-columns: repeat(3, 1fr);
}
@include break-huge() {
grid-template-columns: repeat(3, 1fr);
}

.block-editor-block-patterns-list__list-item {
min-height: 240px;
}
.block-editor-block-patterns-list__list-item {
min-height: 240px;
}

.block-editor-inserter__media-list__list-item {
height: inherit;
min-height: 100px;
max-height: 800px;
}
.block-editor-inserter__media-list__list-item {
height: inherit;
min-height: 100px;
max-height: 800px;
}
}

Expand Down
5 changes: 0 additions & 5 deletions tools/eslint/suppressions.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,6 @@
"count": 2
}
},
"packages/block-editor/src/components/inserter/block-patterns-explorer/pattern-list.js": {
"@wordpress/use-recommended-components": {
"count": 1
}
},
"packages/block-editor/src/components/inserter/block-patterns-tab/pattern-category-previews.js": {
"@wordpress/use-recommended-components": {
"count": 5
Expand Down
Loading