@workday/canvas-kit-docs 6.9.0-next.0 → 6.9.0-next.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.
- package/dist/commonjs/index.js +13 -6
- package/dist/commonjs/lib/Specifications.d.ts.map +1 -1
- package/dist/commonjs/lib/Specifications.js +3 -1
- package/dist/commonjs/lib/docs.js +1 -0
- package/dist/commonjs/lib/specs.js +259 -2
- package/dist/es6/lib/Specifications.d.ts.map +1 -1
- package/dist/es6/lib/specs.js +259 -2
- package/dist/mdx/{4.0-MIGRATION-GUIDE.mdx → 4.0-UPGRADE-GUIDE.mdx} +1 -1
- package/dist/mdx/{5.0-MIGRATION-GUIDE.mdx → 5.0-UPGRADE-GUIDE.mdx} +3 -3
- package/dist/mdx/{6.0-MIGRATION-GUIDE.mdx → 6.0-UPGRADE-GUIDE.mdx} +4 -4
- package/dist/mdx/7.0-UPGRADE-GUIDE.mdx +1006 -0
- package/dist/mdx/COMPOUND_COMPONENTS.mdx +2 -2
- package/dist/mdx/CONTRIBUTING.mdx +2 -2
- package/dist/mdx/TESTING.mdx +1 -1
- package/dist/mdx/changelog.stories.mdx +1 -0
- package/dist/mdx/labs-react/search-form/examples/Basic.tsx +4 -2
- package/dist/mdx/labs-react/search-form/examples/CustomTheme.tsx +4 -2
- package/dist/mdx/labs-react/search-form/examples/Grow.tsx +4 -2
- package/dist/mdx/labs-react/search-form/examples/RTL.tsx +4 -2
- package/dist/mdx/labs-react/search-form/examples/Theming.tsx +4 -2
- package/dist/mdx/preview-react/_examples/SidePanelWithOverlay.mdx +8 -0
- package/dist/mdx/preview-react/_examples/examples/SidePanelWithOverlay.tsx +31 -0
- package/dist/mdx/preview-react/_examples/examples/TextInputWithFormik.tsx +3 -3
- package/dist/mdx/preview-react/form-field/examples/Custom.tsx +4 -5
- package/dist/mdx/preview-react/menu/Menu.mdx +1 -1
- package/dist/mdx/preview-react/menu/examples/ContextMenu.tsx +2 -2
- package/dist/mdx/preview-react/menu/examples/Icons.tsx +0 -1
- package/dist/mdx/preview-react/pill/Pill.mdx +241 -0
- package/dist/mdx/preview-react/pill/examples/Basic.tsx +18 -0
- package/dist/mdx/preview-react/pill/examples/WithAvatar.tsx +21 -0
- package/dist/mdx/preview-react/pill/examples/WithCount.tsx +9 -0
- package/dist/mdx/preview-react/pill/examples/WithList.tsx +31 -0
- package/dist/mdx/preview-react/pill/examples/WithReadOnly.tsx +15 -0
- package/dist/mdx/preview-react/pill/examples/WithRemovable.tsx +25 -0
- package/dist/mdx/preview-react/pill/examples/test-avatar.png +0 -0
- package/dist/mdx/preview-react/side-panel/SidePanel.mdx +5 -3
- package/dist/mdx/preview-react/side-panel/examples/AlwaysOpen.tsx +16 -22
- package/dist/mdx/preview-react/side-panel/examples/Basic.tsx +9 -14
- package/dist/mdx/preview-react/side-panel/examples/ExternalControl.tsx +9 -13
- package/dist/mdx/preview-react/side-panel/examples/HiddenName.tsx +1 -1
- package/dist/mdx/preview-react/side-panel/examples/OnExpandedChange.tsx +1 -1
- package/dist/mdx/preview-react/side-panel/examples/OnStateTransition.tsx +1 -1
- package/dist/mdx/preview-react/side-panel/examples/RightOrigin.tsx +17 -24
- package/dist/mdx/preview-react/side-panel/examples/Variant.tsx +9 -14
- package/dist/mdx/preview-react/text-area/examples/Alert.tsx +2 -1
- package/dist/mdx/preview-react/text-area/examples/HiddenLabel.tsx +6 -4
- package/dist/mdx/preview-react/text-area/examples/RefForwarding.tsx +1 -1
- package/dist/mdx/preview-react/text-input/examples/Alert.tsx +2 -1
- package/dist/mdx/preview-react/text-input/examples/HiddenLabel.tsx +6 -4
- package/dist/mdx/preview-react/text-input/examples/RefForwarding.tsx +1 -1
- package/dist/mdx/preview-react/text-input/examples/ThemedAlert.tsx +2 -1
- package/dist/mdx/react/_examples/SegmentedControlWithText.mdx +12 -0
- package/dist/mdx/react/_examples/examples/GlobalHeader.tsx +7 -6
- package/dist/mdx/react/_examples/examples/PageHeader.tsx +5 -5
- package/dist/mdx/react/_examples/examples/SegmentControlWithText.tsx +119 -0
- package/dist/mdx/react/action-bar/ActionBar.mdx +126 -23
- package/dist/mdx/react/action-bar/examples/Basic.tsx +7 -4
- package/dist/mdx/react/action-bar/examples/DeleteAction.tsx +15 -0
- package/dist/mdx/react/action-bar/examples/Icons.tsx +18 -0
- package/dist/mdx/react/action-bar/examples/OverflowActionBar.tsx +59 -0
- package/dist/mdx/react/banner/Banner.mdx +203 -19
- package/dist/mdx/react/banner/PropTables.splitprops.tsx +39 -0
- package/dist/mdx/react/banner/examples/ActionText.tsx +8 -1
- package/dist/mdx/react/banner/examples/Basic.tsx +8 -1
- package/dist/mdx/react/banner/examples/Error.tsx +8 -1
- package/dist/mdx/react/banner/examples/RefForwarding.tsx +25 -0
- package/dist/mdx/react/banner/examples/Sticky.tsx +12 -7
- package/dist/mdx/react/banner/examples/StickyAnimation.tsx +64 -0
- package/dist/mdx/react/banner/examples/StickyRTL.tsx +35 -0
- package/dist/mdx/react/banner/examples/ThemedAlert.tsx +28 -0
- package/dist/mdx/react/banner/examples/ThemedError.tsx +29 -0
- package/dist/mdx/react/button/button/Button.mdx +3 -3
- package/dist/mdx/react/button/button/Hyperlink.mdx +72 -0
- package/dist/mdx/react/button/button/examples/ExternalHyperlink.tsx +7 -0
- package/dist/mdx/react/button/button/examples/ExternalHyperlinkInverse.tsx +12 -0
- package/dist/mdx/react/button/button/examples/Hyperlink.tsx +5 -0
- package/dist/mdx/react/button/button/examples/HyperlinkInverse.tsx +12 -0
- package/dist/mdx/react/button/button/examples/Primary.tsx +11 -3
- package/dist/mdx/react/button/button/examples/PrimaryInverse.tsx +11 -3
- package/dist/mdx/react/button/button/examples/Secondary.tsx +11 -3
- package/dist/mdx/react/button/button/examples/SecondaryInverse.tsx +11 -3
- package/dist/mdx/react/button/button/examples/Tertiary.tsx +9 -4
- package/dist/mdx/react/button/button/examples/TertiaryInverse.tsx +12 -3
- package/dist/mdx/react/card/card.mdx +2 -2
- package/dist/mdx/react/card/examples/Depth.tsx +1 -1
- package/dist/mdx/react/checkbox/Checkbox.mdx +7 -0
- package/dist/mdx/react/checkbox/examples/Indeterminate.tsx +1 -1
- package/dist/mdx/react/checkbox/examples/Inverse.tsx +22 -0
- package/dist/mdx/react/checkbox/examples/RefForwarding.tsx +1 -1
- package/dist/mdx/react/collection/Collection.mdx +136 -0
- package/dist/mdx/react/collection/examples/Basic.tsx +12 -0
- package/dist/mdx/react/collection/examples/BasicVirtual.tsx +24 -0
- package/dist/mdx/react/collection/examples/DynamicItems.tsx +20 -0
- package/dist/mdx/react/collection/examples/IdentifiedItems.tsx +12 -0
- package/dist/mdx/react/collection/examples/MultiSelection.tsx +56 -0
- package/dist/mdx/react/collection/examples/RovingFocus.tsx +39 -0
- package/dist/mdx/react/collection/examples/Selection.tsx +58 -0
- package/dist/mdx/react/color-picker/color-input/ColorInput.mdx +2 -2
- package/dist/mdx/react/color-picker/color-preview/ColorPreview.mdx +2 -2
- package/dist/mdx/{labs-react/common → react/layout}/Box.mdx +3 -6
- package/dist/mdx/{labs-react → react}/layout/Flex.mdx +24 -27
- package/dist/mdx/{labs-react → react}/layout/Stack.mdx +98 -146
- package/dist/mdx/{labs-react/common → react/layout}/examples/As.tsx +1 -1
- package/dist/mdx/{labs-react/common → react/layout}/examples/Border.tsx +1 -1
- package/dist/mdx/{labs-react/common → react/layout}/examples/Color.tsx +1 -1
- package/dist/mdx/{labs-react/common → react/layout}/examples/Depth.tsx +9 -3
- package/dist/mdx/{labs-react → react}/layout/examples/Flex/FlexCard.tsx +2 -3
- package/dist/mdx/{labs-react → react}/layout/examples/Flex/FlexLayout.tsx +1 -1
- package/dist/mdx/{labs-react → react}/layout/examples/Flex/Usage.tsx +2 -3
- package/dist/mdx/{labs-react/common → react/layout}/examples/FlexItem.tsx +1 -2
- package/dist/mdx/{labs-react/common → react/layout}/examples/Layout.tsx +1 -1
- package/dist/mdx/{labs-react/common → react/layout}/examples/Position.tsx +1 -1
- package/dist/mdx/{labs-react → react}/layout/examples/PropTables.splitprops.tsx +1 -1
- package/dist/mdx/{labs-react/common → react/layout}/examples/Ref.tsx +1 -1
- package/dist/mdx/{labs-react/common → react/layout}/examples/Space.tsx +1 -1
- package/dist/mdx/{labs-react → react}/layout/examples/Stack/BasicStack.tsx +1 -1
- package/dist/mdx/{labs-react → react}/layout/examples/Stack/HStackCards.tsx +2 -3
- package/dist/mdx/{labs-react → react}/layout/examples/Stack/NestedStacks.tsx +1 -1
- package/dist/mdx/react/layout/examples/Stack/ShouldWrapChildren.tsx +28 -0
- package/dist/mdx/{labs-react → react}/layout/examples/Stack/StackCard.tsx +2 -2
- package/dist/mdx/{labs-react → react}/layout/examples/Stack/StackItems.tsx +1 -2
- package/dist/mdx/{labs-react → react}/layout/examples/Stack/VStackCards.tsx +2 -2
- package/dist/mdx/react/menu/Menu.mdx +123 -0
- package/dist/mdx/react/menu/examples/Basic.tsx +26 -0
- package/dist/mdx/react/menu/examples/ContextMenu.tsx +25 -0
- package/dist/mdx/react/menu/examples/Icons.tsx +41 -0
- package/dist/mdx/react/modal/Modal.mdx +34 -11
- package/dist/mdx/react/modal/examples/Basic.tsx +4 -2
- package/dist/mdx/react/modal/examples/BodyOverflow.tsx +56 -0
- package/dist/mdx/react/modal/examples/CustomFocus.tsx +4 -2
- package/dist/mdx/react/modal/examples/FullOverflow.tsx +55 -0
- package/dist/mdx/react/modal/examples/ReturnFocus.tsx +5 -3
- package/dist/mdx/react/modal/examples/WithoutCloseIcon.tsx +4 -2
- package/dist/mdx/react/pagination/PropTables.splitprops.tsx +1 -1
- package/dist/mdx/react/pagination/pagination.mdx +14 -14
- package/dist/mdx/react/popup/Popup.mdx +2 -1
- package/dist/mdx/react/popup/examples/Basic.tsx +1 -1
- package/dist/mdx/react/popup/examples/FocusRedirect.tsx +3 -2
- package/dist/mdx/react/popup/examples/FocusTrap.tsx +1 -1
- package/dist/mdx/react/popup/examples/FullScreen.tsx +1 -1
- package/dist/mdx/react/popup/examples/InitialFocus.tsx +4 -2
- package/dist/mdx/react/popup/examples/MultiplePopups.tsx +1 -1
- package/dist/mdx/react/popup/examples/NestedPopups.tsx +18 -18
- package/dist/mdx/react/popup/examples/RTL.tsx +6 -3
- package/dist/mdx/react/radio/Radio.mdx +7 -0
- package/dist/mdx/react/radio/examples/Inverse.tsx +23 -0
- package/dist/mdx/react/segmented-control/SegmentedControl.mdx +2 -2
- package/dist/mdx/react/segmented-control/examples/Basic.tsx +13 -11
- package/dist/mdx/react/skeleton/examples/Basic.tsx +1 -1
- package/dist/mdx/react/skeleton/examples/Color.tsx +1 -2
- package/dist/mdx/react/skeleton/examples/Simulation.tsx +11 -10
- package/dist/mdx/react/status-indicator/StatusIndicator.mdx +12 -0
- package/dist/mdx/react/status-indicator/examples/MaxWidth.tsx +30 -0
- package/dist/mdx/react/tabs/Tabs.mdx +14 -17
- package/dist/mdx/react/tabs/examples/DynamicTabs.tsx +6 -13
- package/dist/mdx/react/tabs/examples/HoistedModel.tsx +8 -8
- package/dist/mdx/react/tabs/examples/Icons.tsx +4 -4
- package/dist/mdx/react/tabs/examples/NamedTabs.tsx +10 -10
- package/dist/mdx/react/tabs/examples/OverflowTabs.tsx +4 -8
- package/dist/mdx/react/tabs/examples/SinglePanel.tsx +3 -3
- package/dist/mdx/react/text-input/examples/Basic.tsx +3 -0
- package/dist/mdx/react/tooltip/Tooltip.mdx +2 -2
- package/dist/mdx/react/tooltip/examples/Default.tsx +2 -2
- package/dist/mdx/react/tooltip/examples/UseTooltip.tsx +2 -2
- package/package.json +9 -17
- package/dist/mdx/labs-react/common/examples/PropTables.splitprops.tsx +0 -91
- package/dist/mdx/labs-react/layout/examples/Stack/ShouldWrapChildren.tsx +0 -33
- package/dist/mdx/react/button/icon-button/IconButton.mdx +0 -103
- package/dist/mdx/react/button/icon-button/examples/Circle.tsx +0 -6
- package/dist/mdx/react/button/icon-button/examples/CircleFilled.tsx +0 -8
- package/dist/mdx/react/button/icon-button/examples/Inverse.tsx +0 -20
- package/dist/mdx/react/button/icon-button/examples/InverseFilled.tsx +0 -20
- package/dist/mdx/react/button/icon-button/examples/MirroredIcon.tsx +0 -11
- package/dist/mdx/react/button/icon-button/examples/Plain.tsx +0 -8
- package/dist/mdx/react/button/icon-button/examples/Square.tsx +0 -8
- package/dist/mdx/react/button/icon-button/examples/SquareFilled.tsx +0 -8
- package/dist/mdx/react/button/icon-button/examples/Toggleable.tsx +0 -20
- package/ts3.5/dist/commonjs/index.d.ts +0 -4
- package/ts3.5/dist/commonjs/lib/Specifications.d.ts +0 -6
- package/ts3.5/dist/commonjs/lib/docs.d.ts +0 -5
- package/ts3.5/dist/commonjs/lib/specs.d.ts +0 -16
- package/ts3.5/dist/es6/index.d.ts +0 -4
- package/ts3.5/dist/es6/lib/Specifications.d.ts +0 -6
- package/ts3.5/dist/es6/lib/docs.d.ts +0 -5
- package/ts3.5/dist/es6/lib/specs.d.ts +0 -16
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import {ListBox} from '@workday/canvas-kit-react/collection';
|
|
2
|
+
|
|
3
|
+
import Basic from './examples/Basic';
|
|
4
|
+
import DynamicItems from './examples/DynamicItems';
|
|
5
|
+
import BasicVirtual from './examples/BasicVirtual';
|
|
6
|
+
import IdentifiedItems from './examples/IdentifiedItems';
|
|
7
|
+
import RovingFocus from './examples/RovingFocus';
|
|
8
|
+
import Selection from './examples/Selection';
|
|
9
|
+
import MultiSelection from './examples/MultiSelection';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
# Canvas Kit Collection API
|
|
13
|
+
|
|
14
|
+
The Collection API is a system of models and behaviors for creating lists and grids. For example,
|
|
15
|
+
`Tabs` uses collection behaviors and so does `Menu`. The UI of each looks very different, but much
|
|
16
|
+
of the behavior is shared. The Collection API should be used if a component doesn't already exist to
|
|
17
|
+
satisfy your needs.
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
yarn add @workday/canvas-kit-react
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### ListBox
|
|
28
|
+
|
|
29
|
+
The `ListBox` is a basic component that offers vertical rendering of a collection in the form of a
|
|
30
|
+
2-dimension list. It understands virtualization, rendering only visible items in the DOM while also
|
|
31
|
+
providing aria attributes to allow screen readers to still navigate virtual lists. The `ListBox`
|
|
32
|
+
contains a basic `ListBox.Item` that renders list items that render correctly with virtualization
|
|
33
|
+
and adds `aria-setsize` and `aria-posinset` for screen readers.
|
|
34
|
+
|
|
35
|
+
The `ListBox` is very basic and only adds enough functionality to render correctly. No additional
|
|
36
|
+
behaviors are added to navigate or select. React Hooks are provided to add this functionality and
|
|
37
|
+
are used by higher level components like `Menu` and `Menu.Item` which utilize `ListBox`.
|
|
38
|
+
|
|
39
|
+
<ArgsTable of={ListBox} />
|
|
40
|
+
|
|
41
|
+
#### Basic Example
|
|
42
|
+
|
|
43
|
+
The `ListBox` on its own isn't very useful. It registers each item with the model. The
|
|
44
|
+
`ListBox.Item` only uses the `useListItemRegister` hook which handles registration of static items
|
|
45
|
+
to the model. The `ListBox` uses `useListRenderItems` which handles rendering static items as well
|
|
46
|
+
as [Dynamic List](#dynamic-list) example).
|
|
47
|
+
|
|
48
|
+
<ExampleCodeBlock code={Basic} />
|
|
49
|
+
|
|
50
|
+
#### Identifying Items
|
|
51
|
+
|
|
52
|
+
A list item takes an optional `data-id` property that will be used to identify an item. Without a
|
|
53
|
+
`data-id`, the identifier will be the item's index when first registered. The basic example has a
|
|
54
|
+
`data-id` attribute that is a string representation of the index. Providing a `data-id` will
|
|
55
|
+
override to a value of your choosing. This identifier will be used by other hooks to identify the
|
|
56
|
+
item for selection, maintaining a cursor, or anything else.
|
|
57
|
+
|
|
58
|
+
<ExampleCodeBlock code={IdentifiedItems} />
|
|
59
|
+
|
|
60
|
+
#### Dynamic Items
|
|
61
|
+
|
|
62
|
+
The `ListBox` also handles a dynamic collection of items. Instead of providing each `ListBox.Item`
|
|
63
|
+
statically, provide a render function instead. The function is called with an `items` value that is
|
|
64
|
+
the same was what's provided to the model. By default, providing items will enable virtualization.
|
|
65
|
+
This example adds a `maxHeight` to ensure overflow. Virtualization uses absolute positioning of each
|
|
66
|
+
item, which could cause problems for popup menus. If your item count is low, pass
|
|
67
|
+
`shouldVirtualize={false}` to disable virtualization.
|
|
68
|
+
|
|
69
|
+
<ExampleCodeBlock code={DynamicItems} />
|
|
70
|
+
|
|
71
|
+
### List Model
|
|
72
|
+
|
|
73
|
+
The List model contains the the state and events necessary to track items, selection, and a cursor.
|
|
74
|
+
Various hooks can be used for a List model to create common behaviors associated with lists, such as
|
|
75
|
+
navigating a list with a keyboard, selection (single and multiple), and virtualization.
|
|
76
|
+
|
|
77
|
+
A list also has a "cursor". A cursor is often represented by focus, but it is not always a 1:1
|
|
78
|
+
mapping. Think of the cursor as the focus item within the list. If the list has browser focus, the
|
|
79
|
+
cursor will map to browser focus. Behaviors such as `useListRovingFocus` will map the cursor to the
|
|
80
|
+
active tab stop of the list. For more information, see
|
|
81
|
+
[Roving Tabindex](https://w3c.github.io/aria-practices/#kbd_roving_tabindex). `useListRovingFocus`
|
|
82
|
+
adds keyboard events that map to navigation events. A [Navigation Manager](#navigation-manager) is
|
|
83
|
+
used to map new cursor ids to these events. The `ListModel` takes an optional `navigation`
|
|
84
|
+
configuration to change the default navigation behavior. The default navigation manager is a
|
|
85
|
+
[wrappingNavigationManager](#wrappingnavigationmanager) meaning the cursor will wrap around the
|
|
86
|
+
beginning and the ends. The cursor also provides a [navigationManager](#navigationmanager) that does
|
|
87
|
+
not wrap. This is the default navigation for grids.
|
|
88
|
+
|
|
89
|
+
The cursor also adds the concept of `orientation` which defaults to `'vertical'`. A Tab list is an
|
|
90
|
+
example of a `'horizontal'` list.
|
|
91
|
+
|
|
92
|
+
### Grid
|
|
93
|
+
|
|
94
|
+
A Cursor List can become a grid if a `columnCount` is provided. The array of items is still flat,
|
|
95
|
+
but navigational controls are now in two dimensions instead of one. A one dimension list is
|
|
96
|
+
bidirectionally aware, but a grid will always
|
|
97
|
+
|
|
98
|
+
#### Navigation Manager
|
|
99
|
+
|
|
100
|
+
#### Roving Tabindex
|
|
101
|
+
|
|
102
|
+
The list system also includes a cursor that extends the list. A cursor is mostly used for focusing
|
|
103
|
+
items. The [roving tabindex](https://w3c.github.io/aria-practices/#kbd_roving_tabindex) is a
|
|
104
|
+
well-supported way to accomplish accessibility requirements for focusing items within a list. This
|
|
105
|
+
example shows how to use `useListRovingFocus`. This example uses the `ListBox` component, but the
|
|
106
|
+
default `ListBox.Item` is very basic. We have two options, we can either pass additional
|
|
107
|
+
functionality via `elemPropsHook` or by creating a new item using our elemProps hook primitives.
|
|
108
|
+
Both will be demonstrated. Creating a custom item is recommended if you create a custom component
|
|
109
|
+
and export it. Using `elemPropsHook` with `ListBox.Item` is recommended only for one-off instances.
|
|
110
|
+
|
|
111
|
+
You can either use the tab key for focus on an item or click on an item and then use the up/down
|
|
112
|
+
keys to navigation the list. By default, the list is set to wrap navigation using the
|
|
113
|
+
`wrappingNavigationManager`. Only a single item in the list is a focus stop that "roves" as the
|
|
114
|
+
up/down arrows are pressed.
|
|
115
|
+
|
|
116
|
+
**Note:** This example doesn't meet accessibility requirements. The list will have to have some type
|
|
117
|
+
of context. Like "navigation list" or "menu list".
|
|
118
|
+
|
|
119
|
+
<ExampleCodeBlock code={RovingFocus} />
|
|
120
|
+
|
|
121
|
+
#### Selection
|
|
122
|
+
|
|
123
|
+
Lists support selection. `useSelectionItem` is applied to an item which adds an `onClick` that adds
|
|
124
|
+
the item to the `state.selectedIds`. The default selection manager is a single select. This example
|
|
125
|
+
uses `ListBox` and creates a custom `SelectableItem` elemProps hook and component.
|
|
126
|
+
|
|
127
|
+
<ExampleCodeBlock code={Selection} />
|
|
128
|
+
|
|
129
|
+
#### Multiple Selection
|
|
130
|
+
|
|
131
|
+
Lists support selection. `useSelectionItem` is applied to an item which adds an `onClick` that adds
|
|
132
|
+
the item to the `state.selectedIds`. The default selection manager is a single select.
|
|
133
|
+
|
|
134
|
+
<ExampleCodeBlock code={MultiSelection} />
|
|
135
|
+
|
|
136
|
+
### Hooks
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {ListBox, useListItemRovingFocus} from '@workday/canvas-kit-react/collection';
|
|
4
|
+
|
|
5
|
+
interface Item {
|
|
6
|
+
id: string;
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const items: Item[] = Array(1000)
|
|
11
|
+
.fill(true)
|
|
12
|
+
.map((_, index) => ({id: String(index + 1), text: `Item - ${index + 1}`}));
|
|
13
|
+
|
|
14
|
+
export default () => {
|
|
15
|
+
return (
|
|
16
|
+
<ListBox items={items} maxHeight={300}>
|
|
17
|
+
{(item: Item) => (
|
|
18
|
+
<ListBox.Item data-id={item.id} elemPropsHook={useListItemRovingFocus}>
|
|
19
|
+
{item.text}
|
|
20
|
+
</ListBox.Item>
|
|
21
|
+
)}
|
|
22
|
+
</ListBox>
|
|
23
|
+
);
|
|
24
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {ListBox} from '@workday/canvas-kit-react/collection';
|
|
4
|
+
|
|
5
|
+
interface Item {
|
|
6
|
+
id: string;
|
|
7
|
+
text: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const items: Item[] = Array(1000)
|
|
11
|
+
.fill(true)
|
|
12
|
+
.map((_, index) => ({id: String(index + 1), text: `Item - ${index + 1}`}));
|
|
13
|
+
|
|
14
|
+
export default () => {
|
|
15
|
+
return (
|
|
16
|
+
<ListBox items={items} maxHeight={300}>
|
|
17
|
+
{(item: Item) => <ListBox.Item data-id={item.id}>{item.text}</ListBox.Item>}
|
|
18
|
+
</ListBox>
|
|
19
|
+
);
|
|
20
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {ListBox} from '@workday/canvas-kit-react/collection';
|
|
4
|
+
|
|
5
|
+
export default () => {
|
|
6
|
+
return (
|
|
7
|
+
<ListBox>
|
|
8
|
+
<ListBox.Item data-id="first">First</ListBox.Item>
|
|
9
|
+
<ListBox.Item data-id="second">Second</ListBox.Item>
|
|
10
|
+
</ListBox>
|
|
11
|
+
);
|
|
12
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useListItemRegister,
|
|
5
|
+
useListItemRovingFocus,
|
|
6
|
+
useListItemSelect,
|
|
7
|
+
useListModel,
|
|
8
|
+
ListItemProps,
|
|
9
|
+
ListBox,
|
|
10
|
+
} from '@workday/canvas-kit-react/collection';
|
|
11
|
+
import {composeHooks, createSubcomponent} from '@workday/canvas-kit-react/common';
|
|
12
|
+
import {multiSelectionManager} from '../../lib/useSelectionListModel';
|
|
13
|
+
|
|
14
|
+
const useMultiSelectItem = composeHooks(
|
|
15
|
+
useListItemSelect,
|
|
16
|
+
useListItemRovingFocus,
|
|
17
|
+
useListItemRegister
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const Item = createSubcomponent('button')({
|
|
21
|
+
displayName: 'MultiSelectableItem',
|
|
22
|
+
modelHook: useListModel,
|
|
23
|
+
elemPropsHook: useMultiSelectItem,
|
|
24
|
+
})<ListItemProps>((elemProps, Element, model) => {
|
|
25
|
+
return (
|
|
26
|
+
<Element
|
|
27
|
+
role="listitem"
|
|
28
|
+
{...elemProps}
|
|
29
|
+
style={{
|
|
30
|
+
background: model.state.selectedIds.includes(elemProps['data-id']) ? 'gray' : 'white',
|
|
31
|
+
}}
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
export default () => {
|
|
37
|
+
const model = useListModel({
|
|
38
|
+
initialSelectedIds: ['first', 'second'],
|
|
39
|
+
selection: multiSelectionManager,
|
|
40
|
+
orientation: 'horizontal',
|
|
41
|
+
});
|
|
42
|
+
return (
|
|
43
|
+
<>
|
|
44
|
+
<ListBox model={model}>
|
|
45
|
+
<Item data-id="first">First</Item>
|
|
46
|
+
<Item data-id="second">Second</Item>
|
|
47
|
+
<Item data-id="third">Third</Item>
|
|
48
|
+
</ListBox>
|
|
49
|
+
|
|
50
|
+
<p>Cursor ID: {model.state.cursorId}</p>
|
|
51
|
+
<p>
|
|
52
|
+
Selected IDs: {(model.state.selectedIds !== 'all' ? model.state.selectedIds : []).join(',')}
|
|
53
|
+
</p>
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useListItemRegister,
|
|
5
|
+
useListItemRovingFocus,
|
|
6
|
+
useListModel,
|
|
7
|
+
ListBox,
|
|
8
|
+
ListItemProps,
|
|
9
|
+
} from '@workday/canvas-kit-react/collection';
|
|
10
|
+
import {composeHooks, createSubcomponent} from '@workday/canvas-kit-react/common';
|
|
11
|
+
|
|
12
|
+
// create our own hook using `useListItemRegister` and `useListItemRovingFocus`. Note the
|
|
13
|
+
// `useListItemRegister` must be the last hook when using `composeHooks`
|
|
14
|
+
const useRovingFocusItem = composeHooks(useListItemRovingFocus, useListItemRegister);
|
|
15
|
+
|
|
16
|
+
// create our own item. We use `modelHook` to define which model should be used and `elemPropsHook`
|
|
17
|
+
// to determine which elemProps hook should be used. `elemProps` will be populated with props to
|
|
18
|
+
// pass to the element
|
|
19
|
+
const RovingFocusItem = createSubcomponent('li')({
|
|
20
|
+
displayName: 'RovingFocusItem',
|
|
21
|
+
modelHook: useListModel,
|
|
22
|
+
elemPropsHook: useRovingFocusItem,
|
|
23
|
+
})<ListItemProps>((elemProps, Element) => {
|
|
24
|
+
return <Element {...elemProps} />;
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export default () => {
|
|
28
|
+
return (
|
|
29
|
+
<ListBox>
|
|
30
|
+
{/* We can use `ListBox.Item` and add `useListItemRovingFocus`. Useful for one-off */}
|
|
31
|
+
<ListBox.Item data-id="first" elemPropsHook={useListItemRovingFocus}>
|
|
32
|
+
First
|
|
33
|
+
</ListBox.Item>
|
|
34
|
+
{/* Use a custom item. Useful for reusing components */}
|
|
35
|
+
<RovingFocusItem data-id="second">Second</RovingFocusItem>
|
|
36
|
+
<RovingFocusItem data-id="third">Third</RovingFocusItem>
|
|
37
|
+
</ListBox>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
useListItemRegister,
|
|
5
|
+
useListItemRovingFocus,
|
|
6
|
+
useListItemSelect,
|
|
7
|
+
useListModel,
|
|
8
|
+
ListItemProps,
|
|
9
|
+
ListBox,
|
|
10
|
+
} from '@workday/canvas-kit-react/collection';
|
|
11
|
+
import {
|
|
12
|
+
composeHooks,
|
|
13
|
+
createElemPropsHook,
|
|
14
|
+
createSubcomponent,
|
|
15
|
+
} from '@workday/canvas-kit-react/common';
|
|
16
|
+
|
|
17
|
+
// Create a custom hook for our item
|
|
18
|
+
const useItem = composeHooks(
|
|
19
|
+
createElemPropsHook(useListModel)((model, ref, elemProps: ListItemProps) => {
|
|
20
|
+
return {
|
|
21
|
+
role: 'listitem',
|
|
22
|
+
style: {
|
|
23
|
+
background: model.state.selectedIds.includes(elemProps['data-id']) ? 'gray' : 'white',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}),
|
|
27
|
+
useListItemSelect,
|
|
28
|
+
useListItemRovingFocus,
|
|
29
|
+
useListItemRegister
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
// Create a custom item
|
|
33
|
+
const SelectableItem = createSubcomponent('button')({
|
|
34
|
+
displayName: 'SelectableItem',
|
|
35
|
+
modelHook: useListModel,
|
|
36
|
+
elemPropsHook: useItem,
|
|
37
|
+
})<ListItemProps>((elemProps, Element) => {
|
|
38
|
+
return <Element {...elemProps} />;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
export default () => {
|
|
42
|
+
const model = useListModel({
|
|
43
|
+
initialSelectedIds: ['first'],
|
|
44
|
+
orientation: 'horizontal',
|
|
45
|
+
});
|
|
46
|
+
return (
|
|
47
|
+
<>
|
|
48
|
+
<ListBox model={model}>
|
|
49
|
+
<SelectableItem data-id="first">First</SelectableItem>
|
|
50
|
+
<SelectableItem data-id="second">Second</SelectableItem>
|
|
51
|
+
<SelectableItem data-id="third">Third</SelectableItem>
|
|
52
|
+
</ListBox>
|
|
53
|
+
|
|
54
|
+
<p>Cursor ID: {model.state.cursorId}</p>
|
|
55
|
+
<p>Selected ID: {model.state.selectedIds[0]}</p>
|
|
56
|
+
</>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
@@ -105,12 +105,12 @@ standards.
|
|
|
105
105
|
|
|
106
106
|
<ExampleCodeBlock code={Error} />
|
|
107
107
|
|
|
108
|
-
## Props
|
|
108
|
+
## Color Input Props
|
|
109
109
|
|
|
110
110
|
Undocumented props are spread to the underlying `<input type="text">` element.
|
|
111
111
|
|
|
112
112
|
<ArgsTable of={ColorInput} />
|
|
113
113
|
|
|
114
|
-
## Specifications
|
|
114
|
+
## Color Input Specifications
|
|
115
115
|
|
|
116
116
|
<Specifications file="ColorPicker.spec.ts" name="ColorInput" />
|
|
@@ -42,12 +42,12 @@ relative to the Color Preview. `labelPosition` accepts the following values:
|
|
|
42
42
|
|
|
43
43
|
<ExampleCodeBlock code={LabelPosition} />
|
|
44
44
|
|
|
45
|
-
## Props
|
|
45
|
+
## Color Preview Props
|
|
46
46
|
|
|
47
47
|
Undocumented props are spread to the underlying `<input type="text">` element.
|
|
48
48
|
|
|
49
49
|
<ArgsTable of={ColorPreview} />
|
|
50
50
|
|
|
51
|
-
## Specifications
|
|
51
|
+
## Color Preview Specifications
|
|
52
52
|
|
|
53
53
|
<Specifications file="ColorPicker.spec.ts" name="ColorPreview" />
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {Box} from '@workday/canvas-kit-
|
|
1
|
+
import {Box} from '@workday/canvas-kit-react/layout';
|
|
2
2
|
// examples
|
|
3
3
|
import As from './examples/As';
|
|
4
4
|
import Border from './examples/Border';
|
|
@@ -33,9 +33,6 @@ import {
|
|
|
33
33
|
|
|
34
34
|
# Box
|
|
35
35
|
|
|
36
|
-
[](https://github.com/Workday/canvas-kit/tree/master/modules/labs-react/README.md)
|
|
37
|
-
This component is work in progress and currently in pre-release.
|
|
38
|
-
|
|
39
36
|
`Box` is a primitive component that provides a common, ergonomic API around Canvas design tokens. It
|
|
40
37
|
is highly flexible, and its primary purpose is to build other components.
|
|
41
38
|
|
|
@@ -85,14 +82,14 @@ is highly flexible, and its primary purpose is to build other components.
|
|
|
85
82
|
## Usage
|
|
86
83
|
|
|
87
84
|
```tsx
|
|
88
|
-
import {Box, BoxProps} from '@workday/canvas-kit-
|
|
85
|
+
import {Box, BoxProps} from '@workday/canvas-kit-react/layout';
|
|
89
86
|
|
|
90
87
|
interface CardProps extends BoxProps {
|
|
91
88
|
// custom Card props go here
|
|
92
89
|
}
|
|
93
90
|
|
|
94
91
|
const Card = (props: CardProps) => {
|
|
95
|
-
return <Box borderRadius="m" depth={
|
|
92
|
+
return <Box borderRadius="m" depth={1} padding="m" {...props} />;
|
|
96
93
|
};
|
|
97
94
|
```
|
|
98
95
|
|
|
@@ -1,35 +1,43 @@
|
|
|
1
|
-
import {Flex} from '@workday/canvas-kit-
|
|
1
|
+
import {Flex} from '@workday/canvas-kit-react/layout';
|
|
2
2
|
// examples
|
|
3
3
|
import FlexCard from './examples/Flex/FlexCard';
|
|
4
4
|
import FlexLayout from './examples/Flex/FlexLayout';
|
|
5
5
|
import Usage from './examples/Flex/Usage';
|
|
6
|
-
import FlexStyle from './examples/PropTables.splitprops.tsx';
|
|
6
|
+
import {FlexStyle} from './examples/PropTables.splitprops.tsx';
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
# Flex
|
|
10
|
-
|
|
11
|
-
[](https://github.com/Workday/canvas-kit/tree/master/modules/labs-react/README.md)
|
|
12
|
-
This component is work in progress and currently in pre-release.
|
|
9
|
+
# Canvas Kit Flex
|
|
13
10
|
|
|
14
11
|
`Flex` is a low-level layout component that provides a common, ergonomic API for building
|
|
15
12
|
one-dimensional layouts with
|
|
16
13
|
[CSS Flexbox](https://developer.mozilla.org/en-US/docs/Learn/CSS/CSS_layout/Flexbox).
|
|
17
14
|
|
|
18
|
-
##
|
|
15
|
+
## Installation
|
|
19
16
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
- [What's the difference between `Flex` and `Box`?](#whats-the-difference-between-flex-and-box)
|
|
24
|
-
- [Flex Props](#flex-props)
|
|
25
|
-
- [Examples](#examples)
|
|
26
|
-
- [Exhaustive Prop List](#exhaustive-prop-list)
|
|
17
|
+
```sh
|
|
18
|
+
yarn add @workday/canvas-kit-react
|
|
19
|
+
```
|
|
27
20
|
|
|
28
21
|
## Usage
|
|
29
22
|
|
|
23
|
+
### Basic Example
|
|
24
|
+
|
|
30
25
|
<ExampleCodeBlock code={Usage} />
|
|
31
26
|
|
|
32
|
-
|
|
27
|
+
### Rows and Columns
|
|
28
|
+
|
|
29
|
+
You can nest `Flex` components to build layouts with rows and columns.
|
|
30
|
+
|
|
31
|
+
<ExampleCodeBlock code={FlexLayout} />
|
|
32
|
+
|
|
33
|
+
### Small Containers
|
|
34
|
+
|
|
35
|
+
You can also use `Flex` to create layouts within smaller containers, such as this card example
|
|
36
|
+
below:
|
|
37
|
+
|
|
38
|
+
<ExampleCodeBlock code={FlexCard} />
|
|
39
|
+
|
|
40
|
+
### Flex vs. Box
|
|
33
41
|
|
|
34
42
|
`Flex` is built with `Box` and has access to all `BoxProps`. The main differences between `Box` and
|
|
35
43
|
`Flex` are:
|
|
@@ -52,17 +60,6 @@ through style props as well. There are seven flex container props:
|
|
|
52
60
|
|
|
53
61
|
<ArgsTable of={FlexStyle} />
|
|
54
62
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
You can nest `Flex` components to build layouts with rows and columns.
|
|
58
|
-
|
|
59
|
-
<ExampleCodeBlock code={FlexLayout} />
|
|
60
|
-
|
|
61
|
-
You can also use `Flex` to create layouts within smaller containers, such as this card example
|
|
62
|
-
below:
|
|
63
|
-
|
|
64
|
-
<ExampleCodeBlock code={FlexCard} />
|
|
65
|
-
|
|
66
|
-
## Exhaustive Prop List
|
|
63
|
+
### Flex Props (Exhaustive List)
|
|
67
64
|
|
|
68
65
|
<ArgsTable of={Flex} />
|