Skip to content

Commit 567a6a8

Browse files
authored
Merge 6319596 into 159d124
2 parents 159d124 + 6319596 commit 567a6a8

File tree

3 files changed

+15
-184
lines changed

3 files changed

+15
-184
lines changed

.changeset/nasty-nails-appear.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': minor
3+
---
4+
5+
Remove CSS modules flag from Pagination.

packages/react/src/Pagination/Pagination.stories.tsx

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,4 @@ Playground.argTypes = {
7878
disable: true,
7979
},
8080
},
81-
theme: {
82-
control: false,
83-
table: {
84-
disable: true,
85-
},
86-
},
8781
}

packages/react/src/Pagination/Pagination.tsx

Lines changed: 10 additions & 178 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import React from 'react'
2-
import styled from 'styled-components'
32
import Box from '../Box'
4-
import {get} from '../constants'
53
import type {SxProp} from '../sx'
6-
import sx from '../sx'
74
import {buildComponentData, buildPaginationModel, type PageDataProps} from './model'
85
import type {ResponsiveValue} from '../hooks/useResponsiveValue'
96
import {viewportRanges} from '../hooks/useResponsiveValue'
10-
import {toggleStyledComponent} from '../internal/utils/toggleStyledComponent'
11-
import {useFeatureFlag} from '../FeatureFlags'
7+
import {toggleSxComponent} from '../internal/utils/toggleSxComponent'
128
import {clsx} from 'clsx'
139
import classes from './Pagination.module.css'
1410

15-
const CSS_MODULES_FEATURE_FLAG = 'primer_react_css_modules_ga'
16-
1711
const getViewportRangesToHidePages = (showPages: PaginationProps['showPages']) => {
1812
if (showPages && typeof showPages !== 'boolean') {
1913
return Object.keys(showPages).filter(key => !showPages[key as keyof typeof viewportRanges]) as Array<
@@ -28,124 +22,6 @@ const getViewportRangesToHidePages = (showPages: PaginationProps['showPages']) =
2822
}
2923
}
3024

31-
const Page = toggleStyledComponent(
32-
CSS_MODULES_FEATURE_FLAG,
33-
'a',
34-
styled.a`
35-
display: inline-block;
36-
min-width: 32px; /* primer.control.medium.size */
37-
height: 32px; /* primer.control.medium.size */
38-
padding: 0.5rem calc((2rem - 1.25rem) / 2); /* primer.control.medium.paddingInline.condensed primer.control.medium.paddingBlock */
39-
font-style: normal;
40-
line-height: 1;
41-
color: ${get('colors.fg.default')};
42-
text-align: center;
43-
white-space: nowrap;
44-
vertical-align: middle;
45-
cursor: pointer;
46-
user-select: none;
47-
text-decoration: none;
48-
49-
margin-right: ${get('space.1')};
50-
51-
&:last-child {
52-
margin-right: 0;
53-
}
54-
55-
background-color: transparent;
56-
border-radius: ${get('radii.2')};
57-
transition: background-color 0.2s cubic-bezier(0.3, 0, 0.5, 1);
58-
59-
&:hover,
60-
&:focus {
61-
text-decoration: none;
62-
background-color: ${get('colors.actionListItem.default.hoverBg')};
63-
outline: 0;
64-
transition-duration: 0.1s;
65-
}
66-
67-
&:focus-visible {
68-
outline: 2px solid ${get('colors.accent.emphasis')};
69-
outline-offset: -2px;
70-
}
71-
72-
&:active {
73-
border-color: ${get('colors.border.muted')};
74-
}
75-
76-
&[rel='prev'],
77-
&[rel='next'] {
78-
color: ${get('colors.accent.fg')};
79-
}
80-
81-
&[aria-current],
82-
&[aria-current]:hover {
83-
color: ${get('colors.fg.onEmphasis')};
84-
background-color: ${get('colors.accent.emphasis')};
85-
border-color: transparent;
86-
}
87-
88-
&[aria-current]:focus-visible {
89-
outline: 2px solid ${get('colors.accent.emphasis')};
90-
outline-offset: -2px;
91-
box-shadow: inset 0 0 0 3px ${get('colors.fg.onEmphasis')};
92-
}
93-
94-
&[aria-hidden],
95-
&[aria-hidden]:hover,
96-
&[role='presentation'],
97-
&[role='presentation']:hover {
98-
color: ${get('colors.primer.fg.disabled')}; // check
99-
cursor: default;
100-
background-color: transparent;
101-
}
102-
103-
@supports (clip-path: polygon(50% 0, 100% 50%, 50% 100%)) {
104-
&[rel='prev']::before,
105-
&[rel='next']::after {
106-
display: inline-block;
107-
width: 16px;
108-
height: 16px;
109-
vertical-align: text-bottom;
110-
content: '';
111-
background-color: currentColor;
112-
}
113-
114-
// chevron-left
115-
&[rel='prev']::before {
116-
margin-right: ${get('space.1')};
117-
clip-path: polygon(
118-
9.8px 12.8px,
119-
8.7px 12.8px,
120-
4.5px 8.5px,
121-
4.5px 7.5px,
122-
8.7px 3.2px,
123-
9.8px 4.3px,
124-
6.1px 8px,
125-
9.8px 11.7px,
126-
9.8px 12.8px
127-
);
128-
}
129-
130-
// chevron-right
131-
&[rel='next']::after {
132-
margin-left: ${get('space.1')};
133-
clip-path: polygon(
134-
6.2px 3.2px,
135-
7.3px 3.2px,
136-
11.5px 7.5px,
137-
11.5px 8.5px,
138-
7.3px 12.8px,
139-
6.2px 11.7px,
140-
9.9px 8px,
141-
6.2px 4.3px,
142-
6.2px 3.2px
143-
);
144-
}
145-
}
146-
`,
147-
)
148-
14925
export type PageProps = {
15026
/* Unique key for the page number */
15127
key: string
@@ -158,7 +34,6 @@ export type PageProps = {
15834
} & Omit<PageDataProps['props'], 'as' | 'role'>
15935

16036
type UsePaginationPagesParameters = {
161-
theme?: Record<string, unknown> // set to theme type once /src/theme.js is converted
16237
pageCount: number
16338
currentPage: number
16439
onPageChange: (e: React.MouseEvent, n: number) => void
@@ -170,7 +45,6 @@ type UsePaginationPagesParameters = {
17045
}
17146

17247
function usePaginationPages({
173-
theme,
17448
pageCount,
17549
currentPage,
17650
onPageChange,
@@ -182,8 +56,6 @@ function usePaginationPages({
18256
}: UsePaginationPagesParameters) {
18357
const pageChange = React.useCallback((n: number) => (e: React.MouseEvent) => onPageChange(e, n), [onPageChange])
18458

185-
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
186-
18759
const model = React.useMemo(() => {
18860
return buildPaginationModel(pageCount, currentPage, !!showPages, marginPageCount, surroundingPageCount)
18961
}, [pageCount, currentPage, showPages, marginPageCount, surroundingPageCount])
@@ -196,53 +68,22 @@ function usePaginationPages({
19668
}
19769

19870
return (
199-
<Page {...props} key={key} theme={theme} className={clsx(enabled && classes.Page)}>
71+
<span {...props} key={key} className={clsx(classes.Page)}>
20072
{content}
201-
</Page>
73+
</span>
20274
)
20375
})
204-
}, [model, hrefBuilder, pageChange, renderPage, theme, enabled])
76+
}, [model, hrefBuilder, pageChange, renderPage])
20577

20678
return children
20779
}
20880

209-
const PaginationContainer = toggleStyledComponent(
210-
CSS_MODULES_FEATURE_FLAG,
211-
'nav',
212-
styled.nav<SxProp>`
213-
margin-top: 20px;
214-
margin-bottom: 15px;
215-
text-align: center;
216-
217-
${
218-
// Hides pages based on the viewport range passed to `showPages`
219-
Object.keys(viewportRanges)
220-
.map(viewportRangeKey => {
221-
return `
222-
@media (${viewportRanges[viewportRangeKey as keyof typeof viewportRanges]}) {
223-
.TablePaginationSteps[data-hidden-viewport-ranges*='${viewportRangeKey}'] > *:not(:first-child):not(:last-child) {
224-
display: none;
225-
}
226-
227-
.TablePaginationSteps[data-hidden-viewport-ranges*='${viewportRangeKey}'] > *:first-child {
228-
margin-inline-end: 0;
229-
}
230-
231-
.TablePaginationSteps[data-hidden-viewport-ranges*='${viewportRangeKey}'] > *:last-child {
232-
margin-inline-start: 0;
233-
}
234-
}
235-
`
236-
})
237-
.join('')
238-
}
239-
240-
${sx};
241-
`,
242-
)
81+
const PaginationContainer = toggleSxComponent('nav') as React.ComponentType<
82+
React.HTMLAttributes<HTMLElement> & SxProp & React.PropsWithChildren
83+
>
24384

24485
export type PaginationProps = {
245-
theme?: Record<string, unknown>
86+
className?: string
24687
pageCount: number
24788
currentPage: number
24889
onPageChange?: (e: React.MouseEvent, n: number) => void
@@ -254,7 +95,7 @@ export type PaginationProps = {
25495
}
25596

25697
function Pagination({
257-
theme,
98+
className,
25899
pageCount,
259100
currentPage,
260101
onPageChange = noop,
@@ -266,7 +107,6 @@ function Pagination({
266107
...rest
267108
}: PaginationProps) {
268109
const pageElements = usePaginationPages({
269-
theme,
270110
pageCount,
271111
currentPage,
272112
onPageChange,
@@ -277,18 +117,10 @@ function Pagination({
277117
renderPage,
278118
})
279119

280-
const enabled = useFeatureFlag(CSS_MODULES_FEATURE_FLAG)
281-
282120
return (
283-
<PaginationContainer
284-
className={clsx(enabled && classes.PaginationContainer)}
285-
aria-label="Pagination"
286-
{...rest}
287-
theme={theme}
288-
>
121+
<PaginationContainer className={clsx(classes.PaginationContainer, className)} aria-label="Pagination" {...rest}>
289122
<Box
290123
display="inline-block"
291-
theme={theme}
292124
className={classes.TablePaginationSteps}
293125
data-hidden-viewport-ranges={getViewportRangesToHidePages(showPages).join(' ')}
294126
>

0 commit comments

Comments
 (0)