-
Notifications
You must be signed in to change notification settings - Fork 14
/
DateInputCodePage.tsx
329 lines (325 loc) · 10.4 KB
/
DateInputCodePage.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
import {
DxcFlex,
DxcTable,
DxcParagraph,
DxcLink,
} from "@dxc-technology/halstack-react";
import QuickNavContainer from "@/common/QuickNavContainer";
import QuickNavContainerLayout from "@/common/QuickNavContainerLayout";
import DocFooter from "@/common/DocFooter";
import Code from "@/common/Code";
import Example from "@/common/example/Example";
import basicUsage from "./examples/basicUsage";
import errorHandling from "./examples/errorHandling";
import controlled from "./examples/controlled";
import uncontrolled from "./examples/uncontrolled";
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 input element, only when it is uncontrolled.
</td>
<td>-</td>
</tr>
<tr>
<td>value</td>
<td>
<TableCode>string</TableCode>
</td>
<td>
Value of the input element. If undefined, the component will be
uncontrolled and the value will be managed internally by the
component.
</td>
<td>-</td>
</tr>
<tr>
<td>label</td>
<td>
<TableCode>string</TableCode>
</td>
<td>Text to be placed above the date input.</td>
<td>-</td>
</tr>
<tr>
<td>name</td>
<td>
<TableCode>string</TableCode>
</td>
<td>Name attribute of the input element.</td>
<td>-</td>
</tr>
<tr>
<td>helperText</td>
<td>
<TableCode>string</TableCode>
</td>
<td>Helper text to be placed above the date.</td>
<td>-</td>
</tr>
<tr>
<td>placeholder</td>
<td>
<TableCode>boolean</TableCode>
</td>
<td>
If true, the date format will appear as placeholder in the field.
</td>
<td>
<TableCode>false</TableCode>
</td>
</tr>
<tr>
<td>format</td>
<td>
<TableCode>string</TableCode>
</td>
<td>
The format in which the date value will be displayed. User must
follow this format when editing the value or it will be considered
as an invalid date. In this case, the <Code>onBlur</Code> and{" "}
<Code>onChange</Code> functions will be called with an internal
error as a parameter reporting the situation.
</td>
<td>
<TableCode>'dd-MM-yyyy'</TableCode>
</td>
</tr>
<tr>
<td>clearable</td>
<td>
<TableCode>boolean</TableCode>
</td>
<td>
If true, the date input will have an action to clear the entered
value.
</td>
<td>
<TableCode>false</TableCode>
</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 date will be optional, showing the text '(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. The date picker cannot be opened either. In
addition, the clear action will not be displayed even if the flag
is set to true.
</td>
<td>
<TableCode>false</TableCode>
</td>
</tr>
<tr>
<td>onChange</td>
<td>
<TableCode>
{
"(val: { value: string; error?: string; date?: Date }) => void"
}
</TableCode>
</td>
<td>
This function will be called when the user types within the input
element of the component. An object including the string value,
the error and the date value will be passed to this function. If
the string value is a valid date, <Code>error</Code> will be
undefined. Also, if the string value is not a valid date,{" "}
<Code>date</Code> will be undefined.
</td>
<td>-</td>
</tr>
<tr>
<td>onBlur</td>
<td>
<TableCode>
{
"(val: { value: string; error?: string; date?: Date }) => void"
}
</TableCode>
</td>
<td>
This function will be called when the input element loses the
focus. An object including the string value, the error and the
date value will be passed to this function. If the string value is
a valid date, <Code>error</Code> will be undefined. Also, if the
string value is not a valid date, <Code>date</Code> will be
undefined.
</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 date input
component. 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>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>'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: "Basic usage",
content: <Example example={basicUsage} defaultIsVisible />,
},
{
title: "Controlled",
content: <Example example={controlled} defaultIsVisible />,
},
{
title: "Uncontrolled",
content: <Example example={uncontrolled} defaultIsVisible />,
},
{
title: "Error handling",
content: (
<>
<DxcParagraph>
The component behaviour varies depending on the value of the{" "}
<Code>error</Code>. We recommend reading the description of the
prop carefully to fully understand the following example.
</DxcParagraph>
<Example example={errorHandling} defaultIsVisible />
</>
),
},
],
},
];
const DateInputCodePage = () => {
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/date-input/code/DateInputCodePage.tsx" />
</DxcFlex>
);
};
export default DateInputCodePage;