@@ -25,23 +25,6 @@ export type InputProps = Omit<
25
25
"ref"
26
26
> ;
27
27
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
28
/** React {@link JSX!IntrinsicElements.input} component integrated with {@link !AutoNumeric} and
46
29
* permits interaction with a React state.
47
30
*
@@ -50,48 +33,31 @@ export function AutoNumericInput({
50
33
* JSX!IntrinsicElements.input.props}.
51
34
* @param options.autoNumericOptions - Options passed to {@link !AutoNumeric}. Same as {@link
52
35
* 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`.
36
+ * @param options.valueState - The state and state setter from the parent component.
37
+ * @param options.valueState.state - The state from the parent component to be passed in.
38
+ * @param options.valueState.stateSetter - The callback function that sets
39
+ * `options.valueState.state`.
55
40
* @returns The React component.
56
41
*/
57
- // eslint-disable-next-line @typescript-eslint/unified-signatures
58
42
export function AutoNumericInput ( {
59
43
inputProps,
60
44
autoNumericOptions,
61
45
valueState,
62
- valueStateSetter,
63
46
} : {
64
47
inputProps ?: InputProps ;
65
48
autoNumericOptions ?: CallbackOptions ;
66
- valueState : string ;
67
- valueStateSetter : React . Dispatch < React . SetStateAction < string > > ;
68
- } ) : JSX . Element ;
69
-
70
- export function AutoNumericInput ( {
71
- inputProps,
72
- autoNumericOptions,
73
- valueState,
74
- valueStateSetter,
75
- } :
76
- | {
77
- inputProps ?: InputProps ;
78
- autoNumericOptions ?: CallbackOptions ;
79
- valueState : string ;
80
- valueStateSetter : React . Dispatch < React . SetStateAction < string > > ;
81
- }
82
- | {
83
- inputProps ?: InputProps ;
84
- autoNumericOptions ?: CallbackOptions ;
85
- valueState ?: undefined ;
86
- valueStateSetter ?: undefined ;
87
- } ) : JSX . Element {
49
+ valueState ?: {
50
+ state : string ;
51
+ stateSetter : React . Dispatch < React . SetStateAction < string > > ;
52
+ } ;
53
+ } ) : JSX . Element {
88
54
const stateProps =
89
55
valueState !== undefined
90
56
? {
91
- value : valueState ,
57
+ value : valueState . state ,
92
58
onChange : ( e : ChangeEvent < HTMLInputElement > ) : void => {
93
59
// For input, it is required set value in onChange.
94
- valueStateSetter ( e . currentTarget . value ) ;
60
+ valueState . stateSetter ( e . currentTarget . value ) ;
95
61
if ( inputProps ?. onChange !== undefined ) {
96
62
inputProps . onChange ( e ) ;
97
63
}
@@ -104,7 +70,7 @@ export function AutoNumericInput({
104
70
refKey = "ref"
105
71
props = { { ...inputProps , ...stateProps } }
106
72
autoNumericOptions = { autoNumericOptions }
107
- state = { valueState }
73
+ state = { valueState ?. state }
108
74
/>
109
75
) ;
110
76
}
0 commit comments