@workday/canvas-kit-docs 6.3.4 → 6.3.8

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,8 @@
1
+ import SelectWithFormik from './examples/SelectWithFormik';
2
+
3
+
4
+ # Canvas Kit Examples
5
+
6
+ ## Select With Formik
7
+
8
+ <ExampleCodeBlock code={SelectWithFormik} />
@@ -0,0 +1,8 @@
1
+ import TextInputWithFormik from './examples/TextInputWithFormik';
2
+
3
+
4
+ # Canvas Kit Examples
5
+
6
+ ## Text Input With Formik
7
+
8
+ <ExampleCodeBlock code={TextInputWithFormik} />
@@ -0,0 +1,47 @@
1
+ import * as React from 'react';
2
+ import {useFormik} from 'formik';
3
+ import {Select} from '@workday/canvas-kit-preview-react/select';
4
+ import {
5
+ FormField,
6
+ useFormFieldInput,
7
+ useFormFieldModel,
8
+ } from '@workday/canvas-kit-preview-react/form-field';
9
+
10
+ export default () => {
11
+ const formik = useFormik({
12
+ initialValues: {
13
+ selectedBook: '',
14
+ },
15
+ onSubmit: data => {
16
+ console.log(data);
17
+ },
18
+ });
19
+
20
+ const model = useFormFieldModel();
21
+ const formFieldInputProps = useFormFieldInput(model);
22
+
23
+ return (
24
+ <form onSubmit={formik.handleSubmit}>
25
+ <FormField orientation="vertical" alignItems="stretch">
26
+ <FormField.Label>Choose a book</FormField.Label>
27
+ <Select
28
+ name="selectedBook"
29
+ options={bookList}
30
+ onChange={event => formik.setFieldValue('selectedBook', event.currentTarget.value)}
31
+ value={formik.values.selectedBook}
32
+ grow
33
+ {...formFieldInputProps}
34
+ />
35
+ </FormField>
36
+ </form>
37
+ );
38
+ };
39
+
40
+ const bookList = [
41
+ {label: 'Dessert Person by Claire Saffitz', value: 'dessert person'},
42
+ {label: 'Elements of Pizza by Ken Forkish', value: 'the elements of pizza'},
43
+ {label: 'Flour Water Salt Yeast by Ken Forkish', value: 'flour water salt yeast'},
44
+ {label: 'Mastering Pasta by Marc Verti', value: 'mastering pasta'},
45
+ {label: 'Patisserie by Christophe Felder', value: 'patisserie'},
46
+ {label: 'Tartine by Elisabeth Prueitt & Chad Robertson', value: 'tartine'},
47
+ ];
@@ -3,6 +3,7 @@ import {Specifications} from '@workday/canvas-kit-docs';
3
3
  import {FormField} from '@workday/canvas-kit-preview-react/form-field';
4
4
 
5
5
  import Custom from './examples/Custom';
6
+ import WithSelect from './examples/Select';
6
7
 
7
8
 
8
9
  # Canvas Kit Form Field
@@ -20,8 +21,19 @@ yarn add @workday/canvas-kit-preview-react
20
21
 
21
22
  ### Customizing With Behavior Hooks Example
22
23
 
23
- If you need full customization you can use the form field behavior hooks to build your own solution.
24
- It is also easy it work with custom components or third party libraries and get the CKR
24
+ If you need full customization you can use the `FormField` behavior hooks to build your own
25
+ solution. It is also easy it work with custom components or third party libraries and get the CKR
25
26
  accessibility guarantees by using the `as` prop.
26
27
 
27
- <ExampleCodeBlock code={Custom} />
28
+ <ExampleCodeBlock code={Custom} />
29
+
30
+ ### Use with Select
31
+
32
+ For some custom inputs, such as Canvas Kit's `Select`, you won't be able to reliably cast the
33
+ `FormField.Input` with the `as` prop. Instead you'll want to use `FormField`'s hooks for the
34
+ implementation. In the example below, we're using the `useFormFieldModel` hook to hoist the model
35
+ and providing it to the `useFormFieldInput` behavior hook. Then we pass the model to the `FormField`
36
+ component and the input props to `Select`. This connects `Select` to the `FormField` components and
37
+ provides it with all the accessible attributes it needs.
38
+
39
+ <ExampleCodeBlock code={WithSelect} />
@@ -0,0 +1,50 @@
1
+ import * as React from 'react';
2
+ import {
3
+ FormField,
4
+ useFormFieldInput,
5
+ useFormFieldModel,
6
+ } from '@workday/canvas-kit-preview-react/form-field';
7
+ import {Select} from '@workday/canvas-kit-preview-react/select';
8
+
9
+ export default () => {
10
+ const [selected, setSelected] = React.useState(wineList[0].value);
11
+ // Hoist the FormField model so we can pass it to `useFormFieldInput`
12
+ const model = useFormFieldModel({isRequired: true});
13
+ // Get all the FormField-related input props to pass to `Select`
14
+ const formFieldInputProps = useFormFieldInput(model);
15
+
16
+ return (
17
+ <FormField orientation="vertical" model={model}>
18
+ <FormField.Label>Choose a wine</FormField.Label>
19
+ <Select
20
+ options={wineList}
21
+ value={selected}
22
+ onChange={event => setSelected(event.currentTarget.value)}
23
+ {...formFieldInputProps}
24
+ />
25
+ <FormField.Hint>When in doubt, go with the Chianti.</FormField.Hint>
26
+ </FormField>
27
+ );
28
+ };
29
+
30
+ export default [
31
+ {label: 'Beaujolais', value: 'beaujolais'},
32
+ {label: 'Bordeaux', value: 'bordeaux'},
33
+ {label: 'Cabernet Sauvignon', value: 'cabernet sauvignon'},
34
+ {label: 'Champagne', value: 'champagne'},
35
+ {label: 'Chardonnay', value: 'chardonnay'},
36
+ {label: 'Chianti', value: 'chianti'},
37
+ {label: 'Malbec', value: 'malbec'},
38
+ {label: 'Merlot', value: 'merlot'},
39
+ {label: 'Pinot Grigio', value: 'pinot grigio'},
40
+ {label: 'Pinot Gris', value: 'pinot gris'},
41
+ {label: 'Pinot Noir', value: 'pinot noir'},
42
+ {label: 'Primitivo', value: 'primitivo'},
43
+ {label: 'Prosecco', value: 'prosecco'},
44
+ {label: 'Riesling', value: 'riesling'},
45
+ {label: 'Rioja', value: 'rioja'},
46
+ {label: 'Rosé', value: 'rosé'},
47
+ {label: 'Sauvignon Blanc', value: 'sauvignon blanc'},
48
+ {label: 'Syrah', value: 'syrah'},
49
+ {label: 'Zinfandel', value: 'zinfandel'},
50
+ ];
@@ -16,7 +16,6 @@ import ThemedAlert from './examples/ThemedAlert';
16
16
  import ThemedError from './examples/ThemedError';
17
17
  import Error from './examples/Error';
18
18
  import Alert from './examples/Alert';
19
- import LoginForm from './examples/LoginForm';
20
19
 
21
20
 
22
21
  # Canvas Kit Text Input
@@ -128,12 +127,6 @@ used in an outer ring.
128
127
 
129
128
  <ExampleCodeBlock code={ThemedAlert} />
130
129
 
131
- #### Full example
132
-
133
- Login Form using Formik
134
-
135
- <ExampleCodeBlock code={LoginForm} />
136
-
137
130
  ## Props
138
131
 
139
132
  Undocumented props are spread to the underlying `<input>` element.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workday/canvas-kit-docs",
3
- "version": "6.3.4",
3
+ "version": "6.3.8",
4
4
  "description": "Documentation components of Canvas Kit components",
5
5
  "author": "Workday, Inc. (https://www.workday.com)",
6
6
  "license": "Apache-2.0",
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "@storybook/csf": "0.0.1",
53
- "@workday/canvas-kit-react": "^6.3.4"
53
+ "@workday/canvas-kit-react": "^6.3.8"
54
54
  },
55
55
  "devDependencies": {
56
56
  "fs-extra": "^10.0.0",
@@ -58,5 +58,5 @@
58
58
  "mkdirp": "^1.0.3",
59
59
  "typescript": "^3.8.3"
60
60
  },
61
- "gitHead": "43759dac29aaa53f6f794a739bc9913f1aade55b"
61
+ "gitHead": "a368b19cd0cb84f86289a42040a4756e4d4c8dd1"
62
62
  }