forked from danielyefet/react-input-auto-format
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a81eba3
commit 5c73eec
Showing
11 changed files
with
2,264 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": ["@babel/preset-react"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
node_modules | ||
dist | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
node_modules | ||
dist | ||
dist | ||
node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.