hi-tm 0.3.3 → 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,20 +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 {string} [width=w-full] - The width of the input container, with a default value of 'w-full'.
18
- */
19
- declare const InputMultiselect: ({ label, required, textError, placeholder, onChangeHandler, autoComplete, value, autoFocus, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, 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>;
20
24
  export default InputMultiselect;
@@ -39,43 +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 {string} [width=w-full] - The width of the input container, with a default value of 'w-full'.
57
- */
58
- const InputMultiselect = ({ label, required, textError, placeholder, onChangeHandler, autoComplete, value, autoFocus, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, style = {
42
+ const InputMultiselect = ({ label, required = false, textError, placeholder, onChangeHandler, autoComplete = false, value, autoFocus = false, onFocusHandler, onKeyUpHandler, handleKeyDown: propHandleKeyDown, onBlurHandler, closeIconSRC, inputRef, style = {
59
43
  margin: 'mt-[-6px]',
60
44
  width: 'w-full',
61
- }, }) => {
45
+ }, onCurrentValueChange, }) => {
62
46
  const [items, setItems] = (0, react_1.useState)([]);
63
47
  const [currentValue, setCurrentValue] = (0, react_1.useState)('');
64
48
  const [showError, setShowError] = (0, react_1.useState)(false);
65
- const inputRef = (0, react_1.useRef)(null);
66
- const isErrorVisible = () => {
67
- return !(textError && textError.trim() !== '');
68
- };
69
- (0, react_1.useEffect)(() => {
70
- if (inputRef.current) {
71
- inputRef.current.value = currentValue;
72
- }
73
- }, [currentValue]);
74
49
  (0, react_1.useEffect)(() => {
75
50
  if (value && value.length > 0) {
76
51
  setItems(value);
77
52
  }
78
53
  }, [value]);
54
+ (0, react_1.useEffect)(() => {
55
+ if (onCurrentValueChange) {
56
+ onCurrentValueChange(currentValue);
57
+ }
58
+ }, [currentValue, onCurrentValueChange]);
79
59
  const handleChange = (e) => {
80
60
  setCurrentValue(e.target.value);
81
61
  };
@@ -84,13 +64,13 @@ const InputMultiselect = ({ label, required, textError, placeholder, onChangeHan
84
64
  e.preventDefault();
85
65
  setItems((prevItems) => [...prevItems, currentValue.trim()]);
86
66
  setCurrentValue('');
87
- setShowError(false); // Reset error on Enter
67
+ setShowError(false);
88
68
  }
89
69
  propHandleKeyDown?.(e);
90
70
  };
91
71
  const handleBlur = (e) => {
92
72
  if (currentValue.trim() !== '') {
93
- setShowError(true); // Show error if there's unconfirmed input
73
+ setShowError(true);
94
74
  }
95
75
  onBlurHandler?.(e);
96
76
  };
@@ -100,7 +80,10 @@ const InputMultiselect = ({ label, required, textError, placeholder, onChangeHan
100
80
  const handleRemoveItem = (index) => {
101
81
  setItems((prevItems) => prevItems.filter((_, i) => i !== index));
102
82
  };
103
- 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` },
104
87
  react_1.default.createElement("label", { htmlFor: label, className: "flex items-center gap-2 mx-3" },
105
88
  react_1.default.createElement("p", { className: "text-sm text-text-color-primary font-medium cursor-pointer" }, label),
106
89
  react_1.default.createElement("span", { className: `text-red-primary font-bold ${required ? 'block' : 'hidden'}` }, "*")),
@@ -110,7 +93,7 @@ const InputMultiselect = ({ label, required, textError, placeholder, onChangeHan
110
93
  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" },
111
94
  item,
112
95
  react_1.default.createElement(image_1.default, { src: closeIconSRC, alt: "close", width: 22, height: 22, onClick: () => handleRemoveItem(index), className: "inline-block cursor-pointer" })))),
113
- react_1.default.createElement("input", { ref: inputRef, type: "text", 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 })),
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: onFocusHandler, onKeyUp: onKeyUpHandler, onKeyDown: handleKeyDown, onBlur: handleBlur })),
114
97
  !isErrorVisible() && react_1.default.createElement("p", { className: "text-sm mt-1 text-red-primary" }, textError?.trim())));
115
98
  };
116
99
  exports.default = InputMultiselect;
@@ -12,6 +12,7 @@ export interface InputMultiselectProps {
12
12
  handleKeyDown?: (event: React.KeyboardEvent<HTMLInputElement>) => void;
13
13
  onBlurHandler?: (event: React.FocusEvent) => void;
14
14
  closeIconSRC: string;
15
+ inputRef?: React.RefObject<HTMLInputElement>;
15
16
  style?: {
16
17
  width?: string;
17
18
  margin?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hi-tm",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "styles": "dist/styles/globals.css",
5
5
  "main": "dist/index.js",
6
6
  "exports": {