x-ui-design 1.0.28 → 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,18 +64,20 @@ const InputComponent = ({
56
64
  const animationRef = useRef<number | null>(null);
57
65
 
58
66
  useImperativeHandle(ref, () => ({
59
- retry: () => ({
60
- focus: () => inputRef.current?.focus(),
61
- blur: () => inputRef.current?.blur(),
62
- input: inputRef.current,
63
- nativeElement: inputRef.current,
64
- setSelectionRange: (start: number, end: number) => {
65
- if (inputRef.current) {
66
- inputRef.current.setSelectionRange(start, end);
67
- }
67
+ focus: () => {
68
+ inputRef.current?.focus()
69
+ },
70
+ input: inputRef.current,
71
+ blur: () => {
72
+ inputRef.current?.blur()
73
+ },
74
+ nativeElement: inputRef.current,
75
+ setSelectionRange: (start: number, end: number) => {
76
+ if (inputRef.current) {
77
+ inputRef.current.setSelectionRange(start, end);
68
78
  }
69
- })
70
- }));
79
+ }
80
+ }), []);
71
81
 
72
82
  useEffect(() => {
73
83
  setMaskValue(mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : (value ?? ''));
@@ -205,7 +215,7 @@ const InputComponent = ({
205
215
  ) : null}
206
216
  </div>
207
217
  );
208
- };
218
+ });
209
219
 
210
220
  InputComponent.displayName = 'Input';
211
221
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-ui-design",
3
- "version": "1.0.28",
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