hi-tm 0.3.4 → 0.3.5

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,24 @@
1
1
  import React from 'react';
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
- declare const InputMultiselect: ({ label, required, textError, placeholder, onChangeHandler, autoComplete, value, autoFocus, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, inputRef, style, }: InputMultiselectProps) => React.JSX.Element;
2
+ interface InputMultiselectProps {
3
+ label: string;
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>;
21
24
  export default InputMultiselect;
@@ -39,38 +39,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
39
39
  Object.defineProperty(exports, "__esModule", { value: true });
40
40
  const react_1 = __importStar(require("react"));
41
41
  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
- const InputMultiselect = ({ label, required, textError, placeholder, onChangeHandler, autoComplete, value, autoFocus, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, inputRef, style = {
42
+ const InputMultiselect = ({ label, required = false, textError, placeholder, onChangeHandler, autoComplete = false, value, autoFocus = false, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, inputRef, style = {
60
43
  margin: 'mt-[-6px]',
61
44
  width: 'w-full',
62
- }, }) => {
45
+ }, onCurrentValueChange, }) => {
63
46
  const [items, setItems] = (0, react_1.useState)([]);
64
47
  const [currentValue, setCurrentValue] = (0, react_1.useState)('');
65
48
  const [showError, setShowError] = (0, react_1.useState)(false);
66
- const isErrorVisible = () => {
67
- return !(textError && textError.trim() !== '');
68
- };
69
49
  (0, react_1.useEffect)(() => {
70
50
  if (value && value.length > 0) {
71
51
  setItems(value);
72
52
  }
73
53
  }, [value]);
54
+ (0, react_1.useEffect)(() => {
55
+ if (onCurrentValueChange) {
56
+ onCurrentValueChange(currentValue);
57
+ }
58
+ }, [currentValue, onCurrentValueChange]);
74
59
  const handleChange = (e) => {
75
60
  setCurrentValue(e.target.value);
76
61
  };
@@ -79,13 +64,13 @@ const InputMultiselect = ({ label, required, textError, placeholder, onChangeHan
79
64
  e.preventDefault();
80
65
  setItems((prevItems) => [...prevItems, currentValue.trim()]);
81
66
  setCurrentValue('');
82
- setShowError(false); // Reset error on Enter
67
+ setShowError(false);
83
68
  }
84
69
  propHandleKeyDown?.(e);
85
70
  };
86
71
  const handleBlur = (e) => {
87
72
  if (currentValue.trim() !== '') {
88
- setShowError(true); // Show error if there's unconfirmed input
73
+ setShowError(true);
89
74
  }
90
75
  onBlurHandler?.(e);
91
76
  };
@@ -95,7 +80,10 @@ const InputMultiselect = ({ label, required, textError, placeholder, onChangeHan
95
80
  const handleRemoveItem = (index) => {
96
81
  setItems((prevItems) => prevItems.filter((_, i) => i !== index));
97
82
  };
98
- return (react_1.default.createElement("div", { className: `${style.width} ${style.margin} relative ` },
83
+ const isErrorVisible = () => {
84
+ return !(textError && textError.trim() !== '');
85
+ };
86
+ return (react_1.default.createElement("div", { className: `${style.width} ${style.margin} relative` },
99
87
  react_1.default.createElement("label", { htmlFor: label, className: "flex items-center gap-2 mx-3" },
100
88
  react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium cursor-pointer" }, label),
101
89
  react_1.default.createElement("span", { className: `text-red-primary font-bold ${required ? 'block' : 'hidden'}` }, "*")),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {