-
Notifications
You must be signed in to change notification settings - Fork 67
Expand file tree
/
Copy pathPagination.features.stories.tsx
More file actions
109 lines (95 loc) · 2.45 KB
/
Copy pathPagination.features.stories.tsx
File metadata and controls
109 lines (95 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React from 'react'
import type {Meta, StoryObj} from '@storybook/react'
import {INITIAL_VIEWPORTS} from 'storybook/viewport'
import {Pagination} from './Pagination'
import baseMeta from './Pagination.stories'
const meta = {
...baseMeta,
title: 'Components/Pagination/Features',
parameters: {
viewport: {
viewports: INITIAL_VIEWPORTS,
},
},
} satisfies Meta<typeof Pagination>
export default meta
type Story = StoryObj<typeof Pagination>
export const LargerPageCountMargin: Story = {
args: {
pageCount: 15,
currentPage: 5,
marginPageCount: 4,
},
}
export const HidePageNumbers: Story = {
args: {
pageCount: 15,
currentPage: 5,
showPages: false,
},
}
export const NarrowPageNumbersHiddenByDefault: Story = {
args: {
pageCount: 15,
currentPage: 5,
marginPageCount: 4,
},
globals: {
viewport: {value: 'iphonexr'},
},
}
export const HigherSurroundingPageCount: Story = {
args: {
pageCount: 15,
currentPage: 5,
surroundingPageCount: 4,
},
}
export const PageHandlers: Story = {
render: () => {
const PageHandlersComponent = () => {
const [currentPage, setCurrentPage] = React.useState(5)
const totalPages = 10
const _handlePageChange = (e: React.MouseEvent, pageNumber: number) => {
e.preventDefault()
if (pageNumber === currentPage + 1 && currentPage < totalPages) {
// Next page handler
setCurrentPage(currentPage + 1)
} else if (pageNumber === currentPage - 1 && currentPage > 1) {
// Previous page handler
setCurrentPage(currentPage - 1)
} else if (pageNumber >= 1 && pageNumber <= totalPages) {
setCurrentPage(pageNumber)
}
}
// eslint-disable-next-line no-console
console.log('currentPage: ', currentPage)
return <Pagination pageCount={10} currentPage={currentPage} onPageChange={_handlePageChange} />
}
return <PageHandlersComponent />
},
}
export const CustomAttributeForwarding: Story = {
args: {
pageCount: 15,
currentPage: 5,
surroundingPageCount: 4,
pageAttributesBuilder: n => {
return {
'data-custom-attribute': `custom-attribute-${n}`,
}
},
},
}
export const CustomLabels: Story = {
args: {
pageCount: 15,
currentPage: 5,
labels: {
prev: 'Précédent',
next: 'Suivant',
prevAriaLabel: 'Page précédente',
nextAriaLabel: 'Page suivante',
},
},
}