├── .github └── workflows │ └── nodejs.yml ├── .gitignore ├── .npmignore ├── LICENSE.md ├── README.md ├── babel.config.json ├── dist ├── components │ ├── CurrencyInput.js │ ├── CurrencyInput.test.js │ ├── CurrencyInputTestWrapper.js │ └── FormikTestWrapper.js └── index.js ├── example.gif ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── demo │ ├── App.js │ ├── index.css │ └── index.js ├── index.js ├── lib │ ├── components │ │ ├── CurrencyInput.js │ │ ├── CurrencyInput.test.js │ │ ├── CurrencyInputTestWrapper.js │ │ └── FormikTestWrapper.js │ └── index.js └── setupTests.js └── types └── index.d.ts /.github/workflows/nodejs.yml: -------------------------------------------------------------------------------- 1 | # This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions 3 | 4 | name: Node.js CI 5 | 6 | on: 7 | push: 8 | branches: ["main"] 9 | pull_request: 10 | branches: ["main"] 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | 16 | strategy: 17 | matrix: 18 | node-version: [14.x, 16.x] 19 | # See supported Node.js release schedule at https://nodejs.org/en/about/releases/ 20 | 21 | steps: 22 | - uses: actions/checkout@v3 23 | - name: Use Node.js ${{ matrix.node-version }} 24 | uses: actions/setup-node@v3 25 | with: 26 | node-version: ${{ matrix.node-version }} 27 | cache: "npm" 28 | - run: npm install 29 | - run: npm test 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # dependencies 2 | /node_modules 3 | 4 | # testing 5 | /coverage 6 | 7 | # misc 8 | .DS_Store 9 | .env.local 10 | .env.development.local 11 | .env.test.local 12 | .env.production.local 13 | 14 | npm-debug.log* 15 | yarn-debug.log* 16 | yarn-error.log* 17 | 18 | # Development folders and files 19 | public 20 | src 21 | scripts 22 | config 23 | demo 24 | CHANGELOG.md 25 | README.md 26 | UPGRADE.md 27 | .storybook -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Pedro Resch 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Money Input 2 | 3 | ![npm (scoped)](https://img.shields.io/npm/v/@rschpdr/react-money-input) ![Node.js CI](https://github.com/rschpdr/react-money-input/workflows/Node.js%20CI/badge.svg) 4 | 5 | A currency text input for React that Just Works™ 6 | 7 | - "ATM style" typing, matches user expectations of how a money input should work 8 | - Uses Intl API to display locale accurate currency representations 9 | - Supports custom inputs (e.g. Material UI text fields) 10 | - Returns [`currency.js`](https://github.com/scurker/currency.js/) enforced numeric float values 11 | - Works out of the box with libs like [`Formik`](https://github.com/jaredpalmer/formik) 12 | 13 | ![](example.gif) 14 | 15 | ## Installation 16 | 17 | ```bash 18 | npm install --save @rschpdr/react-money-input currency.js 19 | ``` 20 | 21 | ## Quick Start 22 | 23 | ```javascript 24 | import React, { useState } from "react"; 25 | import MoneyInput from "@rschpdr/react-money-input"; 26 | 27 | function Example(props) { 28 | const [amount, setAmount] = useState(0); 29 | 30 | function handleChange(e) { 31 | setAmount(e.target.value); 32 | } 33 | 34 | return ; 35 | } 36 | 37 | export default Example; 38 | ``` 39 | 40 | ## Props 41 | 42 | | Props | Options | Default | Description | 43 | | -------------- | ----------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- | 44 | | className | string | '' | Regular React classname | 45 | | style | Styles object | {} | Regular React styles object | 46 | | currencyConfig | Currency configuration object |