Debian Codegraph @

node/@patternfly/react-core/src/components/NumberInput/examples/NumberInputDefault.tsx

raw
1 import { useState } from 'react';
2 import { NumberInput } from '@patternfly/react-core';
3
4 export const NumberInputDefault: React.FunctionComponent = () => {
5 const [value, setValue] = useState<number | ''>(90);
6
7 const onMinus = () => {
8 const newValue = (value || 0) - 1;
9 setValue(newValue);
10 };
11
12 const onChange = (event: React.FormEvent<HTMLInputElement>) => {
13 const value = (event.target as HTMLInputElement).value;
14 setValue(value === '' ? value : +value);
15 };
16
17 const onPlus = () => {
18 const newValue = (value || 0) + 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 };