@workday/canvas-kit-docs 5.3.0-next.3 → 5.3.0-next.32

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 (105) hide show
  1. package/LICENSE +1 -1
  2. package/dist/commonjs/lib/specs.js +429 -33
  3. package/dist/es6/lib/specs.js +429 -33
  4. package/dist/mdx/5.0-MIGRATION-GUIDE.mdx +81 -7
  5. package/dist/mdx/6.0-MIGRATION-GUIDE.mdx +560 -0
  6. package/dist/mdx/COMPOUND_COMPONENTS.mdx +31 -30
  7. package/dist/mdx/CONTRIBUTING.mdx +90 -63
  8. package/dist/mdx/TESTING.mdx +29 -5
  9. package/dist/mdx/labs-react/search-form/SearchForm.mdx +64 -0
  10. package/dist/mdx/labs-react/search-form/examples/Basic.tsx +61 -0
  11. package/dist/mdx/labs-react/search-form/examples/CustomTheme.tsx +72 -0
  12. package/dist/mdx/labs-react/search-form/examples/Grow.tsx +62 -0
  13. package/dist/mdx/labs-react/search-form/examples/PropTables.splitProps.tsx +4 -0
  14. package/dist/mdx/labs-react/search-form/examples/RTL.tsx +70 -0
  15. package/dist/mdx/labs-react/search-form/examples/Theming.tsx +64 -0
  16. package/dist/mdx/preview-react/breadcrumbs/Breadcrumbs.mdx +1 -1
  17. package/dist/mdx/preview-react/form-field/FormField.mdx +27 -0
  18. package/dist/mdx/preview-react/form-field/examples/Custom.tsx +57 -0
  19. package/dist/mdx/preview-react/menu/Menu.mdx +17 -9
  20. package/dist/mdx/preview-react/menu/examples/Basic.tsx +65 -10
  21. package/dist/mdx/preview-react/menu/examples/ContextMenu.tsx +47 -29
  22. package/dist/mdx/preview-react/menu/examples/CustomMenuItem.tsx +2 -2
  23. package/dist/mdx/preview-react/menu/examples/Icons.tsx +1 -1
  24. package/dist/mdx/preview-react/menu/examples/ManyItems.tsx +2 -2
  25. package/dist/mdx/preview-react/text-area/TextArea.mdx +122 -0
  26. package/dist/mdx/preview-react/text-area/examples/Alert.tsx +31 -0
  27. package/dist/mdx/preview-react/text-area/examples/Basic.tsx +17 -0
  28. package/dist/mdx/preview-react/text-area/examples/Disabled.tsx +17 -0
  29. package/dist/mdx/preview-react/text-area/examples/Error.tsx +40 -0
  30. package/dist/mdx/preview-react/text-area/examples/Grow.tsx +17 -0
  31. package/dist/mdx/preview-react/text-area/examples/HiddenLabel.tsx +20 -0
  32. package/dist/mdx/preview-react/text-area/examples/LabelPositionHorizontal.tsx +17 -0
  33. package/dist/mdx/preview-react/text-area/examples/LabelPositionVertical.tsx +17 -0
  34. package/dist/mdx/preview-react/text-area/examples/Placeholder.tsx +21 -0
  35. package/dist/mdx/preview-react/text-area/examples/RefForwarding.tsx +28 -0
  36. package/dist/mdx/preview-react/text-area/examples/Required.tsx +17 -0
  37. package/dist/mdx/preview-react/text-area/examples/ResizeConstraints.tsx +22 -0
  38. package/dist/mdx/preview-react/text-input/TextInput.mdx +145 -0
  39. package/dist/mdx/preview-react/text-input/examples/Alert.tsx +40 -0
  40. package/dist/mdx/preview-react/text-input/examples/Basic.tsx +17 -0
  41. package/dist/mdx/preview-react/text-input/examples/Disabled.tsx +17 -0
  42. package/dist/mdx/preview-react/text-input/examples/Error.tsx +40 -0
  43. package/dist/mdx/preview-react/text-input/examples/Grow.tsx +17 -0
  44. package/dist/mdx/preview-react/text-input/examples/HiddenLabel.tsx +20 -0
  45. package/dist/mdx/preview-react/text-input/examples/LabelPositionHorizontal.tsx +17 -0
  46. package/dist/mdx/preview-react/text-input/examples/LabelPositionVertical.tsx +17 -0
  47. package/dist/mdx/preview-react/text-input/examples/LoginForm.tsx +105 -0
  48. package/dist/mdx/preview-react/text-input/examples/Password.tsx +17 -0
  49. package/dist/mdx/preview-react/text-input/examples/Placeholder.tsx +17 -0
  50. package/dist/mdx/preview-react/text-input/examples/RefForwarding.tsx +28 -0
  51. package/dist/mdx/preview-react/text-input/examples/Required.tsx +17 -0
  52. package/dist/mdx/preview-react/text-input/examples/ThemedAlert.tsx +46 -0
  53. package/dist/mdx/preview-react/text-input/examples/ThemedError.tsx +37 -0
  54. package/dist/mdx/react/_examples/CookieBanner.mdx +8 -0
  55. package/dist/mdx/react/_examples/GlobalHeader.mdx +9 -0
  56. package/dist/mdx/react/_examples/PageHeader.mdx +8 -0
  57. package/dist/mdx/react/_examples/examples/CookieBanner.tsx +97 -0
  58. package/dist/mdx/react/_examples/examples/GlobalHeader.tsx +66 -0
  59. package/dist/mdx/react/_examples/examples/PageHeader.tsx +63 -0
  60. package/dist/mdx/react/action-bar/ActionBar.mdx +1 -1
  61. package/dist/mdx/react/button/button/Button.mdx +34 -9
  62. package/dist/mdx/react/button/button/examples/Primary.tsx +11 -1
  63. package/dist/mdx/react/button/button/examples/PrimaryInverse.tsx +14 -0
  64. package/dist/mdx/react/button/button/examples/Secondary.tsx +10 -1
  65. package/dist/mdx/react/button/button/examples/SecondaryInverse.tsx +14 -0
  66. package/dist/mdx/react/button/button/examples/Tertiary.tsx +10 -1
  67. package/dist/mdx/react/button/button/examples/TertiaryInverse.tsx +14 -0
  68. package/dist/mdx/react/button/icon-button/IconButton.mdx +1 -1
  69. package/dist/mdx/react/loading-animation/LoadingAnimation.mdx +5 -0
  70. package/dist/mdx/react/loading-animation/examples/RTL.tsx +16 -0
  71. package/dist/mdx/react/pagination/PropTables.splitprops.tsx +47 -0
  72. package/dist/mdx/react/pagination/examples/{StepControls.tsx → Basic.tsx} +1 -1
  73. package/dist/mdx/react/pagination/examples/GoToForm.tsx +1 -1
  74. package/dist/mdx/react/pagination/examples/HoistedModel.tsx +36 -22
  75. package/dist/mdx/react/pagination/examples/RTL.tsx +1 -1
  76. package/dist/mdx/react/pagination/pagination.mdx +225 -474
  77. package/dist/mdx/react/popup/Popup.mdx +96 -36
  78. package/dist/mdx/react/popup/examples/FullScreen.tsx +115 -0
  79. package/dist/mdx/react/radio/examples/Alert.tsx +3 -3
  80. package/dist/mdx/react/radio/examples/Basic.tsx +3 -3
  81. package/dist/mdx/react/radio/examples/Disabled.tsx +3 -3
  82. package/dist/mdx/react/radio/examples/Error.tsx +3 -3
  83. package/dist/mdx/react/radio/examples/LabelPosition.tsx +3 -3
  84. package/dist/mdx/react/radio/examples/NoValue.tsx +3 -3
  85. package/dist/mdx/react/radio/examples/RefForwarding.tsx +3 -3
  86. package/dist/mdx/react/radio/examples/Required.tsx +3 -3
  87. package/dist/mdx/react/segmented-control/SegmentedControl.mdx +1 -1
  88. package/dist/mdx/react/tabs/Tabs.mdx +67 -36
  89. package/dist/mdx/react/tabs/examples/DisabledTab.tsx +1 -1
  90. package/dist/mdx/react/tabs/examples/DynamicTabs.tsx +82 -38
  91. package/dist/mdx/react/tabs/examples/HoistedModel.tsx +4 -4
  92. package/dist/mdx/react/tabs/examples/Icons.tsx +36 -0
  93. package/dist/mdx/react/tabs/examples/{NamedKeys.tsx → NamedTabs.tsx} +0 -0
  94. package/dist/mdx/react/tabs/examples/OverflowTabs.tsx +58 -0
  95. package/dist/mdx/react/tabs/examples/SinglePanel.tsx +1 -1
  96. package/dist/mdx/react/text-area/TextArea.mdx +1 -1
  97. package/dist/mdx/react/toast/toast.mdx +1 -17
  98. package/dist/mdx/react/tooltip/Tooltip.mdx +9 -1
  99. package/dist/mdx/react/tooltip/examples/DelayedTooltip.tsx +16 -0
  100. package/dist/mdx/react/tooltip/examples/Ellipsis.tsx +6 -0
  101. package/package.json +5 -4
  102. package/dist/mdx/CODE_OF_CONDUCT.md +0 -68
  103. package/dist/mdx/preview-react/menu/examples/ContextMenuTarget.tsx +0 -33
  104. package/dist/mdx/preview-react/menu/examples/ControlButton.tsx +0 -84
  105. package/dist/mdx/react/pagination/examples/ShowAdditionalDetails.tsx +0 -52
@@ -0,0 +1,122 @@
1
+ import {Specifications} from '@workday/canvas-kit-docs';
2
+
3
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
4
+
5
+ import Alert from './examples/Alert';
6
+ import Basic from './examples/Basic';
7
+ import Disabled from './examples/Disabled';
8
+ import Error from './examples/Error';
9
+ import Grow from './examples/Grow';
10
+ import LabelPositionVertical from './examples/LabelPositionVertical';
11
+ import LabelPositionHorizontal from './examples/LabelPositionHorizontal';
12
+ import HiddenLabel from './examples/HiddenLabel';
13
+ import Placeholder from './examples/Placeholder';
14
+ import RefForwarding from './examples/RefForwarding';
15
+ import Required from './examples/Required';
16
+ import ResizeConstraints from './examples/ResizeConstraints';
17
+
18
+
19
+ # Canvas Kit Text Area
20
+
21
+ TextArea's allow users to enter and edit multiple lines of text.
22
+
23
+ [> Workday Design Reference](https://design.workday.com/components/inputs/text-area)
24
+
25
+ ## Installation
26
+
27
+ ```sh
28
+ yarn add @workday/canvas-kit-preview-react
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Basic Example
34
+
35
+ <ExampleCodeBlock code={Basic} />
36
+
37
+ ### Disabled
38
+
39
+ Use `TextArea.Field`'s `disabled` prop to prevent users from interacting with the field.
40
+
41
+ <ExampleCodeBlock code={Disabled} />
42
+
43
+ ### Placeholder
44
+
45
+ Use `TextArea.Field`'s `placeholder` prop to display a sample of its expected format or value before
46
+ a value has been provided.
47
+
48
+ <ExampleCodeBlock code={Placeholder} />
49
+
50
+ ### Required
51
+
52
+ Use `TextArea.Field`'s `isRequired` prop (or use with the `useTextAreaModel` hook) to indicate that
53
+ the field is required. This will also add a red asterisk to `TextArea.Label`.
54
+
55
+ <ExampleCodeBlock code={Required} />
56
+
57
+ ### Ref Forwarding
58
+
59
+ `TextArea` supports [ref forwarding](https://reactjs.org/docs/forwarding-refs.html). It will forward
60
+ `ref` to its underlying `<textarea>` element.
61
+
62
+ <ExampleCodeBlock code={RefForwarding} />
63
+
64
+ ### Resize Constraints
65
+
66
+ Use the `resize` css attribute to restrict resizing of it to certain dimensions.
67
+
68
+ <ExampleCodeBlock code={ResizeConstraints} />
69
+
70
+ ### Grow
71
+
72
+ There are lots of ways to accomplish this. The `TextArea.Field` extends from Box so it is easy to
73
+ extend full width, e.g. setting width prop to 100%, or you can set the `alignItems` prop to
74
+ `stretch` on `TextArea`, etc.
75
+
76
+ <ExampleCodeBlock code={Grow} />
77
+
78
+ ### Label Position
79
+
80
+ Use the `orientation` property to set `TextArea.Label`'s position. You can override the default
81
+ spacing using the `spacing` prop. Below are examples of both positions:
82
+
83
+ #### Horizontal
84
+
85
+ <ExampleCodeBlock code={LabelPositionHorizontal} />
86
+
87
+ #### Vertical
88
+
89
+ <ExampleCodeBlock code={LabelPositionVertical} />
90
+
91
+ ### Visually Hiding The Label
92
+
93
+ If your label is just for screen reader users you can use the `accessibleHide` utility class from
94
+ `@workday/canvas-kit-react/common`. You will likely want to set the `spacing` prop on `TextArea` to
95
+ `zero`.
96
+
97
+ <ExampleCodeBlock code={HiddenLabel} />
98
+
99
+ ### Error States
100
+
101
+ Use the `hasError` property from `useTextAreaModel` to set the `TextArea` to the Error state. If you
102
+ have an accompanying hint you can use the `TextArea.Hint` subcomponent.
103
+
104
+ <ExampleCodeBlock code={Error} />
105
+
106
+ ### Other Visual States
107
+
108
+ Use the `useThemedRing` hook to change the visual state of the `<textarea>` element.
109
+
110
+ #### Alert
111
+
112
+ <ExampleCodeBlock code={Alert} />
113
+
114
+ ## Props
115
+
116
+ Undocumented props are spread to the underlying `<textarea>` element.
117
+
118
+ <ArgsTable of={TextArea} />
119
+
120
+ ## Specifications
121
+
122
+ <Specifications file="TextAreaPreview.spec.ts" name="Text Area" />
@@ -0,0 +1,31 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/core'
3
+ import React from 'react';
4
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
5
+ import {useThemedRing} from '@workday/canvas-kit-labs-react/common';
6
+ import {space, colors} from '@workday/canvas-kit-react/tokens';
7
+
8
+ export default () => {
9
+ const [value, setValue] = React.useState('');
10
+
11
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
12
+ setValue(event.target.value.slice(0, 10));
13
+ };
14
+
15
+ const alertStyles = useThemedRing(
16
+ value.length < 3 ? 'success' : value.length < 7 ? 'alert' : 'error'
17
+ );
18
+
19
+ const hintColor = value.length < 3 ? colors.greenApple600 : value.length < 7 ? colors.cantaloupe600 : colors.cinnamon500
20
+
21
+ return (
22
+ <TextArea orientation='vertical'>
23
+ <TextArea.Label>Add a comment</TextArea.Label>
24
+ <TextArea.Field css={alertStyles} onChange={handleChange} value={value} />
25
+ <TextArea.Hint paddingTop={space.xxs}>
26
+ <strong>Character Limit: </strong>
27
+ <span css={{color: hintColor}}>{10 - value.length} Left</span>
28
+ </TextArea.Hint>
29
+ </TextArea>
30
+ );
31
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextArea orientation='vertical'>
13
+ <TextArea.Label>Leave a review</TextArea.Label>
14
+ <TextArea.Field onChange={handleChange} value={value} />
15
+ </TextArea>
16
+ );
17
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextArea orientation='vertical'>
13
+ <TextArea.Label>Leave a review</TextArea.Label>
14
+ <TextArea.Field disabled onChange={handleChange} value={value} />
15
+ </TextArea>
16
+ );
17
+ };
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
3
+ import {space} from '@workday/canvas-kit-react/tokens';
4
+
5
+ export default () => {
6
+ const [value, setValue] = React.useState('four');
7
+ const [hint, setHint] = React.useState('');
8
+ const [hasError, setHasError] = React.useState(false);
9
+
10
+ const validateInput = (value: string) => {
11
+ const stringLength = value.length;
12
+ if (stringLength !== 3) {
13
+ setHasError(true);
14
+ const hintStart = 'Word length must be';
15
+ setHint(stringLength < 3 ? `${hintStart} greater than 2` : `${hintStart} less than 4`);
16
+ } else {
17
+ setHasError(false);
18
+ setHint('');
19
+ }
20
+ };
21
+
22
+ React.useEffect(() => {
23
+ validateInput(value);
24
+ // Only run on load
25
+ // eslint-disable-next-line react-hooks/exhaustive-deps
26
+ }, []);
27
+
28
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
29
+ validateInput(event.target.value);
30
+ setValue(event.target.value);
31
+ };
32
+
33
+ return (
34
+ <TextArea hasError={hasError} orientation='vertical'>
35
+ <TextArea.Label>A three letter word</TextArea.Label>
36
+ <TextArea.Field onChange={handleChange} value={value} />
37
+ <TextArea.Hint paddingTop={space.xxs}>{hint}</TextArea.Hint>
38
+ </TextArea>
39
+ );
40
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextArea orientation='vertical' alignItems='stretch'>
13
+ <TextArea.Label>Leave a review</TextArea.Label>
14
+ <TextArea.Field onChange={handleChange} value={value} />
15
+ </TextArea>
16
+ );
17
+ };
@@ -0,0 +1,20 @@
1
+ /** @jsx jsx */
2
+ import { jsx } from '@emotion/core'
3
+ import React from 'react';
4
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
5
+ import { accessibleHide } from '@workday/canvas-kit-react/common';
6
+
7
+ export default () => {
8
+ const [value, setValue] = React.useState('');
9
+
10
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
11
+ setValue(event.target.value);
12
+ };
13
+
14
+ return (
15
+ <TextArea orientation='vertical' spacing='zero'>
16
+ <TextArea.Label css={{...accessibleHide}}>Email</TextArea.Label>
17
+ <TextArea.Field onChange={handleChange} value={value} />
18
+ </TextArea>
19
+ );
20
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextArea orientation='horizontal'>
13
+ <TextArea.Label>Leave a review</TextArea.Label>
14
+ <TextArea.Field onChange={handleChange} value={value} />
15
+ </TextArea>
16
+ );
17
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextArea orientation='vertical' spacing='xxxs'>
13
+ <TextArea.Label>Leave a review</TextArea.Label>
14
+ <TextArea.Field onChange={handleChange} value={value} />
15
+ </TextArea>
16
+ );
17
+ };
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextArea orientation='vertical'>
13
+ <TextArea.Label>Leave a review</TextArea.Label>
14
+ <TextArea.Field
15
+ placeholder="Let us know how we did!"
16
+ onChange={handleChange}
17
+ value={value}
18
+ />
19
+ </TextArea>
20
+ );
21
+ };
@@ -0,0 +1,28 @@
1
+ import React from 'react';
2
+ import {changeFocus} from '@workday/canvas-kit-react/common';
3
+ import {VStack} from '@workday/canvas-kit-labs-react/layout';
4
+ import {SecondaryButton} from '@workday/canvas-kit-react/button';
5
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
6
+
7
+ export default () => {
8
+ const [value, setValue] = React.useState('');
9
+ const ref = React.useRef(null);
10
+
11
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
12
+ setValue(event.target.value);
13
+ };
14
+
15
+ const handleClick = () => {
16
+ changeFocus(ref.current)
17
+ };
18
+
19
+ return (
20
+ <VStack spacing='xxxs' alignItems='flex-start'>
21
+ <TextArea orientation='vertical'>
22
+ <TextArea.Label>Leave a review</TextArea.Label>
23
+ <TextArea.Field onChange={handleChange} value={value} ref={ref} />
24
+ </TextArea>
25
+ <SecondaryButton onClick={handleClick}>Focus Text Area</SecondaryButton>
26
+ </VStack>
27
+ );
28
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextArea isRequired={true} orientation='vertical'>
13
+ <TextArea.Label>Leave a review</TextArea.Label>
14
+ <TextArea.Field onChange={handleChange} value={value} />
15
+ </TextArea>
16
+ );
17
+ };
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import {TextArea} from '@workday/canvas-kit-preview-react/text-area';
3
+ import {styled} from '@workday/canvas-kit-react/common';
4
+
5
+ const StyledField = styled(TextArea.Field)({
6
+ resize: 'vertical',
7
+ });
8
+
9
+ export default () => {
10
+ const [value, setValue] = React.useState('');
11
+
12
+ const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
13
+ setValue(event.target.value);
14
+ };
15
+
16
+ return (
17
+ <TextArea orientation='vertical'>
18
+ <TextArea.Label>Leave a review</TextArea.Label>
19
+ <StyledField onChange={handleChange} value={value} />
20
+ </TextArea>
21
+ );
22
+ };
@@ -0,0 +1,145 @@
1
+ import {Specifications} from '@workday/canvas-kit-docs';
2
+
3
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
4
+
5
+ import Basic from './examples/Basic';
6
+ import Disabled from './examples/Disabled';
7
+ import Grow from './examples/Grow';
8
+ import LabelPositionHorizontal from './examples/LabelPositionHorizontal';
9
+ import LabelPositionVertical from './examples/LabelPositionVertical';
10
+ import Placeholder from './examples/Placeholder';
11
+ import RefForwarding from './examples/RefForwarding';
12
+ import Required from './examples/Required';
13
+ import Password from './examples/Password';
14
+ import HiddenLabel from './examples/HiddenLabel';
15
+ import ThemedAlert from './examples/ThemedAlert';
16
+ import ThemedError from './examples/ThemedError';
17
+ import Error from './examples/Error';
18
+ import Alert from './examples/Alert';
19
+ import LoginForm from './examples/LoginForm';
20
+
21
+
22
+ # Canvas Kit Text Input
23
+
24
+ Text Inputs allow users to enter words or characters without styling.
25
+
26
+ [> Workday Design Reference](https://design.workday.com/components/inputs/text-input)
27
+
28
+ ## Installation
29
+
30
+ ```sh
31
+ yarn add @workday/canvas-kit-preview-react
32
+ ```
33
+
34
+ ## Usage
35
+
36
+ ### Basic Example
37
+
38
+ <ExampleCodeBlock code={Basic} />
39
+
40
+ ### Disabled
41
+
42
+ Use `TextInput.Field`s `disabled` prop to prevent users from interacting with it.
43
+
44
+ <ExampleCodeBlock code={Disabled} />
45
+
46
+ ### Placeholder
47
+
48
+ Use `TextInput.Field`s `placeholder` prop to display a sample of its expected format or value before
49
+ a value has been provided.
50
+
51
+ <ExampleCodeBlock code={Placeholder} />
52
+
53
+ ### Required
54
+
55
+ Use `TextInput.Field`'s `isRequired` prop (or use with the `useTextInputModel` hook) to indicate
56
+ that the field is required. This will also add a red asterisk to `TextInput.Label`.
57
+
58
+ <ExampleCodeBlock code={Required} />
59
+
60
+ ### Ref Forwarding
61
+
62
+ All the TextInput subcomponents support
63
+ [ref forwarding](https://reactjs.org/docs/forwarding-refs.html). e.g. TextInput.Field will forward
64
+ `ref` to its underlying `<input type="text">` element.
65
+
66
+ <ExampleCodeBlock code={RefForwarding} />
67
+
68
+ ### Grow
69
+
70
+ There are lots of ways to accomplish this. The TextInput.Field extends from Box so it is easy to
71
+ extend full width, e.g. setting width prop to 100%, or you can set the `alignItems` prop to
72
+ `stretch` on `TextInput`, etc.
73
+
74
+ <ExampleCodeBlock code={Grow} />
75
+
76
+ ### Label Position
77
+
78
+ Use the `orientation` property to set `TextInput.Label`'s position. You can override the default
79
+ spacing using the `spacing` prop. Below are examples of both positions:
80
+
81
+ #### Horizontal
82
+
83
+ <ExampleCodeBlock code={LabelPositionHorizontal} />
84
+
85
+ #### Vertical
86
+
87
+ <ExampleCodeBlock code={LabelPositionVertical} />
88
+
89
+ ### Visually Hiding The Label
90
+
91
+ If your label is just for screen reader users you can use the `accessibleHide` utility class from
92
+ `@workday/canvas-kit-react/common`. You will likely want to set the `spacing` prop on `TextInput` to
93
+ `zero`.
94
+
95
+ <ExampleCodeBlock code={HiddenLabel} />
96
+
97
+ ### Type
98
+
99
+ Use `TextInput.Field`'s `type` prop to customize the input type, e.g. `password`, `email`, etc.
100
+
101
+ <ExampleCodeBlock code={Password} />
102
+
103
+ ### Error States
104
+
105
+ Use the `hasError` property from `useTextInputModel` to set the `TextInput` to the Error state. If
106
+ you have an accompanying hint you can use the TextInput.Hint subcomponent.
107
+
108
+ #### Errors
109
+
110
+ <ExampleCodeBlock code={Error} />
111
+
112
+ #### Themed Errors
113
+
114
+ <ExampleCodeBlock code={ThemedError} />
115
+
116
+ ### Other Visual States
117
+
118
+ Use the `useThemedRing` hook to change the visual state of the input field.
119
+
120
+ #### Alerts
121
+
122
+ <ExampleCodeBlock code={Alert} />
123
+
124
+ #### Themed Alerts
125
+
126
+ If the your theme's `main` color doesn't meet accessibility contrast, the `darkest` color will be
127
+ used in an outer ring.
128
+
129
+ <ExampleCodeBlock code={ThemedAlert} />
130
+
131
+ #### Full example
132
+
133
+ Login Form using Formik
134
+
135
+ <ExampleCodeBlock code={LoginForm} />
136
+
137
+ ## Props
138
+
139
+ Undocumented props are spread to the underlying `<input>` element.
140
+
141
+ <ArgsTable of={TextInput} />
142
+
143
+ ## Specifications
144
+
145
+ <Specifications file="TextInputPreview.spec.ts" name="Text Input" />
@@ -0,0 +1,40 @@
1
+ /** @jsx jsx */
2
+ import {jsx} from '@emotion/core';
3
+ import React from 'react';
4
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
5
+ import {useThemedRing} from '@workday/canvas-kit-labs-react/common';
6
+ import {space} from '@workday/canvas-kit-react/tokens';
7
+
8
+ export default () => {
9
+ const [value, setValue] = React.useState('foo');
10
+
11
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
12
+ setValue(event.target.value);
13
+ };
14
+
15
+ const alertStyles = useThemedRing(
16
+ value.length < 3 ? 'error' : value.length < 5 ? 'alert' : 'success'
17
+ );
18
+
19
+ return (
20
+ <TextInput orientation='vertical'>
21
+ <TextInput.Label>Password</TextInput.Label>
22
+ <TextInput.Field
23
+ css={alertStyles}
24
+ onChange={handleChange}
25
+ value={value}
26
+ type="password"
27
+ />
28
+ <TextInput.Hint paddingTop={space.xxs}>
29
+ <strong>Password Strength: </strong>
30
+ {value.length < 3 ? (
31
+ <span>Weak</span>
32
+ ) : value.length < 5 ? (
33
+ <span>Average</span>
34
+ ) : (
35
+ <span>Strong</span>
36
+ )}
37
+ </TextInput.Hint>
38
+ </TextInput>
39
+ );
40
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextInput orientation='vertical'>
13
+ <TextInput.Label>Email</TextInput.Label>
14
+ <TextInput.Field onChange={handleChange} value={value} />
15
+ </TextInput>
16
+ );
17
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextInput orientation='vertical'>
13
+ <TextInput.Label>Email</TextInput.Label>
14
+ <TextInput.Field onChange={handleChange} value={value} disabled />
15
+ </TextInput>
16
+ );
17
+ };
@@ -0,0 +1,40 @@
1
+ import React from 'react';
2
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
3
+ import {space} from '@workday/canvas-kit-react/tokens';
4
+
5
+ export default () => {
6
+ const [value, setValue] = React.useState('four');
7
+ const [hint, setHint] = React.useState('');
8
+ const [hasError, setHasError] = React.useState(false);
9
+
10
+ const validateInput = (value: string) => {
11
+ const stringLength = value.length;
12
+ if (stringLength !== 3) {
13
+ setHasError(true);
14
+ const hintStart = 'Word length must be';
15
+ setHint(stringLength < 3 ? `${hintStart} greater than 2` : `${hintStart} less than 4`);
16
+ } else {
17
+ setHasError(false);
18
+ setHint('');
19
+ }
20
+ };
21
+
22
+ React.useEffect(() => {
23
+ validateInput(value);
24
+ // Only run on load
25
+ // eslint-disable-next-line react-hooks/exhaustive-deps
26
+ }, []);
27
+
28
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
29
+ validateInput(event.target.value);
30
+ setValue(event.target.value);
31
+ };
32
+
33
+ return (
34
+ <TextInput hasError={hasError} orientation='vertical'>
35
+ <TextInput.Label>A three letter word</TextInput.Label>
36
+ <TextInput.Field onChange={handleChange} value={value} />
37
+ <TextInput.Hint paddingTop={space.xxs}>{hint}</TextInput.Hint>
38
+ </TextInput>
39
+ );
40
+ };
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
3
+
4
+ export default () => {
5
+ const [value, setValue] = React.useState('');
6
+
7
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
8
+ setValue(event.target.value);
9
+ };
10
+
11
+ return (
12
+ <TextInput orientation='vertical' alignItems='stretch'>
13
+ <TextInput.Label>Street Address</TextInput.Label>
14
+ <TextInput.Field onChange={handleChange} value={value} />
15
+ </TextInput>
16
+ );
17
+ };