@workday/canvas-kit-docs 6.0.0-alpha.0-next.34 → 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.
Files changed (53) hide show
  1. package/dist/commonjs/lib/specs.js +168 -2
  2. package/dist/es6/lib/specs.js +168 -2
  3. package/dist/mdx/6.0-MIGRATION-GUIDE.mdx +6 -0
  4. package/dist/mdx/7.0-MIGRATION-GUIDE.mdx +33 -0
  5. package/dist/mdx/preview-react/form-field/FormField.mdx +27 -0
  6. package/dist/mdx/preview-react/form-field/examples/Custom.tsx +57 -0
  7. package/dist/mdx/preview-react/text-area/TextArea.mdx +122 -0
  8. package/dist/mdx/preview-react/text-area/examples/Alert.tsx +31 -0
  9. package/dist/mdx/preview-react/text-area/examples/Basic.tsx +17 -0
  10. package/dist/mdx/preview-react/text-area/examples/Disabled.tsx +17 -0
  11. package/dist/mdx/preview-react/text-area/examples/Error.tsx +40 -0
  12. package/dist/mdx/preview-react/text-area/examples/Grow.tsx +17 -0
  13. package/dist/mdx/preview-react/text-area/examples/HiddenLabel.tsx +20 -0
  14. package/dist/mdx/preview-react/text-area/examples/LabelPositionHorizontal.tsx +17 -0
  15. package/dist/mdx/preview-react/text-area/examples/LabelPositionVertical.tsx +17 -0
  16. package/dist/mdx/preview-react/text-area/examples/Placeholder.tsx +21 -0
  17. package/dist/mdx/preview-react/text-area/examples/RefForwarding.tsx +28 -0
  18. package/dist/mdx/preview-react/text-area/examples/Required.tsx +17 -0
  19. package/dist/mdx/preview-react/text-area/examples/ResizeConstraints.tsx +22 -0
  20. package/dist/mdx/{labs-react → preview-react}/text-input/TextInput.mdx +40 -18
  21. package/dist/mdx/preview-react/text-input/examples/Alert.tsx +40 -0
  22. package/dist/mdx/{labs-react/text-input/examples/HiddenLabel.tsx → preview-react/text-input/examples/Basic.tsx} +3 -3
  23. package/dist/mdx/preview-react/text-input/examples/Disabled.tsx +17 -0
  24. package/dist/mdx/{labs-react → preview-react}/text-input/examples/Error.tsx +6 -9
  25. package/dist/mdx/preview-react/text-input/examples/Grow.tsx +17 -0
  26. package/dist/mdx/preview-react/text-input/examples/HiddenLabel.tsx +20 -0
  27. package/dist/mdx/preview-react/text-input/examples/LabelPositionHorizontal.tsx +17 -0
  28. package/dist/mdx/preview-react/text-input/examples/LabelPositionVertical.tsx +17 -0
  29. package/dist/mdx/{labs-react → preview-react}/text-input/examples/LoginForm.tsx +10 -5
  30. package/dist/mdx/preview-react/text-input/examples/Password.tsx +17 -0
  31. package/dist/mdx/preview-react/text-input/examples/Placeholder.tsx +17 -0
  32. package/dist/mdx/{labs-react → preview-react}/text-input/examples/RefForwarding.tsx +7 -6
  33. package/dist/mdx/preview-react/text-input/examples/Required.tsx +17 -0
  34. package/dist/mdx/preview-react/text-input/examples/ThemedAlert.tsx +46 -0
  35. package/dist/mdx/{labs-react → preview-react}/text-input/examples/ThemedError.tsx +8 -11
  36. package/dist/mdx/react/_examples/GlobalHeader.mdx +9 -0
  37. package/dist/mdx/react/_examples/PageHeader.mdx +8 -0
  38. package/dist/mdx/react/_examples/examples/GlobalHeader.tsx +66 -0
  39. package/dist/mdx/react/_examples/examples/PageHeader.tsx +63 -0
  40. package/dist/mdx/react/loading-animation/LoadingAnimation.mdx +5 -0
  41. package/dist/mdx/react/loading-animation/examples/RTL.tsx +16 -0
  42. package/dist/mdx/react/tooltip/Tooltip.mdx +8 -0
  43. package/dist/mdx/react/tooltip/examples/DelayedTooltip.tsx +16 -0
  44. package/package.json +5 -4
  45. package/dist/mdx/labs-react/text-input/examples/Alert.tsx +0 -46
  46. package/dist/mdx/labs-react/text-input/examples/Basic.tsx +0 -20
  47. package/dist/mdx/labs-react/text-input/examples/Disabled.tsx +0 -20
  48. package/dist/mdx/labs-react/text-input/examples/Grow.tsx +0 -20
  49. package/dist/mdx/labs-react/text-input/examples/LabelPosition.tsx +0 -20
  50. package/dist/mdx/labs-react/text-input/examples/Password.tsx +0 -20
  51. package/dist/mdx/labs-react/text-input/examples/Placeholder.tsx +0 -20
  52. package/dist/mdx/labs-react/text-input/examples/Required.tsx +0 -20
  53. package/dist/mdx/labs-react/text-input/examples/ThemedAlert.tsx +0 -51
@@ -5185,6 +5185,22 @@ module.exports = {specifications: [
5185
5185
  "type": "it",
5186
5186
  "name": "should not show the \"More\" button"
5187
5187
  },
5188
+ {
5189
+ "type": "describe",
5190
+ "name": "when the \"First Tab\" is focused",
5191
+ "children": [
5192
+ {
5193
+ "type": "describe",
5194
+ "name": "when the Tab key is pressed",
5195
+ "children": [
5196
+ {
5197
+ "type": "it",
5198
+ "name": "should focus on the tab panel"
5199
+ }
5200
+ ]
5201
+ }
5202
+ ]
5203
+ },
5188
5204
  {
5189
5205
  "type": "describe",
5190
5206
  "name": "when tab list container is only 500px wide",
@@ -5197,6 +5213,22 @@ module.exports = {specifications: [
5197
5213
  "type": "it",
5198
5214
  "name": "should show the \"More\" button"
5199
5215
  },
5216
+ {
5217
+ "type": "describe",
5218
+ "name": "when the \"First Tab\" is focused",
5219
+ "children": [
5220
+ {
5221
+ "type": "describe",
5222
+ "name": "when the Tab key is pressed",
5223
+ "children": [
5224
+ {
5225
+ "type": "it",
5226
+ "name": "should focus on the \"More\" button"
5227
+ }
5228
+ ]
5229
+ }
5230
+ ]
5231
+ },
5200
5232
  {
5201
5233
  "type": "describe",
5202
5234
  "name": "when the \"More\" button is clicked",
@@ -5363,6 +5395,140 @@ module.exports = {specifications: [
5363
5395
  }
5364
5396
  ]
5365
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
+ },
5366
5532
  {
5367
5533
  "type": "file",
5368
5534
  "name": "TextInput.spec.ts",
@@ -5499,11 +5665,11 @@ module.exports = {specifications: [
5499
5665
  },
5500
5666
  {
5501
5667
  "type": "file",
5502
- "name": "TextInputLabs.spec.ts",
5668
+ "name": "TextInputPreview.spec.ts",
5503
5669
  "children": [
5504
5670
  {
5505
5671
  "type": "describe",
5506
- "name": "TextInput",
5672
+ "name": "Text Input",
5507
5673
  "children": [
5508
5674
  {
5509
5675
  "type": "describe",
@@ -5185,6 +5185,22 @@ module.exports = {specifications: [
5185
5185
  "type": "it",
5186
5186
  "name": "should not show the \"More\" button"
5187
5187
  },
5188
+ {
5189
+ "type": "describe",
5190
+ "name": "when the \"First Tab\" is focused",
5191
+ "children": [
5192
+ {
5193
+ "type": "describe",
5194
+ "name": "when the Tab key is pressed",
5195
+ "children": [
5196
+ {
5197
+ "type": "it",
5198
+ "name": "should focus on the tab panel"
5199
+ }
5200
+ ]
5201
+ }
5202
+ ]
5203
+ },
5188
5204
  {
5189
5205
  "type": "describe",
5190
5206
  "name": "when tab list container is only 500px wide",
@@ -5197,6 +5213,22 @@ module.exports = {specifications: [
5197
5213
  "type": "it",
5198
5214
  "name": "should show the \"More\" button"
5199
5215
  },
5216
+ {
5217
+ "type": "describe",
5218
+ "name": "when the \"First Tab\" is focused",
5219
+ "children": [
5220
+ {
5221
+ "type": "describe",
5222
+ "name": "when the Tab key is pressed",
5223
+ "children": [
5224
+ {
5225
+ "type": "it",
5226
+ "name": "should focus on the \"More\" button"
5227
+ }
5228
+ ]
5229
+ }
5230
+ ]
5231
+ },
5200
5232
  {
5201
5233
  "type": "describe",
5202
5234
  "name": "when the \"More\" button is clicked",
@@ -5363,6 +5395,140 @@ module.exports = {specifications: [
5363
5395
  }
5364
5396
  ]
5365
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
+ },
5366
5532
  {
5367
5533
  "type": "file",
5368
5534
  "name": "TextInput.spec.ts",
@@ -5499,11 +5665,11 @@ module.exports = {specifications: [
5499
5665
  },
5500
5666
  {
5501
5667
  "type": "file",
5502
- "name": "TextInputLabs.spec.ts",
5668
+ "name": "TextInputPreview.spec.ts",
5503
5669
  "children": [
5504
5670
  {
5505
5671
  "type": "describe",
5506
- "name": "TextInput",
5672
+ "name": "Text Input",
5507
5673
  "children": [
5508
5674
  {
5509
5675
  "type": "describe",
@@ -216,6 +216,9 @@ const CustomGlobalHeader = props => {
216
216
  };
217
217
  ```
218
218
 
219
+ You may continue to use this component exactly as you did in v5, but note that we plan to hard-deprecate it in Canvas Kit v7.
220
+ If you would like to migrate away from this deprecated component now, you can reference [this example](https://workday.github.io/canvas-kit/?path=/story/examples-global-header-react--basic) instead.
221
+
219
222
  ### Page Header
220
223
 
221
224
  We are [soft-deprecating](#soft-deprecation) `PageHeader`. It has been renamed to
@@ -267,6 +270,9 @@ export const CustomPageHeader = (props: CustomPageHeaderProps) => {
267
270
  };
268
271
  ```
269
272
 
273
+ You may continue to use this component exactly as you did in v5, but note that we plan to hard-deprecate it in Canvas Kit v7.
274
+ If you would like to migrate away from this deprecated component now, you can reference [this example](https://workday.github.io/canvas-kit/?path=/story/examples-page-header-react--basic) instead.
275
+
270
276
  ## Component Migrations
271
277
 
272
278
  ### Search Bar
@@ -0,0 +1,33 @@
1
+ # Canvas Kit 7.0 Migration Guide
2
+
3
+ Below are the breaking changes made in Canvas Kit v7. Please
4
+ [reach out](https://github.com/Workday/canvas-kit/issues/new?labels=bug&template=bug.md) if you have
5
+ any questions about the update.
6
+
7
+ - [Codemod](#codemod)
8
+
9
+ ## Codemod
10
+
11
+ Please use our [codemod package](https://github.com/Workday/canvas-kit/tree/master/modules/codemod)
12
+ to automatically update your code to work with a majority of the breaking changes in the migration
13
+ from Canvas Kit v6 to v7:
14
+
15
+ ```sh
16
+ > npx @workday/canvas-kit-codemod v7 [path]
17
+ ```
18
+
19
+ > Note: This codemod only works on `.js`, `.jsx`, `.ts`, and `.tsx` extensions. You may need to make
20
+ > some manual changes in other file types (`.json`, `.mdx`, `.md`, etc.).
21
+
22
+ > Note: You may need to run your linter after executing the codemod, as it's resulting formatting
23
+ > (spacing, quotes, etc.) may not match your project's styling.
24
+
25
+ **Breaking changes accounted for by this codemod will be marked with a 🤖.**
26
+
27
+ **Please verify all changes made by the codemod. As a safety precaution, we recommend committing the
28
+ changes from the codemod as a single isolated commit (separate from other changes) so you can
29
+ rollback more easily if necessary.**
30
+
31
+ [Let us know](https://github.com/Workday/canvas-kit/issues/new?labels=bug&template=bug.md) if you
32
+ encounter any issues or use cases that we've missed. The `@workday/canvas-kit-codemod` package will
33
+ help us maintain additional codemod transforms to make future migrations easier.
@@ -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
+ };