Socket
Socket
Sign inDemoInstall

react-intl-currency-input

Package Overview
Dependencies
192
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-intl-currency-input

A React component for i18n currency input using the Intl API.


Version published
Weekly downloads
3.5K
increased by2.25%
Maintainers
1
Install size
32.7 MB
Created
Weekly downloads
 

Readme

Source

react-intl-currency-input

A React component for i18n currency input using Intl API.

Installation

$ npm install react-intl-currency-input --save-dev

How to use

import React from "react"
import IntlCurrencyInput from "react-intl-currency-input"

const currencyConfig = {
  locale: "pt-BR",
  formats: {
    number: {
      BRL: {
        style: "currency",
        currency: "BRL",
        minimumFractionDigits: 2,
        maximumFractionDigits: 2,
      },
    },
  },
};

const BrlCurrencyComponent = () => {
  const handleChange = (event, value, maskedValue) => {
    event.preventDefault();

    console.log(value); // value without mask (ex: 1234.56)
    console.log(maskedValue); // masked value (ex: R$1234,56)
  };

  return(
    <IntlCurrencyInput currency="BRL" config={currencyConfig}
            onChange={handleChange} />
  );
}

export default BrlCurrencyComponent;

Example

example

To run the example:

$ npm run example:start

And a new browser window will open at http://localhost:3000

Properties

NameTypeDefaultDescription
defaultValuenumber0Sets the default / initial value to be used by the component on the first load
currencystringUSDSets the currency code
configobjectUSD related configurationConfiguration object compliant with react-intl intlShape
autoFocusbooleanfalseEnables auto-focus when the component gets displayed
autoSelectbooleanfalseEnables auto-select when the component gets displayed
autoResetbooleanfalseResets component's internal state when loses focus
onChangefunctionundefined(event, value, maskedValued) => {}

Exposes the Event itself, the value with no mask and maskedValue for displaying purposes
onFocusfunctionundefined(event, value, maskedValued) => {

Called when the component gains focus
onBlurfunctionundefined(event, value, maskedValued) => {

Called when the component loses focus
onKeyPressfunctionundefined(event, key, keyCode) => {}

Called when a key is pressed
maxnumberundefinedMaximum value for the input. Input does not change if the value is greater than max

All the other undocumented properties available for any React Component should also be available.

TO-DO

  • Add unit tests
  • Add a Storybook for examples and UI tests

Keywords

FAQs

Last updated on 09 Mar 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc