hi-tm 0.3.5 → 0.3.7
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,24 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
required?: boolean;
|
|
5
|
-
textError?: string;
|
|
6
|
-
placeholder: string;
|
|
7
|
-
onChangeHandler: (value: string[]) => void;
|
|
8
|
-
autoComplete?: boolean;
|
|
9
|
-
value: string[];
|
|
10
|
-
autoFocus?: boolean;
|
|
11
|
-
onFocusHandler?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
|
12
|
-
onKeyUpHandler?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
13
|
-
handleKeyDown?: (e: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
14
|
-
onBlurHandler?: (e: React.FocusEvent<HTMLInputElement>) => void;
|
|
15
|
-
closeIconSRC: string;
|
|
16
|
-
inputRef?: React.RefObject<HTMLInputElement>;
|
|
17
|
-
style?: {
|
|
18
|
-
margin?: string;
|
|
19
|
-
width?: string;
|
|
20
|
-
};
|
|
21
|
-
onCurrentValueChange?: (value: string) => void;
|
|
22
|
-
}
|
|
23
|
-
declare const InputMultiselect: React.FC<InputMultiselectProps>;
|
|
2
|
+
import { InputMultiselectProps } from '../../types/Inputs/InputMultiselectType';
|
|
3
|
+
declare const InputMultiselect: ({ label, required, textError, placeholder, onChangeHandler, autoComplete, value, autoFocus, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, inputRef, style, }: InputMultiselectProps) => React.JSX.Element;
|
|
24
4
|
export default InputMultiselect;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
// InputMultiselect.tsx
|
|
2
3
|
'use client';
|
|
3
4
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
5
|
if (k2 === undefined) k2 = k;
|
|
@@ -39,11 +40,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
39
40
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
41
|
const react_1 = __importStar(require("react"));
|
|
41
42
|
const image_1 = __importDefault(require("next/image"));
|
|
42
|
-
const InputMultiselect = ({ label, required
|
|
43
|
+
const InputMultiselect = ({ label, required, textError, placeholder, onChangeHandler, autoComplete, value, autoFocus, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, inputRef, style = {
|
|
43
44
|
margin: 'mt-[-6px]',
|
|
44
45
|
width: 'w-full',
|
|
45
|
-
},
|
|
46
|
-
const [items, setItems] = (0, react_1.useState)([]);
|
|
46
|
+
}, }) => {
|
|
47
|
+
const [items, setItems] = (0, react_1.useState)(value || []);
|
|
47
48
|
const [currentValue, setCurrentValue] = (0, react_1.useState)('');
|
|
48
49
|
const [showError, setShowError] = (0, react_1.useState)(false);
|
|
49
50
|
(0, react_1.useEffect)(() => {
|
|
@@ -51,13 +52,11 @@ const InputMultiselect = ({ label, required = false, textError, placeholder, onC
|
|
|
51
52
|
setItems(value);
|
|
52
53
|
}
|
|
53
54
|
}, [value]);
|
|
54
|
-
(0, react_1.useEffect)(() => {
|
|
55
|
-
if (onCurrentValueChange) {
|
|
56
|
-
onCurrentValueChange(currentValue);
|
|
57
|
-
}
|
|
58
|
-
}, [currentValue, onCurrentValueChange]);
|
|
59
55
|
const handleChange = (e) => {
|
|
60
56
|
setCurrentValue(e.target.value);
|
|
57
|
+
if (e.target.value.trim() !== '') {
|
|
58
|
+
setShowError(false);
|
|
59
|
+
}
|
|
61
60
|
};
|
|
62
61
|
const handleKeyDown = (e) => {
|
|
63
62
|
if (e.key === 'Enter' && currentValue.trim() !== '') {
|
|
@@ -72,28 +71,31 @@ const InputMultiselect = ({ label, required = false, textError, placeholder, onC
|
|
|
72
71
|
if (currentValue.trim() !== '') {
|
|
73
72
|
setShowError(true);
|
|
74
73
|
}
|
|
74
|
+
else {
|
|
75
|
+
setShowError(false);
|
|
76
|
+
}
|
|
75
77
|
onBlurHandler?.(e);
|
|
76
78
|
};
|
|
79
|
+
const handleFocus = (e) => {
|
|
80
|
+
setShowError(false);
|
|
81
|
+
onFocusHandler?.(e);
|
|
82
|
+
};
|
|
77
83
|
(0, react_1.useEffect)(() => {
|
|
78
84
|
onChangeHandler(items);
|
|
79
|
-
}, [items]);
|
|
85
|
+
}, [items, onChangeHandler]);
|
|
80
86
|
const handleRemoveItem = (index) => {
|
|
81
87
|
setItems((prevItems) => prevItems.filter((_, i) => i !== index));
|
|
82
88
|
};
|
|
83
|
-
const isErrorVisible = () => {
|
|
84
|
-
return !(textError && textError.trim() !== '');
|
|
85
|
-
};
|
|
86
89
|
return (react_1.default.createElement("div", { className: `${style.width} ${style.margin} relative` },
|
|
87
90
|
react_1.default.createElement("label", { htmlFor: label, className: "flex items-center gap-2 mx-3" },
|
|
88
91
|
react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium cursor-pointer" }, label),
|
|
89
92
|
react_1.default.createElement("span", { className: `text-red-primary font-bold ${required ? 'block' : 'hidden'}` }, "*")),
|
|
90
|
-
react_1.default.createElement("div", { className: `w-full h-10 flex gap-1 items-center justify-between bg-inherit outline-none border rounded-lg text-sm px-2 ${
|
|
91
|
-
? 'border-gray-tertiary focus:border-gray-quaternary'
|
|
92
|
-
: 'border-red-primary'}` },
|
|
93
|
+
react_1.default.createElement("div", { className: `w-full h-10 flex gap-1 items-center justify-between bg-inherit outline-none border rounded-lg text-sm px-2 ${!textError ? 'border-gray-tertiary focus:border-gray-quaternary' : 'border-red-primary'}` },
|
|
93
94
|
items.map((item, index) => (react_1.default.createElement("span", { key: index, className: "bg-gray-secondary text-text-color-primary px-2 py-1 rounded flex items-center justify-center gap-1" },
|
|
94
95
|
item,
|
|
95
96
|
react_1.default.createElement(image_1.default, { src: closeIconSRC, alt: "close", width: 22, height: 22, onClick: () => handleRemoveItem(index), className: "inline-block cursor-pointer" })))),
|
|
96
|
-
react_1.default.createElement("input", { ref: inputRef, type: "text", value: currentValue, id: label, placeholder: items.length === 0 ? placeholder : '', onChange: handleChange, autoComplete: autoComplete ? 'on' : 'off', autoFocus: autoFocus, className: "outline-none bg-inherit flex-grow", required: required, onFocus:
|
|
97
|
-
|
|
97
|
+
react_1.default.createElement("input", { ref: inputRef, type: "text", value: currentValue, id: label, placeholder: items.length === 0 ? placeholder : '', onChange: handleChange, autoComplete: autoComplete ? 'on' : 'off', autoFocus: autoFocus, className: "outline-none bg-inherit flex-grow", required: required, onFocus: handleFocus, onKeyUp: onKeyUpHandler, onKeyDown: handleKeyDown, onBlur: handleBlur })),
|
|
98
|
+
textError && react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError),
|
|
99
|
+
showError && !textError && (react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, "\u0628\u0631\u0627\u06CC \u062B\u0628\u062A \u0628\u0627\u0631\u06A9\u062F \u06A9\u0644\u06CC\u062F Enter \u0631\u0627 \u0641\u0634\u0627\u0631 \u062F\u0647\u06CC\u062F"))));
|
|
98
100
|
};
|
|
99
101
|
exports.default = InputMultiselect;
|
|
@@ -6,7 +6,7 @@ export interface InputMultiselectProps {
|
|
|
6
6
|
autoComplete: boolean;
|
|
7
7
|
autoFocus: boolean;
|
|
8
8
|
value: string[] | null;
|
|
9
|
-
onChangeHandler:
|
|
9
|
+
onChangeHandler: (value: string[]) => void;
|
|
10
10
|
onFocusHandler?: (event: React.FocusEvent) => void;
|
|
11
11
|
onKeyUpHandler?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|
|
12
12
|
handleKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
|