0.4.1 • Published 9 months ago

@alexzunik/react-native-money-input v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

react-native-money-input

šŸ”„šŸ”„šŸ”„ Fully native money input for React Native. Based original TextInput component.

šŸš€ Example

iOSAndroid
iOS DemoAndroid Demo

šŸ“„ Installation

yarn add @alexzunik/react-native-money-input

npx pod-install

šŸŽ® Usage

import { MoneyTextInput } from '@alexzunik/react-native-money-input';

// ...

const Component = () => {
  const [value, setValue] = React.useState<string>();
  return (
    <MoneyTextInput
        value={value}
        onChangeText={(formatted, extracted) => {
          console.log(formatted) // $1,234,567.89
          console.log(extracted) // 1234567.89
          setValue(extracted)
        }}
        prefix="$"
        groupingSeparator=","
        fractionSeparator="."
      />
  )
}

šŸ“¦ Props

The component fully inherits TextInput props and brings new props. See below:

export interface MoneyTextInputProps extends TextInputProps, MaskOptions {
  /**
   * Callback with entered value
   *
   * @param formatted {string} formatted text
   * @param extracted {string} extracted text
   */
  onChangeText: (formatted: string, extracted?: string) => void;
}
interface MaskOptions {
  /**
   * Separator between integer number groups
   *
   * Default: `space`
   */
  groupingSeparator?: string;
  /**
   * Separator between integer and fraction parts.
   * Will be ignored if you set maximumFractionalDigits = 0
   *
   * Default: system separator
   */
  fractionSeparator?: string;
  /**
   * Prefix before number.
   *
   * For example: if prefix = `$` input will be `$1,234.43`
   *
   * Default: `undefined`
   */
  prefix?: string;
  /**
   * Suffix after number.
   *
   * For example: if suffix = ` EUR` input will be `1 234,43 EUR`
   *
   * Default: `undefined`
   */
  suffix?: string;
  /**
   * Maximum length in integer part, exclude separators
   * Maximum possible value is 36
   *
   * Default: `36`
   */
  maximumIntegerDigits?: number;
  /**
   * Maximum length in fractional part
   *
   * Default: `2`
   */
  maximumFractionalDigits?: number;
  /**
   * Minimum numeric value.
   * It will be set to input if user enters value less than minValue
   */
  minValue?: number;
  /**
   * Maximum numeric value.
   * It will be set to input if user enters value greater than maxValue
   */
  maxValue?: number;
}

āš ļø limitations

  • Maximum possible value for property maximumIntegerDigits is 36

šŸ‘Øā€šŸ”§ Testing

in order to load mocks provided by react-native-money-input add following to your jest config in jest.config.json:

"setupFiles": ["./node_modules/@alexzunik/react-native-money-input/jest/setup.js"]

šŸ¤ Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

0.3.5

11 months ago

0.4.1

9 months ago

0.4.0

9 months ago

0.3.4

11 months ago

0.3.2

1 year ago

0.3.3

1 year ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.3.1

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago