Skip to content

Commit 5c73eec

Browse files
committed
Add input
1 parent a81eba3 commit 5c73eec

11 files changed

+2264
-7
lines changed

.babelrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-react"]
3+
}

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
node_modules
2-
dist
1+
dist
2+
node_modules

.prettierignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
node_modules
2-
dist
1+
dist
2+
node_modules

README.md

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# react-input-auto-format
2+
3+
A super simple input component that formats as you type.
4+
5+
```HTML
6+
<Input format="## - ## - ##">
7+
```
8+
9+
![Formatted input](/images/input.gif)
10+
11+
## Quick start
12+
13+
Install it...
14+
15+
```sh
16+
npm install react-input-auto-format
17+
```
18+
19+
Have fun:
20+
21+
```JSX
22+
import Input from 'react-input-auto-format';
23+
24+
function Foo () {
25+
return <Input format="## - ## - ##" />;
26+
}
27+
```
28+
29+
The `format` prop accepts a pattern. The `#` character represents any number or letter. You can put whatever else you like in there.
30+
31+
### Examples:
32+
33+
| Pattern | Result |
34+
| ------------------ | ------------ |
35+
| \#\# / \#\# | 12 / 34 |
36+
| \#\# - \#\# - \#\# | 12 - 34 - 56 |
37+
| \#\#\#\# \#\#\# | LM68 XKC |
38+
39+
## Getting the raw value
40+
41+
To get the unformatted value, use the `onValueChange` prop.
42+
43+
```JSX
44+
function Foo () {
45+
46+
handleValueChange(value) {
47+
console.log(value); // 123456
48+
}
49+
50+
return <Input
51+
format="## - ## - ##"
52+
onValueChange={handleValueChange}
53+
/>;
54+
}
55+
```
56+
57+
## Everything else
58+
59+
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`.

images/input.gif

22.2 KB
Loading

index.js

-1
This file was deleted.

0 commit comments

Comments
 (0)