Number input component with more flexible options very easy to use. compatible with Formik library 👀.
npm install @deberoppa/react-numeric-input --save
Add it to your script like this:
// es6
import RNI from '@deberoppa/react-numeric-input';
<RNI/>
// Or to add class:
<RNI className="my-custom-class1"/>
Most of the time you will need to specify min, max, value and step like the native numeric input.
<RNI min={0} max={100} step={5} value={60}/>
You can use step and precision props to make the input working with floating point numbers.
<RNI step={0.25} precision={2} value={30.25}/>
In the mobile the input must change display so the click on the buttons will be comfortable.
<RNI mobile={true}/>
You can add prefix or suffix to the value like this:
// Prefix
<RNI prefix="$" value={30} /> // output: $30
// Suffix
<RNI suffix="€" value={40}/> // output : 40€
You can add you custom format to the value.
function myCustomFormat(number) {
return '$$' + number + '$$';
}
<RNI value={40} format={myCustomFormat}/> // output: $$40$$
readOnly : The value cannot be updated by button's click or text entry. ( The input is only a display )
disabled : Disable the input.
// readOnly
<RNI readOnly />
// disabled
<RNI disabled />
See the examples page here.
Name | Type | Default |
---|---|---|
value | number or string |
"" which converts to 0 |
min | number |
Number.MIN_SAFE_INTEGER |
max | number |
Number.MAX_SAFE_INTEGER |
step | number |
1 |
precision | number |
0 |
prefix | string |
'' |
sufix | string |
'' |
format | function |
null |
className | string |
none |
readOnly | true , false |
false |
disabled | true , false |
false |
mobile | true , false |
false |
onChange - Event handler when the input's value changed
function onChangeHandler(valuer) {
console.log(value)
}
<RNI value={9} onChange={onChangeHandler}/>
This project was bootstrapped with create-react-library.
MIT © deberoppa7