| 1 |
import { useState } from 'react'; |
| 2 |
import { NumberInput } from '@patternfly/react-core'; |
| 3 |
|
| 4 |
export const NumberInputDisabled: React.FunctionComponent = () => { |
| 5 |
const [value, setValue] = useState<number | ''>(100); |
| 6 |
const minValue = 0; |
| 7 |
const maxValue = 100; |
| 8 |
|
| 9 |
const onMinus = () => { |
| 10 |
const newValue = (value || 0) - 1; |
| 11 |
setValue(newValue); |
| 12 |
}; |
| 13 |
|
| 14 |
const onChange = (event: React.FormEvent<HTMLInputElement>) => { |
| 15 |
const value = (event.target as HTMLInputElement).value; |
| 16 |
setValue(value === '' ? value : +value); |
| 17 |
}; |
| 18 |
|
| 19 |
const onPlus = () => { |
| 20 |
const newValue = (value || 0) + 1; |
| 21 |
setValue(newValue); |
| 22 |
}; |
| 23 |
|
| 24 |
return ( |
| 25 |
<NumberInput |
| 26 |
value={value} |
| 27 |
min={minValue} |
| 28 |
max={maxValue} |
| 29 |
onMinus={onMinus} |
| 30 |
onChange={onChange} |
| 31 |
onPlus={onPlus} |
| 32 |
inputName="input" |
| 33 |
inputAriaLabel="number input" |
| 34 |
minusBtnAriaLabel="minus" |
| 35 |
plusBtnAriaLabel="plus" |
| 36 |
unit="%" |
| 37 |
isDisabled |
| 38 |
/> |
| 39 |
); |
| 40 |
}; |