@workday/canvas-kit-docs 5.2.2 → 5.2.6
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/lib/specs.js +1 -1
- package/dist/es6/lib/specs.js +1 -1
- package/dist/mdx/4.0-MIGRATION-GUIDE.mdx +1 -1
- package/dist/mdx/preview-react/side-panel/SidePanel.mdx +1 -1
- package/dist/mdx/react/card/card.mdx +1 -1
- package/dist/mdx/react/tabs/Tabs.mdx +121 -80
- package/dist/mdx/react/tabs/TabsModel.splitprops.tsx +5 -0
- package/dist/mdx/react/tabs/examples/{Simple.tsx → Basic.tsx} +0 -0
- package/package.json +3 -3
|
@@ -4555,7 +4555,7 @@ module.exports = {specifications: [
|
|
|
4555
4555
|
"children": [
|
|
4556
4556
|
{
|
|
4557
4557
|
"type": "describe",
|
|
4558
|
-
"name": "given the [Components/Containers/Tabs/React,
|
|
4558
|
+
"name": "given the [Components/Containers/Tabs/React, Basic] story is rendered",
|
|
4559
4559
|
"children": [
|
|
4560
4560
|
{
|
|
4561
4561
|
"type": "it",
|
package/dist/es6/lib/specs.js
CHANGED
|
@@ -4555,7 +4555,7 @@ module.exports = {specifications: [
|
|
|
4555
4555
|
"children": [
|
|
4556
4556
|
{
|
|
4557
4557
|
"type": "describe",
|
|
4558
|
-
"name": "given the [Components/Containers/Tabs/React,
|
|
4558
|
+
"name": "given the [Components/Containers/Tabs/React, Basic] story is rendered",
|
|
4559
4559
|
"children": [
|
|
4560
4560
|
{
|
|
4561
4561
|
"type": "it",
|
|
@@ -44,7 +44,7 @@ Non-breaking:
|
|
|
44
44
|
## Theming Changes
|
|
45
45
|
|
|
46
46
|
We have promoted all of the theming functionality out of Canvas Kit Labs.
|
|
47
|
-
[It now lives in `@workday/canvas-kit-react-common`](https://github.com/Workday/canvas-kit/tree/
|
|
47
|
+
[It now lives in `@workday/canvas-kit-react-common`](https://github.com/Workday/canvas-kit/tree/v4.0.0/modules/common/react/lib/theming).
|
|
48
48
|
This includes the `CanvasProvider` component. We've also made some stability improvements (see
|
|
49
49
|
below).
|
|
50
50
|
|
|
@@ -143,7 +143,7 @@ Below is an example:
|
|
|
143
143
|
```tsx
|
|
144
144
|
import {useSidePanel} from '@workday/canvas-kit-preview-react/side-panel';
|
|
145
145
|
|
|
146
|
-
const {expanded,
|
|
146
|
+
const {expanded, setExpanded, panelProps, labelProps, controlProps} = useSidePanel({
|
|
147
147
|
initialExpanded: false,
|
|
148
148
|
panelId: 'custom-panel-id',
|
|
149
149
|
labelId: 'custom-label-id',
|
|
@@ -8,7 +8,7 @@ import Padding from './examples/Padding';
|
|
|
8
8
|
# Canvas Kit Card
|
|
9
9
|
|
|
10
10
|
A Card is a preview that serves as an entry point to more detailed information. Card is a
|
|
11
|
-
presentational [compound component](/getting-started/for-developers/resources/compound-components/
|
|
11
|
+
presentational [compound component](/getting-started/for-developers/resources/compound-components/)
|
|
12
12
|
used as a building block for other components such as [Popup](/components/popups/popup/) and
|
|
13
13
|
[Modal](/components/popups/modal/).
|
|
14
14
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {Tabs} from '@workday/canvas-kit-react/tabs';
|
|
2
2
|
import {Specifications} from '@workday/canvas-kit-docs';
|
|
3
3
|
|
|
4
|
-
import
|
|
4
|
+
import Basic from './examples/Basic';
|
|
5
5
|
import NamedKeys from './examples/NamedKeys';
|
|
6
6
|
import RightToLeft from './examples/RightToLeft';
|
|
7
7
|
import DisabledTab from './examples/DisabledTab';
|
|
@@ -9,9 +9,20 @@ import SinglePanel from './examples/SinglePanel';
|
|
|
9
9
|
import AlternativeTabStop from './examples/AlternativeTabStop';
|
|
10
10
|
import HoistedModel from './examples/HoistedModel';
|
|
11
11
|
import DynamicTabs from './examples/DynamicTabs';
|
|
12
|
+
import {
|
|
13
|
+
TabsModelConfigComponent,
|
|
14
|
+
TabsStateComponent,
|
|
15
|
+
TabsEventsComponent,
|
|
16
|
+
} from './TabsModel.splitprops.tsx';
|
|
12
17
|
|
|
13
18
|
|
|
14
|
-
# Canvas Kit
|
|
19
|
+
# Canvas Kit Tabs
|
|
20
|
+
|
|
21
|
+
`Tabs` is a [compound component](/getting-started/for-developers/resources/compound-components/)
|
|
22
|
+
which can be composed in a variety of different ways. It follows the
|
|
23
|
+
[W3 Tabs specification](https://www.w3.org/TR/wai-aria-practices/#tabpanel).
|
|
24
|
+
|
|
25
|
+
[> Workday Design Reference](https://design.workday.com/components/navigation/tabs)
|
|
15
26
|
|
|
16
27
|
## Installation
|
|
17
28
|
|
|
@@ -21,80 +32,65 @@ yarn add @workday/canvas-kit-react
|
|
|
21
32
|
|
|
22
33
|
## Usage
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
[W3 Tabs specification](https://www.w3.org/TR/wai-aria-practices/#tabpanel). `Tabs` is a
|
|
26
|
-
[Compound Component](/getting-started/for-developers/resources/compound-components/), which means it
|
|
27
|
-
can be composed in a variety of different ways. We'll first cover some basic usage examples followed
|
|
28
|
-
by more advanced usage.
|
|
35
|
+
### Basic Example
|
|
29
36
|
|
|
30
|
-
|
|
37
|
+
`Tabs` includes a container `Tabs` component and the following subcomponents: `Tabs.List`,
|
|
38
|
+
`Tabs.Item` and `Tabs.Panel`.
|
|
31
39
|
|
|
32
|
-
|
|
33
|
-
[Advanced Usage](#advanced-usage) section for details on supporting custom implementations.
|
|
40
|
+
<ExampleCodeBlock code={Basic} />
|
|
34
41
|
|
|
35
|
-
|
|
42
|
+
### Hoisted Model
|
|
36
43
|
|
|
37
|
-
|
|
44
|
+
By default, `Tabs` will create and use its own [model](#model) internally. Alternatively, you may
|
|
45
|
+
configure your own model with `useTabsModel` and pass it to `Tabs` via the `model` prop. This
|
|
46
|
+
pattern is referred to as hoisting the model and provides direct access to its `state` and `events`
|
|
47
|
+
outside of the `Tabs` component.
|
|
38
48
|
|
|
39
|
-
|
|
49
|
+
In this example, we set up external observation of the model state and create an external button to
|
|
50
|
+
trigger an event to change the active tab.
|
|
40
51
|
|
|
41
|
-
|
|
52
|
+
<ExampleCodeBlock code={HoistedModel} />
|
|
42
53
|
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
### Named Keys
|
|
55
|
+
|
|
56
|
+
`Tabs.Item` and `Tabs.Panel` both take an optional `name` attribute that is used for the
|
|
57
|
+
`onActivate` callback. This example is identical to the Basic Example, but with named keys for the
|
|
58
|
+
`Tabs.Item` and `Tabs.Panel` subcomponents.
|
|
45
59
|
|
|
46
60
|
<ExampleCodeBlock code={NamedKeys} />
|
|
47
61
|
|
|
48
|
-
|
|
62
|
+
### Right-to-Left
|
|
49
63
|
|
|
50
64
|
`Tabs` supports right-to-left through the theme of the `CanvasProvider`.
|
|
51
65
|
|
|
52
66
|
<ExampleCodeBlock code={RightToLeft} />
|
|
53
67
|
|
|
54
|
-
|
|
68
|
+
### Disabled Tab
|
|
55
69
|
|
|
56
|
-
|
|
70
|
+
Set the `disabled` prop of a `Tabs.Item` to `true` to disable it.
|
|
57
71
|
|
|
58
72
|
<ExampleCodeBlock code={DisabledTab} />
|
|
59
73
|
|
|
60
|
-
|
|
74
|
+
### Alternative Tab Stop
|
|
61
75
|
|
|
62
76
|
By default, tab panels are focusable for accessibility. If the contents of a tab panel have a
|
|
63
|
-
focusable element, you may disable this default behavior by setting `tabIndex`
|
|
64
|
-
example has a tab panel with a focusable button
|
|
77
|
+
focusable element, you may disable this default behavior by setting the `tabIndex` prop of
|
|
78
|
+
`Tabs.Panel` to `undefined`. This example has a tab panel with a focusable button.
|
|
65
79
|
|
|
66
80
|
<ExampleCodeBlock code={AlternativeTabStop} />
|
|
67
81
|
|
|
68
|
-
###
|
|
69
|
-
|
|
70
|
-
Below are some examples for more advanced / custom use cases. We expect most people won't need to
|
|
71
|
-
read this section, but if you're needing to go beyond basic examples or are curious, feel free to
|
|
72
|
-
explore this section. While these examples are not exhaustive, they provide additional insight into
|
|
73
|
-
what's possible.
|
|
74
|
-
|
|
75
|
-
#### Hoisted Model
|
|
76
|
-
|
|
77
|
-
The `Tabs` component takes in an optional `model` property. If not defined, it will create and use
|
|
78
|
-
its own. Hoisting the model allows access to state and events outside the `Tabs` component family.
|
|
79
|
-
You can create a `TabsModel` using the `useTabsModel` hook and configure the model with the same
|
|
80
|
-
configuration that the `Tabs` component receives. If you pass in a configured model, configuration
|
|
81
|
-
properties passed to the `Tabs` component will be ignored.
|
|
82
|
-
|
|
83
|
-
In this example, we'll set up external observation of the `TabsModel` state and set up an external
|
|
84
|
-
button to trigger an event to change the currently active tab.
|
|
85
|
-
|
|
86
|
-
<ExampleCodeBlock code={HoistedModel} />
|
|
82
|
+
### Single Tab Panel
|
|
87
83
|
|
|
88
|
-
|
|
84
|
+
The compound component pattern allows for advanced composition. For example, `Tabs` can be composed
|
|
85
|
+
to have only a single `Tabs.Panel` using attribute overrides and callbacks. More information about
|
|
86
|
+
attributes and callbacks can be found in the prop tables below for each subcomponent.
|
|
89
87
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
and callbacks are in property tables below for each subcomponent. In this example, we'll use a
|
|
93
|
-
Hoisted model and the `activeTab` property of the state to show content of our `contents` object.
|
|
88
|
+
In this example, we use a hoisted model and the `activeTab` property of the state to show content
|
|
89
|
+
from the `contents` object.
|
|
94
90
|
|
|
95
91
|
<ExampleCodeBlock code={SinglePanel} />
|
|
96
92
|
|
|
97
|
-
|
|
93
|
+
### Dynamic Tabs
|
|
98
94
|
|
|
99
95
|
The `Tabs.Item` component takes in an optional `index` property if you want to specify the position
|
|
100
96
|
of a tab. If not defined, by default it will append tabs to the end. For example, if your tabs are
|
|
@@ -107,83 +103,128 @@ the end.
|
|
|
107
103
|
|
|
108
104
|
### Tabs
|
|
109
105
|
|
|
110
|
-
The `Tabs` component is the container component that is responsible for creating a `TabsModel` that
|
|
111
|
-
is shared using React context. It does not represent a real element.
|
|
112
|
-
|
|
113
106
|
#### Usage
|
|
114
107
|
|
|
108
|
+
`Tabs` is a container component that is responsible for creating a `TabsModel` and sharing it with
|
|
109
|
+
its children using React context. It does not represent a real element.
|
|
110
|
+
|
|
115
111
|
```tsx
|
|
116
|
-
//
|
|
117
|
-
<Tabs onActivate={({
|
|
118
|
-
{/* sub components go here */ }
|
|
119
|
-
</Tabs>
|
|
112
|
+
// Configuration
|
|
113
|
+
<Tabs onActivate={({data}) => console.log('Activated tab', data.tab)}>{/* Subcomponents */}</Tabs>;
|
|
120
114
|
|
|
121
115
|
// OR
|
|
122
116
|
|
|
123
|
-
// model
|
|
124
|
-
const model = useTabsModel(
|
|
117
|
+
// Hoisted model
|
|
118
|
+
const model = useTabsModel({
|
|
119
|
+
onActivate({data}) {
|
|
120
|
+
console.log('Activated Tab', data.tab);
|
|
121
|
+
},
|
|
122
|
+
});
|
|
125
123
|
|
|
126
|
-
<Tabs model={model}>
|
|
127
|
-
{/* sub components go here */ }
|
|
128
|
-
</Tabs>
|
|
124
|
+
<Tabs model={model}>{/* Subcomponents */}</Tabs>;
|
|
129
125
|
```
|
|
130
126
|
|
|
131
|
-
####
|
|
127
|
+
#### Props
|
|
132
128
|
|
|
133
|
-
|
|
129
|
+
Note that if you pass in a `model` configured with `useTabsModel`, configuration props passed to
|
|
130
|
+
`Tabs` will be ignored.
|
|
134
131
|
|
|
135
|
-
|
|
132
|
+
<ArgsTable of={Tabs} />
|
|
136
133
|
|
|
137
134
|
### Tabs.List
|
|
138
135
|
|
|
139
|
-
`Tabs.List` is a `div` element with a `role=tablist`. It is a container for `Tabs.Item` components.
|
|
140
|
-
Any additional attributes provided will be forwared to the dom element.
|
|
141
|
-
|
|
142
136
|
#### Usage
|
|
143
137
|
|
|
138
|
+
`Tabs.List` is a `div` element with a `role=tablist`. It is a container for `Tabs.Item`
|
|
139
|
+
subcomponents.
|
|
140
|
+
|
|
144
141
|
```tsx
|
|
145
|
-
<Tabs.List>{/* Tabs.Items
|
|
142
|
+
<Tabs.List>{/* Tabs.Items */}</Tabs.List>
|
|
146
143
|
```
|
|
147
144
|
|
|
148
|
-
####
|
|
145
|
+
#### Props
|
|
149
146
|
|
|
150
|
-
|
|
147
|
+
Undocumented props are spread to the underlying `div` element.
|
|
151
148
|
|
|
152
|
-
|
|
149
|
+
<ArgsTable of={Tabs.List} />
|
|
153
150
|
|
|
154
151
|
### Tabs.Item
|
|
155
152
|
|
|
153
|
+
#### Usage
|
|
154
|
+
|
|
156
155
|
`Tabs.Item` is a `button` element with a `role=tab`. Each `Tabs.Item` is associated with a
|
|
157
156
|
`Tabs.Panel` either by a `name` attribute or by the position in the list. If a `name` is provided,
|
|
158
|
-
it must match the name passed to the `Tabs.Panel` component.
|
|
159
|
-
|
|
160
|
-
#### Usage
|
|
157
|
+
it must match the name passed to the corresponding `Tabs.Panel` component.
|
|
161
158
|
|
|
162
159
|
```tsx
|
|
163
160
|
<Tabs.Item name="first">First Tab</Tabs.Item>
|
|
164
161
|
```
|
|
165
162
|
|
|
166
|
-
####
|
|
163
|
+
#### Props
|
|
167
164
|
|
|
168
|
-
|
|
165
|
+
Undocumented props are spread to the underlying `button` element.
|
|
169
166
|
|
|
170
|
-
|
|
167
|
+
<ArgsTable of={Tabs.Item} />
|
|
171
168
|
|
|
172
169
|
### Tabs.Panel
|
|
173
170
|
|
|
171
|
+
#### Usage
|
|
172
|
+
|
|
174
173
|
`Tabs.Panel` is a `div` element with a `role=tabpanel`. It is focusable by default. Each
|
|
175
174
|
`Tabs.Panel` is controlled by a `Tabs.Item` either by a `name` attribute or by the position in the
|
|
176
|
-
list. If a `name` is provided, it must match the name passed to the `Tabs.Item`
|
|
175
|
+
list. If a `name` is provided, it must match the name passed to the corresponding `Tabs.Item`
|
|
176
|
+
component.
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
```tsx
|
|
179
|
+
<Tabs.Panel name="first">{/* Contents of the tab panel */}</Tabs.Panel>
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
#### Props
|
|
183
|
+
|
|
184
|
+
Undocumented props are spread to the underlying `div` element.
|
|
185
|
+
|
|
186
|
+
<ArgsTable of={Tabs.Panel} />
|
|
187
|
+
|
|
188
|
+
## Model
|
|
189
|
+
|
|
190
|
+
If `Tabs` was stripped of all its markup, attributes, and styling, what would remain is the
|
|
191
|
+
[model](/getting-started/for-developers/resources/compound-components/#models). The model is an
|
|
192
|
+
object composed of two parts: `state` which describes the current snapshot in time of the component
|
|
193
|
+
and `events` which describes events that can be sent to the model.
|
|
194
|
+
|
|
195
|
+
By default, `Tabs` will create and use its own model internally. Alternatively, if you need direct
|
|
196
|
+
access to the model's `state` and `events`, you may configure your own model with `useTabsModel` and
|
|
197
|
+
pass it to `Tabs` via a pattern called
|
|
198
|
+
[hoisting the model](/getting-started/for-developers/resources/compound-components/#configuring-a-model).
|
|
179
199
|
|
|
180
200
|
```tsx
|
|
181
|
-
|
|
201
|
+
const model = useTabsModel({
|
|
202
|
+
onActivate({data}) {
|
|
203
|
+
console.log('Activated Tab', data);
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
<Tabs model={model}>{/* Subcomponents */}</Tabs>;
|
|
182
208
|
```
|
|
183
209
|
|
|
184
|
-
|
|
210
|
+
### Config
|
|
211
|
+
|
|
212
|
+
`useTabsModel` accepts a configuration object with the following properties and returns a
|
|
213
|
+
`TabsModel` with `state` and `events` properties.
|
|
214
|
+
|
|
215
|
+
<ArgsTable of={TabsModelConfigComponent} />
|
|
216
|
+
|
|
217
|
+
### State
|
|
218
|
+
|
|
219
|
+
The `TabsModel` `state` is an object with the following properties.
|
|
220
|
+
|
|
221
|
+
<ArgsTable of={TabsStateComponent} />
|
|
222
|
+
|
|
223
|
+
### Events
|
|
224
|
+
|
|
225
|
+
The `TabsModel` `events` is an object with the following properties.
|
|
185
226
|
|
|
186
|
-
<
|
|
227
|
+
<ArgsTable of={TabsEventsComponent} />
|
|
187
228
|
|
|
188
229
|
## Specifications
|
|
189
230
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import {TabsModelConfig, TabsState, TabsEvents} from '@workday/canvas-kit-react/tabs';
|
|
2
|
+
|
|
3
|
+
export const TabsModelConfigComponent = (_: TabsModelConfig) => <div />;
|
|
4
|
+
export const TabsStateComponent = (_: TabsState) => <div />;
|
|
5
|
+
export const TabsEventsComponent = (_: TabsEvents) => <div />;
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workday/canvas-kit-docs",
|
|
3
|
-
"version": "5.2.
|
|
3
|
+
"version": "5.2.6",
|
|
4
4
|
"description": "Documentation components of Canvas Kit components",
|
|
5
5
|
"author": "Workday, Inc. (https://www.workday.com)",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
],
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@storybook/csf": "0.0.1",
|
|
52
|
-
"@workday/canvas-kit-react": "^5.2.
|
|
52
|
+
"@workday/canvas-kit-react": "^5.2.6"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"fs-extra": "^10.0.0",
|
|
@@ -57,5 +57,5 @@
|
|
|
57
57
|
"mkdirp": "^1.0.3",
|
|
58
58
|
"typescript": "^3.8.3"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "995afb783905539646bfb52f824b1c018da9df57"
|
|
61
61
|
}
|