@workday/canvas-kit-docs 11.0.0-alpha.671-next.0 → 11.0.0-alpha.693-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.
Files changed (27) hide show
  1. package/dist/es6/lib/docs.js +2498 -294
  2. package/dist/es6/lib/specs.js +24 -0
  3. package/dist/es6/mdx/versionsTable.d.ts +2 -0
  4. package/dist/es6/mdx/versionsTable.d.ts.map +1 -0
  5. package/dist/es6/mdx/versionsTable.js +76 -0
  6. package/dist/mdx/11.0-UPGRADE-GUIDE.mdx +14 -2
  7. package/dist/mdx/Versions.mdx +8 -0
  8. package/dist/mdx/preview-react/_examples/TablesAdvanced.mdx +84 -0
  9. package/dist/mdx/preview-react/_examples/examples/Table/WithExpandableRows.tsx +219 -0
  10. package/dist/mdx/preview-react/_examples/examples/Table/WithSelectableRows.tsx +156 -0
  11. package/dist/mdx/preview-react/_examples/examples/Table/WithSortableColumnHeaders.tsx +213 -0
  12. package/dist/mdx/preview-react/side-panel/examples/Basic.tsx +17 -15
  13. package/dist/mdx/preview-react/side-panel/examples/RightOrigin.tsx +14 -12
  14. package/dist/mdx/preview-react/side-panel/examples/Variant.tsx +14 -12
  15. package/dist/mdx/preview-react/table/Table.mdx +16 -1
  16. package/dist/mdx/preview-react/table/examples/RightToLeft.tsx +38 -0
  17. package/dist/mdx/react/select/Select.mdx +82 -7
  18. package/dist/mdx/react/select/examples/Basic.tsx +1 -1
  19. package/dist/mdx/react/select/examples/Complex.tsx +11 -16
  20. package/dist/mdx/react/select/examples/FetchingDynamicItems.tsx +103 -0
  21. package/dist/mdx/react/select/examples/Grow.tsx +1 -5
  22. package/dist/mdx/react/select/examples/HoistedModel.tsx +8 -15
  23. package/dist/mdx/react/select/examples/InitialSelectedItem.tsx +60 -0
  24. package/dist/mdx/react/select/examples/LabelPosition.tsx +1 -3
  25. package/dist/mdx/react/select/examples/Placeholder.tsx +41 -0
  26. package/dist/mdx/react/select/examples/RefForwarding.tsx +1 -0
  27. package/package.json +6 -6
@@ -0,0 +1,213 @@
1
+ import React from 'react';
2
+
3
+ import {createComponent} from '@workday/canvas-kit-react/common';
4
+ import {Table} from '@workday/canvas-kit-preview-react/table';
5
+ import {Tooltip} from '@workday/canvas-kit-react/tooltip';
6
+ import {TertiaryButton} from '@workday/canvas-kit-react/button';
7
+ import {Text} from '@workday/canvas-kit-react/text';
8
+ import {sortDownIcon, sortUpIcon} from '@workday/canvas-system-icons-web';
9
+ import {createStyles} from '@workday/canvas-kit-styling';
10
+ import {system} from '@workday/canvas-tokens-web';
11
+
12
+ interface CountryData {
13
+ country: string;
14
+ capital: string;
15
+ population: number;
16
+ }
17
+
18
+ const countryData: CountryData[] = [
19
+ {country: 'Australia', capital: 'Canberra', population: 25690000},
20
+ {country: 'Bahamas', capital: 'Nassau', population: 407906},
21
+ {country: 'Canada', capital: 'Ottawa', population: 38250000},
22
+ {country: 'Fiji', capital: 'Suva', population: 924610},
23
+ {country: 'Ghana', capital: 'Accra', population: 32830000},
24
+ {country: 'Hong Kong', capital: 'City of Victoria', population: 7413000},
25
+ {country: 'India', capital: 'New Delhi', population: 1408000000},
26
+ {country: 'Ireland', capital: 'Dublin', population: 5033000},
27
+ {country: 'Jamaica', capital: 'Kingston', population: 2828000},
28
+ {country: 'Kenya', capital: 'Nairobi', population: 53010000},
29
+ {country: 'Micronesia', capital: 'Palikir', population: 113131},
30
+ {country: 'New Zealand', capital: 'Wellington', population: 5123000},
31
+ {country: 'Philippines', capital: 'Manila', population: 113900000},
32
+ {country: 'Puerto Rico', capital: 'San Juan', population: 3264000},
33
+ {country: 'Samoa', capital: 'Apia', population: 218764},
34
+ {country: 'Singapore', capital: 'Singapore', population: 5454000},
35
+ {country: 'Tanzania', capital: 'Dodoma', population: 63590000},
36
+ {country: 'United Kingdom', capital: 'London', population: 67330000},
37
+ {country: 'United States', capital: 'Washington, D.C.', population: 331900000},
38
+ {country: 'Zimbabwe', capital: 'Harare', population: 15990000},
39
+ ];
40
+
41
+ type SortOrder = 'ascending' | 'descending' | 'none';
42
+
43
+ interface HeaderRowState {
44
+ column1SortDirection: SortOrder;
45
+ column2SortDirection: SortOrder;
46
+ column3SortDirection: SortOrder;
47
+ }
48
+
49
+ interface HeaderRowAction {
50
+ column: 'Country' | 'Capital' | 'Population';
51
+ payload: CountryData[];
52
+ }
53
+
54
+ const initialHeaderRowState: HeaderRowState = {
55
+ column1SortDirection: 'none',
56
+ column2SortDirection: 'none',
57
+ column3SortDirection: 'none',
58
+ };
59
+
60
+ /**
61
+ * Given the current sort order, return the next sort order
62
+ */
63
+ function getNextSortOrder(sortOrder: SortOrder) {
64
+ return sortOrder === 'ascending' ? 'descending' : 'ascending';
65
+ }
66
+
67
+ function headerRowReducer(state: HeaderRowState, action: HeaderRowAction): HeaderRowState {
68
+ switch (action.column) {
69
+ case 'Country':
70
+ if (state.column1SortDirection === 'ascending') {
71
+ action.payload.sort((a, b) => b.country.localeCompare(a.country));
72
+ } else {
73
+ action.payload.sort((a, b) => a.country.localeCompare(b.country));
74
+ }
75
+
76
+ return {
77
+ ...initialHeaderRowState,
78
+ column1SortDirection: getNextSortOrder(state.column1SortDirection),
79
+ };
80
+
81
+ case 'Capital':
82
+ if (state.column2SortDirection === 'ascending') {
83
+ action.payload.sort((a, b) => b.capital.localeCompare(a.capital));
84
+ } else {
85
+ action.payload.sort((a, b) => a.capital.localeCompare(b.capital));
86
+ }
87
+
88
+ return {
89
+ ...initialHeaderRowState,
90
+ column2SortDirection: getNextSortOrder(state.column2SortDirection),
91
+ };
92
+
93
+ case 'Population':
94
+ if (state.column3SortDirection === 'ascending') {
95
+ action.payload.sort((a, b) => b.population - a.population);
96
+ } else {
97
+ action.payload.sort();
98
+ }
99
+
100
+ return {
101
+ ...initialHeaderRowState,
102
+ column3SortDirection: getNextSortOrder(state.column3SortDirection),
103
+ };
104
+
105
+ default:
106
+ return initialHeaderRowState;
107
+ }
108
+ }
109
+
110
+ interface SortableColumnHeaderProps {
111
+ label: string;
112
+ onSortAction: (label: string) => void;
113
+ children?: React.ReactNode;
114
+ sortOrder: SortOrder;
115
+ }
116
+
117
+ const getSortIcon = (sortOrder?: SortOrder) => {
118
+ if (sortOrder === 'ascending') {
119
+ return sortUpIcon;
120
+ } else if (sortOrder === 'descending') {
121
+ return sortDownIcon;
122
+ } else {
123
+ return undefined;
124
+ }
125
+ };
126
+
127
+ export default createComponent('th')({
128
+ displayName: 'SortableColumnHeader',
129
+ Component: (
130
+ {label, sortOrder, onSortAction, children, ...elemProps}: SortableColumnHeaderProps,
131
+ ref
132
+ ) => {
133
+ return (
134
+ <Table.Header ref={ref} scope="col" aria-sort={sortOrder} {...elemProps}>
135
+ <Tooltip type="describe" title={`Sort ${getNextSortOrder(sortOrder)}`}>
136
+ <TertiaryButton
137
+ icon={getSortIcon(sortOrder)}
138
+ iconPosition="end"
139
+ onClick={() => onSortAction(label)}
140
+ >
141
+ {children}
142
+ </TertiaryButton>
143
+ </Tooltip>
144
+ </Table.Header>
145
+ );
146
+ },
147
+ });
148
+
149
+ const textStyles = createStyles({
150
+ paddingInlineStart: system.space.x3,
151
+ });
152
+
153
+ export default () => {
154
+ const [headerRowState, headerRowDispatch] = React.useReducer(
155
+ headerRowReducer,
156
+ initialHeaderRowState
157
+ );
158
+
159
+ function sortColumnHandler(columnName) {
160
+ headerRowDispatch({
161
+ column: columnName,
162
+ payload: countryData,
163
+ });
164
+ }
165
+
166
+ return (
167
+ <Table maxHeight="40rem">
168
+ <Table.Caption>Population Listed by Country (2021)</Table.Caption>
169
+ <Table.Head>
170
+ <Table.Row>
171
+ <SortableColumnHeader
172
+ label="Country"
173
+ sortOrder={headerRowState.column1SortDirection as SortOrder}
174
+ onSortAction={sortColumnHandler}
175
+ >
176
+ Country
177
+ </SortableColumnHeader>
178
+ <SortableColumnHeader
179
+ label="Capital"
180
+ sortOrder={headerRowState.column2SortDirection as SortOrder}
181
+ onSortAction={sortColumnHandler}
182
+ >
183
+ Capital
184
+ </SortableColumnHeader>
185
+ <SortableColumnHeader
186
+ label="Population"
187
+ sortOrder={headerRowState.column3SortDirection as SortOrder}
188
+ onSortAction={sortColumnHandler}
189
+ >
190
+ Population
191
+ </SortableColumnHeader>
192
+ </Table.Row>
193
+ </Table.Head>
194
+ <Table.Body>
195
+ {countryData.map(item => {
196
+ return (
197
+ <Table.Row key={item.country}>
198
+ <Table.Header scope="row">
199
+ <Text cs={textStyles}>{item.country}</Text>
200
+ </Table.Header>
201
+ <Table.Cell>
202
+ <Text cs={textStyles}>{item.capital}</Text>
203
+ </Table.Cell>
204
+ <Table.Cell>
205
+ <Text cs={textStyles}>{item.population.toLocaleString()}</Text>
206
+ </Table.Cell>
207
+ </Table.Row>
208
+ );
209
+ })}
210
+ </Table.Body>
211
+ </Table>
212
+ );
213
+ };
@@ -20,26 +20,28 @@ export default () => {
20
20
  expanded ? 'expanded' : 'collapsed'
21
21
  );
22
22
 
23
+ const expandedContent = (
24
+ <Flex alignItems="center" paddingY="s" paddingX="s">
25
+ <Flex marginInlineEnd="s">
26
+ <AccentIcon icon={rocketIcon} />
27
+ </Flex>
28
+ <Text as="h3" typeLevel="body.large" color="licorice500" fontWeight="bold" {...labelProps}>
29
+ Tasks Panel
30
+ </Text>
31
+ </Flex>
32
+ );
33
+
23
34
  return (
24
35
  <CanvasProvider theme={{canvas: {direction}}}>
25
36
  <Flex height={320}>
26
37
  <SidePanel {...panelProps} onStateTransition={setPanelState}>
27
38
  <SidePanel.ToggleButton {...controlProps} />
28
- {panelState === 'expanded' && (
29
- <Flex alignItems="center" paddingY="s" paddingX="s">
30
- <Flex marginInlineEnd="s">
31
- <AccentIcon icon={rocketIcon} />
32
- </Flex>
33
- <Text
34
- as="h3"
35
- typeLevel="body.large"
36
- color="licorice500"
37
- fontWeight="bold"
38
- {...labelProps}
39
- >
40
- Tasks Panel
41
- </Text>
42
- </Flex>
39
+ {panelState === 'expanded' ? (
40
+ expandedContent
41
+ ) : (
42
+ <Text hidden {...labelProps}>
43
+ Tasks Panel
44
+ </Text>
43
45
  )}
44
46
  </SidePanel>
45
47
  <Flex
@@ -21,21 +21,23 @@ const RightPanel = () => {
21
21
  expanded ? 'expanded' : 'collapsed'
22
22
  );
23
23
 
24
+ const expandedContent = (
25
+ <Flex alignItems="center" justifyContent="flex-end" paddingY="s" paddingX="s">
26
+ <Text as="h3" typeLevel="body.large" color="licorice500" fontWeight="bold" {...labelProps}>
27
+ Tasks Panel
28
+ </Text>
29
+ </Flex>
30
+ );
31
+
24
32
  return (
25
33
  <StyledSidePanel {...panelProps} onStateTransition={setPanelState} origin="right">
26
34
  <SidePanel.ToggleButton {...controlProps} />
27
- {panelState === 'expanded' && (
28
- <Flex alignItems="center" justifyContent="flex-end" paddingY="s" paddingX="s">
29
- <Text
30
- as="h3"
31
- typeLevel="body.large"
32
- color="licorice500"
33
- fontWeight="bold"
34
- {...labelProps}
35
- >
36
- Tasks Panel
37
- </Text>
38
- </Flex>
35
+ {panelState === 'expanded' ? (
36
+ expandedContent
37
+ ) : (
38
+ <Text hidden {...labelProps}>
39
+ Tasks Panel
40
+ </Text>
39
41
  )}
40
42
  </StyledSidePanel>
41
43
  );
@@ -18,23 +18,25 @@ export default () => {
18
18
  expanded ? 'expanded' : 'collapsed'
19
19
  );
20
20
 
21
+ const expandedContent = (
22
+ <Flex alignItems="center" paddingY="s" paddingX="s">
23
+ <Text as="h3" typeLevel="body.large" color="licorice500" fontWeight="bold" {...labelProps}>
24
+ Alternate Panel
25
+ </Text>
26
+ </Flex>
27
+ );
28
+
21
29
  return (
22
30
  <CanvasProvider theme={{canvas: {direction}}}>
23
31
  <Flex height={320} backgroundColor="soap100">
24
32
  <SidePanel {...panelProps} onStateTransition={setPanelState} variant="alternate">
25
33
  <SidePanel.ToggleButton {...controlProps} />
26
- {panelState === 'expanded' && (
27
- <Flex alignItems="center" paddingY="s" paddingX="s">
28
- <Text
29
- as="h3"
30
- typeLevel="body.large"
31
- color="licorice500"
32
- fontWeight="bold"
33
- {...labelProps}
34
- >
35
- Alternate Panel
36
- </Text>
37
- </Flex>
34
+ {panelState === 'expanded' ? (
35
+ expandedContent
36
+ ) : (
37
+ <Text hidden {...labelProps}>
38
+ Tasks Panel
39
+ </Text>
38
40
  )}
39
41
  </SidePanel>
40
42
  <Flex
@@ -1,9 +1,10 @@
1
- import {SymbolDoc, Specifications} from '@workday/canvas-kit-docs';
1
+ import {SymbolDoc} from '@workday/canvas-kit-docs';
2
2
  import {Table} from '@workday/canvas-kit-preview-react/table';
3
3
  // Examples
4
4
  import Basic from './examples/Basic';
5
5
  import BasicWithHeading from './examples/BasicWithHeading';
6
6
  import FixedColumn from './examples/FixedColumn';
7
+ import RightToLeft from './examples/RightToLeft';
7
8
 
8
9
 
9
10
  # Canvas Kit Table
@@ -29,6 +30,12 @@ customization of the title/heading of their table.
29
30
 
30
31
  <ExampleCodeBlock code={BasicWithHeading} />
31
32
 
33
+ ### Right to Left
34
+
35
+ Table supports right-to-left languages when specified in the CanvasProvider theme.
36
+
37
+ <ExampleCodeBlock code={RightToLeft} />
38
+
32
39
  ### Example with Caption
33
40
 
34
41
  Users are free to use a `caption` instead of a heading. A `caption` is not required but it is good
@@ -46,6 +53,14 @@ Users may add styles to the `Table.Header` to render a fixed column. The example
46
53
 
47
54
  <ExampleCodeBlock code={FixedColumn} />
48
55
 
56
+ ### Advanced
57
+
58
+ You can also find several advanced Table examples in our Storybook Examples section.
59
+
60
+ - [Expandable Rows](/docs/examples-tables-advanced--expandable-rows)
61
+ - [Selectable Rows ](/docs/examples-tables-advanced--selectable-rows)
62
+ - [Sortable Column Headers](/docs/examples-tables-advanced--sortable-column-headers)
63
+
49
64
  ## Component API
50
65
 
51
66
  <SymbolDoc name="Table" fileName="/preview-react/" />
@@ -0,0 +1,38 @@
1
+ import React from 'react';
2
+
3
+ import {Table} from '@workday/canvas-kit-preview-react/table';
4
+ import {CanvasProvider, ContentDirection} from '@workday/canvas-kit-react/common';
5
+
6
+ export default () => {
7
+ return (
8
+ <CanvasProvider theme={{canvas: {direction: ContentDirection.RTL}}}>
9
+ <Table>
10
+ <Table.Caption>משקאות קפה וגדלים</Table.Caption>
11
+ <Table.Head>
12
+ <Table.Row>
13
+ <Table.Header scope="col" backgroundColor="soap100">
14
+ מַשׁקֶה
15
+ </Table.Header>
16
+ <Table.Header scope="col" backgroundColor="soap100">
17
+ גודל
18
+ </Table.Header>
19
+ </Table.Row>
20
+ </Table.Head>
21
+ <Table.Body>
22
+ <Table.Row>
23
+ <Table.Cell>אספרסו</Table.Cell>
24
+ <Table.Cell>1 גר</Table.Cell>
25
+ </Table.Row>
26
+ <Table.Row>
27
+ <Table.Cell>מקיאטו</Table.Cell>
28
+ <Table.Cell>2 גרם אספרסו</Table.Cell>
29
+ </Table.Row>
30
+ <Table.Row>
31
+ <Table.Cell>גזירה</Table.Cell>
32
+ <Table.Cell>2 גרם אספרסו, 1 גרם חלב מוקצף</Table.Cell>
33
+ </Table.Row>
34
+ </Table.Body>
35
+ </Table>
36
+ </CanvasProvider>
37
+ );
38
+ };
@@ -15,6 +15,9 @@ import Required from './examples/Required';
15
15
  import MenuHeight from './examples/MenuHeight';
16
16
  import HoistedModel from './examples/HoistedModel';
17
17
  import RefForwarding from './examples/RefForwarding';
18
+ import FetchingDynamicItems from './examples/FetchingDynamicItems';
19
+ import Placeholder from './examples/Placeholder';
20
+ import InitialSelectedItem from './examples/InitialSelectedItem';
18
21
 
19
22
 
20
23
  # Canvas Kit Select
@@ -86,6 +89,10 @@ and provides direct access to its `state` and `events` outside of the `Select` c
86
89
  In this example, we set up external observation of the model state and create an external button to
87
90
  trigger an event to change the selected item.
88
91
 
92
+ **Note: If your array of objects uses an `id` property and a `text` property there is no need to use
93
+ the helper functions of `getId` or `getTextValue`. The collection system and the `Select` use these
94
+ properties by default for keyboard navigation and selected the `id` based on the item clicked.**
95
+
89
96
  <ExampleCodeBlock code={HoistedModel} />
90
97
 
91
98
  ### Label Position Horizontal
@@ -199,18 +206,43 @@ Use the error state when the selection is no longer valid.
199
206
 
200
207
  <ExampleCodeBlock code={Error} />
201
208
 
209
+ ### Initial Selected Item
210
+
211
+ You can set `initialSelectedIds` to the value that you want initially selected.
212
+
213
+ <ExampleCodeBlock code={InitialSelectedItem} />
214
+
215
+ ### Placeholder
216
+
217
+ You can change the placeholder text by passing in a string value to the `placeholder` attribute on
218
+ the `Select.Input`.
219
+
220
+ <ExampleCodeBlock code={Placeholder} />
221
+
222
+ ### Fetching Dynamic Items
223
+
224
+ It's common to load items from a server call. Hoisting the `model` and setting your items on state
225
+ allows you to pass those items to your `model`. You can leverage React state to set your items on
226
+ load as well as displaying a placeholder indicating when items are loaded.
227
+
228
+ **Note: In this case we need to use `getId` and `getTextValue` because our data doesn't have the
229
+ properties of `id` or `text`. Using these helper functions sets the `serverId` to be `id` and
230
+ `label` to be `text`.**
231
+
232
+ <ExampleCodeBlock code={FetchingDynamicItems} />
233
+
202
234
  ### Complex
203
235
 
204
- When registering items in an array of objects, it's common to have an `id` that is different than
205
- the text value displayed in the UI. Typically, this `id` is used to send to the server. Use the `id`
206
- value to set the `data-id` property on `Select.Item` to ensure proper keyboard handling and
207
- type-ahead.
236
+ When registering items in an array of objects, it's common to have the text that is displayed to the user be
237
+ different than an id. In this example, `serverId` and `label` properties need to be remapped to
238
+ `id` and `text` hence the usage of `getId` and `getTextValue`. If your object has the properties
239
+ `text` and `id`, there would be no need for this.
208
240
 
209
241
  <ExampleCodeBlock code={Complex} />
210
242
 
211
- By default, the identifier and text value are `id` and `text` properties respectively. If your data
212
- object for each item is different, provide a `getId` or `getTextValue` function to the model config.
213
- For example:
243
+ **Note: By default, the identifier and text value are `id` and `text` properties respectively. If
244
+ your data object for each item is different, provide a `getId` or `getTextValue` function to the
245
+ model config. For example:**
214
246
 
215
247
  ```jsx
216
248
  const items = [
@@ -225,6 +257,49 @@ const items = [
225
257
  </Select>;
226
258
  ```
227
259
 
260
+ ### When to use `getId`, or `getTextValue`
261
+
262
+ - `getId`: This is an optional function to return the id of an item. If not provided, the default
263
+ function will return the `id` property from the object of each item. If you did not provide
264
+ `items`, do not override this function. Instead provide static
265
+ items via JSX. the list will create an internal array of items where `id` is the only property and
266
+ the default `getId` will return the desired result. **Note: If your array of objects has a
267
+ different property for `id`, like `serverId`, use this function to set the id.**
268
+
269
+ ```tsx
270
+ const options = [{text: 'Pizza', serverId: 'pizza-1'}, {text: 'Cheeseburger', serverId: 'cheeseburger'}]
271
+ <Select items={options} getId={(item) => item.serverId}>
272
+ <FormField label="Your Label">
273
+ <Select.Input onChange={e => handleChange(e)} id="contact-select" />
274
+ <Select.Popper>
275
+ <Select.Card>
276
+ <Select.List>{item => <Select.Item>{item.text}</Select.Item>}</Select.List>
277
+ </Select.Card>
278
+ </Select.Popper>
279
+ </FormField>
280
+ </Select>
281
+ ```
282
+
283
+ - `getTextValue`: Optional function to return the text representation of an item. If not provided,
284
+ the default function will return the `text` property of the object of each item or an empty string
285
+ if there is no `text` property. If you did not provide `items`, do not override this function.
286
+ **Note: If your array of objects has a different property for `text`, like `label`, use this
287
+ function to set the text.**
288
+
289
+ ```tsx
290
+ const options = [{label: 'Pizza', id: 'pizza-1'}, {label: 'Cheeseburger', id: 'cheeseburger'}]
291
+ <Select items={options} getTextValue={(item) => item.label}>
292
+ <FormField label="Your Label">
293
+ <Select.Input onChange={e => handleChange(e)} id="contact-select" />
294
+ <Select.Popper>
295
+ <Select.Card>
296
+ <Select.List>{item => <Select.Item>{item.label}</Select.Item>}</Select.List>
297
+ </Select.Card>
298
+ </Select.Popper>
299
+ </FormField>
300
+ </Select>
301
+ ```
302
+
228
303
  ## Component API
229
304
 
230
305
  <SymbolDoc name="Select" fileName="/react/" />
@@ -24,7 +24,7 @@ export default () => {
24
24
  <Select items={options}>
25
25
  <FormField>
26
26
  <FormField.Label>Contact</FormField.Label>
27
- <FormField.Input as={Select.Input} onChange={e => handleChange(e)} />
27
+ <FormField.Input as={Select.Input} onChange={handleChange} />
28
28
  <Select.Popper>
29
29
  <Select.Card>
30
30
  <Select.List>
@@ -4,14 +4,14 @@ import {Select} from '@workday/canvas-kit-react/select';
4
4
  import {Flex} from '@workday/canvas-kit-react/layout';
5
5
 
6
6
  const options = [
7
- {id: 'email', text: 'E-mail'},
8
- {id: 'phone', text: 'Phone'},
9
- {id: 'fax', text: 'Fax'},
10
- {id: 'mail', text: 'Mail'},
11
- {id: 'mobile', text: 'Mobile Phone'},
7
+ {serverId: 'email', label: 'E-mail'},
8
+ {serverId: 'phone', label: 'Phone'},
9
+ {serverId: 'fax', label: 'Fax'},
10
+ {serverId: 'mail', label: 'Mail'},
11
+ {serverId: 'mobile', label: 'Mobile Phone'},
12
12
  {
13
- id: 'oasis',
14
- text: 'The Ontologically Anthropocentric Sensory Immersive Simulation',
13
+ serverId: 'oasis',
14
+ label: 'The Ontologically Anthropocentric Sensory Immersive Simulation',
15
15
  },
16
16
  ];
17
17
 
@@ -20,24 +20,19 @@ export default () => {
20
20
  const [id, setId] = React.useState('');
21
21
 
22
22
  const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
23
- setValue(event.target.value);
24
- };
25
-
26
- const handleSelect = ({id}: {id: string}) => {
27
- setId(id);
23
+ setId(event.target.value);
24
+ setValue(options.find(item => item.serverId === event.target.value)!.label);
28
25
  };
29
26
 
30
27
  return (
31
28
  <Flex flexDirection="column">
32
- <Select items={options} onSelect={handleSelect}>
29
+ <Select items={options} getId={item => item.serverId} getTextValue={item => item.label}>
33
30
  <FormField>
34
31
  <FormField.Label>Contact</FormField.Label>
35
32
  <FormField.Input as={Select.Input} onChange={e => handleChange(e)} />
36
33
  <Select.Popper>
37
34
  <Select.Card>
38
- <Select.List>
39
- {item => <Select.Item data-id={item.id}>{item.text}</Select.Item>}
40
- </Select.List>
35
+ <Select.List>{item => <Select.Item>{item.label}</Select.Item>}</Select.List>
41
36
  </Select.Card>
42
37
  </Select.Popper>
43
38
  </FormField>