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.
@@ -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
- const InputComponent = ({
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
- }: InputProps) => {
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: () => inputRef.current?.focus(),
60
- blur: () => inputRef.current?.blur(),
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-ui-design",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "license": "ISC",
5
5
  "author": "Gabriel Boyajyan",
6
6
  "main": "dist/index.js",
package/src/app/page.tsx CHANGED
@@ -10,7 +10,7 @@ export default function Home() {
10
10
  if (ref.current) {
11
11
  console.log(ref.current);
12
12
 
13
- ref.current?.retry().focus();
13
+ ref.current?.focus();
14
14
  }
15
15
  }, [])
16
16