react-input-currency

npm install --save react-input-currency

Usage no npm install needed!

<script type="module">
  import reactInputCurrency from 'https://cdn.skypack.dev/react-input-currency';
</script>

README

react-input-currency

NPM JavaScript Style Guide

Install

npm install --save react-input-currency

Usage

import React, { Component } from 'react'

import InputCurrency from 'react-input-currency'

class Example extends Component {
  constructor() {
    super();
    this.state = {
      value: '20',
    }
  }
  render () {
    return (
      <InputCurrency 
        value={this.state.value}
        onChange={({ value }) => this.setState({ value })}
      />
    );
  }
}

Styling

If you want the text aligned right:

.style {
    text-align: right;
}
...
<InputCurrency className={style} {...props}  />

Props

Parameter Type Description
value string/number Field value.
id string Field id.
name string Field name.
required boolean Html5 required
onChange function Callback function called when value changes, returns an object { name: props.name, value: masked input value }
className string Jsx className

Mask props

Parameter Default Type
decimal . string
prefix $ string
thousands , string
Example

const maskProps = {
    decimal: ',',
    prefix: 'R

,
    thousands: '.'
}

<InputCurrency {...maskProps}  />

Will give the mask R$ 2.500,00

License

MIT © alom2