@leonardodino/rifm

0.3.0 • Public • Published

RIFM - React Input Format & Mask

Is a tiny (≈ 650-750b) component to transform any input component into formatted or masked input.

Demo

Highlights

  • Dependency free
  • Tiny (≈ 650b)
  • Supports any input.
  • Can mask input and format

Example

import { Rifm } from 'rifm';
import { Value } from 'react-powerplug';
import TextField from '@material-ui/core/TextField';
import { css } from 'emotion';

const numberFormat = (str: string) => {
  const r = parseInt(str.replace(/[^\d]+/gi, ''), 10);
  return r ? r.toLocaleString('en') : '';
}

...

  <Value initial={''}>
    {text => (
      <Rifm
        value={text.value}
        onChange={text.set}
        format={numberFormat}
      >
        {({ value, onChange }) => (
          <TextField
            value={value}
            label={'Float'}
            onChange={onChange}
            className={css({input: {textAlign:"right"}})}
            type="tel"
          />
        )}
      </Rifm>
    )}
  </Value>

...

Demo

Demo source

Install

  yarn add rifm
  npm -i rifm

Thanks

@TrySound for incredible help and support on this

Readme

Keywords

none

Package Sidebar

Install

npm i @leonardodino/rifm

Weekly Downloads

0

Version

0.3.0

License

MIT

Unpacked Size

15.8 kB

Total Files

13

Last publish

Collaborators

  • leonardodino