@patternfly/react-core 4.242.8 → 4.243.1
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.
- package/CHANGELOG.md +19 -0
- package/dist/esm/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/esm/components/DatePicker/DatePicker.js +4 -2
- package/dist/esm/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/esm/components/TextArea/TextArea.d.ts +17 -11
- package/dist/esm/components/TextArea/TextArea.d.ts.map +1 -1
- package/dist/esm/components/TextArea/TextArea.js +8 -3
- package/dist/esm/components/TextArea/TextArea.js.map +1 -1
- package/dist/esm/components/TextInput/TextInput.d.ts +21 -16
- package/dist/esm/components/TextInput/TextInput.d.ts.map +1 -1
- package/dist/esm/components/TextInput/TextInput.js +7 -4
- package/dist/esm/components/TextInput/TextInput.js.map +1 -1
- package/dist/js/components/DatePicker/DatePicker.d.ts.map +1 -1
- package/dist/js/components/DatePicker/DatePicker.js +4 -2
- package/dist/js/components/DatePicker/DatePicker.js.map +1 -1
- package/dist/js/components/TextArea/TextArea.d.ts +17 -11
- package/dist/js/components/TextArea/TextArea.d.ts.map +1 -1
- package/dist/js/components/TextArea/TextArea.js +9 -4
- package/dist/js/components/TextArea/TextArea.js.map +1 -1
- package/dist/js/components/TextInput/TextInput.d.ts +21 -16
- package/dist/js/components/TextInput/TextInput.d.ts.map +1 -1
- package/dist/js/components/TextInput/TextInput.js +8 -5
- package/dist/js/components/TextInput/TextInput.js.map +1 -1
- package/dist/umd/react-core.min.css +1090 -1068
- package/dist/umd/react-core.min.js +3 -3
- package/package.json +6 -6
- package/src/components/DatePicker/DatePicker.tsx +4 -2
- package/src/components/DatePicker/__tests__/DatePicker.test.tsx +22 -1
- package/src/components/NumberInput/examples/NumberInput.md +9 -448
- package/src/components/NumberInput/examples/NumberInputCustomStep.tsx +29 -0
- package/src/components/NumberInput/examples/NumberInputCustomStepAndThreshold.tsx +52 -0
- package/src/components/NumberInput/examples/NumberInputDefault.tsx +34 -0
- package/src/components/NumberInput/examples/NumberInputDisabled.tsx +40 -0
- package/src/components/NumberInput/examples/NumberInputUnit.tsx +57 -0
- package/src/components/NumberInput/examples/NumberInputUnitThreshold.tsx +55 -0
- package/src/components/NumberInput/examples/NumberInputVaryingSizes.tsx +80 -0
- package/src/components/NumberInput/examples/{WithStatus.tsx → NumberInputWithStatus.tsx} +4 -3
- package/src/components/TextArea/TextArea.tsx +21 -13
- package/src/components/TextArea/__tests__/TextArea.test.tsx +20 -6
- package/src/components/TextArea/__tests__/__snapshots__/TextArea.test.tsx.snap +31 -5
- package/src/components/TextArea/examples/TextArea.md +30 -0
- package/src/components/TextInput/TextInput.tsx +26 -18
- package/src/components/TextInput/__tests__/TextInput.test.tsx +16 -2
- package/src/components/TextInput/__tests__/__snapshots__/TextInput.test.tsx.snap +36 -4
- package/src/components/TextInput/examples/TextInput.md +23 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.243.1",
|
|
4
4
|
"description": "This library provides a set of common React components for use with the PatternFly reference implementation.",
|
|
5
5
|
"main": "dist/js/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"generate": "node scripts/copyStyles.js"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@patternfly/react-icons": "^4.92.
|
|
48
|
-
"@patternfly/react-styles": "^4.91.
|
|
49
|
-
"@patternfly/react-tokens": "^4.93.
|
|
47
|
+
"@patternfly/react-icons": "^4.92.5",
|
|
48
|
+
"@patternfly/react-styles": "^4.91.5",
|
|
49
|
+
"@patternfly/react-tokens": "^4.93.5",
|
|
50
50
|
"focus-trap": "6.9.2",
|
|
51
51
|
"react-dropzone": "9.0.0",
|
|
52
52
|
"tippy.js": "5.1.2",
|
|
53
53
|
"tslib": "^2.0.0"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
|
-
"@patternfly/patternfly": "4.
|
|
56
|
+
"@patternfly/patternfly": "4.217.0",
|
|
57
57
|
"@rollup/plugin-commonjs": "^21.0.0",
|
|
58
58
|
"@rollup/plugin-node-resolve": "^13.0.0",
|
|
59
59
|
"@rollup/plugin-replace": "^3.0.0",
|
|
@@ -70,5 +70,5 @@
|
|
|
70
70
|
"react": "^16.8 || ^17 || ^18",
|
|
71
71
|
"react-dom": "^16.8 || ^17 || ^18"
|
|
72
72
|
},
|
|
73
|
-
"gitHead": "
|
|
73
|
+
"gitHead": "eb89462c9bbd1414e2da9f3b77601f965ba03bf2"
|
|
74
74
|
}
|
|
@@ -120,7 +120,9 @@ const DatePickerBase = (
|
|
|
120
120
|
setPristine(!value);
|
|
121
121
|
}, [value]);
|
|
122
122
|
|
|
123
|
-
const setError = (date: Date) =>
|
|
123
|
+
const setError = (date: Date) => {
|
|
124
|
+
setErrorText(validators.map(validator => validator(date)).join('\n') || '');
|
|
125
|
+
};
|
|
124
126
|
|
|
125
127
|
const onTextInput = (value: string) => {
|
|
126
128
|
setValue(value);
|
|
@@ -236,7 +238,7 @@ const DatePickerBase = (
|
|
|
236
238
|
isDisabled={isDisabled}
|
|
237
239
|
aria-label={ariaLabel}
|
|
238
240
|
placeholder={placeholder}
|
|
239
|
-
validated={errorText ? 'error' : 'default'}
|
|
241
|
+
validated={errorText.trim() ? 'error' : 'default'}
|
|
240
242
|
value={value}
|
|
241
243
|
onChange={onTextInput}
|
|
242
244
|
onBlur={onInputBlur}
|
|
@@ -1,8 +1,29 @@
|
|
|
1
|
-
import { render } from '@testing-library/react';
|
|
1
|
+
import { screen, render } from '@testing-library/react';
|
|
2
2
|
import { DatePicker } from '../DatePicker';
|
|
3
3
|
import React from 'react';
|
|
4
|
+
import userEvent from '@testing-library/user-event';
|
|
4
5
|
|
|
5
6
|
test('disabled date picker', () => {
|
|
6
7
|
const { asFragment } = render(<DatePicker value="2020-11-20" isDisabled aria-label="disabled date picker" />);
|
|
7
8
|
expect(asFragment()).toMatchSnapshot();
|
|
8
9
|
});
|
|
10
|
+
|
|
11
|
+
test('Date picker with multiple validators does not show invalid icon on valid input', async () => {
|
|
12
|
+
const user = userEvent.setup();
|
|
13
|
+
|
|
14
|
+
const rangeValidator = (date: Date) => {
|
|
15
|
+
return '';
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const rangeValidatorB = (date: Date) => {
|
|
19
|
+
return '';
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
render(<DatePicker value="2020-03-17" validators={[rangeValidator, rangeValidatorB]} />);
|
|
23
|
+
|
|
24
|
+
await user.click(screen.getByRole('textbox'));
|
|
25
|
+
|
|
26
|
+
await user.click(document.body);
|
|
27
|
+
|
|
28
|
+
expect(screen.getByRole('textbox')).not.toBeInvalid();
|
|
29
|
+
});
|
|
@@ -9,479 +9,40 @@ propComponents: ['NumberInput']
|
|
|
9
9
|
|
|
10
10
|
### Default
|
|
11
11
|
|
|
12
|
-
```
|
|
13
|
-
import React from 'react';
|
|
14
|
-
import { NumberInput } from '@patternfly/react-core';
|
|
15
|
-
|
|
16
|
-
class BasicNumberInput extends React.Component {
|
|
17
|
-
constructor(props) {
|
|
18
|
-
super(props);
|
|
19
|
-
this.state = {
|
|
20
|
-
value: 90
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
this.onMinus = () => {
|
|
24
|
-
this.setState({
|
|
25
|
-
value: this.state.value - 1
|
|
26
|
-
});
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
this.onChange = event => {
|
|
30
|
-
this.setState({
|
|
31
|
-
value: Number(event.target.value)
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
this.onPlus = () => {
|
|
36
|
-
this.setState({
|
|
37
|
-
value: this.state.value + 1
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
render() {
|
|
43
|
-
const { value } = this.state;
|
|
44
|
-
return (
|
|
45
|
-
<NumberInput
|
|
46
|
-
value={value}
|
|
47
|
-
onMinus={this.onMinus}
|
|
48
|
-
onChange={this.onChange}
|
|
49
|
-
onPlus={this.onPlus}
|
|
50
|
-
inputName="input"
|
|
51
|
-
inputAriaLabel="number input"
|
|
52
|
-
minusBtnAriaLabel="minus"
|
|
53
|
-
plusBtnAriaLabel="plus"
|
|
54
|
-
/>
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
12
|
+
```ts file="./NumberInputDefault.tsx"
|
|
58
13
|
```
|
|
59
14
|
|
|
60
15
|
### With unit
|
|
61
16
|
|
|
62
|
-
```
|
|
63
|
-
import React from 'react';
|
|
64
|
-
import { NumberInput } from '@patternfly/react-core';
|
|
65
|
-
|
|
66
|
-
class UnitNumberInput extends React.Component {
|
|
67
|
-
constructor(props) {
|
|
68
|
-
super(props);
|
|
69
|
-
this.state = {
|
|
70
|
-
value1: 90,
|
|
71
|
-
value2: (1.0).toFixed(2)
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
this.onMinus1 = () => {
|
|
75
|
-
this.setState({
|
|
76
|
-
value1: this.state.value1 - 1
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
this.onChange1 = event => {
|
|
81
|
-
this.setState({
|
|
82
|
-
value1: Number(event.target.value)
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
this.onPlus1 = () => {
|
|
87
|
-
this.setState({
|
|
88
|
-
value1: this.state.value1 + 1
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
this.onMinus2 = () => {
|
|
93
|
-
this.setState({
|
|
94
|
-
value2: (Number(this.state.value2) - 0.01).toFixed(2)
|
|
95
|
-
});
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
this.onChange2 = event => {
|
|
99
|
-
this.setState({
|
|
100
|
-
value2: event.target.value
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
this.onPlus2 = () => {
|
|
105
|
-
this.setState({
|
|
106
|
-
value2: (Number(this.state.value2) + 0.01).toFixed(2)
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
render() {
|
|
112
|
-
const { value1, value2 } = this.state;
|
|
113
|
-
return (
|
|
114
|
-
<React.Fragment>
|
|
115
|
-
<NumberInput
|
|
116
|
-
value={value1}
|
|
117
|
-
onMinus={this.onMinus1}
|
|
118
|
-
onChange={this.onChange1}
|
|
119
|
-
onPlus={this.onPlus1}
|
|
120
|
-
inputName="input 1"
|
|
121
|
-
inputAriaLabel="number input 1"
|
|
122
|
-
minusBtnAriaLabel="minus 1"
|
|
123
|
-
plusBtnAriaLabel="plus 1"
|
|
124
|
-
unit="%"
|
|
125
|
-
/>
|
|
126
|
-
<br />
|
|
127
|
-
<br />
|
|
128
|
-
<NumberInput
|
|
129
|
-
value={value2}
|
|
130
|
-
onMinus={this.onMinus2}
|
|
131
|
-
onChange={this.onChange2}
|
|
132
|
-
onPlus={this.onPlus2}
|
|
133
|
-
inputName="input 2"
|
|
134
|
-
inputAriaLabel="number input 2"
|
|
135
|
-
minusBtnAriaLabel="minus 0.01"
|
|
136
|
-
plusBtnAriaLabel="plus 0.01"
|
|
137
|
-
unit="$"
|
|
138
|
-
unitPosition="before"
|
|
139
|
-
/>
|
|
140
|
-
</React.Fragment>
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
17
|
+
```ts file="./NumberInputUnit.tsx"
|
|
144
18
|
```
|
|
145
19
|
|
|
146
20
|
### With unit and thresholds
|
|
147
21
|
|
|
148
|
-
```
|
|
149
|
-
import React from 'react';
|
|
150
|
-
import { NumberInput } from '@patternfly/react-core';
|
|
151
|
-
|
|
152
|
-
class UnitThresholdNumberInput extends React.Component {
|
|
153
|
-
constructor(props) {
|
|
154
|
-
super(props);
|
|
155
|
-
this.state = {
|
|
156
|
-
value: 0
|
|
157
|
-
};
|
|
158
|
-
this.minValue = 0;
|
|
159
|
-
this.maxValue = 10;
|
|
160
|
-
|
|
161
|
-
this.normalizeBetween = (value, min, max) => {
|
|
162
|
-
if (min !== undefined && max !== undefined) {
|
|
163
|
-
return Math.max(Math.min(value, max), min);
|
|
164
|
-
} else if (value <= min) {
|
|
165
|
-
return min;
|
|
166
|
-
} else if (value >= max) {
|
|
167
|
-
return max;
|
|
168
|
-
}
|
|
169
|
-
return value;
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
this.onMinus = () => {
|
|
173
|
-
this.setState({
|
|
174
|
-
value: this.normalizeBetween(this.state.value - 1, this.minValue, this.maxValue)
|
|
175
|
-
});
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
this.onChange = event => {
|
|
179
|
-
const newValue = isNaN(event.target.value) ? 0 : Number(event.target.value);
|
|
180
|
-
this.setState({
|
|
181
|
-
value: newValue > this.maxValue ? this.maxValue : newValue < this.minValue ? this.minValue : newValue
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
this.onPlus = () => {
|
|
186
|
-
this.setState({
|
|
187
|
-
value: this.normalizeBetween(this.state.value + 1, this.minValue, this.maxValue)
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
render() {
|
|
193
|
-
const { value } = this.state;
|
|
194
|
-
|
|
195
|
-
return (
|
|
196
|
-
<React.Fragment>
|
|
197
|
-
With a minimum value of 0 and maximum value of 10
|
|
198
|
-
<br />
|
|
199
|
-
<NumberInput
|
|
200
|
-
value={value}
|
|
201
|
-
min={this.minValue}
|
|
202
|
-
max={this.maxValue}
|
|
203
|
-
onMinus={this.onMinus}
|
|
204
|
-
onChange={this.onChange}
|
|
205
|
-
onPlus={this.onPlus}
|
|
206
|
-
inputName="input"
|
|
207
|
-
inputAriaLabel="number input"
|
|
208
|
-
minusBtnAriaLabel="minus"
|
|
209
|
-
plusBtnAriaLabel="plus"
|
|
210
|
-
unit="%"
|
|
211
|
-
/>
|
|
212
|
-
</React.Fragment>
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
22
|
+
```ts file="./NumberInputUnitThreshold.tsx"
|
|
216
23
|
```
|
|
217
24
|
|
|
218
25
|
### Disabled
|
|
219
26
|
|
|
220
|
-
```
|
|
221
|
-
import React from 'react';
|
|
222
|
-
import { NumberInput } from '@patternfly/react-core';
|
|
223
|
-
|
|
224
|
-
class DisabledNumberInput extends React.Component {
|
|
225
|
-
constructor(props) {
|
|
226
|
-
super(props);
|
|
227
|
-
this.state = {
|
|
228
|
-
value: 100
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
this.onMinus = () => {
|
|
232
|
-
this.setState({
|
|
233
|
-
value: this.state.value - 1
|
|
234
|
-
});
|
|
235
|
-
};
|
|
236
|
-
|
|
237
|
-
this.onChange = event => {
|
|
238
|
-
this.setState({
|
|
239
|
-
value: Number(event.target.value)
|
|
240
|
-
});
|
|
241
|
-
};
|
|
242
|
-
|
|
243
|
-
this.onPlus = () => {
|
|
244
|
-
this.setState({
|
|
245
|
-
value: this.state.value + 1
|
|
246
|
-
});
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
render() {
|
|
251
|
-
const { value } = this.state;
|
|
252
|
-
const minValue = 0;
|
|
253
|
-
const maxValue = 100;
|
|
254
|
-
|
|
255
|
-
return (
|
|
256
|
-
<NumberInput
|
|
257
|
-
value={value}
|
|
258
|
-
min={minValue}
|
|
259
|
-
max={maxValue}
|
|
260
|
-
onMinus={this.onMinus}
|
|
261
|
-
onChange={this.onChange}
|
|
262
|
-
onPlus={this.onPlus}
|
|
263
|
-
inputName="input"
|
|
264
|
-
inputAriaLabel="number input"
|
|
265
|
-
minusBtnAriaLabel="minus"
|
|
266
|
-
plusBtnAriaLabel="plus"
|
|
267
|
-
unit="%"
|
|
268
|
-
isDisabled
|
|
269
|
-
/>
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
27
|
+
```ts file="./NumberInputDisabled.tsx"
|
|
274
28
|
```
|
|
29
|
+
|
|
275
30
|
### With status
|
|
276
31
|
|
|
277
|
-
```ts file="./
|
|
32
|
+
```ts file="./NumberInputWithStatus.tsx"
|
|
278
33
|
```
|
|
279
34
|
|
|
280
35
|
### Varying sizes
|
|
281
36
|
|
|
282
|
-
```
|
|
283
|
-
import React from 'react';
|
|
284
|
-
import { NumberInput } from '@patternfly/react-core';
|
|
285
|
-
|
|
286
|
-
class NumberInputSizes extends React.Component {
|
|
287
|
-
constructor(props) {
|
|
288
|
-
super(props);
|
|
289
|
-
this.state = {
|
|
290
|
-
input1Value: 1,
|
|
291
|
-
input2Value: 1234567890,
|
|
292
|
-
input3Value: 5,
|
|
293
|
-
input4Value: 12345
|
|
294
|
-
};
|
|
295
|
-
|
|
296
|
-
this.onChange = event => {
|
|
297
|
-
this.setState({
|
|
298
|
-
[`${event.target.name}Value`]: Number(event.target.value)
|
|
299
|
-
});
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
this.onMinus = (e, inputName) => {
|
|
303
|
-
this.setState({
|
|
304
|
-
[`${inputName}Value`]: this.state[`${inputName}Value`] - 1
|
|
305
|
-
});
|
|
306
|
-
};
|
|
307
|
-
|
|
308
|
-
this.onPlus = (e, inputName) => {
|
|
309
|
-
this.setState({
|
|
310
|
-
[`${inputName}Value`]: this.state[`${inputName}Value`] + 1
|
|
311
|
-
});
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
render() {
|
|
316
|
-
const { input1Value, input2Value, input3Value, input4Value } = this.state;
|
|
317
|
-
|
|
318
|
-
return (
|
|
319
|
-
<React.Fragment>
|
|
320
|
-
<NumberInput
|
|
321
|
-
value={input1Value}
|
|
322
|
-
onMinus={this.onMinus}
|
|
323
|
-
onChange={this.onChange}
|
|
324
|
-
onPlus={this.onPlus}
|
|
325
|
-
inputName="input1"
|
|
326
|
-
inputAriaLabel="number input 1"
|
|
327
|
-
minusBtnAriaLabel="input 2 minus"
|
|
328
|
-
plusBtnAriaLabel="input 2 plus"
|
|
329
|
-
widthChars={1}
|
|
330
|
-
/>
|
|
331
|
-
<br />
|
|
332
|
-
<br />
|
|
333
|
-
<NumberInput
|
|
334
|
-
value={input2Value}
|
|
335
|
-
onMinus={this.onMinus}
|
|
336
|
-
onChange={this.onChange}
|
|
337
|
-
onPlus={this.onPlus}
|
|
338
|
-
inputName="input2"
|
|
339
|
-
inputAriaLabel="number input 2"
|
|
340
|
-
minusBtnAriaLabel="input 2 minus"
|
|
341
|
-
plusBtnAriaLabel="input 2 plus"
|
|
342
|
-
widthChars={10}
|
|
343
|
-
/>
|
|
344
|
-
<br />
|
|
345
|
-
<br />
|
|
346
|
-
<NumberInput
|
|
347
|
-
value={input3Value}
|
|
348
|
-
onMinus={this.onMinus}
|
|
349
|
-
onChange={this.onChange}
|
|
350
|
-
onPlus={this.onPlus}
|
|
351
|
-
inputName="input3"
|
|
352
|
-
inputAriaLabel="number input 3"
|
|
353
|
-
minusBtnAriaLabel="input 3 minus"
|
|
354
|
-
plusBtnAriaLabel="input 3 plus"
|
|
355
|
-
widthChars={5}
|
|
356
|
-
/>
|
|
357
|
-
<br />
|
|
358
|
-
<br />
|
|
359
|
-
<NumberInput
|
|
360
|
-
value={input4Value}
|
|
361
|
-
onMinus={this.onMinus}
|
|
362
|
-
onChange={this.onChange}
|
|
363
|
-
onPlus={this.onPlus}
|
|
364
|
-
inputName="input4"
|
|
365
|
-
inputAriaLabel="number input 4"
|
|
366
|
-
minusBtnAriaLabel="input 4 minus"
|
|
367
|
-
plusBtnAriaLabel="input 4 plus"
|
|
368
|
-
widthChars={5}
|
|
369
|
-
/>
|
|
370
|
-
</React.Fragment>
|
|
371
|
-
);
|
|
372
|
-
}
|
|
373
|
-
}
|
|
37
|
+
```ts file="./NumberInputVaryingSizes.tsx"
|
|
374
38
|
```
|
|
375
39
|
|
|
376
40
|
### Custom increment/decrement
|
|
377
41
|
|
|
378
|
-
```
|
|
379
|
-
import React from 'react';
|
|
380
|
-
import { NumberInput } from '@patternfly/react-core';
|
|
381
|
-
|
|
382
|
-
class CustomStepNumberInput extends React.Component {
|
|
383
|
-
constructor(props) {
|
|
384
|
-
super(props);
|
|
385
|
-
this.state = {
|
|
386
|
-
value: 90,
|
|
387
|
-
step: 3
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
this.stepper = step => () => {
|
|
391
|
-
this.setState(prev => ({ ...prev, value: prev.value + step }));
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
this.onChange = event => {
|
|
395
|
-
this.setState({
|
|
396
|
-
value: Number(event.target.value)
|
|
397
|
-
});
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
render() {
|
|
402
|
-
const { value } = this.state;
|
|
403
|
-
return (
|
|
404
|
-
<NumberInput
|
|
405
|
-
value={value}
|
|
406
|
-
onMinus={this.stepper(-3)}
|
|
407
|
-
onChange={this.onChange}
|
|
408
|
-
onPlus={this.stepper(3)}
|
|
409
|
-
inputName="input"
|
|
410
|
-
inputAriaLabel="number input"
|
|
411
|
-
minusBtnAriaLabel="minus"
|
|
412
|
-
plusBtnAriaLabel="plus"
|
|
413
|
-
/>
|
|
414
|
-
);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
42
|
+
```ts file="./NumberInputCustomStep.tsx"
|
|
417
43
|
```
|
|
418
44
|
|
|
419
45
|
### Custom increment/decrement and thresholds
|
|
420
46
|
|
|
421
|
-
```
|
|
422
|
-
import React from 'react';
|
|
423
|
-
import { NumberInput } from '@patternfly/react-core';
|
|
424
|
-
|
|
425
|
-
class CustomStepNumberInput extends React.Component {
|
|
426
|
-
constructor(props) {
|
|
427
|
-
super(props);
|
|
428
|
-
this.state = {
|
|
429
|
-
value: 90,
|
|
430
|
-
step: 3
|
|
431
|
-
};
|
|
432
|
-
this.minValue = 90;
|
|
433
|
-
this.maxValue = 100;
|
|
434
|
-
|
|
435
|
-
this.normalizeBetween = (value, min, max) => {
|
|
436
|
-
if (min !== undefined && max !== undefined) {
|
|
437
|
-
return Math.max(Math.min(value, max), min);
|
|
438
|
-
} else if (value <= min) {
|
|
439
|
-
return min;
|
|
440
|
-
} else if (value >= max) {
|
|
441
|
-
return max;
|
|
442
|
-
}
|
|
443
|
-
return value;
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
this.stepper = step => () => {
|
|
447
|
-
this.setState(prev => ({
|
|
448
|
-
...prev,
|
|
449
|
-
value: this.normalizeBetween(prev.value + step, this.minValue, this.maxValue)
|
|
450
|
-
}));
|
|
451
|
-
};
|
|
452
|
-
|
|
453
|
-
this.onChange = event => {
|
|
454
|
-
const newValue = isNaN(event.target.value) ? 0 : Number(event.target.value);
|
|
455
|
-
this.setState({
|
|
456
|
-
value: newValue
|
|
457
|
-
});
|
|
458
|
-
};
|
|
459
|
-
|
|
460
|
-
this.onBlur = event => {
|
|
461
|
-
const newValue = isNaN(event.target.value) ? 0 : Number(event.target.value);
|
|
462
|
-
this.setState({
|
|
463
|
-
value: newValue > this.maxValue ? this.maxValue : newValue < this.minValue ? this.minValue : newValue
|
|
464
|
-
});
|
|
465
|
-
};
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
render() {
|
|
469
|
-
const { value } = this.state;
|
|
470
|
-
return (
|
|
471
|
-
<NumberInput
|
|
472
|
-
value={value}
|
|
473
|
-
min={this.minValue}
|
|
474
|
-
max={this.maxValue}
|
|
475
|
-
onMinus={this.stepper(-3)}
|
|
476
|
-
onChange={this.onChange}
|
|
477
|
-
onBlur={this.onBlur}
|
|
478
|
-
onPlus={this.stepper(3)}
|
|
479
|
-
inputName="input"
|
|
480
|
-
inputAriaLabel="number input"
|
|
481
|
-
minusBtnAriaLabel="minus"
|
|
482
|
-
plusBtnAriaLabel="plus"
|
|
483
|
-
/>
|
|
484
|
-
);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
47
|
+
```ts file="./NumberInputCustomStepAndThreshold.tsx"
|
|
487
48
|
```
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NumberInput } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const NumberInputCustomStep: React.FunctionComponent = () => {
|
|
5
|
+
const [value, setValue] = React.useState(90);
|
|
6
|
+
const step = 3;
|
|
7
|
+
|
|
8
|
+
const stepper = (stepValue: number) => {
|
|
9
|
+
setValue(value + stepValue);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const onChange = (event: React.FormEvent<HTMLInputElement>) => {
|
|
13
|
+
const target = event.target as HTMLInputElement;
|
|
14
|
+
setValue(Number(target.value));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
return (
|
|
18
|
+
<NumberInput
|
|
19
|
+
value={value}
|
|
20
|
+
onMinus={() => stepper(-step)}
|
|
21
|
+
onChange={onChange}
|
|
22
|
+
onPlus={() => stepper(step)}
|
|
23
|
+
inputName="input"
|
|
24
|
+
inputAriaLabel="number input"
|
|
25
|
+
minusBtnAriaLabel="minus"
|
|
26
|
+
plusBtnAriaLabel="plus"
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NumberInput } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const NumberInputCustomStepAndThreshold: React.FunctionComponent = () => {
|
|
5
|
+
const [value, setValue] = React.useState(90);
|
|
6
|
+
const minValue = 90;
|
|
7
|
+
const maxValue = 100;
|
|
8
|
+
const step = 3;
|
|
9
|
+
|
|
10
|
+
const normalizeBetween = (value, min, max) => {
|
|
11
|
+
if (min !== undefined && max !== undefined) {
|
|
12
|
+
return Math.max(Math.min(value, max), min);
|
|
13
|
+
} else if (value <= min) {
|
|
14
|
+
return min;
|
|
15
|
+
} else if (value >= max) {
|
|
16
|
+
return max;
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const stepper = (stepValue: number) => {
|
|
22
|
+
setValue(value + stepValue);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const onChange = (event: React.FormEvent<HTMLInputElement>) => {
|
|
26
|
+
const target = event.target as HTMLInputElement;
|
|
27
|
+
const newValue = normalizeBetween(isNaN(+target.value) ? 0 : Number(target.value), minValue, maxValue);
|
|
28
|
+
setValue(newValue);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const onBlur = (event: React.FormEvent<HTMLInputElement>) => {
|
|
32
|
+
const target = event.target as HTMLInputElement;
|
|
33
|
+
const newValue = normalizeBetween(isNaN(+target.value) ? 0 : Number(target.value), minValue, maxValue);
|
|
34
|
+
setValue(newValue);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<NumberInput
|
|
39
|
+
value={value}
|
|
40
|
+
min={minValue}
|
|
41
|
+
max={maxValue}
|
|
42
|
+
onMinus={() => stepper(-step)}
|
|
43
|
+
onChange={onChange}
|
|
44
|
+
onBlur={onBlur}
|
|
45
|
+
onPlus={() => stepper(step)}
|
|
46
|
+
inputName="input"
|
|
47
|
+
inputAriaLabel="number input"
|
|
48
|
+
minusBtnAriaLabel="minus"
|
|
49
|
+
plusBtnAriaLabel="plus"
|
|
50
|
+
/>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { NumberInput } from '@patternfly/react-core';
|
|
3
|
+
|
|
4
|
+
export const NumberInputDefault: React.FunctionComponent = () => {
|
|
5
|
+
const [value, setValue] = React.useState(90);
|
|
6
|
+
|
|
7
|
+
const onMinus = () => {
|
|
8
|
+
const newValue = value - 1;
|
|
9
|
+
setValue(newValue);
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const onChange = (event: React.FormEvent<HTMLInputElement>) => {
|
|
13
|
+
const target = event.target as HTMLInputElement;
|
|
14
|
+
setValue(Number(target.value));
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const onPlus = () => {
|
|
18
|
+
const newValue = value + 1;
|
|
19
|
+
setValue(newValue);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<NumberInput
|
|
24
|
+
value={value}
|
|
25
|
+
onMinus={onMinus}
|
|
26
|
+
onChange={onChange}
|
|
27
|
+
onPlus={onPlus}
|
|
28
|
+
inputName="input"
|
|
29
|
+
inputAriaLabel="number input"
|
|
30
|
+
minusBtnAriaLabel="minus"
|
|
31
|
+
plusBtnAriaLabel="plus"
|
|
32
|
+
/>
|
|
33
|
+
);
|
|
34
|
+
};
|