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

Always show the total number of patterns even with only one page #54813

Merged
merged 3 commits into from
Sep 26, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ function BlockPatternList(
<BlockPatternPlaceholder key={ pattern.name } />
);
} ) }
{ pagingProps && pagingProps.numPages > 1 && (
<BlockPatternsPaging { ...pagingProps } />
) }
{ pagingProps && <BlockPatternsPaging { ...pagingProps } /> }
</Composite>
);
}
Expand Down
111 changes: 57 additions & 54 deletions packages/block-editor/src/components/block-patterns-paging/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,66 +27,69 @@ export default function Pagination( {
)
}
</Text>
<HStack
expanded={ false }
spacing={ 3 }
justify="flex-start"
className="block-editor-patterns__grid-pagination"
>
<HStack
expanded={ false }
spacing={ 1 }
className="block-editor-patterns__grid-pagination-previous"
>
<Button
variant="tertiary"
onClick={ () => changePage( 1 ) }
disabled={ currentPage === 1 }
aria-label={ __( 'First page' ) }
>
<span>«</span>
</Button>
<Button
variant="tertiary"
onClick={ () => changePage( currentPage - 1 ) }
disabled={ currentPage === 1 }
aria-label={ __( 'Previous page' ) }
>
<span>‹</span>
</Button>
</HStack>
<Text variant="muted">
{ sprintf(
// translators: %1$s: Current page number, %2$s: Total number of pages.
_x( '%1$s of %2$s', 'paging' ),
currentPage,
numPages
) }
</Text>

{ numPages > 1 && (
<HStack
expanded={ false }
spacing={ 1 }
className="block-editor-patterns__grid-pagination-next"
spacing={ 3 }
justify="flex-start"
className="block-editor-patterns__grid-pagination"
>
<Button
variant="tertiary"
onClick={ () => changePage( currentPage + 1 ) }
disabled={ currentPage === numPages }
aria-label={ __( 'Next page' ) }
<HStack
expanded={ false }
spacing={ 1 }
className="block-editor-patterns__grid-pagination-previous"
>
<span>›</span>
</Button>
<Button
variant="tertiary"
onClick={ () => changePage( numPages ) }
disabled={ currentPage === numPages }
aria-label={ __( 'Last page' ) }
size="default"
<Button
variant="tertiary"
onClick={ () => changePage( 1 ) }
disabled={ currentPage === 1 }
aria-label={ __( 'First page' ) }
>
<span>«</span>
</Button>
<Button
variant="tertiary"
onClick={ () => changePage( currentPage - 1 ) }
disabled={ currentPage === 1 }
aria-label={ __( 'Previous page' ) }
>
<span>‹</span>
</Button>
</HStack>
<Text variant="muted">
{ sprintf(
// translators: %1$s: Current page number, %2$s: Total number of pages.
_x( '%1$s of %2$s', 'paging' ),
currentPage,
numPages
) }
</Text>
<HStack
expanded={ false }
spacing={ 1 }
className="block-editor-patterns__grid-pagination-next"
>
<span>»</span>
</Button>
<Button
variant="tertiary"
onClick={ () => changePage( currentPage + 1 ) }
disabled={ currentPage === numPages }
aria-label={ __( 'Next page' ) }
>
<span>›</span>
</Button>
<Button
variant="tertiary"
onClick={ () => changePage( numPages ) }
disabled={ currentPage === numPages }
aria-label={ __( 'Last page' ) }
size="default"
>
<span>»</span>
</Button>
</HStack>
</HStack>
</HStack>
) }
</VStack>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,17 @@ function PatternList( { searchValue, selectedCategory, patternCategories } ) {

<InserterListbox>
{ hasItems && (
<BlockPatternsList
shownPatterns={ pagingProps.categoryPatternsAsyncList }
blockPatterns={ pagingProps.categoryPatterns }
onClickPattern={ onClickPattern }
isDraggable={ false }
/>
) }
{ pagingProps.numPages > 1 && (
<BlockPatternsPaging { ...pagingProps } />
<>
<BlockPatternsList
shownPatterns={
pagingProps.categoryPatternsAsyncList
}
blockPatterns={ pagingProps.categoryPatterns }
onClickPattern={ onClickPattern }
isDraggable={ false }
/>
<BlockPatternsPaging { ...pagingProps } />
</>
) }
</InserterListbox>
</div>
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,7 @@ $block-inserter-tabs-height: 44px;
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);
Expand Down
Loading