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

Apply minimal variant to pagination dropdown #63815

Merged
merged 16 commits into from
Aug 13, 2024
Merged
51 changes: 35 additions & 16 deletions packages/dataviews/src/components/dataviews-pagination/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,31 @@ function DataViewsPagination() {
onChangeView,
paginationInfo: { totalItems = 0, totalPages },
} = useContext( DataViewsContext );

if ( ! totalItems || ! totalPages ) {
return null;
}

const currentPage = view.page ?? 1;
const pageSelectOptions = Array.from( Array( totalPages ) ).map(
( _, i ) => {
const page = i + 1;
return {
value: page.toString(),
label: page.toString(),
'aria-label':
currentPage === page
? sprintf(
// translators: Current page number in total number of pages
__( 'Page %1$s of %2$s' ),
currentPage,
totalPages
)
: page.toString(),
};
}
);

return (
!! totalItems &&
totalPages !== 1 && (
Expand All @@ -37,37 +58,35 @@ function DataViewsPagination() {
<HStack
justify="flex-start"
expanded={ false }
spacing={ 2 }
className="dataviews-pagination__page-selection"
spacing={ 1 }
className="dataviews-pagination__page-select"
>
{ createInterpolateElement(
sprintf(
// translators: %s: Total number of pages.
_x( 'Page <CurrentPageControl /> of %s', 'paging' ),
// translators: 1: Current page number, 2: Total number of pages.
_x(
'<div>Page</div>%1$s<div>of %2$s</div>',
'paging'
),
'<CurrentPage />',
totalPages
),
{
CurrentPageControl: (
div: <div aria-hidden />,
CurrentPage: (
<SelectControl
aria-label={ __( 'Current page' ) }
value={ view.page?.toString() }
options={ Array.from(
Array( totalPages )
).map( ( _, i ) => {
const page = i + 1;
return {
value: page.toString(),
label: page.toString(),
};
} ) }
value={ currentPage.toString() }
options={ pageSelectOptions }
onChange={ ( newValue ) => {
onChangeView( {
...view,
page: +newValue,
} );
} }
size="compact"
size="small"
__nextHasNoMarginBottom
variant="minimal"
/>
),
}
Expand Down
13 changes: 10 additions & 3 deletions packages/dataviews/src/components/dataviews-pagination/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@
@include reduce-motion("transition");
}

.dataviews-pagination__page-selection {
.dataviews-pagination__page-select {
color: $gray-900;
Copy link
Contributor

Choose a reason for hiding this comment

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

If we remove this style, the color override appears not to be necessary:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good spot!

font-size: 11px;
text-transform: uppercase;
font-weight: 500;
color: $gray-900;
text-transform: uppercase;

@include break-small() {
.components-select-control__input {
font-size: 11px !important;
font-weight: 500;
}
}
}

/* stylelint-disable-next-line scss/at-rule-no-unknown -- '@container' not globally permitted */
Expand Down
Loading