x-ui-design 1.0.29 → 1.0.30
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 +7 -3
- package/dist/esm/types/index.d.ts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.esm.js +10 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +10 -7
- package/dist/index.js.map +1 -1
- package/lib/components/Input/Input.tsx +19 -7
- package/package.json +1 -1
- package/src/app/page.tsx +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import React, {
|
|
4
|
+
ForwardedRef,
|
|
4
5
|
KeyboardEvent,
|
|
5
6
|
MouseEvent,
|
|
6
7
|
useEffect,
|
|
@@ -17,7 +18,15 @@ 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
|
+
type InputHandle = {
|
|
22
|
+
focus: () => void;
|
|
23
|
+
input: HTMLInputElement | null;
|
|
24
|
+
blur: () => void;
|
|
25
|
+
nativeElement: HTMLInputElement | null;
|
|
26
|
+
setSelectionRange: (start: number, end: number) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const InputComponent = React.forwardRef<InputHandle, InputProps>(({
|
|
21
30
|
size = 'large',
|
|
22
31
|
error,
|
|
23
32
|
suffix,
|
|
@@ -45,9 +54,8 @@ const InputComponent = ({
|
|
|
45
54
|
defaultValue,
|
|
46
55
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
47
56
|
child,
|
|
48
|
-
ref,
|
|
49
57
|
...props
|
|
50
|
-
}:
|
|
58
|
+
}, ref: ForwardedRef<InputHandle>) => {
|
|
51
59
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
52
60
|
const lastKeyPressed = useRef<string | null>(null);
|
|
53
61
|
const internalValue = mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : value ?? '';
|
|
@@ -56,16 +64,20 @@ const InputComponent = ({
|
|
|
56
64
|
const animationRef = useRef<number | null>(null);
|
|
57
65
|
|
|
58
66
|
useImperativeHandle(ref, () => ({
|
|
59
|
-
focus: () =>
|
|
60
|
-
|
|
67
|
+
focus: () => {
|
|
68
|
+
inputRef.current?.focus()
|
|
69
|
+
},
|
|
61
70
|
input: inputRef.current,
|
|
71
|
+
blur: () => {
|
|
72
|
+
inputRef.current?.blur()
|
|
73
|
+
},
|
|
62
74
|
nativeElement: inputRef.current,
|
|
63
75
|
setSelectionRange: (start: number, end: number) => {
|
|
64
76
|
if (inputRef.current) {
|
|
65
77
|
inputRef.current.setSelectionRange(start, end);
|
|
66
78
|
}
|
|
67
79
|
}
|
|
68
|
-
}));
|
|
80
|
+
}), []);
|
|
69
81
|
|
|
70
82
|
useEffect(() => {
|
|
71
83
|
setMaskValue(mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : (value ?? ''));
|
|
@@ -203,7 +215,7 @@ const InputComponent = ({
|
|
|
203
215
|
) : null}
|
|
204
216
|
</div>
|
|
205
217
|
);
|
|
206
|
-
};
|
|
218
|
+
});
|
|
207
219
|
|
|
208
220
|
InputComponent.displayName = 'Input';
|
|
209
221
|
|
package/package.json
CHANGED