Skip to content

Commit 705c846

Browse files
authored
Document AutoNumericInput (#5)
1 parent 63ef899 commit 705c846

File tree

3 files changed

+66
-9
lines changed

3 files changed

+66
-9
lines changed

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "react-autonumeric",
33
"version": "1.0.0",
44
"type": "module",
5-
"main": "dist/index.js",
5+
"browser": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"files": [
88
"/dist/*.d.ts",
@@ -14,14 +14,23 @@
1414
"dev": "vite",
1515
"compile": "tsc --build . src/lib src/test src/demo",
1616
"coverage": "vitest run --coverage --typecheck",
17-
"doc": "npm run compile && typedoc && replace-in-files --string '=\"assets/' --replacement '=\"/assets/' docs/404.html",
17+
"doc": "typedoc && replace-in-files --string '=\"assets/' --replacement '=\"/assets/' docs/404.html",
1818
"format": "eslint --fix . && prettier . --write",
1919
"lint": "eslint . --report-unused-disable-directives --max-warnings 0 && prettier . --check",
20+
"prepack": "npm run clean && npm run compile",
2021
"preview": "vite preview",
2122
"test": "vitest --typecheck",
2223
"test-once": "npm run coverage",
2324
"test-all": "npm run lint && npm run compile && npm run test-once && npm run doc"
2425
},
26+
"repository": {
27+
"type": "git",
28+
"url": "git+https://github.com/8hobbies/react-autonumeric.git"
29+
},
30+
"keywords": [
31+
"react",
32+
"autonumeric"
33+
],
2534
"dependencies": {
2635
"@8hobbies/utils": "^1.2.1",
2736
"autonumeric": "^4.10.5",

src/lib/AutoNumericInput.tsx

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,56 @@
1717

1818
import type { ChangeEvent, ClassAttributes, InputHTMLAttributes } from "react";
1919
import AutoNumericComponent from "./AutoNumericComponent";
20+
import type { CallbackOptions } from "autonumeric";
2021

21-
type InputProps = Omit<
22+
/** Same as {@link JSX!IntrinsicElements.input.props} excluding the `ref` property. */
23+
export type InputProps = Omit<
2224
InputHTMLAttributes<HTMLInputElement> & ClassAttributes<HTMLInputElement>,
2325
"ref"
2426
>;
2527

28+
/** React {@link JSX!IntrinsicElements.input} component integrated with {@link !AutoNumeric}.
29+
*
30+
* @param options - Options of the component.
31+
* @param options.inputProps - Options passed to {@link JSX!IntrinsicElements.input}. Same as {@link
32+
* JSX!IntrinsicElements.input.props} excluding the `ref` property.
33+
* @param options.autoNumericOptions - Options passed to {@link !AutoNumeric}. Same as {@link
34+
* AutoNumeric!Options}.
35+
* @returns The React component.
36+
*/
37+
export function AutoNumericInput({
38+
inputProps,
39+
autoNumericOptions,
40+
}: {
41+
inputProps?: InputProps;
42+
autoNumericOptions?: CallbackOptions;
43+
}): JSX.Element;
44+
45+
/** React {@link JSX!IntrinsicElements.input} component integrated with {@link !AutoNumeric} and
46+
* permits interaction with a React state.
47+
*
48+
* @param options - Options of the component.
49+
* @param options.inputProps - Options passed to {@link JSX!IntrinsicElements.input}. Same as {@link
50+
* JSX!IntrinsicElements.input.props}.
51+
* @param options.autoNumericOptions - Options passed to {@link !AutoNumeric}. Same as {@link
52+
* AutoNumeric!Options}.
53+
* @param options.valueState - The state from the parent component to be passed in.
54+
* @param options.valueStateSetter - The callback function that sets `options.valueState`.
55+
* @returns The React component.
56+
*/
57+
// eslint-disable-next-line @typescript-eslint/unified-signatures
58+
export function AutoNumericInput({
59+
inputProps,
60+
autoNumericOptions,
61+
valueState,
62+
valueStateSetter,
63+
}: {
64+
inputProps?: InputProps;
65+
autoNumericOptions?: CallbackOptions;
66+
valueState: string;
67+
valueStateSetter: React.Dispatch<React.SetStateAction<string>>;
68+
}): JSX.Element;
69+
2670
export function AutoNumericInput({
2771
inputProps,
2872
autoNumericOptions,
@@ -31,17 +75,13 @@ export function AutoNumericInput({
3175
}:
3276
| {
3377
inputProps?: InputProps;
34-
autoNumericOptions?: Parameters<
35-
typeof AutoNumericComponent
36-
>[0]["autoNumericOptions"];
78+
autoNumericOptions?: CallbackOptions;
3779
valueState: string;
3880
valueStateSetter: React.Dispatch<React.SetStateAction<string>>;
3981
}
4082
| {
4183
inputProps?: InputProps;
42-
autoNumericOptions?: Parameters<
43-
typeof AutoNumericComponent
44-
>[0]["autoNumericOptions"];
84+
autoNumericOptions?: CallbackOptions;
4585
valueState?: undefined;
4686
valueStateSetter?: undefined;
4787
}): JSX.Element {

typedoc.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,15 @@
1414
"sitemapBaseUrl": "https://react-autonumeric.8hob.io",
1515
"externalSymbolLinkMappings": {
1616
"global": {
17+
"AutoNumeric": "https://docs.autonumeric.org/Documentation/methods/",
1718
"typeof": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof"
19+
},
20+
"JSX": {
21+
"IntrinsicElements.input": "https://react.dev/reference/react-dom/components/input",
22+
"IntrinsicElements.input.props": "https://react.dev/reference/react-dom/components/input#props"
23+
},
24+
"AutoNumeric": {
25+
"Options": "https://docs.autonumeric.org/Documentation/configuration%20options/"
1826
}
1927
},
2028
"extraFooter": "&copy; 2024 <a href=\"https://8hob.io\">8 Hobbies, LLC</a>",

0 commit comments

Comments
 (0)