hi-tm 0.3.4 → 0.3.6

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,21 +1,4 @@
1
1
  import React from 'react';
2
2
  import { InputMultiselectProps } from '../../types/Inputs/InputMultiselectType';
3
- /**
4
- * @param {string} label - The label for the input field.
5
- * @param {boolean} required - Indicates whether the input is required.
6
- * @param {string | undefined} textError - The error message to display if validation fails.
7
- * @param {string} placeholder - The placeholder text for the input field.
8
- * @param {Function} onChangeHandler - Callback function triggered when the list of items changes.
9
- * @param {boolean} autoComplete - Specifies whether autocomplete is enabled for the input field.
10
- * @param {string[]} value - The initial list of selected items. => string[]
11
- * @param {boolean} autoFocus - Determines whether the input should autofocus on render.
12
- * @param {Function | undefined} onFocusHandler - Callback function triggered when the input gains focus.
13
- * @param {Function | undefined} onKeyUpHandler - Callback function triggered when a key is released while the input is focused.
14
- * @param {Function | undefined} handleKeyDown - Callback function triggered when a key is pressed while the input is focused.
15
- * @param {Function | undefined} onBlurHandler - Callback function triggered when the input loses focus.
16
- * @param {string} closeIconSRC - The source URL for the close icon image.
17
- * @param {React.RefObject<HTMLInputElement>} inputRef - Ref for the input element.
18
- * @param {string} [width=w-full] - The width of the input container, with a default value of 'w-full'.
19
- */
20
3
  declare const InputMultiselect: ({ label, required, textError, placeholder, onChangeHandler, autoComplete, value, autoFocus, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, inputRef, style, }: InputMultiselectProps) => React.JSX.Element;
21
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,33 +40,13 @@ 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
- /**
43
- * @param {string} label - The label for the input field.
44
- * @param {boolean} required - Indicates whether the input is required.
45
- * @param {string | undefined} textError - The error message to display if validation fails.
46
- * @param {string} placeholder - The placeholder text for the input field.
47
- * @param {Function} onChangeHandler - Callback function triggered when the list of items changes.
48
- * @param {boolean} autoComplete - Specifies whether autocomplete is enabled for the input field.
49
- * @param {string[]} value - The initial list of selected items. => string[]
50
- * @param {boolean} autoFocus - Determines whether the input should autofocus on render.
51
- * @param {Function | undefined} onFocusHandler - Callback function triggered when the input gains focus.
52
- * @param {Function | undefined} onKeyUpHandler - Callback function triggered when a key is released while the input is focused.
53
- * @param {Function | undefined} handleKeyDown - Callback function triggered when a key is pressed while the input is focused.
54
- * @param {Function | undefined} onBlurHandler - Callback function triggered when the input loses focus.
55
- * @param {string} closeIconSRC - The source URL for the close icon image.
56
- * @param {React.RefObject<HTMLInputElement>} inputRef - Ref for the input element.
57
- * @param {string} [width=w-full] - The width of the input container, with a default value of 'w-full'.
58
- */
59
43
  const InputMultiselect = ({ label, required, textError, placeholder, onChangeHandler, autoComplete, value, autoFocus, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, inputRef, style = {
60
44
  margin: 'mt-[-6px]',
61
45
  width: 'w-full',
62
46
  }, }) => {
63
- const [items, setItems] = (0, react_1.useState)([]);
47
+ const [items, setItems] = (0, react_1.useState)(value || []);
64
48
  const [currentValue, setCurrentValue] = (0, react_1.useState)('');
65
49
  const [showError, setShowError] = (0, react_1.useState)(false);
66
- const isErrorVisible = () => {
67
- return !(textError && textError.trim() !== '');
68
- };
69
50
  (0, react_1.useEffect)(() => {
70
51
  if (value && value.length > 0) {
71
52
  setItems(value);
@@ -73,39 +54,48 @@ const InputMultiselect = ({ label, required, textError, placeholder, onChangeHan
73
54
  }, [value]);
74
55
  const handleChange = (e) => {
75
56
  setCurrentValue(e.target.value);
57
+ if (e.target.value.trim() !== '') {
58
+ setShowError(false);
59
+ }
76
60
  };
77
61
  const handleKeyDown = (e) => {
78
62
  if (e.key === 'Enter' && currentValue.trim() !== '') {
79
63
  e.preventDefault();
80
64
  setItems((prevItems) => [...prevItems, currentValue.trim()]);
81
65
  setCurrentValue('');
82
- setShowError(false); // Reset error on Enter
66
+ setShowError(false);
83
67
  }
84
68
  propHandleKeyDown?.(e);
85
69
  };
86
70
  const handleBlur = (e) => {
87
71
  if (currentValue.trim() !== '') {
88
- setShowError(true); // Show error if there's unconfirmed input
72
+ setShowError(true);
73
+ }
74
+ else {
75
+ setShowError(false);
89
76
  }
90
77
  onBlurHandler?.(e);
91
78
  };
79
+ const handleFocus = (e) => {
80
+ setShowError(false);
81
+ onFocusHandler?.(e);
82
+ };
92
83
  (0, react_1.useEffect)(() => {
93
84
  onChangeHandler(items);
94
- }, [items]);
85
+ }, [items, onChangeHandler]);
95
86
  const handleRemoveItem = (index) => {
96
87
  setItems((prevItems) => prevItems.filter((_, i) => i !== index));
97
88
  };
98
- return (react_1.default.createElement("div", { className: `${style.width} ${style.margin} relative ` },
89
+ return (react_1.default.createElement("div", { className: `${style.width} ${style.margin} relative` },
99
90
  react_1.default.createElement("label", { htmlFor: label, className: "flex items-center gap-2 mx-3" },
100
91
  react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium cursor-pointer" }, label),
101
92
  react_1.default.createElement("span", { className: `text-red-primary font-bold ${required ? 'block' : 'hidden'}` }, "*")),
102
- 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 ${isErrorVisible()
103
- ? 'border-gray-tertiary focus:border-gray-quaternary'
104
- : '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'}` },
105
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" },
106
95
  item,
107
96
  react_1.default.createElement(image_1.default, { src: closeIconSRC, alt: "close", width: 22, height: 22, onClick: () => handleRemoveItem(index), className: "inline-block cursor-pointer" })))),
108
- 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: onFocusHandler, onKeyUp: onKeyUpHandler, onKeyDown: handleKeyDown, onBlur: handleBlur })),
109
- !isErrorVisible() && react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError?.trim())));
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"))));
110
100
  };
111
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: any;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {