@patternfly/react-core 4.198.18 → 4.198.19

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@patternfly/react-core",
3
- "version": "4.198.18",
3
+ "version": "4.198.19",
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.49.18",
38
- "@patternfly/react-styles": "^4.48.18",
39
- "@patternfly/react-tokens": "^4.50.18",
37
+ "@patternfly/react-icons": "^4.49.19",
38
+ "@patternfly/react-styles": "^4.48.19",
39
+ "@patternfly/react-tokens": "^4.50.19",
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": "cddb168bc8c901582a0a7cde8eabd692b9c85b6d"
63
+ "gitHead": "5b472303da22cb9c67e9977b3933f6576c27ac01"
64
64
  }
@@ -83,6 +83,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
83
83
  const numberInputUnit = <div className={css(styles.numberInputUnit)}>{unit}</div>;
84
84
  const keyDownHandler =
85
85
  inputProps && inputProps.onKeyDown ? inputProps.onKeyDown : defaultKeyDownHandler({ inputName, onMinus, onPlus });
86
+
86
87
  return (
87
88
  <div
88
89
  className={css(styles.numberInput, className)}
@@ -99,7 +100,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
99
100
  <Button
100
101
  variant="control"
101
102
  aria-label={minusBtnAriaLabel}
102
- isDisabled={isDisabled || value === min}
103
+ isDisabled={isDisabled || value <= min}
103
104
  onClick={evt => onMinus(evt, inputName)}
104
105
  {...minusBtnProps}
105
106
  >
@@ -122,7 +123,7 @@ export const NumberInput: React.FunctionComponent<NumberInputProps> = ({
122
123
  <Button
123
124
  variant="control"
124
125
  aria-label={plusBtnAriaLabel}
125
- isDisabled={isDisabled || value === max}
126
+ isDisabled={isDisabled || value >= max}
126
127
  onClick={evt => onPlus(evt, inputName)}
127
128
  {...plusBtnProps}
128
129
  >
@@ -159,9 +159,20 @@ class UnitThresholdNumberInput extends React.Component {
159
159
  this.minValue = 0;
160
160
  this.maxValue = 10;
161
161
 
162
+ this.normalizeBetween = (value, min, max) => {
163
+ if (min !== undefined && max !== undefined) {
164
+ return Math.max(Math.min(value, max), min);
165
+ } else if (value <= min) {
166
+ return min;
167
+ } else if (value >= max) {
168
+ return max;
169
+ }
170
+ return value;
171
+ };
172
+
162
173
  this.onMinus = () => {
163
174
  this.setState({
164
- value: this.state.value - 1
175
+ value: this.normalizeBetween(this.state.value - 1, this.minValue, this.maxValue)
165
176
  });
166
177
  };
167
178
 
@@ -174,7 +185,7 @@ class UnitThresholdNumberInput extends React.Component {
174
185
 
175
186
  this.onPlus = () => {
176
187
  this.setState({
177
- value: this.state.value + 1
188
+ value: this.normalizeBetween(this.state.value + 1, this.minValue, this.maxValue)
178
189
  });
179
190
  };
180
191
  }
@@ -369,12 +380,12 @@ class CustomStepNumberInput extends React.Component {
369
380
  super(props);
370
381
  this.state = {
371
382
  value: 90,
372
- step: 3,
383
+ step: 3
373
384
  };
374
385
 
375
386
  this.stepper = step => () => {
376
- this.setState(prev => ({...prev, value: prev.value + step }))
377
- }
387
+ this.setState(prev => ({ ...prev, value: prev.value + step }));
388
+ };
378
389
 
379
390
  this.onChange = event => {
380
391
  this.setState({
@@ -400,3 +411,65 @@ class CustomStepNumberInput extends React.Component {
400
411
  }
401
412
  }
402
413
  ```
414
+
415
+ ### Custom increment/decrement and thresholds
416
+
417
+ ```js
418
+ import React from 'react';
419
+ import { NumberInput } from '@patternfly/react-core';
420
+
421
+ class CustomStepNumberInput extends React.Component {
422
+ constructor(props) {
423
+ super(props);
424
+ this.state = {
425
+ value: 90,
426
+ step: 3
427
+ };
428
+ this.minValue = 90;
429
+ this.maxValue = 100;
430
+
431
+ this.normalizeBetween = (value, min, max) => {
432
+ if (min !== undefined && max !== undefined) {
433
+ return Math.max(Math.min(value, max), min);
434
+ } else if (value <= min) {
435
+ return min;
436
+ } else if (value >= max) {
437
+ return max;
438
+ }
439
+ return value;
440
+ };
441
+
442
+ this.stepper = step => () => {
443
+ this.setState(prev => ({
444
+ ...prev,
445
+ value: this.normalizeBetween(prev.value + step, this.minValue, this.maxValue)
446
+ }));
447
+ };
448
+
449
+ this.onChange = event => {
450
+ const newValue = isNaN(event.target.value) ? 0 : Number(event.target.value);
451
+ this.setState({
452
+ value: newValue > this.maxValue ? this.maxValue : newValue < this.minValue ? this.minValue : newValue
453
+ });
454
+ };
455
+ }
456
+
457
+ render() {
458
+ const { value } = this.state;
459
+ return (
460
+ <NumberInput
461
+ value={value}
462
+ min={this.minValue}
463
+ max={this.maxValue}
464
+ onMinus={this.stepper(-3)}
465
+ onChange={this.onChange}
466
+ onPlus={this.stepper(3)}
467
+ inputName="input"
468
+ inputAriaLabel="number input"
469
+ minusBtnAriaLabel="minus"
470
+ plusBtnAriaLabel="plus"
471
+ />
472
+ );
473
+ }
474
+ }
475
+ ```