@workday/canvas-kit-docs 12.0.0-alpha.918-next.0 → 12.0.0-alpha.921-next.0

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,92 @@
1
+ import React from 'react';
2
+
3
+ import {FormField} from '@workday/canvas-kit-react/form-field';
4
+ import {PrimaryButton, SecondaryButton} from '@workday/canvas-kit-react/button';
5
+ import {Flex} from '@workday/canvas-kit-react/layout';
6
+
7
+ import {MultiSelect} from '@workday/canvas-kit-preview-react/multi-select';
8
+
9
+ const items = [
10
+ {id: '1', text: 'Cheese'},
11
+ {id: '2', text: 'Olives'},
12
+ {id: '3', text: 'Onions'},
13
+ {id: '4', text: 'Pepperoni'},
14
+ {id: '5', text: 'Peppers'},
15
+ ];
16
+
17
+ export default () => {
18
+ const formRef = React.useRef<HTMLFormElement>(null);
19
+ const [value, setValue] = React.useState('1');
20
+ const [label, setLabel] = React.useState('Cheese');
21
+
22
+ function handleOnChange(event: React.ChangeEvent<HTMLInputElement>) {
23
+ const value = event.currentTarget.value;
24
+ setValue(value);
25
+ setLabel(
26
+ value
27
+ .split(', ')
28
+ .map(item => items.find(i => i.id === item)?.text || 'Not Found')
29
+ .join(', ')
30
+ );
31
+ }
32
+
33
+ return (
34
+ <>
35
+ <form
36
+ onSubmit={e => {
37
+ console.log('form submitted');
38
+ e.preventDefault();
39
+ }}
40
+ ref={formRef}
41
+ >
42
+ <Flex gap="s" flexDirection="column">
43
+ <MultiSelect items={items}>
44
+ <FormField orientation="horizontal">
45
+ <FormField.Label>Toppings</FormField.Label>
46
+ <FormField.Input
47
+ as={MultiSelect.Input}
48
+ placeholder="Select Multiple"
49
+ name="toppings"
50
+ onChange={handleOnChange}
51
+ value={value}
52
+ />
53
+ <MultiSelect.Popper>
54
+ <MultiSelect.Card>
55
+ <MultiSelect.List>
56
+ {item => (
57
+ <MultiSelect.Item data-id={item.id}>
58
+ <MultiSelect.Item.Text>{item.text}</MultiSelect.Item.Text>
59
+ </MultiSelect.Item>
60
+ )}
61
+ </MultiSelect.List>
62
+ </MultiSelect.Card>
63
+ </MultiSelect.Popper>
64
+ </FormField>
65
+ </MultiSelect>
66
+ <Flex gap="s">
67
+ <SecondaryButton
68
+ onClick={e => {
69
+ setValue('1, 2, 3');
70
+ }}
71
+ >
72
+ Set to "Cheese, Olives, Onions" via React `value`
73
+ </SecondaryButton>
74
+ <SecondaryButton
75
+ onClick={e => {
76
+ const input = formRef.current.querySelector('[name=toppings]') as HTMLInputElement;
77
+ input.value = '1, 2';
78
+ }}
79
+ >
80
+ Set to "Cheese, Olives" via DOM `value`
81
+ </SecondaryButton>
82
+ </Flex>
83
+ <div>
84
+ <PrimaryButton type="submit">Submit</PrimaryButton>
85
+ </div>
86
+ <div>Selected ID: {value}</div>
87
+ <div>Selected Label: {label}</div>
88
+ </Flex>
89
+ </form>
90
+ </>
91
+ );
92
+ };
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+
3
+ import {FormField} from '@workday/canvas-kit-react/form-field';
4
+ import {
5
+ mediaPauseIcon,
6
+ mediaPlayIcon,
7
+ mediaTopicsIcon,
8
+ skipIcon,
9
+ previousIcon,
10
+ } from '@workday/canvas-system-icons-web';
11
+
12
+ import {MultiSelect} from '@workday/canvas-kit-preview-react/multi-select';
13
+
14
+ const items = [
15
+ {id: '1', text: 'Pause', icon: mediaPauseIcon},
16
+ {id: '2', text: 'Play', icon: mediaPlayIcon},
17
+ {id: '3', text: 'Skip', icon: skipIcon},
18
+ {id: '4', text: 'Previous', icon: previousIcon},
19
+ ];
20
+
21
+ export default () => {
22
+ return (
23
+ <MultiSelect items={items}>
24
+ <FormField orientation="horizontal">
25
+ <FormField.Label>Controls</FormField.Label>
26
+ <FormField.Input as={MultiSelect.Input} placeholder="Select Multiple" />
27
+ <MultiSelect.Popper>
28
+ <MultiSelect.Card>
29
+ <MultiSelect.List>
30
+ {item => (
31
+ <MultiSelect.Item data-id={item.id}>
32
+ <MultiSelect.Item.Icon icon={item.icon} />
33
+ <MultiSelect.Item.Text>{item.text}</MultiSelect.Item.Text>
34
+ <MultiSelect.Item.Icon icon={mediaTopicsIcon} />
35
+ </MultiSelect.Item>
36
+ )}
37
+ </MultiSelect.List>
38
+ </MultiSelect.Card>
39
+ </MultiSelect.Popper>
40
+ </FormField>
41
+ </MultiSelect>
42
+ );
43
+ };
@@ -0,0 +1,123 @@
1
+ import React from 'react';
2
+
3
+ import {system} from '@workday/canvas-tokens-web';
4
+
5
+ import {createStyles} from '@workday/canvas-kit-styling';
6
+ import {LoadReturn} from '@workday/canvas-kit-react/collection';
7
+ import {CanvasProvider} from '@workday/canvas-kit-react/common';
8
+ import {useComboboxLoader} from '@workday/canvas-kit-react/combobox';
9
+ import {FormField} from '@workday/canvas-kit-react/form-field';
10
+
11
+ import {MultiSelect, useMultiSelectModel} from '@workday/canvas-kit-preview-react/multi-select';
12
+ import {StyledMenuItem} from '@workday/canvas-kit-react/menu';
13
+
14
+ const mainContentStyles = createStyles({
15
+ padding: system.space.x4,
16
+ });
17
+
18
+ const colors = ['Red', 'Blue', 'Purple', 'Green', 'Pink'];
19
+ const fruits = ['Apple', 'Orange', 'Banana', 'Grape', 'Lemon', 'Lime'];
20
+ const options = Array(1000)
21
+ .fill('')
22
+ .map((_, index) => {
23
+ return {
24
+ id: `${index + 1}`,
25
+ text: `${colors[index % colors.length]} ${fruits[index % fruits.length]} ${index + 1}`,
26
+ };
27
+ });
28
+
29
+ export default () => {
30
+ const [value, setValue] = React.useState('');
31
+
32
+ const {model, loader} = useComboboxLoader(
33
+ {
34
+ // You can start with any number that makes sense.
35
+ total: 0,
36
+
37
+ // Pick whatever number makes sense for your API
38
+ pageSize: 20,
39
+
40
+ // A load function that will be called by the loader. You must return a promise that returns
41
+ // an object like `{items: [], total: 0}`. The `items` will be merged into the loader's cache
42
+ async load({pageNumber, pageSize, filter}) {
43
+ return new Promise<LoadReturn<(typeof options)[0]>>(resolve => {
44
+ // simulate a server response by resolving after a period of time
45
+ setTimeout(() => {
46
+ // simulate paging and filtering based on pre-computed items
47
+ const start = (pageNumber - 1) * pageSize;
48
+ const end = start + pageSize;
49
+ const filteredItems = options.filter(item => {
50
+ if (filter === '' || typeof filter !== 'string') {
51
+ return true;
52
+ }
53
+ return item.text.toLowerCase().includes(filter.toLowerCase());
54
+ });
55
+
56
+ const total = filteredItems.length;
57
+ const items = filteredItems.slice(start, end);
58
+
59
+ resolve({
60
+ items,
61
+ total,
62
+ });
63
+ }, 300);
64
+ });
65
+ },
66
+ onShow() {
67
+ // The `shouldLoad` cancels while the combobox menu is hidden, so let's load when it is
68
+ // visible
69
+ loader.load();
70
+ },
71
+ },
72
+ useMultiSelectModel
73
+ );
74
+
75
+ return (
76
+ <CanvasProvider>
77
+ <>
78
+ <form
79
+ onSubmit={e => {
80
+ console.log('form submitted');
81
+ e.preventDefault();
82
+ }}
83
+ >
84
+ <main className={mainContentStyles}>
85
+ <MultiSelect model={model}>
86
+ <FormField orientation="horizontal">
87
+ <FormField.Label>Fruits</FormField.Label>
88
+ <FormField.Input
89
+ as={MultiSelect.SearchInput}
90
+ placeholder="Search"
91
+ name="toppings"
92
+ onChange={e => {
93
+ setValue(e.currentTarget.value);
94
+ }}
95
+ value={value}
96
+ />
97
+ <MultiSelect.Popper>
98
+ <MultiSelect.Card>
99
+ {model.state.items.length === 0 && (
100
+ <StyledMenuItem as="span">No Results Found</StyledMenuItem>
101
+ )}
102
+ {model.state.items.length > 0 && (
103
+ <MultiSelect.List maxHeight={200}>
104
+ {item =>
105
+ item ? (
106
+ <MultiSelect.Item data-id={item.id}>
107
+ <MultiSelect.Item.Text>{item.text}</MultiSelect.Item.Text>
108
+ </MultiSelect.Item>
109
+ ) : undefined
110
+ }
111
+ </MultiSelect.List>
112
+ )}
113
+ </MultiSelect.Card>
114
+ </MultiSelect.Popper>
115
+ </FormField>
116
+ </MultiSelect>
117
+ </main>
118
+ </form>
119
+ <div>Selected: {value}</div>
120
+ </>
121
+ </CanvasProvider>
122
+ );
123
+ };
@@ -66,6 +66,7 @@ export default () => {
66
66
  </SegmentedControl.Item>
67
67
  </SegmentedControl.List>
68
68
  </SegmentedControl>
69
+ <p>Selected: {containerWidth}</p>
69
70
  </footer>
70
71
  </div>
71
72
  );
@@ -78,7 +78,8 @@ on a dark or colorful background such as `blueberry400`.
78
78
 
79
79
  ### Grow Prop
80
80
 
81
- The example below shows the use of the `grow` prop on different variants of buttons. This will set the width of the button to the width of its container.
81
+ The example below shows the use of the `grow` prop on different variants of buttons. This will set
82
+ the width of the button to the width of its container.
82
83
 
83
84
  <ExampleCodeBlock code={Grow} />
84
85
 
@@ -106,4 +107,4 @@ should be used for navigation.
106
107
 
107
108
  ## Specifications
108
109
 
109
- <Specifications file="Button.spec.ts" name="Button" />
110
+ <Specifications file="Button.spec.tsx" name="Button" />
@@ -36,13 +36,16 @@ two separate `input` elements.
36
36
  the same as the user input. Any prop related to the function of forms will be passed here. For
37
37
  example, the `name` attribute will be passed here. The `ref` will be pointed to this element.
38
38
 
39
+ `Select` and `MultiSelect` are examples of constrained comboboxes.
40
+
39
41
  ### Arbitrary
40
42
 
41
43
  An arbitrary combobox allows the user to enter any value. The list of options are presented as
42
44
  suggestions and selecting an option will prefill the combobox with the value of the option. The user
43
45
  is still allowed to modify the combobox even after an option is entered. With arbitrary comboboxes,
44
46
  there is only one `input` element. Arbitrary combobox inputs should use the
45
- [useComboboxInputArbitrary](#usecomboboxinputarbirary) hook.
47
+ [useComboboxInputArbitrary](#usecomboboxinputarbirary) hook. Typeahead or `Autocomplete` are
48
+ examples are arbitrary value comboboxes.
46
49
 
47
50
  ## Installation
48
51
 
@@ -1,5 +1,3 @@
1
- import {Markdown} from '@storybook/blocks';
2
-
3
1
  import {ExampleCodeBlock, SymbolDoc, Specifications} from '@workday/canvas-kit-docs';
4
2
  import Basic from './examples/Basic';
5
3
  import ContextMenu from './examples/ContextMenu';
@@ -34,18 +32,14 @@ model which composes a list model and a popup model and sets up accessibility fe
34
32
  [Actions Menu pattern](https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/examples/menu-button-actions/)
35
33
  using roving tabindex. Below is table of supported keyboard shortcuts and associated actions.
36
34
 
37
- <Markdown>
38
- {`
39
35
  | Key | Action |
40
36
  | ------------------ | ------------------------------------------------------------------------------------------------------------ |
41
- | \`Enter\` or \`Space\` | Activates the menu item and then closes the menu |
42
- | \`Escape\` | Closes the menu |
43
- | \`Up Arrow\` | Moves focus to the previous menu item – if focus is on first menu item, it moves focus to the last menu item |
44
- | \`Down Arrow\` | Moves focus to the next menu item – if focus is on last menu item, it moves focus to the first menu item |
45
- | \`Home\` | Moves focus to the first menu item |
46
- | \`End\` | Moves focus to the last menu item |
47
- `}
48
- </Markdown>
37
+ | `Enter` or `Space` | Activates the menu item and then closes the menu |
38
+ | `Escape` | Closes the menu |
39
+ | `Up Arrow` | Moves focus to the previous menu item – if focus is on first menu item, it moves focus to the last menu item |
40
+ | `Down Arrow` | Moves focus to the next menu item – if focus is on last menu item, it moves focus to the first menu item |
41
+ | `Home` | Moves focus to the first menu item |
42
+ | `End` | Moves focus to the last menu item |
49
43
 
50
44
  ### Context Menu
51
45
 
@@ -1,5 +1,3 @@
1
- import {Markdown} from '@storybook/blocks';
2
-
3
1
  import {ExampleCodeBlock, SymbolDoc} from '@workday/canvas-kit-docs';
4
2
  import {StatusIndicator} from '@workday/canvas-kit-preview-react/status-indicator';
5
3
 
@@ -38,18 +36,14 @@ yarn add @workday/canvas-kit-react
38
36
  Note that the `type` prop is required (there is no default value). `type` accepts the following
39
37
  values:
40
38
 
41
- <Markdown>
42
- {`
43
39
  | Type | Suggested Purpose |
44
40
  | ---------------------------------- | ---------------------------------------------------------------------------------------------- |
45
- | \`StatusIndicator.Type.Gray\` | Basic, general status. No action required. |
46
- | \`StatusIndicator.Type.Orange\` | Signifies alerts, that a user must take action, or that something requires attention. |
47
- | \`StatusIndicator.Type.Blue\` | Signifies an item in progress, an update, or a current status. |
48
- | \`StatusIndicator.Type.Green\` | Signifies success, completion, or celebration. |
49
- | \`StatusIndicator.Type.Red\` | Signifies an error or issue, or removal or destruction. |
50
- | \`StatusIndicator.Type.Transparent\` | General status and related information intended for use on top of imagery, video, or graphics. |
51
- `}
52
- </Markdown>
41
+ | `StatusIndicator.Type.Gray` | Basic, general status. No action required. |
42
+ | `StatusIndicator.Type.Orange` | Signifies alerts, that a user must take action, or that something requires attention. |
43
+ | `StatusIndicator.Type.Blue` | Signifies an item in progress, an update, or a current status. |
44
+ | `StatusIndicator.Type.Green` | Signifies success, completion, or celebration. |
45
+ | `StatusIndicator.Type.Red` | Signifies an error or issue, or removal or destruction. |
46
+ | `StatusIndicator.Type.Transparent` | General status and related information intended for use on top of imagery, video, or graphics. |
53
47
 
54
48
  ### Emphasis
55
49
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-docs",
3
- "version": "12.0.0-alpha.918-next.0",
3
+ "version": "12.0.0-alpha.921-next.0",
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,10 +44,10 @@
44
44
  "dependencies": {
45
45
  "@emotion/styled": "^11.6.0",
46
46
  "@storybook/csf": "0.0.1",
47
- "@workday/canvas-kit-labs-react": "^12.0.0-alpha.918-next.0",
48
- "@workday/canvas-kit-preview-react": "^12.0.0-alpha.918-next.0",
49
- "@workday/canvas-kit-react": "^12.0.0-alpha.918-next.0",
50
- "@workday/canvas-kit-styling": "^12.0.0-alpha.918-next.0",
47
+ "@workday/canvas-kit-labs-react": "^12.0.0-alpha.921-next.0",
48
+ "@workday/canvas-kit-preview-react": "^12.0.0-alpha.921-next.0",
49
+ "@workday/canvas-kit-react": "^12.0.0-alpha.921-next.0",
50
+ "@workday/canvas-kit-styling": "^12.0.0-alpha.921-next.0",
51
51
  "@workday/canvas-system-icons-web": "^3.0.0",
52
52
  "@workday/canvas-tokens-web": "^2.0.1",
53
53
  "markdown-to-jsx": "^7.2.0",
@@ -60,5 +60,5 @@
60
60
  "mkdirp": "^1.0.3",
61
61
  "typescript": "5.0"
62
62
  },
63
- "gitHead": "3f21a8c474728598369595c8978854dab2355235"
63
+ "gitHead": "55250dda338c8adc6587b7254c8a38201830f27c"
64
64
  }