1.2.16 • Published 3 years ago

react-number-variants v1.2.16

Weekly downloads
54
License
SEE LICENSE IN li...
Repository
github
Last release
3 years ago

A multi-purpose React number component with variants for numbers, currencies, and percentages

Features include:

  • format number on-blur; unformat on-focus
  • format based on locale and currency
  • min and max
  • variable number of decimals places
  • show error messages (above or below input)
  • output an event with the input value (on-change or on-blur)

Live demo with examples

https://react-number-variants.netlify.com/

GitHub

https://github.com/MachineLlama/react-number-variants

NPM

https://www.npmjs.com/package/react-number-variants

Usage

npm install react-number-variants --save
or
yarn add react-number-variants

In your React component:

import Number from 'react-number-variants';

Simple example:

<Number
  inputClassName="form-control"
  minNumberOfDecimals={1}
  maxNumberOfDecimals={3}
  onEvent={(event, value) =>
    this.setState({ event, value })
  }
/>

License

Absolutely none; feel free to clone and use any part of this code anywhere you want

Props (all optional)

PropDescriptionTypeDefault
idID of the entire Number component containerstring'react-number-variants'
inputIdID of the input boxstring'number-input'
classNameClassName of the entire Number component containerstring'number-container'
inputClassNameClassName of the input boxstring'number-input'
valueThe default starting value for the inputnumbernull
typeThe type of number rendered; either 'number', 'percent', or 'currency'string'number'
localeThe locale of the number renderedstring'en-US'
currencyIf type is set to 'currency', then this prop will determine the symbol displayedstring'USD'
minThe minimum value the number can benumbernull
maxThe maximum value the number can benumbernull
minNumberOfDecimalsMinimum number of decimal places allowed for valuenumber0 (can't be less than 0)
maxNumberOfDecimalsMaximum number of decimal places allowed for valuenumber20 (can't be greater than 20)
showErrorDetermines whether to show the error message or notbooleanfalse
errorIdID of the error messagestring'error-message'
errorClassNameClassName of the error messagestring'error-message'
errorLocationLocation of the error message. Can be either 'top' or 'bottom', relative to the input boxstring'bottom'
errorMessageThe error message displayedstring'error'
emitOnChangeDetermines whether to emit an event message on-change (can be used for performance or validation purposes)booleantrue
emitOnBlurDetermines whether to emit an event message on-blurbooleantrue
onEventFunction that can be used to get the event name and value from the input. Can be used to drive external events in your React component (like with validation to show the error message)functionnull
disabledDisable inputbooleanfalse
placeholderPlaceholder textstringundefined
1.2.12

3 years ago

1.2.13

3 years ago

1.2.11

3 years ago

1.2.16

3 years ago

1.2.14

3 years ago

1.2.15

3 years ago

1.2.7

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.9

3 years ago

1.2.4

3 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.1.2

4 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago