-
Notifications
You must be signed in to change notification settings - Fork 14
/
NumberInputCodePage.tsx
256 lines (253 loc) · 8.84 KB
/
NumberInputCodePage.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
import { DxcFlex, 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 errorUsage from "./examples/errorHandling";
import HeaderDescriptionCell from "@/common/HeaderDescriptionCell";
import StatusTag from "@/common/StatusTag";
const sections = [
{
title: "Props",
content: (
<DxcTable>
<thead>
<tr>
<th>Name</th>
<th>Default</th>
<HeaderDescriptionCell>Description</HeaderDescriptionCell>
</tr>
</thead>
<tbody>
<tr>
<td>defaultValue: string</td>
<td></td>
<td>
Initial value of the input element, only when it is uncontrolled.
</td>
</tr>
<tr>
<td>value: string</td>
<td></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>
</tr>
<tr>
<td>label: string</td>
<td></td>
<td>Text to be placed above the number.</td>
</tr>
<tr>
<td>name: string</td>
<td></td>
<td>Name attribute of the input element.</td>
</tr>
<tr>
<td>helperText: string</td>
<td></td>
<td>Helper text to be placed above the number.</td>
</tr>
<tr>
<td>placeholder: string</td>
<td></td>
<td>Text to be put as placeholder of the number.</td>
</tr>
<tr>
<td>disabled: boolean</td>
<td>
<Code>false</Code>
</td>
<td>If true, the component will be disabled.</td>
</tr>
<tr>
<td>optional: boolean</td>
<td>
<Code>false</Code>
</td>
<td>
If true, the number will be optional, showing{" "}
<Code>(Optional)</Code> next to the label. Otherwise, the field
will be considered required and an error will be passed as a
parameter to the OnBlur and onChange functions when it has not
been filled.
</td>
</tr>
<tr>
<td>
<DxcFlex direction="column" gap="0.25rem" alignItems="baseline">
<StatusTag status="Information">New</StatusTag>readOnly: boolean
</DxcFlex>
</td>
<td>
<Code>false</Code>
</td>
<td>
If true, the component will not be mutable, meaning the user can
not edit the control. The value won't change when pressing on the
up or down arrows and neither on the spin buttons.
</td>
</tr>
<tr>
<td>prefix: string</td>
<td></td>
<td>Prefix to be placed before the number value.</td>
</tr>
<tr>
<td>suffix: string</td>
<td></td>
<td>Suffix to be placed after the number value.</td>
</tr>
<tr>
<td>min: number</td>
<td></td>
<td>
Minimum value allowed by the number input. If the typed value by
the user is lower than min, the onBlur and onChange functions will
be called with the current value and an internal error informing
that the current value is not correct. If a valid state is
reached, the error parameter will not be defined in both events.
</td>
</tr>
<tr>
<td>max: number</td>
<td></td>
<td>
Maximum value allowed by the number input. If the typed value by
the user surpasses max, the onBlur and onChange functions will be
called with the current value and an internal error informing that
the current value is not correct. If a valid state is reached, the
error parameter will not be defined in both events.
</td>
</tr>
<tr>
<td>step: number</td>
<td></td>
<td>
The step interval to use when using the up and down arrows to
adjust the value.
</td>
</tr>
<tr>
<td>onChange: function</td>
<td></td>
<td>
This function will be called when the user types within the input
element of the component. An object including the current value
and the error (if the value entered is not valid) will be passed
to this function. An example of this object is: {"{ "}
<Code>value: value, error: error</Code>
{" }"}. If there is no error, error will not be defined.
</td>
</tr>
<tr>
<td>onBlur: function</td>
<td></td>
<td>
This function will be called when the input element loses the
focus. An object including the input value and the error (if the
value entered is not valid) will be passed to this function. An
example of this object is: {"{ "}
<Code>value: value, error: error</Code>
{" }"}. If there is no error, error will not be defined.
</td>
</tr>
<tr>
<td>error: string</td>
<td></td>
<td>
If it is a defined value and also a truthy string, the component
will change its appearance, showing the error below the 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>
</tr>
<tr>
<td>autocomplete: string</td>
<td>
<Code>'off'</Code>
</td>
<td>
HTML autocomplete 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: 'on', 'off',
'email', 'username', 'new-password', ...
</td>
</tr>
<tr>
<td>margin: string | object</td>
<td></td>
<td>
Size of the margin to be applied to the component ('xxsmall' |
'xsmall' | 'small' | 'medium' | 'large' | 'xlarge' | 'xxlarge').
You can pass an object with 'top', 'bottom', 'left' and 'right'
properties in order to specify different margin sizes.
</td>
</tr>
<tr>
<td>size: string | object</td>
<td>
<Code>'medium'</Code>
</td>
<td>
Size of the component ('small' | 'medium' | 'large' |
'fillParent').
</td>
</tr>
<tr>
<td>tabIndex: number</td>
<td>
<Code>0</Code>
</td>
<td>Value of the tabindex attribute.</td>
</tr>
<tr>
<td>ref: object</td>
<td></td>
<td>Reference to the component.</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={errorUsage} defaultIsVisible />,
},
],
},
];
const NumberInputCodePage = () => {
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/number-input/code/NumberInputCodePage.tsx" />
</DxcFlex>
);
};
export default NumberInputCodePage;