x-ui-design 1.0.22 → 1.0.23

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
+ 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
- export interface MyInputHandle {
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<HTMLInputElement | { focus: () => void; blur: () => void; input: HTMLInputElement | null; nativeElement: HTMLInputElement | null; setSelectionRange: (start: number, end: number) => void; }, InputProps>(({
29
22
  size = 'large',
30
23
  error,
31
24
  suffix,
@@ -49,13 +42,10 @@ const InputComponent = ({
49
42
  // @ts-expect-error
50
43
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
51
44
  __injected,
52
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
53
45
  defaultValue,
54
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
55
46
  child,
56
- ref,
57
47
  ...props
58
- }: InputProps) => {
48
+ }, ref) => {
59
49
  const inputRef = useRef<HTMLInputElement>(null);
60
50
  const lastKeyPressed = useRef<string | null>(null);
61
51
  const internalValue = mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : value ?? '';
@@ -63,25 +53,15 @@ const InputComponent = ({
63
53
  const [iconRenderVisible, setIconRenderVisible] = useState(false);
64
54
  const animationRef = useRef<number | null>(null);
65
55
 
66
- useImperativeHandle<HTMLInputElement, HTMLInputElement>(ref, () => {
67
- if (inputRef.current) {
68
- const input = inputRef.current;
69
-
70
- (input as any).setSelectionRangeCustom = (start: number, end: number) => {
71
- input.setSelectionRange(start, end);
72
- };
73
-
74
- (input as any).nativeElement = input;
75
-
76
- return input;
56
+ useImperativeHandle(ref, () => ({
57
+ focus: () => inputRef.current?.focus(),
58
+ blur: () => inputRef.current?.blur(),
59
+ input: inputRef.current,
60
+ nativeElement: inputRef.current,
61
+ setSelectionRange: (start: number, end: number) => {
62
+ inputRef.current?.setSelectionRange(start, end);
77
63
  }
78
-
79
- return {
80
- focus: () => inputRef.current?.focus(),
81
- blur: () => inputRef.current?.blur(),
82
- setSelectionRange: () => {},
83
- } as any;
84
- }, [inputRef]);
64
+ }), [inputRef]);
85
65
 
86
66
  useEffect(() => {
87
67
  setMaskValue(mask ? applyMask(stripMask(`${value ?? ''}`, mask, maskChar), mask, maskChar).masked : (value ?? ''));
@@ -219,7 +199,7 @@ const InputComponent = ({
219
199
  ) : null}
220
200
  </div>
221
201
  );
222
- };
202
+ });
223
203
 
224
204
  InputComponent.displayName = 'Input';
225
205
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-ui-design",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "license": "ISC",
5
5
  "author": "Gabriel Boyajyan",
6
6
  "main": "dist/index.js",
package/src/app/page.tsx CHANGED
@@ -13,6 +13,8 @@ export default function Home() {
13
13
 
14
14
  useEffect(() => {
15
15
  if (ref.current) {
16
+ console.log(ref.current);
17
+
16
18
  ref.current.focus();
17
19
  }
18
20
  }, [])