@workday/canvas-kit-docs 6.0.6 → 6.1.2
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/dist/commonjs/lib/specs.js +136 -2
- package/dist/es6/lib/specs.js +136 -2
- 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/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/button/button/examples/Primary.tsx +4 -3
- 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/tooltip/Tooltip.mdx +8 -0
- package/dist/mdx/react/tooltip/examples/DelayedTooltip.tsx +16 -0
- package/package.json +5 -4
- 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
|
@@ -5395,6 +5395,140 @@ module.exports = {specifications: [
|
|
|
5395
5395
|
}
|
|
5396
5396
|
]
|
|
5397
5397
|
},
|
|
5398
|
+
{
|
|
5399
|
+
"type": "file",
|
|
5400
|
+
"name": "TextAreaPreview.spec.ts",
|
|
5401
|
+
"children": [
|
|
5402
|
+
{
|
|
5403
|
+
"type": "describe",
|
|
5404
|
+
"name": "Text Area",
|
|
5405
|
+
"children": [
|
|
5406
|
+
{
|
|
5407
|
+
"type": "describe",
|
|
5408
|
+
"name": "given the 'Basic' story is rendered",
|
|
5409
|
+
"children": [
|
|
5410
|
+
{
|
|
5411
|
+
"type": "it",
|
|
5412
|
+
"name": "should not have any axe errors"
|
|
5413
|
+
},
|
|
5414
|
+
{
|
|
5415
|
+
"type": "describe",
|
|
5416
|
+
"name": "when clicked",
|
|
5417
|
+
"children": [
|
|
5418
|
+
{
|
|
5419
|
+
"type": "it",
|
|
5420
|
+
"name": "should be focused"
|
|
5421
|
+
}
|
|
5422
|
+
]
|
|
5423
|
+
},
|
|
5424
|
+
{
|
|
5425
|
+
"type": "describe",
|
|
5426
|
+
"name": "when text is entered",
|
|
5427
|
+
"children": [
|
|
5428
|
+
{
|
|
5429
|
+
"type": "it",
|
|
5430
|
+
"name": "should reflect the text typed"
|
|
5431
|
+
}
|
|
5432
|
+
]
|
|
5433
|
+
}
|
|
5434
|
+
]
|
|
5435
|
+
},
|
|
5436
|
+
{
|
|
5437
|
+
"type": "describe",
|
|
5438
|
+
"name": "given the 'Alert' story is rendered",
|
|
5439
|
+
"children": [
|
|
5440
|
+
{
|
|
5441
|
+
"type": "it",
|
|
5442
|
+
"name": "should not have any axe errors"
|
|
5443
|
+
},
|
|
5444
|
+
{
|
|
5445
|
+
"type": "describe",
|
|
5446
|
+
"name": "when clicked",
|
|
5447
|
+
"children": [
|
|
5448
|
+
{
|
|
5449
|
+
"type": "it",
|
|
5450
|
+
"name": "should be focused"
|
|
5451
|
+
}
|
|
5452
|
+
]
|
|
5453
|
+
},
|
|
5454
|
+
{
|
|
5455
|
+
"type": "describe",
|
|
5456
|
+
"name": "when text is entered",
|
|
5457
|
+
"children": [
|
|
5458
|
+
{
|
|
5459
|
+
"type": "it",
|
|
5460
|
+
"name": "should reflect the text typed"
|
|
5461
|
+
}
|
|
5462
|
+
]
|
|
5463
|
+
}
|
|
5464
|
+
]
|
|
5465
|
+
},
|
|
5466
|
+
{
|
|
5467
|
+
"type": "describe",
|
|
5468
|
+
"name": "given the 'Error' story is rendered",
|
|
5469
|
+
"children": [
|
|
5470
|
+
{
|
|
5471
|
+
"type": "it",
|
|
5472
|
+
"name": "should not have any axe errors"
|
|
5473
|
+
},
|
|
5474
|
+
{
|
|
5475
|
+
"type": "describe",
|
|
5476
|
+
"name": "when clicked",
|
|
5477
|
+
"children": [
|
|
5478
|
+
{
|
|
5479
|
+
"type": "it",
|
|
5480
|
+
"name": "should be focused"
|
|
5481
|
+
}
|
|
5482
|
+
]
|
|
5483
|
+
},
|
|
5484
|
+
{
|
|
5485
|
+
"type": "describe",
|
|
5486
|
+
"name": "when text is entered",
|
|
5487
|
+
"children": [
|
|
5488
|
+
{
|
|
5489
|
+
"type": "it",
|
|
5490
|
+
"name": "should reflect the text typed"
|
|
5491
|
+
}
|
|
5492
|
+
]
|
|
5493
|
+
}
|
|
5494
|
+
]
|
|
5495
|
+
},
|
|
5496
|
+
{
|
|
5497
|
+
"type": "describe",
|
|
5498
|
+
"name": "given the 'Disabled' story is rendered",
|
|
5499
|
+
"children": [
|
|
5500
|
+
{
|
|
5501
|
+
"type": "it",
|
|
5502
|
+
"name": "should not have any axe errors"
|
|
5503
|
+
},
|
|
5504
|
+
{
|
|
5505
|
+
"type": "it",
|
|
5506
|
+
"name": "should be disabled"
|
|
5507
|
+
}
|
|
5508
|
+
]
|
|
5509
|
+
},
|
|
5510
|
+
{
|
|
5511
|
+
"type": "describe",
|
|
5512
|
+
"name": "given the 'Placeholder' story is rendered",
|
|
5513
|
+
"children": [
|
|
5514
|
+
{
|
|
5515
|
+
"type": "it",
|
|
5516
|
+
"name": "should not have any axe errors"
|
|
5517
|
+
},
|
|
5518
|
+
{
|
|
5519
|
+
"type": "it",
|
|
5520
|
+
"name": "should render a placeholder text"
|
|
5521
|
+
},
|
|
5522
|
+
{
|
|
5523
|
+
"type": "it",
|
|
5524
|
+
"name": "should reflect the text typed"
|
|
5525
|
+
}
|
|
5526
|
+
]
|
|
5527
|
+
}
|
|
5528
|
+
]
|
|
5529
|
+
}
|
|
5530
|
+
]
|
|
5531
|
+
},
|
|
5398
5532
|
{
|
|
5399
5533
|
"type": "file",
|
|
5400
5534
|
"name": "TextInput.spec.ts",
|
|
@@ -5531,11 +5665,11 @@ module.exports = {specifications: [
|
|
|
5531
5665
|
},
|
|
5532
5666
|
{
|
|
5533
5667
|
"type": "file",
|
|
5534
|
-
"name": "
|
|
5668
|
+
"name": "TextInputPreview.spec.ts",
|
|
5535
5669
|
"children": [
|
|
5536
5670
|
{
|
|
5537
5671
|
"type": "describe",
|
|
5538
|
-
"name": "
|
|
5672
|
+
"name": "Text Input",
|
|
5539
5673
|
"children": [
|
|
5540
5674
|
{
|
|
5541
5675
|
"type": "describe",
|
package/dist/es6/lib/specs.js
CHANGED
|
@@ -5395,6 +5395,140 @@ module.exports = {specifications: [
|
|
|
5395
5395
|
}
|
|
5396
5396
|
]
|
|
5397
5397
|
},
|
|
5398
|
+
{
|
|
5399
|
+
"type": "file",
|
|
5400
|
+
"name": "TextAreaPreview.spec.ts",
|
|
5401
|
+
"children": [
|
|
5402
|
+
{
|
|
5403
|
+
"type": "describe",
|
|
5404
|
+
"name": "Text Area",
|
|
5405
|
+
"children": [
|
|
5406
|
+
{
|
|
5407
|
+
"type": "describe",
|
|
5408
|
+
"name": "given the 'Basic' story is rendered",
|
|
5409
|
+
"children": [
|
|
5410
|
+
{
|
|
5411
|
+
"type": "it",
|
|
5412
|
+
"name": "should not have any axe errors"
|
|
5413
|
+
},
|
|
5414
|
+
{
|
|
5415
|
+
"type": "describe",
|
|
5416
|
+
"name": "when clicked",
|
|
5417
|
+
"children": [
|
|
5418
|
+
{
|
|
5419
|
+
"type": "it",
|
|
5420
|
+
"name": "should be focused"
|
|
5421
|
+
}
|
|
5422
|
+
]
|
|
5423
|
+
},
|
|
5424
|
+
{
|
|
5425
|
+
"type": "describe",
|
|
5426
|
+
"name": "when text is entered",
|
|
5427
|
+
"children": [
|
|
5428
|
+
{
|
|
5429
|
+
"type": "it",
|
|
5430
|
+
"name": "should reflect the text typed"
|
|
5431
|
+
}
|
|
5432
|
+
]
|
|
5433
|
+
}
|
|
5434
|
+
]
|
|
5435
|
+
},
|
|
5436
|
+
{
|
|
5437
|
+
"type": "describe",
|
|
5438
|
+
"name": "given the 'Alert' story is rendered",
|
|
5439
|
+
"children": [
|
|
5440
|
+
{
|
|
5441
|
+
"type": "it",
|
|
5442
|
+
"name": "should not have any axe errors"
|
|
5443
|
+
},
|
|
5444
|
+
{
|
|
5445
|
+
"type": "describe",
|
|
5446
|
+
"name": "when clicked",
|
|
5447
|
+
"children": [
|
|
5448
|
+
{
|
|
5449
|
+
"type": "it",
|
|
5450
|
+
"name": "should be focused"
|
|
5451
|
+
}
|
|
5452
|
+
]
|
|
5453
|
+
},
|
|
5454
|
+
{
|
|
5455
|
+
"type": "describe",
|
|
5456
|
+
"name": "when text is entered",
|
|
5457
|
+
"children": [
|
|
5458
|
+
{
|
|
5459
|
+
"type": "it",
|
|
5460
|
+
"name": "should reflect the text typed"
|
|
5461
|
+
}
|
|
5462
|
+
]
|
|
5463
|
+
}
|
|
5464
|
+
]
|
|
5465
|
+
},
|
|
5466
|
+
{
|
|
5467
|
+
"type": "describe",
|
|
5468
|
+
"name": "given the 'Error' story is rendered",
|
|
5469
|
+
"children": [
|
|
5470
|
+
{
|
|
5471
|
+
"type": "it",
|
|
5472
|
+
"name": "should not have any axe errors"
|
|
5473
|
+
},
|
|
5474
|
+
{
|
|
5475
|
+
"type": "describe",
|
|
5476
|
+
"name": "when clicked",
|
|
5477
|
+
"children": [
|
|
5478
|
+
{
|
|
5479
|
+
"type": "it",
|
|
5480
|
+
"name": "should be focused"
|
|
5481
|
+
}
|
|
5482
|
+
]
|
|
5483
|
+
},
|
|
5484
|
+
{
|
|
5485
|
+
"type": "describe",
|
|
5486
|
+
"name": "when text is entered",
|
|
5487
|
+
"children": [
|
|
5488
|
+
{
|
|
5489
|
+
"type": "it",
|
|
5490
|
+
"name": "should reflect the text typed"
|
|
5491
|
+
}
|
|
5492
|
+
]
|
|
5493
|
+
}
|
|
5494
|
+
]
|
|
5495
|
+
},
|
|
5496
|
+
{
|
|
5497
|
+
"type": "describe",
|
|
5498
|
+
"name": "given the 'Disabled' story is rendered",
|
|
5499
|
+
"children": [
|
|
5500
|
+
{
|
|
5501
|
+
"type": "it",
|
|
5502
|
+
"name": "should not have any axe errors"
|
|
5503
|
+
},
|
|
5504
|
+
{
|
|
5505
|
+
"type": "it",
|
|
5506
|
+
"name": "should be disabled"
|
|
5507
|
+
}
|
|
5508
|
+
]
|
|
5509
|
+
},
|
|
5510
|
+
{
|
|
5511
|
+
"type": "describe",
|
|
5512
|
+
"name": "given the 'Placeholder' story is rendered",
|
|
5513
|
+
"children": [
|
|
5514
|
+
{
|
|
5515
|
+
"type": "it",
|
|
5516
|
+
"name": "should not have any axe errors"
|
|
5517
|
+
},
|
|
5518
|
+
{
|
|
5519
|
+
"type": "it",
|
|
5520
|
+
"name": "should render a placeholder text"
|
|
5521
|
+
},
|
|
5522
|
+
{
|
|
5523
|
+
"type": "it",
|
|
5524
|
+
"name": "should reflect the text typed"
|
|
5525
|
+
}
|
|
5526
|
+
]
|
|
5527
|
+
}
|
|
5528
|
+
]
|
|
5529
|
+
}
|
|
5530
|
+
]
|
|
5531
|
+
},
|
|
5398
5532
|
{
|
|
5399
5533
|
"type": "file",
|
|
5400
5534
|
"name": "TextInput.spec.ts",
|
|
@@ -5531,11 +5665,11 @@ module.exports = {specifications: [
|
|
|
5531
5665
|
},
|
|
5532
5666
|
{
|
|
5533
5667
|
"type": "file",
|
|
5534
|
-
"name": "
|
|
5668
|
+
"name": "TextInputPreview.spec.ts",
|
|
5535
5669
|
"children": [
|
|
5536
5670
|
{
|
|
5537
5671
|
"type": "describe",
|
|
5538
|
-
"name": "
|
|
5672
|
+
"name": "Text Input",
|
|
5539
5673
|
"children": [
|
|
5540
5674
|
{
|
|
5541
5675
|
"type": "describe",
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {Specifications} from '@workday/canvas-kit-docs';
|
|
2
|
+
|
|
3
|
+
import {FormField} from '@workday/canvas-kit-preview-react/form-field';
|
|
4
|
+
|
|
5
|
+
import Custom from './examples/Custom';
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
# Canvas Kit Form Field
|
|
9
|
+
|
|
10
|
+
FormField allows users to wrap input components to make them accessible. You usually won't want to
|
|
11
|
+
use FormField directly but instead should use the specific component you need, e.g. `TextInput`.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
yarn add @workday/canvas-kit-preview-react
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Customizing With Behavior Hooks Example
|
|
22
|
+
|
|
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
|
|
25
|
+
accessibility guarantees by using the `as` prop.
|
|
26
|
+
|
|
27
|
+
<ExampleCodeBlock code={Custom} />
|
|
@@ -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
|
+
};
|
|
@@ -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
|
+
};
|