@charcoal-ui/react 5.5.0-beta.3 → 5.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Pagination/index.d.ts +5 -3
- package/dist/components/Pagination/index.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/components/Pagination/Pagination.story.tsx +13 -0
- package/src/components/Pagination/index.tsx +38 -28
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@charcoal-ui/react",
|
|
3
|
-
"version": "5.5.
|
|
3
|
+
"version": "5.5.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -54,10 +54,10 @@
|
|
|
54
54
|
"react-compiler-runtime": "1.0.0",
|
|
55
55
|
"react-stately": "^3.26.0",
|
|
56
56
|
"warning": "^4.0.3",
|
|
57
|
-
"@charcoal-ui/foundation": "5.5.
|
|
58
|
-
"@charcoal-ui/
|
|
59
|
-
"@charcoal-ui/
|
|
60
|
-
"@charcoal-ui/utils": "5.5.
|
|
57
|
+
"@charcoal-ui/foundation": "5.5.1",
|
|
58
|
+
"@charcoal-ui/theme": "5.5.1",
|
|
59
|
+
"@charcoal-ui/icons": "5.5.1",
|
|
60
|
+
"@charcoal-ui/utils": "5.5.1"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"react": ">=17.0.0"
|
|
@@ -131,3 +131,16 @@ export const LinkPaginationWithLinkProps: StoryObj<typeof Pagination> = {
|
|
|
131
131
|
</div>
|
|
132
132
|
),
|
|
133
133
|
}
|
|
134
|
+
|
|
135
|
+
export const ComponentAStory: StoryObj<typeof Pagination> = {
|
|
136
|
+
render: () => {
|
|
137
|
+
return (
|
|
138
|
+
<Pagination
|
|
139
|
+
page={5}
|
|
140
|
+
pageCount={100}
|
|
141
|
+
component="a"
|
|
142
|
+
makeUrl={(p) => `https://example.com?page=${p}`}
|
|
143
|
+
/>
|
|
144
|
+
)
|
|
145
|
+
},
|
|
146
|
+
}
|
|
@@ -2,7 +2,7 @@ import './index.css'
|
|
|
2
2
|
|
|
3
3
|
import { usePaginationWindow } from './helper'
|
|
4
4
|
import { useClassNames } from '../../_lib/useClassNames'
|
|
5
|
-
import IconButton from '../IconButton'
|
|
5
|
+
import IconButton, { IconButtonProps } from '../IconButton'
|
|
6
6
|
import {
|
|
7
7
|
PaginationContext,
|
|
8
8
|
usePaginationContext,
|
|
@@ -14,9 +14,10 @@ import {
|
|
|
14
14
|
|
|
15
15
|
type NavButtonProps = {
|
|
16
16
|
direction: 'prev' | 'next'
|
|
17
|
+
ariaLabel: IconButtonProps['aria-label']
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
function NavButton({ direction }: NavButtonProps) {
|
|
20
|
+
function NavButton({ direction, ariaLabel }: NavButtonProps) {
|
|
20
21
|
'use memo'
|
|
21
22
|
const {
|
|
22
23
|
page,
|
|
@@ -44,6 +45,7 @@ function NavButton({ direction }: NavButtonProps) {
|
|
|
44
45
|
icon={isPrev ? '24/Prev' : '24/Next'}
|
|
45
46
|
size={size}
|
|
46
47
|
hidden={disabled}
|
|
48
|
+
aria-label={ariaLabel}
|
|
47
49
|
{...(isLinkMode && makeUrl
|
|
48
50
|
? {
|
|
49
51
|
component: LinkComponent as 'a',
|
|
@@ -122,11 +124,13 @@ function PageItem({ value }: { value: number | string }) {
|
|
|
122
124
|
)
|
|
123
125
|
}
|
|
124
126
|
|
|
125
|
-
interface
|
|
127
|
+
interface PaginationCommonProps {
|
|
126
128
|
page: number
|
|
127
129
|
pageCount: number
|
|
128
130
|
pageRangeDisplayed?: PageRangeDisplayed
|
|
129
131
|
size?: Size
|
|
132
|
+
ariaLabelPrev?: string
|
|
133
|
+
ariaLabelNext?: string
|
|
130
134
|
}
|
|
131
135
|
|
|
132
136
|
type NavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'onChange'>
|
|
@@ -150,29 +154,33 @@ type NavProps = Omit<React.ComponentPropsWithoutRef<'nav'>, 'onChange'>
|
|
|
150
154
|
* // Link mode with linkProps (e.g. Next.js scroll)
|
|
151
155
|
* <Pagination page={1} pageCount={10} makeUrl={(p) => `?page=${p}`} component={Link} linkProps={{ scroll: 'marker' }} />
|
|
152
156
|
*/
|
|
153
|
-
export type PaginationProps<T extends React.ElementType = 'a'> =
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
157
|
+
export type PaginationProps<T extends React.ElementType = 'a'> =
|
|
158
|
+
PaginationCommonProps &
|
|
159
|
+
NavProps &
|
|
160
|
+
(
|
|
161
|
+
| {
|
|
162
|
+
onChange(newPage: number): void
|
|
163
|
+
makeUrl?: never
|
|
164
|
+
component?: never
|
|
165
|
+
linkProps?: undefined
|
|
166
|
+
}
|
|
167
|
+
| {
|
|
168
|
+
makeUrl(page: number): string
|
|
169
|
+
onChange?: never
|
|
170
|
+
/**
|
|
171
|
+
* The component used for link elements. Receives `href`, `className`, and `children`.
|
|
172
|
+
* @default 'a'
|
|
173
|
+
*/
|
|
174
|
+
component?: T
|
|
175
|
+
/**
|
|
176
|
+
* Additional props passed to all link elements (e.g. Next.js Link's scroll, prefetch).
|
|
177
|
+
*/
|
|
178
|
+
linkProps?: Omit<
|
|
179
|
+
React.ComponentPropsWithoutRef<T>,
|
|
180
|
+
'href' | 'children'
|
|
181
|
+
>
|
|
182
|
+
}
|
|
183
|
+
)
|
|
176
184
|
|
|
177
185
|
export default function Pagination<T extends React.ElementType = 'a'>({
|
|
178
186
|
page,
|
|
@@ -184,6 +192,8 @@ export default function Pagination<T extends React.ElementType = 'a'>({
|
|
|
184
192
|
component: LinkComponent = 'a' as T,
|
|
185
193
|
linkProps,
|
|
186
194
|
className,
|
|
195
|
+
ariaLabelNext = 'Next',
|
|
196
|
+
ariaLabelPrev = 'Previous',
|
|
187
197
|
...navProps
|
|
188
198
|
}: PaginationProps<T>) {
|
|
189
199
|
'use memo'
|
|
@@ -217,11 +227,11 @@ export default function Pagination<T extends React.ElementType = 'a'>({
|
|
|
217
227
|
{...navProps}
|
|
218
228
|
className={classNames}
|
|
219
229
|
>
|
|
220
|
-
<NavButton direction="prev" />
|
|
230
|
+
<NavButton direction="prev" ariaLabel={ariaLabelPrev} />
|
|
221
231
|
{window.map((p) => (
|
|
222
232
|
<PageItem key={p} value={p} />
|
|
223
233
|
))}
|
|
224
|
-
<NavButton direction="next" />
|
|
234
|
+
<NavButton direction="next" ariaLabel={ariaLabelNext} />
|
|
225
235
|
</nav>
|
|
226
236
|
</PaginationContext.Provider>
|
|
227
237
|
)
|