-
Notifications
You must be signed in to change notification settings - Fork 14
/
TextareaCodePage.tsx
351 lines (348 loc) · 11.7 KB
/
TextareaCodePage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
import { DxcFlex, DxcLink, DxcTable } from "@dxc-technology/halstack-react";
import QuickNavContainerLayout from "@/common/QuickNavContainerLayout";
import QuickNavContainer from "@/common/QuickNavContainer";
import Code from "@/common/Code";
import DocFooter from "@/common/DocFooter";
import Example from "@/common/example/Example";
import controlled from "./examples/controlled";
import uncontrolled from "./examples/uncontrolled";
import errorHandling from "./examples/errorHandling";
import StatusBadge from "@/common/StatusBadge";
import TableCode from "@/common/TableCode";
const sections = [
{
title: "Props",
content: (
<DxcTable>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
</thead>
<tbody>
<tr>
<td>defaultValue</td>
<td>
<TableCode>string</TableCode>
</td>
<td>
Initial value of the textarea, only when it is uncontrolled.
</td>
<td>-</td>
</tr>
<tr>
<td>value</td>
<td>
<TableCode>string</TableCode>
</td>
<td>
Value of the textarea. If undefined, the component will be
uncontrolled and the value will be managed internally.
</td>
<td>-</td>
</tr>
<tr>
<td>label</td>
<td>
<TableCode>string</TableCode>
</td>
<td>Text to be placed above the textarea.</td>
<td>-</td>
</tr>
<tr>
<td>name</td>
<td>
<TableCode>string</TableCode>
</td>
<td>Name attribute of the textarea element.</td>
<td>-</td>
</tr>
<tr>
<td>helperText</td>
<td>
<TableCode>string</TableCode>
</td>
<td>Helper text to be placed above the textarea.</td>
<td>-</td>
</tr>
<tr>
<td>placeholder</td>
<td>
<TableCode>string</TableCode>
</td>
<td>Text to be put as placeholder of the textarea.</td>
<td>-</td>
</tr>
<tr>
<td>disabled</td>
<td>
<TableCode>boolean</TableCode>
</td>
<td>If true, the component will be disabled.</td>
<td>
<TableCode>false</TableCode>
</td>
</tr>
<tr>
<td>optional</td>
<td>
<TableCode>boolean</TableCode>
</td>
<td>
If true, the textarea will be optional, showing '(Optional)' next
to the label. Otherwise, the field will be considered required and
an error will be passed as a parameter to the <Code>onBlur</Code>{" "}
and <Code>onChange</Code> functions when it has not been filled.
</td>
<td>
<TableCode>false</TableCode>
</td>
</tr>
<tr>
<td>readOnly</td>
<td>
<TableCode>boolean</TableCode>
</td>
<td>
If true, the component will not be mutable, meaning the user can
not edit the control.
</td>
<td>
<TableCode>false</TableCode>
</td>
</tr>
<tr>
<td>verticalGrow</td>
<td>
<TableCode>'auto' | 'manual' | 'none'</TableCode>
</td>
<td>
Defines the textarea's ability to resize vertically. It can be:
<ul>
<li>
<b>'auto'</b>: The textarea grows or shrinks automatically in
order to fit the content.
</li>
<li>
<b>'manual'</b>: The height of the textarea is enabled to be
manually modified.
</li>
<li>
<b>'none'</b>: The textarea has a fixed height and can't be
modified.
</li>
</ul>
</td>
<td>
<TableCode>'auto'</TableCode>
</td>
</tr>
<tr>
<td>rows</td>
<td>
<TableCode>number</TableCode>
</td>
<td>Number of rows of the textarea.</td>
<td>
<TableCode>4</TableCode>
</td>
</tr>
<tr>
<td>onChange</td>
<td>
<TableCode>
{"(val: { value: string; error?: string }) => void"}
</TableCode>
</td>
<td>
This function will be called when the user types within the
textarea. An object including the current value and the error (if
the value entered is not valid) will be passed to this function.
If there is no error, <Code>error</Code> will not be defined.
</td>
<td>-</td>
</tr>
<tr>
<td>onBlur</td>
<td>
<TableCode>
{"(val: { value: string; error?: string }) => void"}
</TableCode>
</td>
<td>
This function will be called when the textarea loses the focus. An
object including the textarea value and the error (if the value
entered is not valid) will be passed to this function. If there is
no error, <Code>error</Code> will not be defined.
</td>
<td>-</td>
</tr>
<tr>
<td>error</td>
<td>
<TableCode>string</TableCode>
</td>
<td>
If it is a defined value and also a truthy string, the component
will change its appearance, showing the error below the textarea.
If the defined value is an empty string, it will reserve a space
below the component for a future error, but it would not change
its look. In case of being undefined or null, both the appearance
and the space for the error message would not be modified.
</td>
<td>-</td>
</tr>
<tr>
<td>pattern</td>
<td>
<TableCode>string</TableCode>
</td>
<td>
Regular expression that defines the valid format allowed by the
textarea. This will be checked both when the textarea loses the
focus and while typing within it. If the string entered does not
match the pattern, the <Code>onBlur</Code> and{" "}
<Code>onChange</Code> functions will be called with the current
value and an internal error informing that this value does not
match the pattern. If the pattern is met, the error parameter of
both events will not be defined.
</td>
<td>-</td>
</tr>
<tr>
<td>minLength</td>
<td>
<TableCode>number</TableCode>
</td>
<td>
Specifies the minimum length allowed by the textarea. This will be
checked both when the input element loses the focus and while
typing within it. If the string entered does not comply the
minimum length, the <Code>onBlur</Code> and <Code>onChange</Code>{" "}
functions will be called with the current value and an internal
error informing that the value length does not comply the
specified range. If a valid length is reached, the error parameter
of both events will not be defined.
</td>
<td>-</td>
</tr>
<tr>
<td>maxLength</td>
<td>
<TableCode>number</TableCode>
</td>
<td>
Specifies the maximum length allowed by the textarea. This will be
checked both when the input element loses the focus and while
typing within it. If the string entered does not comply the
maximum length, the <Code>onBlur</Code> and <Code>onChange</Code>{" "}
functions will be called with the current value and an internal
error informing that the value length does not comply the
specified range. If a valid length is reached, the error parameter
of both events will not be defined.
</td>
<td>-</td>
</tr>
<tr>
<td>autocomplete</td>
<td>
<TableCode>string</TableCode>
</td>
<td>
HTML <Code>autocomplete</Code> attribute. Lets the user specify if
any permission the user agent has to provide automated assistance
in filling out the input value. Its value must be one of all the
possible values of the HTML autocomplete attribute. See{" "}
<DxcLink href="https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/autocomplete">
MDN
</DxcLink>{" "}
for further information.
</td>
<td>
<TableCode>'off'</TableCode>
</td>
</tr>
<tr>
<td>margin</td>
<td>
<TableCode>
'xxsmall' | 'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' |
'xxlarge' | Margin
</TableCode>
</td>
<td>
Size of the margin to be applied to the component. You can pass an
object with 'top', 'bottom', 'left' and 'right' properties in
order to specify different margin sizes.
</td>
<td>-</td>
</tr>
<tr>
<td>size</td>
<td>
<TableCode>'small' | 'medium' | 'large' | 'fillParent'</TableCode>
</td>
<td>Size of the component.</td>
<td>
<TableCode>'medium'</TableCode>
</td>
</tr>
<tr>
<td>tabIndex</td>
<td>
<TableCode>number</TableCode>
</td>
<td>
Value of the <Code>tabindex</Code> attribute.
</td>
<td>
<TableCode>0</TableCode>
</td>
</tr>
<tr>
<td>ref</td>
<td>
<TableCode>{"React.Ref <HTMLDivElement>"}</TableCode>
</td>
<td>Reference to the component.</td>
<td>-</td>
</tr>
</tbody>
</DxcTable>
),
},
{
title: "Examples",
subSections: [
{
title: "Controlled",
content: <Example example={controlled} defaultIsVisible />,
},
{
title: "Uncontrolled",
content: <Example example={uncontrolled} defaultIsVisible />,
},
{
title: "Error handling",
content: <Example example={errorHandling} defaultIsVisible />,
},
],
},
];
const TextareaCodePage = () => {
return (
<DxcFlex direction="column" gap="4rem">
<QuickNavContainerLayout>
<QuickNavContainer
sections={sections}
startHeadingLevel={2}
></QuickNavContainer>
</QuickNavContainerLayout>
<DocFooter githubLink="https://github.com/dxc-technology/halstack-react/blob/master/website/screens/components/textarea/code/TextareaCodePage.tsx" />
</DxcFlex>
);
};
export default TextareaCodePage;