Skip to content

Commit

Permalink
Add input
Browse files Browse the repository at this point in the history
  • Loading branch information
danielyefet committed Oct 3, 2021
1 parent a81eba3 commit 5c73eec
Show file tree
Hide file tree
Showing 11 changed files with 2,264 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["@babel/preset-react"]
}
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
dist
dist
node_modules
4 changes: 2 additions & 2 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
dist
dist
node_modules
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# react-input-auto-format

A super simple input component that formats as you type.

```HTML
<Input format="## - ## - ##">
```

![Formatted input](/images/input.gif)

## Quick start

Install it...

```sh
npm install react-input-auto-format
```

Have fun:

```JSX
import Input from 'react-input-auto-format';

function Foo () {
return <Input format="## - ## - ##" />;
}
```

The `format` prop accepts a pattern. The `#` character represents any number or letter. You can put whatever else you like in there.

### Examples:

| Pattern | Result |
| ------------------ | ------------ |
| \#\# / \#\# | 12 / 34 |
| \#\# - \#\# - \#\# | 12 - 34 - 56 |
| \#\#\#\# \#\#\# | LM68 XKC |

## Getting the raw value

To get the unformatted value, use the `onValueChange` prop.

```JSX
function Foo () {

handleValueChange(value) {
console.log(value); // 123456
}

return <Input
format="## - ## - ##"
onValueChange={handleValueChange}
/>;
}
```

## Everything else

All other props work the same as you would expect for a native input component. If you want the formatted value, use a normal `onChange` attribute and pull out `event.target.value`.
Binary file added images/input.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion index.js

This file was deleted.

Loading

0 comments on commit 5c73eec

Please sign in to comment.