Skip to content

Commit 09a680f

Browse files
matthprostlisalupi
authored andcommitted
refactor(Pagination): to use vanilla extract (#5665)
1 parent cb6863b commit 09a680f

File tree

5 files changed

+116
-231
lines changed

5 files changed

+116
-231
lines changed

.changeset/hungry-laws-joke.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ultraviolet/ui": minor
3+
---
4+
5+
Refactor `<Pagination />` to use vanilla extract

packages/ui/src/components/Pagination/PaginationButtons.tsx

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,12 @@
11
'use client'
22

3-
import styled from '@emotion/styled'
43
import { ArrowLeftIcon, ArrowRightIcon } from '@ultraviolet/icons'
54
import { useCallback, useMemo } from 'react'
65
import { Button } from '../Button'
76
import { Stack } from '../Stack'
87
import { Text } from '../Text'
98
import { getPageNumbers } from './getPageNumbers'
10-
11-
const PageNumbersContainer = styled(Stack)`
12-
margin: 0 ${({ theme }) => theme.space['1']};
13-
`
14-
15-
const PageButton = styled(Button, {
16-
shouldForwardProp: prop => !['width'].includes(prop),
17-
})<{ width: string }>`
18-
width: ${({ theme, width }) => (width === 'small' ? theme.sizing[400] : theme.sizing[500])};
19-
`
20-
21-
const Ellipsis = styled(Text, {
22-
shouldForwardProp: prop => !['width'].includes(prop),
23-
})<{ size: string }>`
24-
align-content: center;
25-
padding: ${({ theme }) => theme.space[1]};
26-
height: ${({ theme, size }) => (size === 'small' ? theme.sizing[400] : theme.sizing[500])};
27-
width: ${({ theme, size }) => (size === 'small' ? theme.sizing[400] : theme.sizing[500])};
28-
`
9+
import { ellipsisClass, pageButton, pageNumbersContainer } from './styles.css'
2910

3011
type PaginationButtonsProps = {
3112
page: number
@@ -56,31 +37,31 @@ const MakeButton = ({
5637
}: MakeButtonProps) => (
5738
<>
5839
{hasEllipsisBefore ? (
59-
<Ellipsis
40+
<Text
6041
aria-label="ellipsis"
6142
as="span"
43+
className={ellipsisClass[perPage ? 'small' : 'medium']}
6244
disabled={disabled}
6345
placement="center"
6446
prominence="default"
6547
sentiment="neutral"
66-
size={perPage ? 'small' : 'medium'}
6748
variant="body"
6849
>
6950
...
70-
</Ellipsis>
51+
</Text>
7152
) : null}
72-
<PageButton
53+
<Button
7354
aria-current={pageNumber === page}
55+
className={pageButton[perPage ? 'small' : 'medium']}
7456
disabled={disabled}
7557
onClick={handlePageClick(pageNumber)}
7658
sentiment={pageNumber === page ? 'primary' : 'neutral'}
7759
size={perPage ? 'small' : 'medium'}
7860
type="button"
7961
variant={pageNumber === page ? 'filled' : 'outlined'}
80-
width={perPage ? 'small' : 'medium'}
8162
>
8263
{pageNumber}
83-
</PageButton>
64+
</Button>
8465
</>
8566
)
8667

@@ -128,7 +109,7 @@ export const PaginationButtons = ({
128109
<ArrowLeftIcon />
129110
</Button>
130111
</Stack>
131-
<PageNumbersContainer direction="row" gap={1}>
112+
<Stack className={pageNumbersContainer} direction="row" gap={1}>
132113
{pageNumbersToDisplay.map((pageNumber, index) => (
133114
<MakeButton
134115
disabled={disabled}
@@ -145,7 +126,7 @@ export const PaginationButtons = ({
145126
perPage={perPage}
146127
/>
147128
))}
148-
</PageNumbersContainer>
129+
</Stack>
149130
<Stack gap={1}>
150131
<Button
151132
aria-label="Next"

packages/ui/src/components/Pagination/PerPage.tsx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use client'
22

3-
import styled from '@emotion/styled'
43
import type { Dispatch, SetStateAction } from 'react'
54
import { SelectInput } from '../SelectInput'
65
import { Stack } from '../Stack'
@@ -25,11 +24,6 @@ const optionsItemsPerPage = [
2524
},
2625
]
2726

28-
const StyledSelectInput = styled(SelectInput)`
29-
width: fit-content;
30-
min-width: none;
31-
`
32-
3327
type PerPageProps = {
3428
perPage: number
3529
onChangePerPage?: (perPage: number) => void
@@ -60,11 +54,14 @@ export const PerPage = ({
6054
<Text as="span" prominence="weak" sentiment="neutral" variant="body">
6155
{perPageText ?? 'Items per page'}
6256
</Text>
63-
<StyledSelectInput
57+
<SelectInput
6458
name="select-items-per-page"
6559
onChange={handleChange}
6660
options={optionsItemsPerPage}
6761
size="small"
62+
style={{
63+
width: 'fit-content',
64+
}}
6865
value={perPage.toString()}
6966
/>
7067
<Text as="span" prominence="weak" sentiment="neutral" variant="body">

0 commit comments

Comments
 (0)