Coder Social home page Coder Social logo

react-money-input's Introduction

React Money Input

npm (scoped) Node.js CI

A currency text input for React that Just Works™

  • "ATM style" typing, matches user expectations of how a money input should work
  • Uses Intl API to display locale accurate currency representations
  • Supports custom inputs (e.g. Material UI text fields)
  • Returns currency.js enforced numeric float values
  • Works out of the box with libs like Formik

Installation

npm install --save @rschpdr/react-money-input currency.js

Quick Start

import React, { useState } from "react";
import MoneyInput from "@rschpdr/react-money-input";

function Example(props) {
  const [amount, setAmount] = useState(0);

  function handleChange(e) {
    setAmount(e.target.value);
  }

  return <MoneyInput onChange={handleChange} value={amount} />;
}

export default Example;

Props

Props Options Default Description
className string '' Regular React classname
style Styles object {} Regular React styles object
currencyConfig Currency configuration object
  • locale: string = "en-US"
  • currencyCode: string = "USD"
  • currencyDisplay: string = "symbol"
  • useGrouping: boolean = true
  • minimumFractionDigits: number = undefined
Config options for Number.toLocaleString method. See more
customInput Component Reference undefined Support for custom inputs e.g. Material UI TextField
name string undefined Regular name HTML property
id string undefined Regular id HTML property
max number Number.MAX_SAFE_INTEGER Maximum allowed value
onChange (event) => any undefined onChange event handler. event is a fake Synthetic Event with only value, name and id properties defined inside target
value number undefined Input value

Custom Inputs

Simply pass the custom input component as a prop. Pass the custom input props directly to MoneyInput:

import React, { useState } from "react";
import { TextField } from "@material-ui/core";
import MoneyInput from "@rschpdr/react-money-input";

function Example(props) {
  const [amount, setAmount] = useState(0);

  function handleChange(e) {
    setAmount(e.target.value);
  }

  return (
    <MoneyInput
      customInput={TextField}
      variant="outlined"
      label="Custom Input!"
      onChange={handleChange}
      value={amount}
    />
  );
}

export default Example;

Contributing

All contributions welcome! Feel free to raise issues or submit a PR.

License

This project is licensed under the MIT License - see LICENSE.md for details.

Acknowledgments

Go give them stars!

react-money-input's People

Contributors

rschpdr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.