@workday/canvas-kit-docs 8.3.2 → 8.3.4
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.
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
Pagination,
|
|
4
|
+
getLastPage,
|
|
5
|
+
getVisibleResultsMax,
|
|
6
|
+
getVisibleResultsMin,
|
|
7
|
+
usePaginationModel,
|
|
8
|
+
} from '@workday/canvas-kit-react/pagination';
|
|
9
|
+
import {Flex} from '@workday/canvas-kit-react/layout';
|
|
10
|
+
import {Text} from '@workday/canvas-kit-react/text';
|
|
11
|
+
import {useResizeObserver, useTheme} from '@workday/canvas-kit-react/common';
|
|
12
|
+
|
|
13
|
+
export default () => {
|
|
14
|
+
const resultCount = 10;
|
|
15
|
+
const totalCount = 100;
|
|
16
|
+
const lastPage = getLastPage(resultCount, totalCount);
|
|
17
|
+
// Normally, rangeSize can be a static value, but we're making it stateful,
|
|
18
|
+
// so we can update it using useResizeObserver
|
|
19
|
+
const [rangeSize, setRangeSize] = React.useState(5);
|
|
20
|
+
const model = usePaginationModel({
|
|
21
|
+
lastPage,
|
|
22
|
+
rangeSize,
|
|
23
|
+
});
|
|
24
|
+
// We're only using this state to display the container width;
|
|
25
|
+
const [containerWidth, setContainerWidth] = React.useState(0);
|
|
26
|
+
// We're using breakpoints from the theme as reference points to adjust the range
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
const {values: breakpointValues} = theme.canvas.breakpoints;
|
|
29
|
+
|
|
30
|
+
// We'll use this ref to measure the size of the container
|
|
31
|
+
const containerRef = React.useRef(null);
|
|
32
|
+
useResizeObserver({
|
|
33
|
+
ref: containerRef,
|
|
34
|
+
onResize: ({width}) => {
|
|
35
|
+
// Note: onResizeObserver only accounts for the size of the container.
|
|
36
|
+
// It does not factor in margin, padding, or border widths.
|
|
37
|
+
// If you want to be exact, adjust your math to account for those.
|
|
38
|
+
// If you're okay with being close enough on the measurements, this is fine.
|
|
39
|
+
if (width) {
|
|
40
|
+
// updating the container width for the display text
|
|
41
|
+
setContainerWidth(width);
|
|
42
|
+
// helper functions for better readability
|
|
43
|
+
const isBetweenZeroAndSmall = width >= breakpointValues.zero && width < breakpointValues.s;
|
|
44
|
+
const isBetweenSmallAndMedium = width >= breakpointValues.s && width < breakpointValues.m;
|
|
45
|
+
const isBetweenMediumAndLarge = width >= breakpointValues.m && width < breakpointValues.l;
|
|
46
|
+
const isBetweenLargeAndXLarge = width >= breakpointValues.l && width < breakpointValues.xl;
|
|
47
|
+
// We're checking the rangeSize at each level to prevent extra re-renders.
|
|
48
|
+
if (rangeSize !== 1 && isBetweenZeroAndSmall) {
|
|
49
|
+
setRangeSize(1);
|
|
50
|
+
}
|
|
51
|
+
if (rangeSize !== 3 && isBetweenSmallAndMedium) {
|
|
52
|
+
setRangeSize(3);
|
|
53
|
+
}
|
|
54
|
+
if (rangeSize !== 5 && isBetweenMediumAndLarge) {
|
|
55
|
+
setRangeSize(5);
|
|
56
|
+
}
|
|
57
|
+
if (rangeSize !== 7 && isBetweenLargeAndXLarge) {
|
|
58
|
+
setRangeSize(7);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<Flex
|
|
66
|
+
border="solid 1px"
|
|
67
|
+
ref={containerRef}
|
|
68
|
+
justifyContent="space-between"
|
|
69
|
+
padding="s"
|
|
70
|
+
alignItems="center"
|
|
71
|
+
>
|
|
72
|
+
<Text typeLevel="body.small" fontWeight="bold">
|
|
73
|
+
Width: {containerWidth}px
|
|
74
|
+
</Text>
|
|
75
|
+
<Pagination model={model} aria-label="Pagination">
|
|
76
|
+
<Pagination.Controls>
|
|
77
|
+
<Pagination.StepToPreviousButton aria-label="Previous" />
|
|
78
|
+
<Pagination.PageList>
|
|
79
|
+
{({state}) =>
|
|
80
|
+
state.range.map(pageNumber => (
|
|
81
|
+
<Pagination.PageListItem key={pageNumber}>
|
|
82
|
+
<Pagination.PageButton
|
|
83
|
+
aria-label={`Page ${pageNumber}`}
|
|
84
|
+
pageNumber={pageNumber}
|
|
85
|
+
/>
|
|
86
|
+
</Pagination.PageListItem>
|
|
87
|
+
))
|
|
88
|
+
}
|
|
89
|
+
</Pagination.PageList>
|
|
90
|
+
<Pagination.StepToNextButton aria-label="Next" />
|
|
91
|
+
</Pagination.Controls>
|
|
92
|
+
<Pagination.AdditionalDetails shouldHideDetails>
|
|
93
|
+
{({state}) =>
|
|
94
|
+
`${getVisibleResultsMin(state.currentPage, resultCount)}-${getVisibleResultsMax(
|
|
95
|
+
state.currentPage,
|
|
96
|
+
resultCount,
|
|
97
|
+
totalCount
|
|
98
|
+
)} of ${totalCount} results`
|
|
99
|
+
}
|
|
100
|
+
</Pagination.AdditionalDetails>
|
|
101
|
+
</Pagination>
|
|
102
|
+
</Flex>
|
|
103
|
+
);
|
|
104
|
+
};
|
|
@@ -5,6 +5,7 @@ import CustomRange from './examples/CustomRange';
|
|
|
5
5
|
import JumpControls from './examples/JumpControls';
|
|
6
6
|
import GoToForm from './examples/GoToForm';
|
|
7
7
|
import HoistedModel from './examples/HoistedModel';
|
|
8
|
+
import ResponsiveRange from './examples/ResponsiveRange';
|
|
8
9
|
import RTL from './examples/RTL';
|
|
9
10
|
import {
|
|
10
11
|
PaginationHoistedComponent,
|
|
@@ -90,6 +91,13 @@ This example uses a custom range that allows you to control the width of the com
|
|
|
90
91
|
|
|
91
92
|
<ExampleCodeBlock code={CustomRange} />
|
|
92
93
|
|
|
94
|
+
### Responsive Range
|
|
95
|
+
|
|
96
|
+
In some situations, you might want to adjust Pagination's range based on the width of the container.
|
|
97
|
+
You can use `useResizeObserver` to accomplish this as in the example below.
|
|
98
|
+
|
|
99
|
+
<ExampleCodeBlock code={ResponsiveRange} />
|
|
100
|
+
|
|
93
101
|
## Components
|
|
94
102
|
|
|
95
103
|
### Pagination
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-docs",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.4",
|
|
4
4
|
"description": "Documentation components of Canvas Kit components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@storybook/csf": "0.0.1",
|
|
45
|
-
"@workday/canvas-kit-react": "^8.3.
|
|
45
|
+
"@workday/canvas-kit-react": "^8.3.4"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"fs-extra": "^10.0.0",
|
|
@@ -50,5 +50,5 @@
|
|
|
50
50
|
"mkdirp": "^1.0.3",
|
|
51
51
|
"typescript": "4.1"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "e997dc142da034d2b2bdbae2c7585a8b4429e2f8"
|
|
54
54
|
}
|