|
| 1 | +import type { StoryObj, Meta } from '@storybook/react'; |
| 2 | +import React from 'react'; |
| 3 | + |
| 4 | +import { TextareaField } from './TextareaField-v2'; |
| 5 | + |
| 6 | +const meta: Meta<typeof TextareaField> = { |
| 7 | + title: 'Components/V2/TextareaField', |
| 8 | + component: TextareaField, |
| 9 | + args: { |
| 10 | + placeholder: 'Enter long-form text here', |
| 11 | + defaultValue: `Lorem ipsum, dolor sit amet consectetur adipisicing elit. Id neque nemo |
| 12 | +dicta rerum commodi et fugiat quo optio veniam! Ea odio corporis nemo |
| 13 | +praesentium, commodi eligendi asperiores quis dolorum porro.`, |
| 14 | + label: 'Textarea Field', |
| 15 | + rows: 5, |
| 16 | + fieldNote: 'Longer Field description', |
| 17 | + spellCheck: false, |
| 18 | + }, |
| 19 | + parameters: { |
| 20 | + badges: ['intro-1.3', 'current-2.0'], |
| 21 | + }, |
| 22 | + decorators: [(Story) => <div className="p-8">{Story()}</div>], |
| 23 | +}; |
| 24 | + |
| 25 | +export default meta; |
| 26 | +type Story = StoryObj<typeof TextareaField>; |
| 27 | + |
| 28 | +export const Default: Story = { |
| 29 | + render: (args) => ( |
| 30 | + <TextareaField aria-label="Text Label" {...args}></TextareaField> |
| 31 | + ), |
| 32 | +}; |
| 33 | + |
| 34 | +/** |
| 35 | + * You can specify the content of `TextareaField` by using children. Convenient for cases where |
| 36 | + * specifying `value` or `defaultValue` is inconvenient. |
| 37 | + */ |
| 38 | +export const WhenUsingChildren: Story = { |
| 39 | + args: { |
| 40 | + children: `Lorem ipsum, dolor sit amet consectetur adipisicing elit. Id neque nemo |
| 41 | + dicta rerum commodi et fugiat quo optio veniam! Ea odio corporis nemo |
| 42 | + praesentium, commodi eligendi asperiores quis dolorum porro.`, |
| 43 | + defaultValue: '', |
| 44 | + }, |
| 45 | +}; |
| 46 | + |
| 47 | +/** |
| 48 | + * `TextareaField` does not require any initial content. |
| 49 | + */ |
| 50 | +export const WhenNoDefaultValue: Story = { |
| 51 | + args: { |
| 52 | + defaultValue: undefined, |
| 53 | + fieldNote: undefined, |
| 54 | + }, |
| 55 | +}; |
| 56 | + |
| 57 | +export const WhenDisabled: Story = { |
| 58 | + args: { |
| 59 | + disabled: true, |
| 60 | + rows: 2, |
| 61 | + }, |
| 62 | + parameters: { |
| 63 | + axe: { |
| 64 | + // Disabled input does not need to meet color contrast |
| 65 | + disabledRules: ['color-contrast'], |
| 66 | + }, |
| 67 | + }, |
| 68 | +}; |
| 69 | + |
| 70 | +export const WhenReadOnly: Story = { |
| 71 | + args: { |
| 72 | + readOnly: true, |
| 73 | + rows: 2, |
| 74 | + }, |
| 75 | + parameters: { |
| 76 | + axe: { |
| 77 | + // Disabled input does not need to meet color contrast |
| 78 | + disabledRules: ['color-contrast'], |
| 79 | + }, |
| 80 | + }, |
| 81 | +}; |
| 82 | + |
| 83 | +export const WhenError: Story = { |
| 84 | + args: { |
| 85 | + isError: true, |
| 86 | + fieldNote: 'Text should be at least 100 characters', |
| 87 | + }, |
| 88 | +}; |
| 89 | + |
| 90 | +export const WhenWarning: Story = { |
| 91 | + args: { |
| 92 | + isWarning: true, |
| 93 | + fieldNote: 'Text should be at least 100 characters', |
| 94 | + }, |
| 95 | +}; |
| 96 | + |
| 97 | +export const WhenRequired: Story = { |
| 98 | + args: { |
| 99 | + required: true, |
| 100 | + showHint: true, |
| 101 | + }, |
| 102 | +}; |
| 103 | + |
| 104 | +export const WhenOptional: Story = { |
| 105 | + args: { |
| 106 | + required: false, |
| 107 | + showHint: true, |
| 108 | + }, |
| 109 | +}; |
| 110 | + |
| 111 | +/** |
| 112 | + * You can size `TextareaField` by specifying `row` attribute, inherited from |
| 113 | + * [textarea](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea). |
| 114 | + */ |
| 115 | +export const WithADifferentSize: Story = { |
| 116 | + args: { |
| 117 | + rows: 10, |
| 118 | + }, |
| 119 | +}; |
| 120 | + |
| 121 | +/** |
| 122 | + * You can lock the maximum length of the text content of `TextareaField`. When setting `maxLength`, |
| 123 | + * the field will reuse the browser's [textarea](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea) |
| 124 | + * behavior (e.g., prevent further text from being typed, prevent keydown events, etc.). |
| 125 | + */ |
| 126 | +export const WithAMaxLength: Story = { |
| 127 | + args: { |
| 128 | + rows: 10, |
| 129 | + maxLength: 144, |
| 130 | + required: true, |
| 131 | + }, |
| 132 | + render: (args) => <TextareaField {...args} />, |
| 133 | +}; |
| 134 | + |
| 135 | +/** |
| 136 | + * If you want to signal that a field has reached a maximum length but want to allow more text to be typed, you can use |
| 137 | + * `recommendedMaxLength`. This will show a similar UI to using `maxLength` but will allow more text to be typed, and |
| 138 | + * emit any appropriate events. |
| 139 | + */ |
| 140 | +export const WithARecommendedLength: Story = { |
| 141 | + args: { |
| 142 | + rows: 10, |
| 143 | + recommendedMaxLength: 144, |
| 144 | + required: true, |
| 145 | + }, |
| 146 | + render: (args) => <TextareaField {...args} />, |
| 147 | +}; |
| 148 | + |
| 149 | +/** |
| 150 | + * Both `maxLength` and `recommendedMaxLength` can be specified at the same time. Text length between `recommendedMaxLength` |
| 151 | + * and `maxLength` will show the treatment warning the user about the text length being violated. |
| 152 | + */ |
| 153 | +export const WithBothRecommendedAndMaxLengths: Story = { |
| 154 | + args: { |
| 155 | + rows: 10, |
| 156 | + maxLength: 256, |
| 157 | + recommendedMaxLength: 144, |
| 158 | + required: true, |
| 159 | + }, |
| 160 | + render: (args) => <TextareaField {...args} />, |
| 161 | +}; |
0 commit comments