Skip to content

Commit 111c0ed

Browse files
authored
Details in README (#11)
1 parent 3b12cc3 commit 111c0ed

File tree

2 files changed

+122
-18
lines changed

2 files changed

+122
-18
lines changed

README.md

+73-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,74 @@
1-
# react-autonumeric
1+
# React-AutoNumeric: React Components that Wrap [AutoNumeric][]
22

3-
Autonumeric as a React component.
3+
[AutoNumeric][] is a powerful library that automatically format numbers and currencies.
4+
React-AutoNumeric brings that power to React.
5+
6+
## Install
7+
8+
```
9+
npm install --save react-autonumeric
10+
```
11+
12+
## Usage
13+
14+
### Most basic usage
15+
16+
```tsx
17+
<AutoNumericInput />
18+
```
19+
20+
creates an [input component][] that is automatically formatted by AutoNumeric.
21+
22+
### Customize the input
23+
24+
```tsx
25+
<AutoNumericInput
26+
inputProps={{ defaultValue: "99.99" }}
27+
autoNumericOptions={{ suffixText: "%" }}
28+
/>
29+
```
30+
31+
### Use predefined AutoNumeric options
32+
33+
```tsx
34+
<AutoNumericInput
35+
inputProps={{ defaultValue: "10000" }}
36+
autoNumericOptions={
37+
AutoNumeric.getPredefinedOptions().commaDecimalCharDotSeparator
38+
}
39+
/>
40+
```
41+
42+
### Interact with `AutoNumericInput` via a React state
43+
44+
```tsx
45+
const [controlledInputState, setControlledInputState] = useState("100");
46+
47+
<AutoNumericInput
48+
valueState={{
49+
state: controlledInputState,
50+
stateSetter: setControlledInputState,
51+
}}
52+
/>
53+
<button
54+
onClick={() => {
55+
setControlledInputState(
56+
(Number(controlledInputState) + 1).toString(),
57+
);
58+
}}
59+
>
60+
Add one
61+
</button>
62+
```
63+
64+
### API References
65+
66+
For more detailed usage, check out the {@link AutoNumericInput} API references.
67+
68+
### Non-Input Usage
69+
70+
If you would like a component other than input that is automatically formatted by AutoNumeric,
71+
please consult {@link AutoNumericComponent}.
72+
73+
[AutoNumeric]: https://autonumeric.org/
74+
[input component]: https://react.dev/reference/react-dom/components/input

src/demo/App.tsx

+49-16
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,61 @@
1515
* limitations under the License.
1616
*/
1717

18+
import AutoNumeric from "autonumeric";
1819
import { AutoNumericInput } from "../lib/AutoNumericInput";
1920
import { useState } from "react";
2021

2122
export default function App(): JSX.Element {
22-
const [controlledInputState, setControlledInputState] = useState("2222");
23+
const [controlledInputState, setControlledInputState] = useState("100");
2324
return (
2425
<>
25-
<AutoNumericInput />
26-
27-
<AutoNumericInput
28-
valueState={{
29-
state: controlledInputState,
30-
stateSetter: setControlledInputState,
31-
}}
32-
/>
33-
<button
34-
onClick={() => {
35-
setControlledInputState("1111");
36-
}}
37-
>
38-
Reset to 1111
39-
</button>
26+
<label>
27+
Most basic usage
28+
<AutoNumericInput />
29+
</label>
30+
31+
<hr />
32+
33+
<label>
34+
Customize the input
35+
<AutoNumericInput
36+
inputProps={{ defaultValue: "99.99" }}
37+
autoNumericOptions={{ suffixText: "%" }}
38+
/>
39+
</label>
40+
41+
<hr />
42+
43+
<label>
44+
Use predefined AutoNumeric options
45+
<AutoNumericInput
46+
inputProps={{ defaultValue: "10000" }}
47+
autoNumericOptions={
48+
AutoNumeric.getPredefinedOptions().commaDecimalCharDotSeparator
49+
}
50+
/>
51+
</label>
52+
53+
<hr />
54+
55+
<label>
56+
Interact with AutoNumericInput via a React state
57+
<AutoNumericInput
58+
valueState={{
59+
state: controlledInputState,
60+
stateSetter: setControlledInputState,
61+
}}
62+
/>
63+
<button
64+
onClick={() => {
65+
setControlledInputState(
66+
(Number(controlledInputState) + 1).toString(),
67+
);
68+
}}
69+
>
70+
Add one
71+
</button>
72+
</label>
4073
</>
4174
);
4275
}

0 commit comments

Comments
 (0)