@workday/canvas-kit-docs 9.0.0-alpha.415-next.17 → 9.0.0-alpha.417-next.19
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.
|
@@ -384,6 +384,23 @@ knows where it needs to go, but the identifier may not be loaded yet. The mechan
|
|
|
384
384
|
is private and should not breaking anything. If you created a custom navigation manager, the
|
|
385
385
|
signature has been changed.
|
|
386
386
|
|
|
387
|
+
The `useListModel` modelHook no longers sets the initial `cursorId` to the first item if no
|
|
388
|
+
`initialCursorId` config option is set. This functionality has been moved to the
|
|
389
|
+
`useListItemRovingFocus` elemProps hook. If you use `useListItemRovingFocus`, the behavior is
|
|
390
|
+
unchanged. If you need the first item to be set as the `cursorId` and you do not use
|
|
391
|
+
`useListItemRovingFocus`, you will have to add this functionality back to your collection logic.
|
|
392
|
+
|
|
393
|
+
The logic to set the `cursorId` to the first item should go into an item elemProps hook that
|
|
394
|
+
contains the following:
|
|
395
|
+
|
|
396
|
+
```ts
|
|
397
|
+
React.useEffect(() => {
|
|
398
|
+
if (!model.state.cursorId && model.state.items.length) {
|
|
399
|
+
model.events.goTo({id: model.state.items[0].id});
|
|
400
|
+
}
|
|
401
|
+
}, [model.state.cursorId, model.state.items, model.events]);
|
|
402
|
+
```
|
|
403
|
+
|
|
387
404
|
## Utility Updates
|
|
388
405
|
|
|
389
406
|
### useTheme and getTheme
|
|
@@ -5,6 +5,7 @@ import {ListBox} from '@workday/canvas-kit-react/collection';
|
|
|
5
5
|
import Basic from './examples/Basic';
|
|
6
6
|
import StringChildren from './examples/StringChildren';
|
|
7
7
|
import DynamicItems from './examples/DynamicItems';
|
|
8
|
+
import DataLoader from './examples/DataLoader';
|
|
8
9
|
import BasicVirtual from './examples/BasicVirtual';
|
|
9
10
|
import IdentifiedItems from './examples/IdentifiedItems';
|
|
10
11
|
import RovingFocus from './examples/RovingFocus';
|
|
@@ -59,6 +60,19 @@ item, which could cause problems for popup menus. If your item count is low, pas
|
|
|
59
60
|
|
|
60
61
|
<ExampleCodeBlock code={DynamicItems} />
|
|
61
62
|
|
|
63
|
+
### DataLoader
|
|
64
|
+
|
|
65
|
+
The collection system comes with a data loader to help with dynamic collections. You must provide
|
|
66
|
+
`total`, `pageSize`, and an asynchronous `load` function. The loader will call the `load` function
|
|
67
|
+
when the user navigates the collection and needs more data. This example shows how to hook up a
|
|
68
|
+
simple data loader and mocks a `load` function to simulate an asynchronous response.
|
|
69
|
+
|
|
70
|
+
The data loader also takes a model argument to know which model to create. The loader configures
|
|
71
|
+
the model to handle asynchronous keyboard navigation and will return the configured model to you
|
|
72
|
+
to pass along to the collection component.
|
|
73
|
+
|
|
74
|
+
<ExampleCodeBlock code={DataLoader} />
|
|
75
|
+
|
|
62
76
|
#### Roving Tabindex
|
|
63
77
|
|
|
64
78
|
The list system also includes a cursor that extends the list. A cursor is mostly used for focusing
|
|
@@ -154,38 +168,15 @@ columns, but not rows. This is the default navigation manager for lists.
|
|
|
154
168
|
|
|
155
169
|
## Hooks
|
|
156
170
|
|
|
157
|
-
|
|
158
|
-
|
|
171
|
+
<>
|
|
159
172
|
<SymbolDoc name="useListItemRegister" fileName="/react/" />
|
|
160
|
-
|
|
161
|
-
### `useListItemAllowChildStrings`
|
|
162
|
-
|
|
163
173
|
<SymbolDoc name="useListItemAllowChildStrings" fileName="/react/" />
|
|
164
|
-
|
|
165
|
-
### `useListItemRovingFocus`
|
|
166
|
-
|
|
167
174
|
<SymbolDoc name="useListItemRovingFocus" fileName="/react/" />
|
|
168
|
-
|
|
169
|
-
### `useListItemSelect`
|
|
170
|
-
|
|
171
175
|
<SymbolDoc name="useListItemSelect" fileName="/react/" />
|
|
172
|
-
|
|
173
|
-
### `useListRenderItems`
|
|
174
|
-
|
|
175
176
|
<SymbolDoc name="useListRenderItems" fileName="/react/" />
|
|
176
|
-
|
|
177
|
-
### `useListResetCursorOnBlur`
|
|
178
|
-
|
|
179
177
|
<SymbolDoc name="useListResetCursorOnBlur" fileName="/react/" />
|
|
180
|
-
|
|
181
|
-
### `useOverflowListItemMeasure`
|
|
182
|
-
|
|
183
178
|
<SymbolDoc name="useOverflowListItemMeasure" fileName="/react/" />
|
|
184
|
-
|
|
185
|
-
### `useOverflowListMeasure`
|
|
186
|
-
|
|
187
179
|
<SymbolDoc name="useOverflowListMeasure" fileName="/react/" />
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
<SymbolDoc name="useOverflowListTarget" fileName="/react/" />
|
|
180
|
+
<SymbolDoc name="useOverflowListTarget" fileName="/react/" />
|
|
181
|
+
<SymbolDoc name="useListLoader" fileName="/react/" />
|
|
182
|
+
</>
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
ListBox,
|
|
5
|
+
useListLoader,
|
|
6
|
+
useListModel,
|
|
7
|
+
useListItemSelect,
|
|
8
|
+
useListItemRovingFocus,
|
|
9
|
+
LoadReturn,
|
|
10
|
+
} from '@workday/canvas-kit-react/collection';
|
|
11
|
+
import {Box, Flex} from '@workday/canvas-kit-react/layout';
|
|
12
|
+
import {composeHooks} from '@workday/canvas-kit-react/common';
|
|
13
|
+
|
|
14
|
+
function pickRandom<T>(arr: T[]): T {
|
|
15
|
+
return arr[Math.floor(Math.random() * arr.length)];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const useListItem = composeHooks(useListItemSelect, useListItemRovingFocus);
|
|
19
|
+
|
|
20
|
+
const colors = ['Blue', 'Red', 'Purple', 'Green', 'Pink'];
|
|
21
|
+
const fruits = ['Apple', 'Orange', 'Banana', 'Grape', 'Lemon', 'Lime'];
|
|
22
|
+
const options = Array(1000)
|
|
23
|
+
.fill('')
|
|
24
|
+
.map((_, index) => {
|
|
25
|
+
return `${pickRandom(colors)} ${pickRandom(fruits)} ${index + 1}`;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
export default () => {
|
|
29
|
+
const [messages, setMessages] = React.useState<string[]>([]);
|
|
30
|
+
|
|
31
|
+
const {model, loader} = useListLoader(
|
|
32
|
+
{
|
|
33
|
+
getId: (item: string) => item,
|
|
34
|
+
getTextValue: (item: string) => item,
|
|
35
|
+
shouldVirtualize: true,
|
|
36
|
+
total: 1000,
|
|
37
|
+
pageSize: 20,
|
|
38
|
+
async load({pageNumber, pageSize}) {
|
|
39
|
+
setMessages(messages => messages.concat(`Page ${pageNumber} loading`));
|
|
40
|
+
|
|
41
|
+
// Return a promise, but use setTimeout to mock a delayed server response
|
|
42
|
+
return new Promise<LoadReturn<string>>(resolve => {
|
|
43
|
+
setTimeout(() => {
|
|
44
|
+
const start = (pageNumber - 1) * pageSize;
|
|
45
|
+
const end = start + pageSize;
|
|
46
|
+
|
|
47
|
+
const total = options.length;
|
|
48
|
+
const items = options.slice(start, end);
|
|
49
|
+
|
|
50
|
+
setMessages(messages => messages.concat(`Page ${pageNumber} loaded`));
|
|
51
|
+
|
|
52
|
+
resolve({
|
|
53
|
+
items,
|
|
54
|
+
total,
|
|
55
|
+
});
|
|
56
|
+
}, 500);
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
useListModel
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<Flex gap="xl">
|
|
65
|
+
<Flex flexDirection="column" gap="zero">
|
|
66
|
+
<p>Scroll or focus and use keys to navigate</p>
|
|
67
|
+
<ListBox model={model} maxHeight={400} width={300}>
|
|
68
|
+
{item => (
|
|
69
|
+
<ListBox.Item
|
|
70
|
+
as="button"
|
|
71
|
+
role="listitem"
|
|
72
|
+
elemPropsHook={useListItem}
|
|
73
|
+
height={20}
|
|
74
|
+
background="transparent"
|
|
75
|
+
border="none"
|
|
76
|
+
>
|
|
77
|
+
{item}
|
|
78
|
+
</ListBox.Item>
|
|
79
|
+
)}
|
|
80
|
+
</ListBox>
|
|
81
|
+
</Flex>
|
|
82
|
+
<Flex flexDirection="column" gap="zero">
|
|
83
|
+
<p>Events:</p>
|
|
84
|
+
<Box as="ul" maxHeight={400} overflowY="auto">
|
|
85
|
+
{messages.map(message => (
|
|
86
|
+
<li key={message}>{message}</li>
|
|
87
|
+
))}
|
|
88
|
+
</Box>
|
|
89
|
+
</Flex>
|
|
90
|
+
</Flex>
|
|
91
|
+
);
|
|
92
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-docs",
|
|
3
|
-
"version": "9.0.0-alpha.
|
|
3
|
+
"version": "9.0.0-alpha.417-next.19+608e353d",
|
|
4
4
|
"description": "Documentation components of Canvas Kit components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -44,9 +44,9 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@emotion/styled": "^11.6.0",
|
|
46
46
|
"@storybook/csf": "0.0.1",
|
|
47
|
-
"@workday/canvas-kit-labs-react": "^9.0.0-alpha.
|
|
48
|
-
"@workday/canvas-kit-preview-react": "^9.0.0-alpha.
|
|
49
|
-
"@workday/canvas-kit-react": "^9.0.0-alpha.
|
|
47
|
+
"@workday/canvas-kit-labs-react": "^9.0.0-alpha.417-next.19+608e353d",
|
|
48
|
+
"@workday/canvas-kit-preview-react": "^9.0.0-alpha.417-next.19+608e353d",
|
|
49
|
+
"@workday/canvas-kit-react": "^9.0.0-alpha.417-next.19+608e353d",
|
|
50
50
|
"@workday/canvas-system-icons-web": "^3.0.0",
|
|
51
51
|
"markdown-to-jsx": "^6.10.3",
|
|
52
52
|
"ts-node": "^10.9.1"
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"mkdirp": "^1.0.3",
|
|
58
58
|
"typescript": "4.2"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "608e353d22b266e70f71a58b8726ca4332d5cf0b"
|
|
61
61
|
}
|