@workday/canvas-kit-docs 6.0.0-alpha.0-next.30 → 6.0.0-alpha.0-next.36
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/LICENSE +1 -1
- package/dist/commonjs/lib/specs.js +295 -33
- package/dist/es6/lib/specs.js +295 -33
- package/dist/mdx/6.0-MIGRATION-GUIDE.mdx +117 -14
- package/dist/mdx/7.0-MIGRATION-GUIDE.mdx +33 -0
- package/dist/mdx/COMPOUND_COMPONENTS.mdx +31 -30
- package/dist/mdx/CONTRIBUTING.mdx +90 -63
- package/dist/mdx/preview-react/breadcrumbs/Breadcrumbs.mdx +1 -1
- package/dist/mdx/preview-react/form-field/FormField.mdx +27 -0
- package/dist/mdx/preview-react/form-field/examples/Custom.tsx +57 -0
- package/dist/mdx/preview-react/menu/examples/Icons.tsx +1 -1
- package/dist/mdx/preview-react/menu/examples/ManyItems.tsx +1 -1
- package/dist/mdx/preview-react/text-area/TextArea.mdx +122 -0
- package/dist/mdx/preview-react/text-area/examples/Alert.tsx +31 -0
- package/dist/mdx/preview-react/text-area/examples/Basic.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/Disabled.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/Error.tsx +40 -0
- package/dist/mdx/preview-react/text-area/examples/Grow.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/HiddenLabel.tsx +20 -0
- package/dist/mdx/preview-react/text-area/examples/LabelPositionHorizontal.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/LabelPositionVertical.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/Placeholder.tsx +21 -0
- package/dist/mdx/preview-react/text-area/examples/RefForwarding.tsx +28 -0
- package/dist/mdx/preview-react/text-area/examples/Required.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/ResizeConstraints.tsx +22 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/TextInput.mdx +40 -18
- package/dist/mdx/preview-react/text-input/examples/Alert.tsx +40 -0
- package/dist/mdx/{labs-react/text-input/examples/HiddenLabel.tsx → preview-react/text-input/examples/Basic.tsx} +3 -3
- package/dist/mdx/preview-react/text-input/examples/Disabled.tsx +17 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/examples/Error.tsx +6 -9
- package/dist/mdx/preview-react/text-input/examples/Grow.tsx +17 -0
- package/dist/mdx/preview-react/text-input/examples/HiddenLabel.tsx +20 -0
- package/dist/mdx/preview-react/text-input/examples/LabelPositionHorizontal.tsx +17 -0
- package/dist/mdx/preview-react/text-input/examples/LabelPositionVertical.tsx +17 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/examples/LoginForm.tsx +10 -5
- package/dist/mdx/preview-react/text-input/examples/Password.tsx +17 -0
- package/dist/mdx/preview-react/text-input/examples/Placeholder.tsx +17 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/examples/RefForwarding.tsx +7 -6
- package/dist/mdx/preview-react/text-input/examples/Required.tsx +17 -0
- package/dist/mdx/preview-react/text-input/examples/ThemedAlert.tsx +46 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/examples/ThemedError.tsx +8 -11
- package/dist/mdx/react/_examples/GlobalHeader.mdx +9 -0
- package/dist/mdx/react/_examples/PageHeader.mdx +8 -0
- package/dist/mdx/react/_examples/examples/GlobalHeader.tsx +66 -0
- package/dist/mdx/react/_examples/examples/PageHeader.tsx +63 -0
- package/dist/mdx/react/action-bar/ActionBar.mdx +1 -1
- package/dist/mdx/react/button/button/Button.mdx +7 -7
- package/dist/mdx/react/button/icon-button/IconButton.mdx +1 -1
- package/dist/mdx/react/loading-animation/LoadingAnimation.mdx +5 -0
- package/dist/mdx/react/loading-animation/examples/RTL.tsx +16 -0
- package/dist/mdx/react/pagination/PropTables.splitprops.tsx +47 -0
- package/dist/mdx/react/pagination/examples/{StepControls.tsx → Basic.tsx} +1 -1
- package/dist/mdx/react/pagination/examples/GoToForm.tsx +1 -1
- package/dist/mdx/react/pagination/examples/HoistedModel.tsx +36 -22
- package/dist/mdx/react/pagination/examples/RTL.tsx +1 -1
- package/dist/mdx/react/pagination/pagination.mdx +225 -474
- package/dist/mdx/react/popup/Popup.mdx +34 -36
- package/dist/mdx/react/radio/examples/Alert.tsx +3 -3
- package/dist/mdx/react/radio/examples/Basic.tsx +3 -3
- package/dist/mdx/react/radio/examples/Disabled.tsx +3 -3
- package/dist/mdx/react/radio/examples/Error.tsx +3 -3
- package/dist/mdx/react/radio/examples/LabelPosition.tsx +3 -3
- package/dist/mdx/react/radio/examples/NoValue.tsx +3 -3
- package/dist/mdx/react/radio/examples/RefForwarding.tsx +3 -3
- package/dist/mdx/react/radio/examples/Required.tsx +3 -3
- package/dist/mdx/react/segmented-control/SegmentedControl.mdx +1 -1
- package/dist/mdx/react/tabs/Tabs.mdx +67 -36
- package/dist/mdx/react/tabs/examples/DisabledTab.tsx +1 -1
- package/dist/mdx/react/tabs/examples/DynamicTabs.tsx +41 -13
- package/dist/mdx/react/tabs/examples/HoistedModel.tsx +4 -4
- package/dist/mdx/react/tabs/examples/Icons.tsx +36 -0
- package/dist/mdx/react/tabs/examples/{NamedKeys.tsx → NamedTabs.tsx} +0 -0
- package/dist/mdx/react/tabs/examples/OverflowTabs.tsx +58 -0
- package/dist/mdx/react/tabs/examples/SinglePanel.tsx +1 -1
- package/dist/mdx/react/toast/toast.mdx +1 -17
- package/dist/mdx/react/tooltip/Tooltip.mdx +9 -1
- package/dist/mdx/react/tooltip/examples/DelayedTooltip.tsx +16 -0
- package/dist/mdx/react/tooltip/examples/Ellipsis.tsx +6 -0
- package/package.json +5 -4
- package/dist/mdx/CODE_OF_CONDUCT.md +0 -68
- package/dist/mdx/labs-react/text-input/examples/Alert.tsx +0 -46
- package/dist/mdx/labs-react/text-input/examples/Basic.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Disabled.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Grow.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/LabelPosition.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Password.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Placeholder.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Required.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/ThemedAlert.tsx +0 -51
- package/dist/mdx/react/pagination/examples/ShowAdditionalDetails.tsx +0 -52
|
@@ -1,84 +1,29 @@
|
|
|
1
1
|
import {Pagination} from '@workday/canvas-kit-react/pagination';
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
import Basic from './examples/Basic';
|
|
3
4
|
import CustomRange from './examples/CustomRange';
|
|
4
5
|
import JumpControls from './examples/JumpControls';
|
|
5
6
|
import GoToForm from './examples/GoToForm';
|
|
6
|
-
import ShowAdditionalDetails from './examples/ShowAdditionalDetails';
|
|
7
7
|
import HoistedModel from './examples/HoistedModel';
|
|
8
8
|
import RTL from './examples/RTL';
|
|
9
|
+
import {
|
|
10
|
+
PaginationHoistedComponent,
|
|
11
|
+
PageButtonComponent,
|
|
12
|
+
PageListComponent,
|
|
13
|
+
AdditionalDetailsComponent,
|
|
14
|
+
PaginationModelConfigComponent,
|
|
15
|
+
PaginationStateComponent,
|
|
16
|
+
PaginationEventsComponent,
|
|
17
|
+
} from './PropTables.splitprops.tsx';
|
|
9
18
|
|
|
10
19
|
|
|
11
|
-
# Canvas Kit
|
|
20
|
+
# Canvas Kit Pagination
|
|
12
21
|
|
|
13
22
|
`Pagination` is a
|
|
14
|
-
[
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- [Canvas Kit React Pagination](#canvas-kit-react-pagination)
|
|
20
|
-
- [Table of Contents](#table-of-contents)
|
|
21
|
-
- [Installation](#installation)
|
|
22
|
-
- [Usage](#usage)
|
|
23
|
-
- [Basic Usage](#basic-usage)
|
|
24
|
-
- [Pagination with Step Controls](#pagination-with-step-controls)
|
|
25
|
-
- [Pagination with Jump Controls](#pagination-with-jump-controls)
|
|
26
|
-
- [Pagination with a GoTo Form](#pagination-with-a-goto-form)
|
|
27
|
-
- [Advanced Usage](#advanced-usage)
|
|
28
|
-
- [Hoisted Model Pattern](#hoisted-model-pattern)
|
|
29
|
-
- [Components](#components)
|
|
30
|
-
- [Pagination](#pagination)
|
|
31
|
-
- [Usage](#usage-1)
|
|
32
|
-
- [Component Props](#component-props)
|
|
33
|
-
- [Pagination.Controls](#paginationcontrols)
|
|
34
|
-
- [Usage](#usage-2)
|
|
35
|
-
- [Component Props](#component-props-1)
|
|
36
|
-
- [Pagination.JumpToFirstButton](#paginationjumptofirstbutton)
|
|
37
|
-
- [Usage](#usage-3)
|
|
38
|
-
- [Component Props](#component-props-2)
|
|
39
|
-
- [Pagination.StepToPreviousButton](#paginationsteptopreviousbutton)
|
|
40
|
-
- [Usage](#usage-4)
|
|
41
|
-
- [Component Props](#component-props-3)
|
|
42
|
-
- [Pagination.StepToNextButton](#paginationsteptonextbutton)
|
|
43
|
-
- [Usage](#usage-5)
|
|
44
|
-
- [Component Props](#component-props-4)
|
|
45
|
-
- [Pagination.JumpToLastButton](#paginationjumptolastbutton)
|
|
46
|
-
- [Usage](#usage-6)
|
|
47
|
-
- [Component Props](#component-props-5)
|
|
48
|
-
- [Pagination.PageList](#paginationpagelist)
|
|
49
|
-
- [Usage](#usage-7)
|
|
50
|
-
- [Component Props](#component-props-6)
|
|
51
|
-
- [Pagination.PageListItem](#paginationpagelistitem)
|
|
52
|
-
- [Usage](#usage-8)
|
|
53
|
-
- [Component Props](#component-props-7)
|
|
54
|
-
- [Pagination.PageButton](#paginationpagebutton)
|
|
55
|
-
- [Usage](#usage-9)
|
|
56
|
-
- [Component Props](#component-props-8)
|
|
57
|
-
- [Pagination.GoToForm](#paginationgotoform)
|
|
58
|
-
- [Usage](#usage-10)
|
|
59
|
-
- [Component Props](#component-props-9)
|
|
60
|
-
- [Pagination.GoToTextInput](#paginationgototextinput)
|
|
61
|
-
- [Usage](#usage-11)
|
|
62
|
-
- [Component Props](#component-props-10)
|
|
63
|
-
- [Pagination.GoToLabel](#paginationgotolabel)
|
|
64
|
-
- [Usage](#usage-12)
|
|
65
|
-
- [Component Props](#component-props-11)
|
|
66
|
-
- [Pagination.AdditionalDetails](#paginationadditionaldetails)
|
|
67
|
-
- [Usage](#usage-13)
|
|
68
|
-
- [Component Props](#component-props-12)
|
|
69
|
-
- [Models, Hooks, & Utils](#models-hooks--utils)
|
|
70
|
-
- [PaginationModel](#paginationmodel)
|
|
71
|
-
- [State](#state)
|
|
72
|
-
- [Events](#events)
|
|
73
|
-
- [usePaginationModel Hook](#usepaginationmodel-hook)
|
|
74
|
-
- [Configuration](#configuration)
|
|
75
|
-
- [Usage](#usage-14)
|
|
76
|
-
- [getLastPage](#getlastpage)
|
|
77
|
-
- [getRangeMin](#getrangemin)
|
|
78
|
-
- [getRangeMax](#getrangemax)
|
|
79
|
-
- [getVisibleResultsMin](#getvisibleresultsmin)
|
|
80
|
-
- [getVisibleResultsMax](#getvisibleresultsmax)
|
|
81
|
-
- [PaginationContext](#paginationcontext)
|
|
23
|
+
[compound component](/getting-started/for-developers/resources/compound-components/) that allows
|
|
24
|
+
users to navigate between pages in a range.
|
|
25
|
+
|
|
26
|
+
[> Workday Design Reference](https://design.workday.com/components/navigation/pagination)
|
|
82
27
|
|
|
83
28
|
## Installation
|
|
84
29
|
|
|
@@ -88,118 +33,71 @@ yarn add @workday/canvas-kit-react
|
|
|
88
33
|
|
|
89
34
|
## Usage
|
|
90
35
|
|
|
91
|
-
|
|
92
|
-
different ways. We'll first cover [basic usage](#basic-usage) examples followed by
|
|
93
|
-
[advanced usage](#advanced-usage). Each of the examples is intended to be standalone, so you can
|
|
94
|
-
skip to the section that best fits your use case.
|
|
36
|
+
### Basic Example
|
|
95
37
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
accessibility can be found in the [Components](#components) section.
|
|
38
|
+
`Pagination` includes a container `Pagination` component and a number of subcomponents which can be
|
|
39
|
+
composed in a variety of ways.
|
|
99
40
|
|
|
100
|
-
|
|
41
|
+
In this example, we set up a basic `Pagination` component with the default range of five pages, as
|
|
42
|
+
well as step controls (`Pagination.StepToPreviousButton` and `Pagination.StepToNextButton`) that
|
|
43
|
+
allow you to move to the previous page or the next page.
|
|
101
44
|
|
|
102
|
-
|
|
45
|
+
<ExampleCodeBlock code={Basic} />
|
|
103
46
|
|
|
104
|
-
|
|
105
|
-
[
|
|
47
|
+
Note that you must include `Pagination.AdditionalDetails` to meet accessibility standards (with one
|
|
48
|
+
exception, see [`Pagination.AdditionalDetails`](#paginationadditionaldetails) for more information).
|
|
49
|
+
It is an `aria-live` region that announces the current page update to screen readers. If you wish to
|
|
50
|
+
prevent it from displaying (as we've done in the remaining examples), you may set its
|
|
51
|
+
`shouldHideDetails` prop to `true`. The visually hidden region will still be accessible to screen
|
|
52
|
+
readers.
|
|
106
53
|
|
|
107
|
-
|
|
54
|
+
### Hoisted Model
|
|
108
55
|
|
|
109
|
-
|
|
110
|
-
`
|
|
56
|
+
By default, `Pagination` will create and use its own [model](#model) internally. Alternatively, you
|
|
57
|
+
may configure your own model with `usePaginationModel` and pass it to `Pagination` via the `model`
|
|
58
|
+
prop. This pattern is referred to as
|
|
59
|
+
[hoisting the model](/getting-started/for-developers/resources/compound-components/#configuring-a-model)
|
|
60
|
+
and provides direct access to its `state` and `events` outside of the `Pagination` component.
|
|
111
61
|
|
|
112
|
-
|
|
62
|
+
In this example, we set up external observation of the model state and create an external button to
|
|
63
|
+
trigger an event to change the current page.
|
|
113
64
|
|
|
114
|
-
|
|
65
|
+
<ExampleCodeBlock code={HoistedModel} />
|
|
115
66
|
|
|
116
|
-
|
|
67
|
+
### Jump Controls
|
|
117
68
|
|
|
118
69
|
This example adds jump controls (`Pagination.JumpToFirstButton` and `Pagination.JumpToLastButton`)
|
|
119
|
-
that allow you to skip to the first and last
|
|
70
|
+
that allow you to skip to the first and last pages in the range.
|
|
120
71
|
|
|
121
72
|
<ExampleCodeBlock code={JumpControls} />
|
|
122
73
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
#### GoTo Form
|
|
74
|
+
### GoTo Form
|
|
126
75
|
|
|
127
76
|
This example adds a form (`Pagination.GoToForm`) that allows you to skip to a specific page within
|
|
128
77
|
the range.
|
|
129
78
|
|
|
130
79
|
<ExampleCodeBlock code={GoToForm} />
|
|
131
80
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
#### Additional Details
|
|
135
|
-
|
|
136
|
-
This example adds a visible section (`Pagination.AdditionalDetails`). It is an `aria-live` region
|
|
137
|
-
that announces the current page update to screen readers. Because of that, it's important to
|
|
138
|
-
**always†** include it in your `Pagination` component.
|
|
139
|
-
|
|
140
|
-
In the case where you would also have multiple `Pagination` components sharing the same state and
|
|
141
|
-
you'd like to keep the `AdditionalDetails` component on multiple, you will need to set
|
|
142
|
-
`shouldAnnounceToScreenReader` to `false` on all but one component to prevent announcement.
|
|
143
|
-
|
|
144
|
-
> **†** _The only exception to this rule is when you have multiple `Pagination` components that are
|
|
145
|
-
> sharing the same state and rendered on the page. You can then safely remove all but one of the
|
|
146
|
-
> `AdditionalDetails` sections. This will prevent a screenreader from announcing updates multiple
|
|
147
|
-
> times to a user._
|
|
148
|
-
|
|
149
|
-
<ExampleCodeBlock code={ShowAdditionalDetails} />
|
|
150
|
-
|
|
151
|
-
---
|
|
81
|
+
### Right-to-Left (RTL)
|
|
152
82
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
This example shows how the component supports right-to-left languages.
|
|
83
|
+
`Pagination` supports right-to-left languages when specified in the `CanvasProvider` `theme`.
|
|
156
84
|
|
|
157
85
|
<ExampleCodeBlock code={RTL} />
|
|
158
86
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
#### Custom Range
|
|
87
|
+
### Custom Range
|
|
162
88
|
|
|
163
89
|
This example uses a custom range that allows you to control the width of the component.
|
|
164
90
|
|
|
165
91
|
<ExampleCodeBlock code={CustomRange} />
|
|
166
92
|
|
|
167
|
-
---
|
|
168
|
-
|
|
169
|
-
### Advanced Usage
|
|
170
|
-
|
|
171
|
-
Below are examples for more advanced / custom usage of these components. We expect most people won't
|
|
172
|
-
need to read this section, but if you're needing to go beyond our basic examples or just curious,
|
|
173
|
-
feel free to explore this section. While this section is not exhaustive, it provides additional
|
|
174
|
-
insight into what's possible.
|
|
175
|
-
|
|
176
|
-
#### Hoisted Model Pattern
|
|
177
|
-
|
|
178
|
-
If you're unfamiliar with compound components, the pagination model, or the `usePaginationModel`
|
|
179
|
-
hook, we would recommend reviewing the [PaginationModel](#paginationmodel) section first.
|
|
180
|
-
|
|
181
|
-
If you want the `Pagination` component to handle its state and events internally and hook into page
|
|
182
|
-
change events, the basic usage examples above should be sufficient. However, if you need external
|
|
183
|
-
access to the model, you can use the hoisted model pattern. You can create a model outside of the
|
|
184
|
-
component with the `usePaginationModel` hook.
|
|
185
|
-
|
|
186
|
-
For this example, we'll create a `Pagination` component that handles 128 total items with 10 items
|
|
187
|
-
per page.
|
|
188
|
-
|
|
189
|
-
<ExampleCodeBlock code={HoistedModel} />
|
|
190
|
-
|
|
191
93
|
## Components
|
|
192
94
|
|
|
193
95
|
### Pagination
|
|
194
96
|
|
|
195
|
-
The `Pagination` component is a wrapper for a React context provider and `nav` element. Child
|
|
196
|
-
components such as `Pagination.StepToPreviousButton`, `Pagination.PageList`, etc. subscribe to that
|
|
197
|
-
context.
|
|
198
|
-
|
|
199
97
|
#### Usage
|
|
200
98
|
|
|
201
|
-
`Pagination`
|
|
202
|
-
|
|
99
|
+
`Pagination` is a container component rendered as a `<nav>` element that is responsible for creating
|
|
100
|
+
a `PaginationModel` and sharing it with its subcomponents using React context.
|
|
203
101
|
|
|
204
102
|
```tsx
|
|
205
103
|
<Pagination
|
|
@@ -209,172 +107,143 @@ provide a configuration as in the example below.
|
|
|
209
107
|
rangeSize={3}
|
|
210
108
|
onPageChange={pageNumber => console.log(pageNumber)}
|
|
211
109
|
>
|
|
212
|
-
{/*
|
|
110
|
+
{/* Child components */}
|
|
213
111
|
</Pagination>
|
|
214
112
|
```
|
|
215
113
|
|
|
216
|
-
|
|
217
|
-
hoisted model pattern. Note that in this pattern, the only props needed are `model` and
|
|
218
|
-
`aria-label`.
|
|
114
|
+
Alternatively, you may pass in a model using the hoisted model pattern.
|
|
219
115
|
|
|
220
116
|
```tsx
|
|
221
|
-
const
|
|
117
|
+
const model = usePaginationModel({
|
|
222
118
|
lastPage: 100,
|
|
223
119
|
initialCurrentPage: 6,
|
|
224
120
|
rangeSize: 3,
|
|
225
121
|
onPageChange: pageNumber => console.log(pageNumber),
|
|
226
|
-
};
|
|
227
|
-
const model = usePaginationModel(modelConfig);
|
|
122
|
+
});
|
|
228
123
|
|
|
229
124
|
return (
|
|
230
125
|
<Pagination aria-label="Pagination" model={model}>
|
|
231
|
-
{/*
|
|
126
|
+
{/* Child components */}
|
|
232
127
|
</Pagination>
|
|
233
128
|
);
|
|
234
129
|
```
|
|
235
130
|
|
|
236
|
-
####
|
|
131
|
+
#### Props
|
|
237
132
|
|
|
238
|
-
|
|
239
|
-
configuration pattern, follow this table:
|
|
133
|
+
Undocumented props are spread to the underlying `<nav>` element.
|
|
240
134
|
|
|
241
|
-
|
|
242
|
-
| ------------------ | ------------------------------ | ---------- | ------- | ---------------------------------------- |
|
|
243
|
-
| aria-label | `string` | ✅ `true` | n/a | "Pagination" (and translated equivalent) |
|
|
244
|
-
| lastPage | `number` | ✅ `true` | n/a | n/a |
|
|
245
|
-
| initialCurrentPage | `number` | 🚫 `false` | 1 | n/a |
|
|
246
|
-
| rangeSize | `number` | 🚫 `false` | 5 | n/a |
|
|
247
|
-
| firstPage | `number` | 🚫 `false` | 1 | n/a |
|
|
248
|
-
| onPageChange | `(pageNumber: number) => void` | 🚫 `false` | n/a | n/a |
|
|
135
|
+
<ArgsTable of={PaginationModelConfigComponent} />
|
|
249
136
|
|
|
250
|
-
|
|
137
|
+
If you're using the hoisted model pattern, follow this table instead (refer to the [Model](#model)
|
|
138
|
+
section for more information about `PaginationModel`):
|
|
251
139
|
|
|
252
|
-
|
|
253
|
-
| ---------- | ----------------- | --------- | ------- | ---------------------------------------- |
|
|
254
|
-
| aria-label | `string` | ✅ `true` | n/a | "Pagination" (and translated equivalent) |
|
|
255
|
-
| model | `PaginationModel` | ✅ `true` | n/a | n/a |
|
|
140
|
+
<ArgsTable of={PaginationHoistedComponent} />
|
|
256
141
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
The `aria-label` prop is required for accessibility. We recommend using `"Pagination"` as seen in
|
|
260
|
-
the example.
|
|
261
|
-
|
|
262
|
-
---
|
|
142
|
+
Note that you must set `aria-label` in either case to meet accessibility standards. We recommend
|
|
143
|
+
setting it to `Pagination` or the translated equivalent.
|
|
263
144
|
|
|
264
145
|
### Pagination.Controls
|
|
265
146
|
|
|
266
|
-
`Pagination.Controls` is a styled `div` wrapper that provides proper alignment and spacing between
|
|
267
|
-
elements inside `Pagination`. It does not handle any internal business logic or state.
|
|
268
|
-
|
|
269
147
|
#### Usage
|
|
270
148
|
|
|
149
|
+
`Pagination.Controls` is a styled `<div>` element that provides proper alignment and spacing between
|
|
150
|
+
elements inside `Pagination`. It does not handle any internal business logic or state.
|
|
151
|
+
|
|
271
152
|
```tsx
|
|
272
|
-
<Pagination.Controls>{/*
|
|
153
|
+
<Pagination.Controls>{/* Child components */}</Pagination.Controls>
|
|
273
154
|
```
|
|
274
155
|
|
|
275
|
-
####
|
|
156
|
+
#### Props
|
|
276
157
|
|
|
277
|
-
|
|
278
|
-
[all native HTMLDivElement props](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/div#Attributes).
|
|
158
|
+
`Pagination.Controls` does not have any documented props.
|
|
279
159
|
|
|
280
|
-
|
|
160
|
+
Undocumented props are spread to the underlying `<div>` element.
|
|
281
161
|
|
|
282
162
|
### Pagination.JumpToFirstButton
|
|
283
163
|
|
|
284
|
-
`Pagination.JumpToFirstButton` is an `IconButton` that subscribes to `Pagination`'s context. This
|
|
285
|
-
allows it to know when to disable and set `currentPage` to the first page.
|
|
286
|
-
|
|
287
164
|
#### Usage
|
|
288
165
|
|
|
166
|
+
`Pagination.JumpToFirstButton` is an `IconButton` that subscribes to the `Pagination` context. This
|
|
167
|
+
allows it to know when to disable and set `currentPage` to the first page.
|
|
168
|
+
|
|
289
169
|
```tsx
|
|
290
170
|
<Pagination.JumpToFirstButton aria-label="First" />
|
|
291
171
|
```
|
|
292
172
|
|
|
293
|
-
####
|
|
294
|
-
|
|
295
|
-
| name | type | required? | default | recommended |
|
|
296
|
-
| ---------- | -------- | --------- | ------- | ----------------------------------- |
|
|
297
|
-
| aria-label | `string` | ✅ `true` | n/a | "First" (and translated equivalent) |
|
|
173
|
+
#### Props
|
|
298
174
|
|
|
299
|
-
|
|
175
|
+
Undocumented props are spread to the underlying `<button>` element. Note that you must set
|
|
176
|
+
`aria-label` to meet accessibility standards. We recommend setting it to `First` or the translated
|
|
177
|
+
equivalent.
|
|
300
178
|
|
|
301
|
-
|
|
179
|
+
`Pagination.JumpToFirstButton` supports all `IconButton` props.
|
|
302
180
|
|
|
303
181
|
### Pagination.StepToPreviousButton
|
|
304
182
|
|
|
305
|
-
`Pagination.StepToPreviousButton` is an `IconButton` that subscribes to `Pagination`'s context. This
|
|
306
|
-
allows it to know when to disable and decrement the `currentPage`.
|
|
307
|
-
|
|
308
183
|
#### Usage
|
|
309
184
|
|
|
185
|
+
`Pagination.StepToPreviousButton` is an `IconButton` that subscribes to the `Pagination` context.
|
|
186
|
+
This allows it to know when to disable and decrement the `currentPage`.
|
|
187
|
+
|
|
310
188
|
```tsx
|
|
311
189
|
<Pagination.StepToPreviousButton aria-label="Previous" />
|
|
312
190
|
```
|
|
313
191
|
|
|
314
|
-
####
|
|
192
|
+
#### Props
|
|
315
193
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
194
|
+
Undocumented props are spread to the underlying `<button>` element. Note that you must set
|
|
195
|
+
`aria-label` to meet accessibility standards. We recommend setting it to `Previous` or the
|
|
196
|
+
translated equivalent.
|
|
319
197
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
---
|
|
198
|
+
`Pagination.StepToPreviousButton` supports all `IconButton` props.
|
|
323
199
|
|
|
324
200
|
### Pagination.StepToNextButton
|
|
325
201
|
|
|
326
|
-
`Pagination.StepToNextButton` is an `IconButton` that subscribes to `Pagination`'s context. This
|
|
327
|
-
allows it to know when to disable and increment the `currentPage`.
|
|
328
|
-
|
|
329
202
|
#### Usage
|
|
330
203
|
|
|
204
|
+
`Pagination.StepToNextButton` is an `IconButton` that subscribes to the `Pagination` context. This
|
|
205
|
+
allows it to know when to disable and increment the `currentPage`.
|
|
206
|
+
|
|
331
207
|
```tsx
|
|
332
208
|
<Pagination.StepToNextButton aria-label="Next" />
|
|
333
209
|
```
|
|
334
210
|
|
|
335
|
-
####
|
|
336
|
-
|
|
337
|
-
| name | type | required? | default | recommended |
|
|
338
|
-
| ---------- | -------- | --------- | ------- | ---------------------------------- |
|
|
339
|
-
| aria-label | `string` | ✅ `true` | n/a | "Next" (and translated equivalent) |
|
|
211
|
+
#### Props
|
|
340
212
|
|
|
341
|
-
|
|
213
|
+
Undocumented props are spread to the underlying `<button>` element. Note that you must set
|
|
214
|
+
`aria-label` to meet accessibility standards. We recommend setting it to `Next` or the translated
|
|
215
|
+
equivalent.
|
|
342
216
|
|
|
343
|
-
|
|
217
|
+
`Pagination.StepToNextButton` supports all `IconButton` props.
|
|
344
218
|
|
|
345
219
|
### Pagination.JumpToLastButton
|
|
346
220
|
|
|
347
|
-
`Pagination.JumpToLastButton` is an `IconButton` that subscribes to `Pagination`'s context. This
|
|
348
|
-
allows it to know when to disable and set `currentPage` to the last page.
|
|
349
|
-
|
|
350
221
|
#### Usage
|
|
351
222
|
|
|
223
|
+
`Pagination.JumpToLastButton` is an `IconButton` that subscribes to the `Pagination` context. This
|
|
224
|
+
allows it to know when to disable and set `currentPage` to the last page.
|
|
225
|
+
|
|
352
226
|
```tsx
|
|
353
227
|
<Pagination.JumpToLastButton aria-label="Last" />
|
|
354
228
|
```
|
|
355
229
|
|
|
356
|
-
####
|
|
357
|
-
|
|
358
|
-
| name | type | required? | default | recommended |
|
|
359
|
-
| ---------- | -------- | --------- | ------- | ---------------------------------- |
|
|
360
|
-
| aria-label | `string` | ✅ `true` | n/a | "Last" (and translated equivalent) |
|
|
230
|
+
#### Props
|
|
361
231
|
|
|
362
|
-
|
|
232
|
+
Undocumented props are spread to the underlying `<button>` element. Note that you must set
|
|
233
|
+
`aria-label` to meet accessibility standards. We recommend setting it to `Last` or the translated
|
|
234
|
+
equivalent.
|
|
363
235
|
|
|
364
|
-
|
|
236
|
+
`Pagination.JumpToLastButton` supports all `IconButton` props.
|
|
365
237
|
|
|
366
238
|
### Pagination.PageList
|
|
367
239
|
|
|
368
|
-
`Pagination.PageList` is an ordered list (`ol`) that subscribes to `Pagination`'s context. This
|
|
369
|
-
allows it generate the `range` of page numbers. It also handles spacing between the child elements.
|
|
370
|
-
This component will accept either child elements or functional children (sometimes called the render
|
|
371
|
-
prop pattern). It's likely you'll want to use the functional children, but in the off-chance you
|
|
372
|
-
need a static list of items, this component will support it. The usage section below will provide
|
|
373
|
-
examples of both.
|
|
374
|
-
|
|
375
240
|
#### Usage
|
|
376
241
|
|
|
377
|
-
|
|
242
|
+
`Pagination.PageList` is an `<ol>` element that subscribes to the `Pagination` context. This allows
|
|
243
|
+
it generate the `range` of page numbers. It also handles spacing between the child elements.
|
|
244
|
+
|
|
245
|
+
This component will accept either child elements or a render prop. In most cases, you'll want to use
|
|
246
|
+
the render prop so you can access the `Pagination` model in order to generate the proper list items.
|
|
378
247
|
|
|
379
248
|
```tsx
|
|
380
249
|
<Pagination.PageList>
|
|
@@ -388,151 +257,135 @@ The functional children snippet below will likely be the most common use case.
|
|
|
388
257
|
</Pagination.PageList>
|
|
389
258
|
```
|
|
390
259
|
|
|
391
|
-
####
|
|
392
|
-
|
|
393
|
-
| name | type | required? | default | recommended |
|
|
394
|
-
| -------- | ---------------------------------------------------------------- | ---------- | ------- | ----------- |
|
|
395
|
-
| children | (model: PaginationModel) => React.ReactNode[] \| React.ReactNode | 🚫 `false` | n/a | n/a |
|
|
260
|
+
#### Props
|
|
396
261
|
|
|
397
|
-
|
|
398
|
-
[all native HTMLOLElement props](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ol#Attributes).
|
|
262
|
+
Undocumented props are spread to the underlying `<ol>` element.
|
|
399
263
|
|
|
400
|
-
|
|
264
|
+
<ArgsTable of={PageListComponent} />
|
|
401
265
|
|
|
402
266
|
### Pagination.PageListItem
|
|
403
267
|
|
|
404
|
-
|
|
268
|
+
#### Usage
|
|
269
|
+
|
|
270
|
+
`Pagination.PageListItem` is a styled `<li>` element. It provides a semantic child element for the
|
|
405
271
|
`PageList` component and is important for accessibility. It does not handle any internal business
|
|
406
272
|
logic or state.
|
|
407
273
|
|
|
408
|
-
#### Usage
|
|
409
|
-
|
|
410
274
|
```tsx
|
|
411
|
-
<Pagination.PageListItem>{/*
|
|
275
|
+
<Pagination.PageListItem>{/* Child element */}</Pagination.PageListItem>
|
|
412
276
|
```
|
|
413
277
|
|
|
414
|
-
####
|
|
278
|
+
#### Props
|
|
415
279
|
|
|
416
|
-
|
|
417
|
-
[all native HTMLLIElement props](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/li#Attributes).
|
|
280
|
+
`Pagination.PageListItem` does not have any documented props.
|
|
418
281
|
|
|
419
|
-
|
|
282
|
+
Undocumented props are spread to the underlying `<li>` element.
|
|
420
283
|
|
|
421
284
|
### Pagination.PageButton
|
|
422
285
|
|
|
423
|
-
`Pagination.PageButton` is an `IconButton` that subscribes to `Pagination`'s context. This allows it
|
|
424
|
-
to know set the `toggled` styling when it is the current item and update the `currentPage`.
|
|
425
|
-
|
|
426
286
|
#### Usage
|
|
427
287
|
|
|
428
|
-
`PageButton`
|
|
288
|
+
`Pagination.PageButton` is an `IconButton` that subscribes to the `Pagination` context. This allows
|
|
289
|
+
it to update the `currentPage` and set the `toggled` styling when it is the current item.
|
|
290
|
+
|
|
291
|
+
`Pagination.PageButton` will render `pageNumber` as its children.
|
|
429
292
|
|
|
430
293
|
```tsx
|
|
431
294
|
<Pagination.PageButton aria-label="Page 2" pageNumber={2} />
|
|
432
295
|
```
|
|
433
296
|
|
|
434
|
-
####
|
|
297
|
+
#### Props
|
|
435
298
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
| pageNumber | `number` | ✅ `true` | n/a | n/a |
|
|
299
|
+
Undocumented props are spread to the underlying `<button>` element. Note that you must set
|
|
300
|
+
`aria-label` to meet accessibility standards. We recommend setting it to `Page ${pageNumber}` or the
|
|
301
|
+
translated equivalent.
|
|
440
302
|
|
|
441
|
-
|
|
303
|
+
<ArgsTable of={PageButtonComponent} />
|
|
442
304
|
|
|
443
|
-
|
|
305
|
+
`Pagination.PageButton` also supports all `IconButton` props.
|
|
444
306
|
|
|
445
307
|
### Pagination.GoToForm
|
|
446
308
|
|
|
447
|
-
`Pagination.GoToForm` is a wrapper for a React context provider and `form` element. Child components
|
|
448
|
-
such as `Pagination.GoToTextInput` and `Pagination.GoToLabel` subscribe to that context to manage
|
|
449
|
-
the form state and behavior as well as update the `currentPage` in the `Pagination` component.
|
|
450
|
-
|
|
451
309
|
#### Usage
|
|
452
310
|
|
|
311
|
+
`Pagination.GoToForm` is a wrapper for a React context provider rendered as a `<form>` element.
|
|
312
|
+
Child components such as `Pagination.GoToTextInput` and `Pagination.GoToLabel` subscribe to that
|
|
313
|
+
context to manage the form state and behavior as well as update the `currentPage` in the
|
|
314
|
+
`Pagination` component.
|
|
315
|
+
|
|
453
316
|
```tsx
|
|
454
|
-
<Pagination.GoToForm>{/*
|
|
317
|
+
<Pagination.GoToForm>{/* Child elements */}</Pagination.GoToForm>
|
|
455
318
|
```
|
|
456
319
|
|
|
457
|
-
####
|
|
320
|
+
#### Props
|
|
458
321
|
|
|
459
|
-
|
|
460
|
-
[all native HTMLFormElement props](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form#Attributes).
|
|
322
|
+
`Pagination.GoToForm` does not have any documented props.
|
|
461
323
|
|
|
462
|
-
|
|
324
|
+
Undocumented props are spread to the underlying `<form>` element.
|
|
463
325
|
|
|
464
326
|
### Pagination.GoToTextInput
|
|
465
327
|
|
|
466
328
|
#### Usage
|
|
467
329
|
|
|
330
|
+
`Pagination.GoToTextInput` is a `TextInput`.
|
|
331
|
+
|
|
468
332
|
```tsx
|
|
469
333
|
<Pagination.GoToTextInput aria-label="Go to page number" />
|
|
470
334
|
```
|
|
471
335
|
|
|
472
|
-
####
|
|
473
|
-
|
|
474
|
-
| name | type | required? | default | recommended |
|
|
475
|
-
| ---------- | -------------------- | ---------- | ------- | ----------------------------------------------- |
|
|
476
|
-
| aria-label | `string` | ✅ `true` | n/a | `Go to page number` (and translated equivalent) |
|
|
477
|
-
| value | `string` \| `number` | 🚫 `false` | "" | n/a |
|
|
336
|
+
#### Props
|
|
478
337
|
|
|
479
|
-
|
|
338
|
+
Undocumented props are spread to the underlying `<input type="text">` element. Note that you must
|
|
339
|
+
set `aria-label` to meet accessibility standards. We recommend setting it to `Go to page number` or
|
|
340
|
+
the translated equivalent.
|
|
480
341
|
|
|
481
|
-
|
|
342
|
+
`Pagination.GoToTextInput` supports all `TextInput` props.
|
|
482
343
|
|
|
483
344
|
### Pagination.GoToLabel
|
|
484
345
|
|
|
485
|
-
`Pagination.GoToLabel` is a styled `label` element that subscribes to the `Pagination` context. This
|
|
486
|
-
allows it to pass the `Pagination` context to child elements.
|
|
487
|
-
|
|
488
346
|
#### Usage
|
|
489
347
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
need static child elements, this component will support it. Examples of both patterns are provided
|
|
493
|
-
below.
|
|
494
|
-
|
|
495
|
-
**Functional Children**
|
|
348
|
+
`Pagination.GoToLabel` is a styled `<label>` element that subscribes to the `Pagination` context.
|
|
349
|
+
This allows it to pass the `Pagination` context to child elements.
|
|
496
350
|
|
|
497
|
-
|
|
351
|
+
This component will accept either child elements or a render prop. In most cases, you'll want to use
|
|
352
|
+
the render prop so you can access the `Pagination` model when generating the label text.
|
|
498
353
|
|
|
499
354
|
```tsx
|
|
500
|
-
<Pagination.GoToLabel>{({state}) => `of ${state.lastPage}
|
|
355
|
+
<Pagination.GoToLabel>{({state}) => `of ${state.lastPage} pages`}</Pagination.GoToLabel>
|
|
501
356
|
```
|
|
502
357
|
|
|
503
|
-
####
|
|
504
|
-
|
|
505
|
-
| name | type | required? | default | recommended |
|
|
506
|
-
| -------- | -------------------------------------------------------------- | ---------- | ------- | ----------- |
|
|
507
|
-
| htmlFor | `string` | 🚫 `false` | n/a | n/a |
|
|
508
|
-
| children | (model: PaginationModel) => React.ReactNode \| React.ReactNode | 🚫 `false` | n/a | n/a |
|
|
358
|
+
#### Props
|
|
509
359
|
|
|
510
|
-
|
|
511
|
-
[all native HTMLLabelElement props](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/label#Attributes).
|
|
360
|
+
Undocumented props are spread to the underlying `<label>` element.
|
|
512
361
|
|
|
513
|
-
|
|
362
|
+
<ArgsTable of={Pagination.GoToLabel} />
|
|
514
363
|
|
|
515
364
|
### Pagination.AdditionalDetails
|
|
516
365
|
|
|
517
|
-
|
|
366
|
+
#### Usage
|
|
367
|
+
|
|
368
|
+
`Pagination.AdditionalDetails` is a styled `<div>` element that subscribes to the `Pagination`
|
|
518
369
|
context. This allows it to pass the `Pagination` context to child elements. It is also an
|
|
519
|
-
`aria-live` region that announces the current page update to screen readers.
|
|
520
|
-
important to always\* include it in your `Pagination` component.
|
|
370
|
+
`aria-live` region that announces the current page update to screen readers.
|
|
521
371
|
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
`
|
|
525
|
-
|
|
372
|
+
`Pagination.AdditionalDetails` must be included in your `Pagination` component to meet accessibility
|
|
373
|
+
standards (with one exception, see below). If you wish to prevent it from displaying, you may set
|
|
374
|
+
its `shouldHideDetails` prop to `true`. The visually hidden region will still be accessible to
|
|
375
|
+
screen readers.
|
|
526
376
|
|
|
527
|
-
|
|
528
|
-
you
|
|
529
|
-
|
|
377
|
+
If you have multiple `Pagination` components sharing the same state and rendered on the same page,
|
|
378
|
+
you may do either of the following to prevent screen readers from announcing the same update
|
|
379
|
+
multiple times:
|
|
530
380
|
|
|
531
|
-
|
|
381
|
+
- Exclude `Pagination.AdditionalDetails` from all but one of the `Pagination` components. This is
|
|
382
|
+
the one case where you may exclude `Pagination.AdditionalDetails` from a `Pagination` component.
|
|
383
|
+
- Include `Pagination.AdditionalDetails` in every `Pagination` component (i.e., you want it to be
|
|
384
|
+
visible for every component), but set the `shouldAnnounceToScreenReader` prop to `false` on all
|
|
385
|
+
but one of them.
|
|
532
386
|
|
|
533
|
-
This component will accept either child elements or
|
|
534
|
-
|
|
535
|
-
need static child elements, this component will support it.
|
|
387
|
+
This component will accept either child elements or a render prop. In most cases, you'll want to use
|
|
388
|
+
the render prop so you can access the `Pagination` model in order to generate the appropriate text.
|
|
536
389
|
|
|
537
390
|
```tsx
|
|
538
391
|
<Pagination.AdditionalDetails>
|
|
@@ -546,145 +399,89 @@ need static child elements, this component will support it.
|
|
|
546
399
|
</Pagination.AdditionalDetails>
|
|
547
400
|
```
|
|
548
401
|
|
|
549
|
-
####
|
|
550
|
-
|
|
551
|
-
| name | type | required? | default | recommended |
|
|
552
|
-
| ---------------------------- | -------------------------------------------------------------- | ---------- | ------- | ----------- |
|
|
553
|
-
| shouldHideDetails | `boolean` | 🚫 `false` | false | n/a |
|
|
554
|
-
| shouldAnnounceToScreenReader | `boolean` | 🚫 `false` | true | n/a |
|
|
555
|
-
| children | (model: PaginationModel) => React.ReactNode \| React.ReactNode | ✅ `true` | n/a | n/a |
|
|
556
|
-
|
|
557
|
-
## Models, Hooks, & Utils
|
|
402
|
+
#### Props
|
|
558
403
|
|
|
559
|
-
|
|
404
|
+
Undocumented props are spread to the underlying `<div>` element.
|
|
560
405
|
|
|
561
|
-
|
|
562
|
-
> in v5 of canvas-kit. While the general concepts are the same, there will be some breaking changes
|
|
563
|
-
> in v5. If you'd like to learn about models and compound components in v5, please refer to
|
|
564
|
-
> [this doc](https://github.com/Workday/canvas-kit/blob/master/modules/docs/mdx/COMPOUND_COMPONENTS.mdx).
|
|
406
|
+
<ArgsTable of={AdditionalDetailsComponent} />
|
|
565
407
|
|
|
566
|
-
|
|
567
|
-
higher-level context API components and following the basic usage guidelines, you shouldn't need to
|
|
568
|
-
know how the model operates to successfully implement the component. But if you have an advanced use
|
|
569
|
-
case or you're feeling curious, this section is for you.
|
|
408
|
+
## Model
|
|
570
409
|
|
|
571
410
|
If `Pagination` was stripped of all its markup, attributes, and styling, what would remain is the
|
|
572
|
-
model. The
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
model's `state` describes the current state of the component, and `events` are functions that act on
|
|
576
|
-
that state (also called behaviors). Below is an example `Pagination` model:
|
|
577
|
-
|
|
578
|
-
```tsx
|
|
579
|
-
const paginationModel = {
|
|
580
|
-
state: {
|
|
581
|
-
firstPage,
|
|
582
|
-
currentPage,
|
|
583
|
-
lastPage,
|
|
584
|
-
range,
|
|
585
|
-
rangeSize,
|
|
586
|
-
},
|
|
587
|
-
events: {
|
|
588
|
-
first,
|
|
589
|
-
last,
|
|
590
|
-
next,
|
|
591
|
-
previous,
|
|
592
|
-
setCurrentPage,
|
|
593
|
-
goTo,
|
|
594
|
-
};
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
```
|
|
598
|
-
|
|
599
|
-
#### State
|
|
600
|
-
|
|
601
|
-
The `state` describes the current state of the `Pagination` component. As events are fired, the
|
|
602
|
-
state is updated, and the component will re-render. Below are the `state` keys and descriptions of
|
|
603
|
-
their values:
|
|
604
|
-
|
|
605
|
-
- `firstPage` - the page number for the first page
|
|
606
|
-
- `currentPage` - the page number for the current page
|
|
607
|
-
- `lastPage` - the page number for the last page (it can also be used as a total page count)
|
|
608
|
-
- `range` - an array of page numbers included in the pagination range
|
|
609
|
-
- `rangeSize` - the size of the pagination range
|
|
610
|
-
|
|
611
|
-
#### Events
|
|
612
|
-
|
|
613
|
-
The model's `events` describe behaviors that act on `state`. Below are the `events` keys and
|
|
614
|
-
descriptions of their values:
|
|
411
|
+
[model](/getting-started/for-developers/resources/compound-components/#models). The model is an
|
|
412
|
+
object composed of two parts: `state` which describes the current snapshot in time of the component
|
|
413
|
+
and `events` which describes events that can be sent to the model.
|
|
615
414
|
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
- `previous` - decrements the current page by 1
|
|
620
|
-
- `goTo` - sets the current page to a given page number\* (with safeguards)
|
|
621
|
-
- `setCurrentPage` - sets the current page to a given page number (no safeguards)
|
|
415
|
+
By default, `Pagination` will create a model and share it internally with its subcomponents using
|
|
416
|
+
React context. You may subscribe to `PaginationContext` if you wish to create a custom subcomponent
|
|
417
|
+
for your implementation. Here's a simple example.
|
|
622
418
|
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
`lastPage`._
|
|
419
|
+
```tsx
|
|
420
|
+
import * as React from 'react';
|
|
421
|
+
import {Pagination, PaginationContext} from '@workday/canvas-kit-react/pagination';
|
|
627
422
|
|
|
628
|
-
|
|
423
|
+
const CustomButton = (props: React.HTMLAttributes<HTMLButtonElement>) => {
|
|
424
|
+
const model = React.useContext(PaginationContext);
|
|
629
425
|
|
|
630
|
-
|
|
426
|
+
const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
|
427
|
+
// If onClick is provided, pass the event along
|
|
428
|
+
props.onClick?.(e);
|
|
429
|
+
model.events.goTo(10);
|
|
430
|
+
};
|
|
631
431
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
432
|
+
return (
|
|
433
|
+
<button onClick={handleClick} {...props}>
|
|
434
|
+
Go To Page 10
|
|
435
|
+
</button>
|
|
436
|
+
);
|
|
437
|
+
};
|
|
635
438
|
|
|
636
|
-
|
|
439
|
+
export const CustomPagination = () => {
|
|
440
|
+
return (
|
|
441
|
+
<Pagination aria-label="Pagination" lastPage={20}>
|
|
442
|
+
<CustomButton aria-label="Page 10" />
|
|
443
|
+
{/* Other subcomponents */}
|
|
444
|
+
</Pagination>
|
|
445
|
+
);
|
|
446
|
+
};
|
|
447
|
+
```
|
|
637
448
|
|
|
638
|
-
|
|
639
|
-
|
|
449
|
+
Alternatively, if you need direct access to the model's `state` and `events` outside of the
|
|
450
|
+
`Pagination` component, you may configure your own model with `usePaginationModel` and pass it to
|
|
451
|
+
`Pagination` via a pattern called
|
|
452
|
+
[hoisting the model](/getting-started/for-developers/resources/compound-components/#configuring-a-model).
|
|
640
453
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
454
|
+
```tsx
|
|
455
|
+
const model = usePaginationModel({
|
|
456
|
+
lastPage,
|
|
457
|
+
onPageChange: number => console.log(number),
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
<Pagination aria-label="Pagination" model={model}>
|
|
461
|
+
{/* Child components */}
|
|
462
|
+
</Pagination>;
|
|
463
|
+
```
|
|
648
464
|
|
|
649
|
-
|
|
465
|
+
### Config
|
|
650
466
|
|
|
651
|
-
|
|
652
|
-
|
|
467
|
+
`usePaginationModel` accepts a configuration object with the following properties and returns a
|
|
468
|
+
`PaginationModel` with `state` and `events` properties.
|
|
653
469
|
|
|
654
|
-
|
|
655
|
-
const paginationConfig = {
|
|
656
|
-
lastPage: 100,
|
|
657
|
-
rangeSize: 3,
|
|
658
|
-
onPageChange: pageNumber => console.log(pageNumber),
|
|
659
|
-
};
|
|
470
|
+
<ArgsTable of={PaginationModelConfigComponent} />
|
|
660
471
|
|
|
661
|
-
|
|
662
|
-
```
|
|
472
|
+
### State
|
|
663
473
|
|
|
664
|
-
|
|
474
|
+
The `PaginationModel` `state` is an object with the following properties.
|
|
665
475
|
|
|
666
|
-
|
|
667
|
-
const paginationConfig = {
|
|
668
|
-
lastPage: 100,
|
|
669
|
-
rangeSize: 3,
|
|
670
|
-
onPageChange: pageNumber => console.log(pageNumber),
|
|
671
|
-
};
|
|
476
|
+
<ArgsTable of={PaginationStateComponent} />
|
|
672
477
|
|
|
673
|
-
|
|
478
|
+
### Events
|
|
674
479
|
|
|
675
|
-
|
|
676
|
-
<Pagination aria-label="Pagination" model={model}>
|
|
677
|
-
{/* child components go here */}
|
|
678
|
-
</Pagination>
|
|
679
|
-
);
|
|
680
|
-
```
|
|
480
|
+
The `PaginationModel` `events` is an object with the following properties.
|
|
681
481
|
|
|
682
|
-
|
|
683
|
-
and `events` outside of the component. You could have an external button trigger events to update
|
|
684
|
-
the state, or have another component use the model's state. See the
|
|
685
|
-
[Advanced Usage](#advanced-usage) section for more detailed information.
|
|
482
|
+
<ArgsTable of={PaginationEventsComponent} />
|
|
686
483
|
|
|
687
|
-
|
|
484
|
+
## Utilities
|
|
688
485
|
|
|
689
486
|
### getLastPage
|
|
690
487
|
|
|
@@ -699,8 +496,6 @@ const totalCount = 128;
|
|
|
699
496
|
const lastPage = getLastPage(resultCount, totalCount); //=> 13
|
|
700
497
|
```
|
|
701
498
|
|
|
702
|
-
---
|
|
703
|
-
|
|
704
499
|
### getRangeMin
|
|
705
500
|
|
|
706
501
|
This function takes the pagination range and returns its minimum value. Here's an example:
|
|
@@ -712,8 +507,6 @@ const range = [1, 2, 3, 4, 5];
|
|
|
712
507
|
const rangeMin = getRangeMin(range); //=> 1
|
|
713
508
|
```
|
|
714
509
|
|
|
715
|
-
---
|
|
716
|
-
|
|
717
510
|
### getRangeMax
|
|
718
511
|
|
|
719
512
|
This function takes the pagination range and returns its maximum value. Here's an example:
|
|
@@ -725,8 +518,6 @@ const range = [1, 2, 3, 4, 5];
|
|
|
725
518
|
const rangeMin = getRangeMax(range); //=> 5
|
|
726
519
|
```
|
|
727
520
|
|
|
728
|
-
---
|
|
729
|
-
|
|
730
521
|
### getVisibleResultsMin
|
|
731
522
|
|
|
732
523
|
This function takes the current page, and number of results per page, and returns the minimum value
|
|
@@ -740,8 +531,6 @@ const resultCount = 10;
|
|
|
740
531
|
const pageMin = getVisibleResultsMin(currentPage, resultCount); //=> 41
|
|
741
532
|
```
|
|
742
533
|
|
|
743
|
-
---
|
|
744
|
-
|
|
745
534
|
### getVisibleResultsMax
|
|
746
535
|
|
|
747
536
|
This function takes the current page, number of results per page, and the total number of results,
|
|
@@ -755,42 +544,4 @@ const currentPage = 5;
|
|
|
755
544
|
const resultCount = 10;
|
|
756
545
|
const totalCount = 42;
|
|
757
546
|
const pageMax = getVisibleResultsMax(currentPage, resultCount, totalCount); //=> 42
|
|
758
|
-
```
|
|
759
|
-
|
|
760
|
-
---
|
|
761
|
-
|
|
762
|
-
### PaginationContext
|
|
763
|
-
|
|
764
|
-
You can also subscribe directly to `PaginationContext`. This is useful if you want to create a new,
|
|
765
|
-
custom subcomponent for your implementation and want it to subscribe to `Pagination`'s context.
|
|
766
|
-
Here's a simple example:
|
|
767
|
-
|
|
768
|
-
```tsx
|
|
769
|
-
import * as React from 'react';
|
|
770
|
-
import {Pagination, PaginationContext} from '@workday/canvas-kit-react/pagination';
|
|
771
|
-
|
|
772
|
-
const CustomButton = (props: React.HTMLAttributes<HTMLButtonElement>) => {
|
|
773
|
-
const model = React.useContext(PaginationContext);
|
|
774
|
-
|
|
775
|
-
const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
|
|
776
|
-
// if onClick is provided, pass the event along
|
|
777
|
-
props.onClick?.(e);
|
|
778
|
-
model.events.goTo(10);
|
|
779
|
-
};
|
|
780
|
-
|
|
781
|
-
return (
|
|
782
|
-
<button onClick={handleClick} {...props}>
|
|
783
|
-
Go To Page 10
|
|
784
|
-
</button>
|
|
785
|
-
);
|
|
786
|
-
};
|
|
787
|
-
|
|
788
|
-
export const CustomPagination = () => {
|
|
789
|
-
return (
|
|
790
|
-
<Pagination aria-label="Pagination" lastPage={20}>
|
|
791
|
-
<CustomButton aria-label="Page 10" />
|
|
792
|
-
{/* other child components go here */}
|
|
793
|
-
</Pagination>
|
|
794
|
-
);
|
|
795
|
-
};
|
|
796
547
|
```
|