x-ui-design 1.0.22 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/types/components/Input/Input.d.ts +1 -11
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.esm.js +19 -19
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +18 -18
- package/dist/index.js.map +1 -1
- package/lib/components/Input/Input.tsx +19 -30
- package/package.json +1 -1
- package/src/app/page.tsx +2 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import React, {
|
|
4
|
+
forwardRef,
|
|
4
5
|
KeyboardEvent,
|
|
5
6
|
MouseEvent,
|
|
6
7
|
useEffect,
|
|
@@ -17,15 +18,7 @@ import { ErrorIcon } from '../Icons/Icons';
|
|
|
17
18
|
import { applyMask, MASK_CHAR, MASK_REGEX, stripMask } from '../../helpers/mask';
|
|
18
19
|
import './style.css';
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
focus: () => void;
|
|
22
|
-
blur: () => void;
|
|
23
|
-
input: HTMLInputElement | null;
|
|
24
|
-
nativeElement: HTMLInputElement | null;
|
|
25
|
-
setSelectionRange: (start: number, end: number) => void;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const InputComponent = ({
|
|
21
|
+
const InputComponent = forwardRef(({
|
|
29
22
|
size = 'large',
|
|
30
23
|
error,
|
|
31
24
|
suffix,
|
|
@@ -53,9 +46,8 @@ const InputComponent = ({
|
|
|
53
46
|
defaultValue,
|
|
54
47
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
55
48
|
child,
|
|
56
|
-
ref,
|
|
57
49
|
...props
|
|
58
|
-
}: InputProps) => {
|
|
50
|
+
}: InputProps, ref) => {
|
|
59
51
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
60
52
|
const lastKeyPressed = useRef<string | null>(null);
|
|
61
53
|
const internalValue = mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : value ?? '';
|
|
@@ -63,25 +55,22 @@ const InputComponent = ({
|
|
|
63
55
|
const [iconRenderVisible, setIconRenderVisible] = useState(false);
|
|
64
56
|
const animationRef = useRef<number | null>(null);
|
|
65
57
|
|
|
66
|
-
useImperativeHandle
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
58
|
+
useImperativeHandle(ref, () => ({
|
|
59
|
+
focus: () => {
|
|
60
|
+
console.info('focusing');
|
|
61
|
+
inputRef.current?.focus()
|
|
62
|
+
},
|
|
63
|
+
blur: () => {
|
|
64
|
+
inputRef.current?.blur()
|
|
65
|
+
},
|
|
66
|
+
input: inputRef.current,
|
|
67
|
+
nativeElement: inputRef.current,
|
|
68
|
+
setSelectionRange: (start: number, end: number) => {
|
|
69
|
+
if (inputRef.current) {
|
|
70
|
+
inputRef.current.setSelectionRange(start, end);
|
|
71
|
+
}
|
|
77
72
|
}
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
focus: () => inputRef.current?.focus(),
|
|
81
|
-
blur: () => inputRef.current?.blur(),
|
|
82
|
-
setSelectionRange: () => {},
|
|
83
|
-
} as any;
|
|
84
|
-
}, [inputRef]);
|
|
73
|
+
}), [ref]);
|
|
85
74
|
|
|
86
75
|
useEffect(() => {
|
|
87
76
|
setMaskValue(mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : (value ?? ''));
|
|
@@ -219,7 +208,7 @@ const InputComponent = ({
|
|
|
219
208
|
) : null}
|
|
220
209
|
</div>
|
|
221
210
|
);
|
|
222
|
-
};
|
|
211
|
+
});
|
|
223
212
|
|
|
224
213
|
InputComponent.displayName = 'Input';
|
|
225
214
|
|
package/package.json
CHANGED