1
1
import { ChevronLeftIcon , ChevronRightIcon } from '@primer/octicons-react'
2
2
import type React from 'react'
3
3
import { useCallback , useMemo , useState } from 'react'
4
- import styled from 'styled-components'
5
- import { get } from '../constants'
6
4
import { Button } from '../internal/components/ButtonReset'
7
5
import { LiveRegion , LiveRegionOutlet , Message } from '../internal/components/LiveRegion'
8
6
import { VisuallyHidden } from '../VisuallyHidden'
9
7
import { warning } from '../utils/warning'
10
8
import type { ResponsiveValue } from '../hooks/useResponsiveValue'
11
9
import { viewportRanges } from '../hooks/useResponsiveValue'
12
10
import { buildPaginationModel } from '../Pagination/model'
13
-
14
- const StyledPagination = styled . nav `
15
- display: flex;
16
- align-items: center;
17
- justify-content: space-between;
18
- column-gap: 1rem;
19
- width: 100%;
20
- grid-area: footer;
21
- padding: 0.5rem 1rem;
22
- border: 1px solid ${ get ( 'colors.border.default' ) } ;
23
- border-top-width: 0;
24
- border-end-start-radius: 6px;
25
- border-end-end-radius: 6px;
26
-
27
- .TablePaginationRange {
28
- color: ${ get ( 'colors.fg.muted' ) } ;
29
- font-size: 0.75rem;
30
- margin: 0;
31
- }
32
-
33
- .TablePaginationSteps {
34
- display: flex;
35
- align-items: center;
36
- flex-wrap: wrap;
37
- list-style: none;
38
- color: ${ get ( 'colors.fg.default' ) } ;
39
- font-size: 0.875rem;
40
- margin: 0;
41
- padding: 0;
42
- }
43
-
44
- .TablePaginationStep:first-of-type {
45
- margin-right: 1rem;
46
- }
47
-
48
- .TablePaginationStep:last-of-type {
49
- margin-left: 1rem;
50
- }
51
-
52
- .TablePaginationAction {
53
- display: flex;
54
- align-items: center;
55
- color: ${ get ( 'colors.fg.muted' ) } ;
56
- font-size: 0.875rem;
57
- line-height: calc(20 / 14);
58
- user-select: none;
59
- padding: 0.5rem;
60
- border-radius: 6px;
61
- }
62
-
63
- .TablePaginationAction[data-has-page] {
64
- color: ${ get ( 'colors.accent.fg' ) } ;
65
- }
66
-
67
- .TablePaginationPage {
68
- min-width: 2rem;
69
- min-height: 2rem;
70
- display: flex;
71
- align-items: center;
72
- justify-content: center;
73
- font-size: 0.875rem;
74
- line-height: calc(20 / 14);
75
- user-select: none;
76
- border-radius: 6px;
77
- padding: 0.5rem calc((2rem - 1.25rem) / 2); /* primer.control.medium.paddingInline.condensed primer.control.medium.paddingBlock */
78
- }
79
-
80
- .TablePaginationAction[data-has-page]:hover,
81
- .TablePaginationAction[data-has-page]:focus,
82
- .TablePaginationPage:hover,
83
- .TablePaginationPage:focus {
84
- background-color: ${ get ( 'colors.actionListItem.default.hoverBg' ) } ;
85
- }
86
-
87
- .TablePaginationPage[data-active='true'] {
88
- background-color: ${ get ( 'colors.accent.emphasis' ) } ;
89
- color: ${ get ( 'colors.fg.onEmphasis' ) } ;
90
- }
91
-
92
- .TablePaginationPage[data-active='true']:focus-visible {
93
- outline: 2px solid var(--bgColor-accent-emphasis);
94
- outline-offset: -2px;
95
- box-shadow: inset 0 0 0 3px var(--fgColor-onEmphasis);
96
- }
97
-
98
- .TablePaginationTruncationStep {
99
- display: flex;
100
- align-items: center;
101
- justify-content: center;
102
- min-width: 2rem;
103
- min-height: 2rem;
104
- user-select: none;
105
- }
106
-
107
- ${
108
- // Hides pages based on the viewport range passed to `showPages`
109
- Object . keys ( viewportRanges )
110
- . map ( viewportRangeKey => {
111
- return `
112
- @media (${ viewportRanges [ viewportRangeKey as keyof typeof viewportRanges ] } ) {
113
- .TablePaginationSteps[data-hidden-viewport-ranges*='${ viewportRangeKey } '] > *:not(:first-child):not(:last-child) {
114
- display: none;
115
- }
116
-
117
- .TablePaginationSteps[data-hidden-viewport-ranges*='${ viewportRangeKey } '] > *:first-child {
118
- margin-inline-end: 0;
119
- }
120
-
121
- .TablePaginationSteps[data-hidden-viewport-ranges*='${ viewportRangeKey } '] > *:last-child {
122
- margin-inline-start: 0;
123
- }
124
- }
125
- `
126
- } )
127
- . join ( '' )
128
- }
129
- `
11
+ import classes from './Pagination.module.css'
12
+ import { clsx } from 'clsx'
130
13
131
14
export type PaginationProps = Omit < React . ComponentPropsWithoutRef < 'nav' > , 'onChange' > & {
132
15
/**
@@ -218,12 +101,15 @@ export function Pagination({
218
101
return (
219
102
< LiveRegion >
220
103
< LiveRegionOutlet />
221
- < StyledPagination aria-label = { label } className = " TablePagination" id = { id } >
104
+ < nav aria-label = { label } className = { clsx ( ' TablePagination' , classes . TablePagination ) } id = { id } >
222
105
< Range pageStart = { pageStart } pageEnd = { pageEnd } totalCount = { totalCount } />
223
- < ol className = "TablePaginationSteps" data-hidden-viewport-ranges = { getViewportRangesToHidePages ( ) . join ( ' ' ) } >
106
+ < ol
107
+ className = { clsx ( 'TablePaginationSteps' , classes . TablePaginationSteps ) }
108
+ data-hidden-viewport-ranges = { getViewportRangesToHidePages ( ) . join ( ' ' ) }
109
+ >
224
110
< Step >
225
111
< Button
226
- className = " TablePaginationAction"
112
+ className = { clsx ( ' TablePaginationAction' , classes . TablePaginationAction ) }
227
113
type = "button"
228
114
data-has-page = { hasPreviousPage ? true : undefined }
229
115
aria-disabled = { ! hasPreviousPage ? true : undefined }
@@ -235,7 +121,7 @@ export function Pagination({
235
121
} }
236
122
>
237
123
{ hasPreviousPage ? < ChevronLeftIcon /> : null }
238
- < span className = "TablePaginationActionLabel" > Previous</ span >
124
+ < span > Previous</ span >
239
125
< VisuallyHidden > page</ VisuallyHidden >
240
126
</ Button >
241
127
</ Step >
@@ -260,7 +146,7 @@ export function Pagination({
260
146
} ) }
261
147
< Step >
262
148
< Button
263
- className = " TablePaginationAction"
149
+ className = { clsx ( ' TablePaginationAction' , classes . TablePaginationAction ) }
264
150
type = "button"
265
151
data-has-page = { hasNextPage ? true : undefined }
266
152
aria-disabled = { ! hasNextPage ? true : undefined }
@@ -271,13 +157,13 @@ export function Pagination({
271
157
selectNextPage ( )
272
158
} }
273
159
>
274
- < span className = "TablePaginationActionLabel" > Next</ span >
160
+ < span > Next</ span >
275
161
< VisuallyHidden > page</ VisuallyHidden >
276
162
{ hasNextPage ? < ChevronRightIcon /> : null }
277
163
</ Button >
278
164
</ Step >
279
165
</ ol >
280
- </ StyledPagination >
166
+ </ nav >
281
167
</ LiveRegion >
282
168
)
283
169
}
@@ -294,7 +180,7 @@ function Range({pageStart, pageEnd, totalCount}: RangeProps) {
294
180
return (
295
181
< >
296
182
< Message value = { `Showing ${ start } through ${ end } of ${ totalCount } ` } />
297
- < p className = " TablePaginationRange" >
183
+ < p className = { clsx ( ' TablePaginationRange' , classes . TablePaginationRange ) } >
298
184
{ start }
299
185
< VisuallyHidden > through </ VisuallyHidden >
300
186
< span aria-hidden = "true" > ‒</ span >
@@ -306,14 +192,14 @@ function Range({pageStart, pageEnd, totalCount}: RangeProps) {
306
192
307
193
function TruncationStep ( ) {
308
194
return (
309
- < li aria-hidden = "true" className = " TablePaginationTruncationStep" >
195
+ < li aria-hidden = "true" className = { clsx ( ' TablePaginationTruncationStep' , classes . TablePaginationTruncationStep ) } >
310
196
…
311
197
</ li >
312
198
)
313
199
}
314
200
315
201
function Step ( { children} : React . PropsWithChildren ) {
316
- return < li className = " TablePaginationStep" > { children } </ li >
202
+ return < li className = { clsx ( ' TablePaginationStep' , classes . TablePaginationStep ) } > { children } </ li >
317
203
}
318
204
319
205
type PageProps = React . PropsWithChildren < {
@@ -324,7 +210,7 @@ type PageProps = React.PropsWithChildren<{
324
210
function Page ( { active, children, onClick} : PageProps ) {
325
211
return (
326
212
< Button
327
- className = " TablePaginationPage"
213
+ className = { clsx ( ' TablePaginationPage' , classes . TablePaginationPage ) }
328
214
type = "button"
329
215
data-active = { active ? true : undefined }
330
216
aria-current = { active ? true : undefined }
0 commit comments