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

added option to show dropdown in pagination #1467

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
20 changes: 16 additions & 4 deletions src/theme/mermaid/pagination.scss
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,35 @@
outline: none;
user-select: none;
}

button:focus {
select {
padding: 6px 14px;
border: 1px solid $gray4;
background-color: $white;
border-right: none;
outline: none;
user-select: none;
}
button:focus,
select:focus {
box-shadow: 0 0 0 2px rgba(149, 189, 243, 0.5);
position: relative;
margin-right: -1px;
border-right: 1px solid $gray4;
}

button:hover {
button:hover,
select:hover {
background-color: $gray2;
color: $darkBlue1;
outline: none;
}

button:disabled,
button[disabled],
button:hover:disabled {
button:hover:disabled,
select:disabled,
select[disabled],
select:hover:disabled {
cursor: default;
background-color: $white;
color: $gray5;
Expand Down
22 changes: 21 additions & 1 deletion src/view/plugin/pagination.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { h, Fragment } from 'preact';
import { h, Fragment, JSX } from 'preact';
import PaginationLimit from '../../pipeline/limit/pagination';
import { classJoin, className } from '../../util/className';
import ServerPaginationLimit from '../../pipeline/limit/serverPagination';
Expand All @@ -14,6 +14,7 @@ export interface PaginationConfig {
prevButton?: boolean;
buttonsCount?: number;
resetPageOnUpdate?: boolean;
showDropdown?: boolean;
server?: {
url?: (prevUrl: string, page: number, limit: number) => string;
body?: (prevBody: BodyInit, page: number, limit: number) => BodyInit;
Expand All @@ -27,6 +28,7 @@ export function Pagination() {
summary = true,
nextButton = true,
prevButton = true,
showDropdown = false,
buttonsCount = 3,
limit = 10,
page = 0,
Expand Down Expand Up @@ -224,6 +226,12 @@ export function Pagination() {
);
};

function handlePageChange(event: JSX.TargetedMouseEvent<HTMLSelectElement>) {
if (event.target instanceof HTMLSelectElement) {
setPage(parseInt(event.target.value, 10));
}
}

return (
<div
className={classJoin(
Expand Down Expand Up @@ -253,6 +261,18 @@ export function Pagination() {

{renderPages()}

{showDropdown && (<select
value={currentPage}
onChange={handlePageChange}
aria-label={_('pagination.selectPage')}
>
{Array.from({ length: pages() }, (_, index) => (
<option key={index} value={index} selected={index === currentPage}>
{index + 1}
</option>
))}
</select>)}

{nextButton && (
<button
tabIndex={0}
Expand Down