@patternfly/react-core 4.190.0 → 4.191.0
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 +11 -0
- package/dist/esm/components/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/esm/components/NumberInput/NumberInput.js +13 -1
- package/dist/esm/components/NumberInput/NumberInput.js.map +1 -1
- package/dist/js/components/NumberInput/NumberInput.d.ts.map +1 -1
- package/dist/js/components/NumberInput/NumberInput.js +13 -1
- package/dist/js/components/NumberInput/NumberInput.js.map +1 -1
- package/dist/umd/react-core.js +12 -1
- package/dist/umd/react-core.min.css +252 -252
- package/dist/umd/react-core.min.js +1 -1
- package/package.json +5 -5
- package/src/components/NumberInput/NumberInput.tsx +17 -0
- package/src/components/NumberInput/__tests__/__snapshots__/NumberInput.test.tsx.snap +10 -0
- package/src/components/NumberInput/examples/NumberInput.md +43 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@patternfly/react-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.191.0",
|
|
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",
|
|
@@ -34,9 +34,9 @@
|
|
|
34
34
|
"generate": "node scripts/copyStyles.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@patternfly/react-icons": "^4.
|
|
38
|
-
"@patternfly/react-styles": "^4.
|
|
39
|
-
"@patternfly/react-tokens": "^4.
|
|
37
|
+
"@patternfly/react-icons": "^4.42.0",
|
|
38
|
+
"@patternfly/react-styles": "^4.41.0",
|
|
39
|
+
"@patternfly/react-tokens": "^4.43.0",
|
|
40
40
|
"focus-trap": "6.2.2",
|
|
41
41
|
"react-dropzone": "9.0.0",
|
|
42
42
|
"tippy.js": "5.1.2",
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"react": "^16.8.0 || ^17.0.0",
|
|
61
61
|
"react-dom": "^16.8.0 || ^17.0.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "77aae8d7980584c12ddcab1522ed9b7931588150"
|
|
64
64
|
}
|
|
@@ -4,6 +4,7 @@ import { css } from '@patternfly/react-styles';
|
|
|
4
4
|
import MinusIcon from '@patternfly/react-icons/dist/esm/icons/minus-icon';
|
|
5
5
|
import PlusIcon from '@patternfly/react-icons/dist/esm/icons/plus-icon';
|
|
6
6
|
import { Button, ButtonProps } from '../Button';
|
|
7
|
+
import { KEY_CODES } from '../../helpers';
|
|
7
8
|
|
|
8
9
|
export interface NumberInputProps extends React.HTMLProps<HTMLDivElement> {
|
|
9
10
|
/** Value of the number input */
|
|
@@ -44,6 +45,19 @@ export interface NumberInputProps extends React.HTMLProps<HTMLDivElement> {
|
|
|
44
45
|
plusBtnProps?: ButtonProps;
|
|
45
46
|
}
|
|
46
47
|
|
|
48
|
+
type DefaultKeyDownHandlerArgs = Pick<NumberInputProps, 'inputName' | 'onMinus' | 'onPlus'>;
|
|
49
|
+
|
|
50
|
+
const defaultKeyDownHandler = (args: DefaultKeyDownHandlerArgs) => (event: React.KeyboardEvent<HTMLInputElement>) => {
|
|
51
|
+
if (KEY_CODES.ARROW_UP === event.keyCode && args.onPlus) {
|
|
52
|
+
event.preventDefault();
|
|
53
|
+
args.onPlus(null, args.inputName);
|
|
54
|
+
}
|
|
55
|
+
if (KEY_CODES.ARROW_DOWN === event.keyCode && args.onMinus) {
|
|
56
|
+
event.preventDefault();
|
|
57
|
+
args.onMinus(null, args.inputName);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
47
61
|
export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
|
|
48
62
|
value = 0,
|
|
49
63
|
className,
|
|
@@ -66,6 +80,8 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
|
|
|
66
80
|
...props
|
|
67
81
|
}: NumberInputProps) => {
|
|
68
82
|
const numberInputUnit = <div className={css(styles.numberInputUnit)}>{unit}</div>;
|
|
83
|
+
const keyDownHandler =
|
|
84
|
+
inputProps && inputProps.onKeyDown ? inputProps.onKeyDown : defaultKeyDownHandler({ inputName, onMinus, onPlus });
|
|
69
85
|
return (
|
|
70
86
|
<div
|
|
71
87
|
className={css(styles.numberInput, className)}
|
|
@@ -100,6 +116,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
|
|
|
100
116
|
{...(onChange && { onChange })}
|
|
101
117
|
{...(!onChange && { readOnly: true })}
|
|
102
118
|
{...inputProps}
|
|
119
|
+
onKeyDown={keyDownHandler}
|
|
103
120
|
/>
|
|
104
121
|
<Button
|
|
105
122
|
variant="control"
|
|
@@ -72,6 +72,7 @@ exports[`numberInput disables lower threshold 1`] = `
|
|
|
72
72
|
<input
|
|
73
73
|
aria-label="Input"
|
|
74
74
|
className="pf-c-form-control"
|
|
75
|
+
onKeyDown={[Function]}
|
|
75
76
|
readOnly={true}
|
|
76
77
|
type="number"
|
|
77
78
|
value={0}
|
|
@@ -209,6 +210,7 @@ exports[`numberInput disables upper threshold 1`] = `
|
|
|
209
210
|
<input
|
|
210
211
|
aria-label="Input"
|
|
211
212
|
className="pf-c-form-control"
|
|
213
|
+
onKeyDown={[Function]}
|
|
212
214
|
readOnly={true}
|
|
213
215
|
type="number"
|
|
214
216
|
value={100}
|
|
@@ -361,6 +363,7 @@ exports[`numberInput passes button props successfully 1`] = `
|
|
|
361
363
|
<input
|
|
362
364
|
aria-label="Input"
|
|
363
365
|
className="pf-c-form-control"
|
|
366
|
+
onKeyDown={[Function]}
|
|
364
367
|
readOnly={true}
|
|
365
368
|
type="number"
|
|
366
369
|
value={5}
|
|
@@ -504,6 +507,7 @@ exports[`numberInput passes input props successfully 1`] = `
|
|
|
504
507
|
className="pf-c-form-control"
|
|
505
508
|
name="test-name"
|
|
506
509
|
onChange={[MockFunction]}
|
|
510
|
+
onKeyDown={[Function]}
|
|
507
511
|
type="number"
|
|
508
512
|
value={5}
|
|
509
513
|
/>
|
|
@@ -645,6 +649,7 @@ exports[`numberInput renders custom width 1`] = `
|
|
|
645
649
|
<input
|
|
646
650
|
aria-label="Input"
|
|
647
651
|
className="pf-c-form-control"
|
|
652
|
+
onKeyDown={[Function]}
|
|
648
653
|
readOnly={true}
|
|
649
654
|
type="number"
|
|
650
655
|
value={5}
|
|
@@ -783,6 +788,7 @@ exports[`numberInput renders defaults & extra props 1`] = `
|
|
|
783
788
|
<input
|
|
784
789
|
aria-label="Input"
|
|
785
790
|
className="pf-c-form-control"
|
|
791
|
+
onKeyDown={[Function]}
|
|
786
792
|
readOnly={true}
|
|
787
793
|
type="number"
|
|
788
794
|
value={0}
|
|
@@ -922,6 +928,7 @@ exports[`numberInput renders disabled 1`] = `
|
|
|
922
928
|
aria-label="Input"
|
|
923
929
|
className="pf-c-form-control"
|
|
924
930
|
disabled={true}
|
|
931
|
+
onKeyDown={[Function]}
|
|
925
932
|
readOnly={true}
|
|
926
933
|
type="number"
|
|
927
934
|
value={90}
|
|
@@ -1066,6 +1073,7 @@ exports[`numberInput renders unit & position 1`] = `
|
|
|
1066
1073
|
<input
|
|
1067
1074
|
aria-label="Input"
|
|
1068
1075
|
className="pf-c-form-control"
|
|
1076
|
+
onKeyDown={[Function]}
|
|
1069
1077
|
readOnly={true}
|
|
1070
1078
|
type="number"
|
|
1071
1079
|
value={5}
|
|
@@ -1204,6 +1212,7 @@ exports[`numberInput renders unit 1`] = `
|
|
|
1204
1212
|
<input
|
|
1205
1213
|
aria-label="Input"
|
|
1206
1214
|
className="pf-c-form-control"
|
|
1215
|
+
onKeyDown={[Function]}
|
|
1207
1216
|
readOnly={true}
|
|
1208
1217
|
type="number"
|
|
1209
1218
|
value={5}
|
|
@@ -1345,6 +1354,7 @@ exports[`numberInput renders value 1`] = `
|
|
|
1345
1354
|
<input
|
|
1346
1355
|
aria-label="Input"
|
|
1347
1356
|
className="pf-c-form-control"
|
|
1357
|
+
onKeyDown={[Function]}
|
|
1348
1358
|
readOnly={true}
|
|
1349
1359
|
type="number"
|
|
1350
1360
|
value={90}
|
|
@@ -357,3 +357,46 @@ class NumberInputSizes extends React.Component {
|
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
```
|
|
360
|
+
|
|
361
|
+
### Custom increment/decrement
|
|
362
|
+
|
|
363
|
+
```js
|
|
364
|
+
import React from 'react';
|
|
365
|
+
import { NumberInput } from '@patternfly/react-core';
|
|
366
|
+
|
|
367
|
+
class CustomStepNumberInput extends React.Component {
|
|
368
|
+
constructor(props) {
|
|
369
|
+
super(props);
|
|
370
|
+
this.state = {
|
|
371
|
+
value: 90,
|
|
372
|
+
step: 3,
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
this.stepper = step => () => {
|
|
376
|
+
this.setState(prev => ({...prev, value: prev.value + step }))
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
this.onChange = event => {
|
|
380
|
+
this.setState({
|
|
381
|
+
value: Number(event.target.value)
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
render() {
|
|
387
|
+
const { value } = this.state;
|
|
388
|
+
return (
|
|
389
|
+
<NumberInput
|
|
390
|
+
value={value}
|
|
391
|
+
onMinus={this.stepper(-3)}
|
|
392
|
+
onChange={this.onChange}
|
|
393
|
+
onPlus={this.stepper(3)}
|
|
394
|
+
inputName="input"
|
|
395
|
+
inputAriaLabel="number input"
|
|
396
|
+
minusBtnAriaLabel="minus"
|
|
397
|
+
plusBtnAriaLabel="plus"
|
|
398
|
+
/>
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
```
|