@workday/canvas-kit-docs 6.0.0-alpha.0-next.30 → 6.0.0-alpha.0-next.36
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/LICENSE +1 -1
- package/dist/commonjs/lib/specs.js +295 -33
- package/dist/es6/lib/specs.js +295 -33
- package/dist/mdx/6.0-MIGRATION-GUIDE.mdx +117 -14
- package/dist/mdx/7.0-MIGRATION-GUIDE.mdx +33 -0
- package/dist/mdx/COMPOUND_COMPONENTS.mdx +31 -30
- package/dist/mdx/CONTRIBUTING.mdx +90 -63
- package/dist/mdx/preview-react/breadcrumbs/Breadcrumbs.mdx +1 -1
- package/dist/mdx/preview-react/form-field/FormField.mdx +27 -0
- package/dist/mdx/preview-react/form-field/examples/Custom.tsx +57 -0
- package/dist/mdx/preview-react/menu/examples/Icons.tsx +1 -1
- package/dist/mdx/preview-react/menu/examples/ManyItems.tsx +1 -1
- package/dist/mdx/preview-react/text-area/TextArea.mdx +122 -0
- package/dist/mdx/preview-react/text-area/examples/Alert.tsx +31 -0
- package/dist/mdx/preview-react/text-area/examples/Basic.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/Disabled.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/Error.tsx +40 -0
- package/dist/mdx/preview-react/text-area/examples/Grow.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/HiddenLabel.tsx +20 -0
- package/dist/mdx/preview-react/text-area/examples/LabelPositionHorizontal.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/LabelPositionVertical.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/Placeholder.tsx +21 -0
- package/dist/mdx/preview-react/text-area/examples/RefForwarding.tsx +28 -0
- package/dist/mdx/preview-react/text-area/examples/Required.tsx +17 -0
- package/dist/mdx/preview-react/text-area/examples/ResizeConstraints.tsx +22 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/TextInput.mdx +40 -18
- package/dist/mdx/preview-react/text-input/examples/Alert.tsx +40 -0
- package/dist/mdx/{labs-react/text-input/examples/HiddenLabel.tsx → preview-react/text-input/examples/Basic.tsx} +3 -3
- package/dist/mdx/preview-react/text-input/examples/Disabled.tsx +17 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/examples/Error.tsx +6 -9
- package/dist/mdx/preview-react/text-input/examples/Grow.tsx +17 -0
- package/dist/mdx/preview-react/text-input/examples/HiddenLabel.tsx +20 -0
- package/dist/mdx/preview-react/text-input/examples/LabelPositionHorizontal.tsx +17 -0
- package/dist/mdx/preview-react/text-input/examples/LabelPositionVertical.tsx +17 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/examples/LoginForm.tsx +10 -5
- package/dist/mdx/preview-react/text-input/examples/Password.tsx +17 -0
- package/dist/mdx/preview-react/text-input/examples/Placeholder.tsx +17 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/examples/RefForwarding.tsx +7 -6
- package/dist/mdx/preview-react/text-input/examples/Required.tsx +17 -0
- package/dist/mdx/preview-react/text-input/examples/ThemedAlert.tsx +46 -0
- package/dist/mdx/{labs-react → preview-react}/text-input/examples/ThemedError.tsx +8 -11
- package/dist/mdx/react/_examples/GlobalHeader.mdx +9 -0
- package/dist/mdx/react/_examples/PageHeader.mdx +8 -0
- package/dist/mdx/react/_examples/examples/GlobalHeader.tsx +66 -0
- package/dist/mdx/react/_examples/examples/PageHeader.tsx +63 -0
- package/dist/mdx/react/action-bar/ActionBar.mdx +1 -1
- package/dist/mdx/react/button/button/Button.mdx +7 -7
- package/dist/mdx/react/button/icon-button/IconButton.mdx +1 -1
- package/dist/mdx/react/loading-animation/LoadingAnimation.mdx +5 -0
- package/dist/mdx/react/loading-animation/examples/RTL.tsx +16 -0
- package/dist/mdx/react/pagination/PropTables.splitprops.tsx +47 -0
- package/dist/mdx/react/pagination/examples/{StepControls.tsx → Basic.tsx} +1 -1
- package/dist/mdx/react/pagination/examples/GoToForm.tsx +1 -1
- package/dist/mdx/react/pagination/examples/HoistedModel.tsx +36 -22
- package/dist/mdx/react/pagination/examples/RTL.tsx +1 -1
- package/dist/mdx/react/pagination/pagination.mdx +225 -474
- package/dist/mdx/react/popup/Popup.mdx +34 -36
- package/dist/mdx/react/radio/examples/Alert.tsx +3 -3
- package/dist/mdx/react/radio/examples/Basic.tsx +3 -3
- package/dist/mdx/react/radio/examples/Disabled.tsx +3 -3
- package/dist/mdx/react/radio/examples/Error.tsx +3 -3
- package/dist/mdx/react/radio/examples/LabelPosition.tsx +3 -3
- package/dist/mdx/react/radio/examples/NoValue.tsx +3 -3
- package/dist/mdx/react/radio/examples/RefForwarding.tsx +3 -3
- package/dist/mdx/react/radio/examples/Required.tsx +3 -3
- package/dist/mdx/react/segmented-control/SegmentedControl.mdx +1 -1
- package/dist/mdx/react/tabs/Tabs.mdx +67 -36
- package/dist/mdx/react/tabs/examples/DisabledTab.tsx +1 -1
- package/dist/mdx/react/tabs/examples/DynamicTabs.tsx +41 -13
- package/dist/mdx/react/tabs/examples/HoistedModel.tsx +4 -4
- package/dist/mdx/react/tabs/examples/Icons.tsx +36 -0
- package/dist/mdx/react/tabs/examples/{NamedKeys.tsx → NamedTabs.tsx} +0 -0
- package/dist/mdx/react/tabs/examples/OverflowTabs.tsx +58 -0
- package/dist/mdx/react/tabs/examples/SinglePanel.tsx +1 -1
- package/dist/mdx/react/toast/toast.mdx +1 -17
- package/dist/mdx/react/tooltip/Tooltip.mdx +9 -1
- package/dist/mdx/react/tooltip/examples/DelayedTooltip.tsx +16 -0
- package/dist/mdx/react/tooltip/examples/Ellipsis.tsx +6 -0
- package/package.json +5 -4
- package/dist/mdx/CODE_OF_CONDUCT.md +0 -68
- package/dist/mdx/labs-react/text-input/examples/Alert.tsx +0 -46
- package/dist/mdx/labs-react/text-input/examples/Basic.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Disabled.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Grow.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/LabelPosition.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Password.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Placeholder.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/Required.tsx +0 -20
- package/dist/mdx/labs-react/text-input/examples/ThemedAlert.tsx +0 -51
- package/dist/mdx/react/pagination/examples/ShowAdditionalDetails.tsx +0 -52
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {
|
|
3
|
+
useFormFieldHint,
|
|
4
|
+
useFormFieldInput,
|
|
5
|
+
useFormFieldLabel,
|
|
6
|
+
useFormFieldModel,
|
|
7
|
+
useFormFieldOrientation,
|
|
8
|
+
FormFieldModelContext,
|
|
9
|
+
} from '@workday/canvas-kit-preview-react/form-field';
|
|
10
|
+
import {useModelContext} from '@workday/canvas-kit-react/common';
|
|
11
|
+
import {Stack} from '@workday/canvas-kit-labs-react/layout';
|
|
12
|
+
|
|
13
|
+
const Label = ({model, children}) => {
|
|
14
|
+
const localModel = useModelContext(FormFieldModelContext, model);
|
|
15
|
+
const props = useFormFieldLabel(localModel);
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<label {...props}>
|
|
19
|
+
{children}
|
|
20
|
+
{model.state.isRequired ? '*' : ''}
|
|
21
|
+
</label>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const Hint = ({model, children}) => {
|
|
26
|
+
const localModel = useModelContext(FormFieldModelContext, model);
|
|
27
|
+
const props = useFormFieldHint(localModel);
|
|
28
|
+
|
|
29
|
+
return <span {...props}>{children}</span>;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const Input = ({model, ...elementProps}) => {
|
|
33
|
+
const localModel = useModelContext(FormFieldModelContext, model);
|
|
34
|
+
const props = useFormFieldInput(localModel, elementProps);
|
|
35
|
+
|
|
36
|
+
return <input type="text" required={model.state.isRequired ? true : false} {...props} />;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default () => {
|
|
40
|
+
const [value, setValue] = React.useState('');
|
|
41
|
+
|
|
42
|
+
const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
43
|
+
setValue(event.target.value);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const model = useFormFieldModel({isRequired: true});
|
|
47
|
+
|
|
48
|
+
const layoutProps = useFormFieldOrientation('vertical')
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<Stack {...layoutProps}>
|
|
52
|
+
<Label model={model}>My Custom Field</Label>
|
|
53
|
+
<Input model={model} value={value} onChange={handleChange} />
|
|
54
|
+
<Hint model={model}>You can be anything</Hint>
|
|
55
|
+
</Stack>
|
|
56
|
+
);
|
|
57
|
+
};
|
|
@@ -10,7 +10,7 @@ import {Menu, MenuItem} from '@workday/canvas-kit-preview-react/menu';
|
|
|
10
10
|
|
|
11
11
|
export default () => {
|
|
12
12
|
return (
|
|
13
|
-
<Menu
|
|
13
|
+
<Menu>
|
|
14
14
|
<MenuItem icon={uploadCloudIcon}>First Item</MenuItem>
|
|
15
15
|
<MenuItem icon={setupIcon}>Second Item (with a really really really long label)</MenuItem>
|
|
16
16
|
<MenuItem isDisabled icon={uploadCloudIcon} secondaryIcon={taskContactIcon}>
|
|
@@ -4,7 +4,7 @@ import {Menu, MenuItem} from '@workday/canvas-kit-preview-react/menu';
|
|
|
4
4
|
|
|
5
5
|
export default () => {
|
|
6
6
|
return (
|
|
7
|
-
<Menu
|
|
7
|
+
<Menu>
|
|
8
8
|
{'One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen'
|
|
9
9
|
.split(' ')
|
|
10
10
|
.map(item => {
|
|
@@ -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
|
+
};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import {Specifications} from '@workday/canvas-kit-docs';
|
|
2
2
|
|
|
3
|
-
import {TextInput} from '@workday/canvas-kit-
|
|
3
|
+
import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
|
|
4
4
|
|
|
5
5
|
import Basic from './examples/Basic';
|
|
6
6
|
import Disabled from './examples/Disabled';
|
|
7
7
|
import Grow from './examples/Grow';
|
|
8
|
-
import
|
|
8
|
+
import LabelPositionHorizontal from './examples/LabelPositionHorizontal';
|
|
9
|
+
import LabelPositionVertical from './examples/LabelPositionVertical';
|
|
9
10
|
import Placeholder from './examples/Placeholder';
|
|
10
11
|
import RefForwarding from './examples/RefForwarding';
|
|
11
12
|
import Required from './examples/Required';
|
|
@@ -27,7 +28,7 @@ Text Inputs allow users to enter words or characters without styling.
|
|
|
27
28
|
## Installation
|
|
28
29
|
|
|
29
30
|
```sh
|
|
30
|
-
yarn add @workday/canvas-kit-react
|
|
31
|
+
yarn add @workday/canvas-kit-preview-react
|
|
31
32
|
```
|
|
32
33
|
|
|
33
34
|
## Usage
|
|
@@ -38,21 +39,21 @@ yarn add @workday/canvas-kit-react
|
|
|
38
39
|
|
|
39
40
|
### Disabled
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
Use `TextInput.Field`s `disabled` prop to prevent users from interacting with it.
|
|
42
43
|
|
|
43
44
|
<ExampleCodeBlock code={Disabled} />
|
|
44
45
|
|
|
45
46
|
### Placeholder
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
Use `TextInput.Field`s `placeholder` prop to display a sample of its expected format or value before
|
|
49
|
+
a value has been provided.
|
|
49
50
|
|
|
50
51
|
<ExampleCodeBlock code={Placeholder} />
|
|
51
52
|
|
|
52
53
|
### Required
|
|
53
54
|
|
|
54
|
-
|
|
55
|
-
required. This will also add
|
|
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`.
|
|
56
57
|
|
|
57
58
|
<ExampleCodeBlock code={Required} />
|
|
58
59
|
|
|
@@ -67,34 +68,42 @@ All the TextInput subcomponents support
|
|
|
67
68
|
### Grow
|
|
68
69
|
|
|
69
70
|
There are lots of ways to accomplish this. The TextInput.Field extends from Box so it is easy to
|
|
70
|
-
extend full width, e.g. setting width prop to 100%, or you can
|
|
71
|
-
|
|
71
|
+
extend full width, e.g. setting width prop to 100%, or you can set the `alignItems` prop to
|
|
72
|
+
`stretch` on `TextInput`, etc.
|
|
72
73
|
|
|
73
74
|
<ExampleCodeBlock code={Grow} />
|
|
74
75
|
|
|
75
76
|
### Label Position
|
|
76
77
|
|
|
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:
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
#### Horizontal
|
|
82
|
+
|
|
83
|
+
<ExampleCodeBlock code={LabelPositionHorizontal} />
|
|
84
|
+
|
|
85
|
+
#### Vertical
|
|
86
|
+
|
|
87
|
+
<ExampleCodeBlock code={LabelPositionVertical} />
|
|
80
88
|
|
|
81
89
|
### Visually Hiding The Label
|
|
82
90
|
|
|
83
|
-
If your label is just for screen reader users you can
|
|
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`.
|
|
84
94
|
|
|
85
95
|
<ExampleCodeBlock code={HiddenLabel} />
|
|
86
96
|
|
|
87
97
|
### Type
|
|
88
98
|
|
|
89
|
-
|
|
90
|
-
type.
|
|
99
|
+
Use `TextInput.Field`'s `type` prop to customize the input type, e.g. `password`, `email`, etc.
|
|
91
100
|
|
|
92
101
|
<ExampleCodeBlock code={Password} />
|
|
93
102
|
|
|
94
103
|
### Error States
|
|
95
104
|
|
|
96
|
-
Use the `hasError` property from useTextInputModel to set the TextInput to the Error state. If
|
|
97
|
-
have an accompanying hint you can use the TextInput.Hint subcomponent.
|
|
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.
|
|
98
107
|
|
|
99
108
|
#### Errors
|
|
100
109
|
|
|
@@ -114,10 +123,23 @@ Use the `useThemedRing` hook to change the visual state of the input field.
|
|
|
114
123
|
|
|
115
124
|
#### Themed Alerts
|
|
116
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
|
+
|
|
117
129
|
<ExampleCodeBlock code={ThemedAlert} />
|
|
118
130
|
|
|
119
131
|
#### Full example
|
|
120
132
|
|
|
121
133
|
Login Form using Formik
|
|
122
134
|
|
|
123
|
-
<ExampleCodeBlock code={LoginForm} />
|
|
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
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {TextInput} from '@workday/canvas-kit-
|
|
2
|
+
import {TextInput} from '@workday/canvas-kit-preview-react/text-input';
|
|
3
3
|
|
|
4
4
|
export default () => {
|
|
5
5
|
const [value, setValue] = React.useState('');
|
|
@@ -9,8 +9,8 @@ export default () => {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
return (
|
|
12
|
-
<TextInput>
|
|
13
|
-
<TextInput.Label
|
|
12
|
+
<TextInput orientation='vertical'>
|
|
13
|
+
<TextInput.Label>Email</TextInput.Label>
|
|
14
14
|
<TextInput.Field onChange={handleChange} value={value} />
|
|
15
15
|
</TextInput>
|
|
16
16
|
);
|