Skip to content

Commit b93b2c4

Browse files
authored
Merge pull request #69 from oasisprotocol/mz/paginationFix-2
Tweak Pagination component
2 parents 6ae23f5 + e9910a2 commit b93b2c4

2 files changed

Lines changed: 70 additions & 3 deletions

File tree

src/components/pagination/index.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@ import * as React from 'react'
22
import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react'
33

44
import { cn } from '../../lib/utils'
5-
import { PaginationContent, PaginationEllipsis, PaginationItem } from '../ui/pagination'
5+
import {
6+
PaginationContent,
7+
PaginationEllipsis as BasePaginationEllipsis,
8+
PaginationItem,
9+
} from '../ui/pagination'
610
import { buttonVariants } from '../ui/button'
711

12+
const PaginationEllipsis = ({ className, ...props }: React.ComponentProps<typeof BasePaginationEllipsis>) => {
13+
return <BasePaginationEllipsis className={cn('max-md:size-5', className)} {...props} />
14+
}
15+
816
type PaginationActionType = 'first' | 'last' | 'page' | 'next' | 'prev'
917

1018
interface PaginationItemProps {
@@ -303,6 +311,10 @@ function Pagination({
303311
}
304312
}
305313

314+
if (isTotalCountClipped) {
315+
items.push(<PaginationEllipsis key="ellipsis-right-total-count-clipped" />)
316+
}
317+
306318
const nextItem: PaginationItemProps = {
307319
type: 'next',
308320
page: selectedPage < count ? selectedPage + 1 : undefined,
@@ -397,7 +409,7 @@ function PaginationLink<C extends React.ElementType = 'a'>({
397409
data-active={selected}
398410
data-disabled={disabled}
399411
className={cn(
400-
'cursor-pointer',
412+
'max-md:size-8',
401413
buttonVariants({
402414
variant: selected ? 'outline' : 'ghost',
403415
size: 'icon',

src/stories/Pagination/Pagination.stories.tsx

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const meta = {
2525
},
2626
isTotalCountClipped: {
2727
description: 'Whether total_count is clipped for performance reasons.',
28-
control: 'number',
28+
control: 'boolean',
2929
},
3030
onPageChange: {
3131
description: 'Optional callback function that is called when a page is selected.',
@@ -58,3 +58,58 @@ export const Default: Story = {
5858
await expect(activePage).toHaveAttribute('aria-current', 'page')
5959
},
6060
}
61+
62+
export const OnePage: Story = {
63+
args: {
64+
totalCount: 6,
65+
selectedPage: 1,
66+
rowsPerPage: 10,
67+
showFirstPageButton: true,
68+
showLastPageButton: true,
69+
isTotalCountClipped: false,
70+
},
71+
}
72+
73+
export const TwoPages: Story = {
74+
args: {
75+
totalCount: 12,
76+
selectedPage: 1,
77+
rowsPerPage: 10,
78+
showFirstPageButton: true,
79+
showLastPageButton: true,
80+
isTotalCountClipped: false,
81+
},
82+
}
83+
84+
export const FirstOfMany: Story = {
85+
args: {
86+
totalCount: 614,
87+
selectedPage: 1,
88+
rowsPerPage: 10,
89+
showFirstPageButton: true,
90+
showLastPageButton: true,
91+
isTotalCountClipped: false,
92+
},
93+
}
94+
95+
export const FirstWithClippedTotal: Story = {
96+
args: {
97+
totalCount: 1000,
98+
selectedPage: 1,
99+
rowsPerPage: 10,
100+
showFirstPageButton: true,
101+
showLastPageButton: true,
102+
isTotalCountClipped: true,
103+
},
104+
}
105+
106+
export const WithClippedTotalWithinRange: Story = {
107+
args: {
108+
totalCount: 1000,
109+
selectedPage: 10,
110+
rowsPerPage: 10,
111+
showFirstPageButton: true,
112+
showLastPageButton: true,
113+
isTotalCountClipped: true,
114+
},
115+
}

0 commit comments

Comments
 (0)