hi-tm 0.9.2 → 0.9.3
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.
- package/dist/components/AutoComplete/AutoComplete.d.ts +3 -3
- package/dist/components/AutoComplete/AutoComplete.js +32 -29
- package/dist/components/DropDowns/CreatableDropDown.js +43 -46
- package/dist/types/AutoComplete/AutoComplete.d.ts +3 -2
- package/dist/types/DropDown/CreatableDropDown.d.ts +0 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { AutoCompleteProps } from
|
|
3
|
-
declare const AutoComplete: ({ data, placeholder, value, label, type, disable, required, textError, iconSRC, isLoading, valueHandler, onChangeHandler, pageHandler, style }: AutoCompleteProps) => React.JSX.Element;
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { AutoCompleteProps } from "../../types/AutoComplete/AutoComplete";
|
|
3
|
+
declare const AutoComplete: ({ data, placeholder, value, label, type, disable, required, textError, iconSRC, isLoading, valueHandler, onChangeHandler, pageHandler, style, }: AutoCompleteProps) => React.JSX.Element;
|
|
4
4
|
export default AutoComplete;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
2
|
+
"use client";
|
|
3
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
4
4
|
if (k2 === undefined) k2 = k;
|
|
5
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -44,9 +44,9 @@ const PersonCard_1 = __importDefault(require("../Cards/AutoComplete&DropDown/Per
|
|
|
44
44
|
const GeographyCard_1 = __importDefault(require("../Cards/AutoComplete&DropDown/GeographyCard"));
|
|
45
45
|
const ItemCard_1 = __importDefault(require("../Cards/AutoComplete&DropDown/ItemCard"));
|
|
46
46
|
const SimpleCard_1 = __importDefault(require("../Cards/AutoComplete&DropDown/SimpleCard"));
|
|
47
|
-
const AutoComplete = ({ data, placeholder, value, label, type, disable, required, textError, iconSRC, isLoading, valueHandler, onChangeHandler, pageHandler, style }) => {
|
|
47
|
+
const AutoComplete = ({ data, placeholder, value, label, type, disable, required, textError, iconSRC, isLoading, valueHandler, onChangeHandler, pageHandler, style, }) => {
|
|
48
48
|
const [selectedItem, setSelectedItem] = (0, react_1.useState)(value || null);
|
|
49
|
-
const [searchTerm, setSearchTerm] = (0, react_1.useState)(
|
|
49
|
+
const [searchTerm, setSearchTerm] = (0, react_1.useState)("");
|
|
50
50
|
const inputRef = (0, react_1.useRef)(null);
|
|
51
51
|
const listRef = (0, react_1.useRef)(null);
|
|
52
52
|
const containerRef = (0, react_1.useRef)(null);
|
|
@@ -58,15 +58,15 @@ const AutoComplete = ({ data, placeholder, value, label, type, disable, required
|
|
|
58
58
|
};
|
|
59
59
|
const handleSelectItem = (item) => {
|
|
60
60
|
setSelectedItem(item);
|
|
61
|
-
setSearchTerm(
|
|
61
|
+
setSearchTerm("");
|
|
62
62
|
};
|
|
63
63
|
const handleRemoveItem = () => {
|
|
64
64
|
setSelectedItem(null);
|
|
65
|
-
setSearchTerm(
|
|
65
|
+
setSearchTerm("");
|
|
66
66
|
inputRef.current?.focus();
|
|
67
67
|
};
|
|
68
68
|
const showError = () => {
|
|
69
|
-
return textError ===
|
|
69
|
+
return textError === "" || textError === null || textError.trim() === "";
|
|
70
70
|
};
|
|
71
71
|
const handleScroll = () => {
|
|
72
72
|
if (!listRef.current)
|
|
@@ -91,42 +91,45 @@ const AutoComplete = ({ data, placeholder, value, label, type, disable, required
|
|
|
91
91
|
valueHandler(selectedItem);
|
|
92
92
|
}, [selectedItem]);
|
|
93
93
|
(0, react_1.useEffect)(() => {
|
|
94
|
-
if (value &&
|
|
94
|
+
if (value &&
|
|
95
|
+
(selectedItem?.id !== value.id || selectedItem?.content !== value.content)) {
|
|
95
96
|
setSelectedItem(value);
|
|
96
97
|
}
|
|
97
98
|
else if (!value && selectedItem) {
|
|
98
99
|
setSelectedItem(null);
|
|
99
100
|
}
|
|
100
101
|
}, [value]);
|
|
101
|
-
return (react_1.default.createElement("div", { className: `${style?.width ||
|
|
102
|
-
react_1.default.createElement("div", { className:
|
|
103
|
-
react_1.default.createElement("label", { htmlFor: label, className: `flex select-none flex-row items-center justify-start gap-1 pb-1 ${disable ?
|
|
104
|
-
react_1.default.createElement("p", { className:
|
|
105
|
-
required && react_1.default.createElement("span", { className: `text-red-primary ${required ?
|
|
106
|
-
react_1.default.createElement("div", { style: { borderRadius:
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
102
|
+
return (react_1.default.createElement("div", { className: `${style?.width || "w-96"} ${style?.margin || ""}`, ref: containerRef },
|
|
103
|
+
react_1.default.createElement("div", { className: "w-full relative" },
|
|
104
|
+
react_1.default.createElement("label", { htmlFor: label, className: `flex select-none flex-row items-center justify-start gap-1 pb-1 ${disable ? "cursor-default" : "cursor-pointer"}` },
|
|
105
|
+
react_1.default.createElement("p", { className: "text-nowrap text-sm font-medium text-text-color-primary" }, label),
|
|
106
|
+
required && (react_1.default.createElement("span", { className: `text-red-primary ${required ? "opacity-100" : "opacity-0"}` }, "*"))),
|
|
107
|
+
react_1.default.createElement("div", { style: { borderRadius: "8px" }, className: ` relative flex w-full flex-wrap items-center overflow-x-auto overflow-y-hidden border-2 ${textError && required
|
|
108
|
+
? "border-red-primary"
|
|
109
|
+
: "border-gray-tertiary"} bg-white-color px-1` }, selectedItem ? (react_1.default.createElement("div", { className: "flex h-9 w-full items-center justify-between rounded" },
|
|
110
|
+
react_1.default.createElement("span", { className: "w-[90%] truncate text-nowrap text-sm" }, selectedItem.content),
|
|
111
|
+
react_1.default.createElement("button", { type: "button", className: "ml-1 flex items-center justify-center", onClick: handleRemoveItem },
|
|
112
|
+
react_1.default.createElement(image_1.default, { src: iconSRC.deleteIconSRC, alt: "Remove", width: 24, height: 24 })))) : (react_1.default.createElement("input", { ref: inputRef, type: "text", className: "h-9 w-full bg-transparent px-1 outline-none", placeholder: placeholder, value: searchTerm, onChange: handleInputChange, disabled: disable }))),
|
|
113
|
+
searchTerm && !selectedItem && (react_1.default.createElement("ul", { ref: listRef, onScroll: handleScroll, className: "absolute left-0 right-0 mt-1 max-h-40 overflow-y-auto rounded border z-[1001] border-gray-tertiary bg-white-color px-1 py-2 shadow" },
|
|
111
114
|
isLoading ? (react_1.default.createElement("li", null, "\u062F\u0631 \u062D\u0627\u0644 \u062F\u0631\u06CC\u0627\u0641\u062A \u0627\u0637\u0644\u0627\u0639\u0627\u062A")) : (data?.map((item) => {
|
|
112
|
-
if (type ===
|
|
113
|
-
return react_1.default.createElement(CourierCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem });
|
|
115
|
+
if (type === "courier") {
|
|
116
|
+
return (react_1.default.createElement(CourierCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem }));
|
|
114
117
|
}
|
|
115
|
-
else if (type ===
|
|
116
|
-
return react_1.default.createElement(PersonCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem });
|
|
118
|
+
else if (type === "person") {
|
|
119
|
+
return (react_1.default.createElement(PersonCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem }));
|
|
117
120
|
}
|
|
118
|
-
else if (type ===
|
|
119
|
-
return react_1.default.createElement(ItemCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem });
|
|
121
|
+
else if (type === "item") {
|
|
122
|
+
return (react_1.default.createElement(ItemCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem }));
|
|
120
123
|
}
|
|
121
|
-
else if (type ===
|
|
122
|
-
return react_1.default.createElement(GeographyCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem });
|
|
124
|
+
else if (type === "geography") {
|
|
125
|
+
return (react_1.default.createElement(GeographyCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem }));
|
|
123
126
|
}
|
|
124
|
-
else if (type ===
|
|
125
|
-
return react_1.default.createElement(SimpleCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem });
|
|
127
|
+
else if (type === "simple") {
|
|
128
|
+
return (react_1.default.createElement(SimpleCard_1.default, { key: item.id, data: item, handleSelectItem: handleSelectItem }));
|
|
126
129
|
}
|
|
127
130
|
return null;
|
|
128
131
|
})),
|
|
129
|
-
data.length === 0 && react_1.default.createElement("li", { className:
|
|
130
|
-
react_1.default.createElement("span", { className: `mr-1 mt-2 text-nowrap text-sm font-normal text-red-primary ${showError() ?
|
|
132
|
+
data.length === 0 && (react_1.default.createElement("li", { className: "px-2 py-1 text-gray-500" }, "\u0645\u0648\u0631\u062F\u06CC \u06CC\u0627\u0641\u062A \u0646\u0634\u062F..."))))),
|
|
133
|
+
react_1.default.createElement("span", { className: `mr-1 mt-2 text-nowrap text-sm font-normal text-red-primary ${showError() ? "opacity-0" : "opacity-100"}` }, textError !== null && textError.trim())));
|
|
131
134
|
};
|
|
132
135
|
exports.default = AutoComplete;
|
|
@@ -41,7 +41,7 @@ const defaultStyles = {
|
|
|
41
41
|
trigger: 'flex items-center border rounded-md px-3 py-2 bg-white cursor-pointer',
|
|
42
42
|
input: 'w-full outline-none',
|
|
43
43
|
dropdown: 'absolute z-10 w-full mt-1 bg-white border border-gray-300 rounded-md shadow-lg max-h-60 overflow-y-auto',
|
|
44
|
-
option: 'py-2 px-3 cursor-pointer flex items-center
|
|
44
|
+
option: 'py-2 px-3 cursor-pointer flex items-center',
|
|
45
45
|
selectedOption: 'font-medium',
|
|
46
46
|
highlightedOption: 'bg-blue-100',
|
|
47
47
|
createOption: 'flex items-center gap-2 py-2 px-3 cursor-pointer hover:bg-blue-50',
|
|
@@ -50,34 +50,20 @@ const defaultStyles = {
|
|
|
50
50
|
noResults: 'py-4 px-3 text-gray-500 flex flex-col items-center justify-center gap-2',
|
|
51
51
|
clearButton: 'p-1 rounded-full hover:bg-gray-100',
|
|
52
52
|
icon: 'w-4 h-4 text-gray-400',
|
|
53
|
-
separator: 'h-4 border-l mx-2',
|
|
54
|
-
selectedOptionIcon: 'w-4 h-4 mr-2 text-blue-500 flex-shrink-0',
|
|
53
|
+
separator: 'h-4 border-l mx-2', // Style for the vertical line separator
|
|
55
54
|
};
|
|
56
55
|
// Helper function to render different icon types
|
|
57
56
|
const renderIcon = (icon, className = '') => {
|
|
58
|
-
if (react_1.default.isValidElement(icon)) {
|
|
59
|
-
// Check if the element can accept className
|
|
60
|
-
if ('props' in icon && typeof icon.props === 'object' && icon.props !== null) {
|
|
61
|
-
// Create a new object with existing props plus className
|
|
62
|
-
const props = {
|
|
63
|
-
...icon.props,
|
|
64
|
-
className: `${icon.props.className || ''} ${className}`.trim(),
|
|
65
|
-
};
|
|
66
|
-
// Return a new element with the updated props
|
|
67
|
-
return react_1.default.cloneElement(icon, props);
|
|
68
|
-
}
|
|
69
|
-
// If we can't add className, just return the element as-is
|
|
70
|
-
return icon;
|
|
71
|
-
}
|
|
72
57
|
if (typeof icon === 'string') {
|
|
73
|
-
return react_1.default.createElement("
|
|
58
|
+
return react_1.default.createElement("img", { src: icon || '/placeholder.svg', alt: "", className: className });
|
|
74
59
|
}
|
|
75
|
-
if (typeof icon === 'object' &&
|
|
60
|
+
else if (typeof icon === 'object' && 'src' in icon) {
|
|
76
61
|
const img = icon;
|
|
77
62
|
return react_1.default.createElement("img", { src: img.src || '/placeholder.svg', alt: img.alt || '', className: className });
|
|
78
63
|
}
|
|
79
|
-
|
|
80
|
-
|
|
64
|
+
else {
|
|
65
|
+
return icon;
|
|
66
|
+
}
|
|
81
67
|
};
|
|
82
68
|
// Helper function to render the no results message
|
|
83
69
|
const renderNoResults = (noResults, className, searchIcon) => {
|
|
@@ -89,7 +75,7 @@ const renderNoResults = (noResults, className, searchIcon) => {
|
|
|
89
75
|
if (typeof noResults === 'string') {
|
|
90
76
|
return react_1.default.createElement("div", { className: className }, noResults);
|
|
91
77
|
}
|
|
92
|
-
if (typeof noResults === 'object' && noResults && 'text' in noResults) {
|
|
78
|
+
else if (typeof noResults === 'object' && noResults && 'text' in noResults) {
|
|
93
79
|
const withText = noResults;
|
|
94
80
|
return (react_1.default.createElement("div", { className: className },
|
|
95
81
|
withText.icon
|
|
@@ -97,7 +83,9 @@ const renderNoResults = (noResults, className, searchIcon) => {
|
|
|
97
83
|
: renderIcon(searchIcon, 'w-6 h-6 mb-1'),
|
|
98
84
|
react_1.default.createElement("span", null, withText.text)));
|
|
99
85
|
}
|
|
100
|
-
|
|
86
|
+
else {
|
|
87
|
+
return noResults;
|
|
88
|
+
}
|
|
101
89
|
};
|
|
102
90
|
function CreatableSelect({ options = [], value, onChange, onClick, onValueChange, onCreateOption, placeholder = 'جستوجو', isLoading = false, isDisabled = false, isCreatable = true, isMultiSelect = false, noOptionsMessage = 'مقدار پیشفرضی وجود ندارد', noResultsFound, loadingMessage = 'در حال بارگذاری...', createOptionMessage = 'ایجاد ', className = '', tailwindStyle = {}, iconSrc = {}, fetchOptions, label, onAddClick, getOptionLabel, getOptionValue, }) {
|
|
103
91
|
// Default icons
|
|
@@ -113,21 +101,26 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
113
101
|
};
|
|
114
102
|
// Merge provided icons with defaults
|
|
115
103
|
const icons = { ...defaultIcons, ...iconSrc };
|
|
116
|
-
const styles = (0, react_1.useMemo)(() => ({
|
|
104
|
+
const styles = (0, react_1.useMemo)(() => ({
|
|
105
|
+
...defaultStyles,
|
|
106
|
+
...tailwindStyle,
|
|
107
|
+
}), [tailwindStyle]);
|
|
117
108
|
// Derivers for label/value to support arbitrary option shapes
|
|
118
109
|
const deriveLabel = (0, react_1.useCallback)((option) => {
|
|
119
110
|
if (getOptionLabel)
|
|
120
111
|
return getOptionLabel(option);
|
|
121
112
|
const anyOption = option;
|
|
122
113
|
const label = anyOption.label ?? anyOption.content ?? anyOption.value;
|
|
123
|
-
|
|
114
|
+
const result = String(label ?? '');
|
|
115
|
+
return result;
|
|
124
116
|
}, [getOptionLabel]);
|
|
125
117
|
const deriveValue = (0, react_1.useCallback)((option) => {
|
|
126
118
|
if (getOptionValue)
|
|
127
119
|
return getOptionValue(option);
|
|
128
120
|
const anyOption = option;
|
|
129
121
|
const base = anyOption.value ?? anyOption.label ?? anyOption.content;
|
|
130
|
-
|
|
122
|
+
const str = String(base ?? deriveLabel(option));
|
|
123
|
+
return str;
|
|
131
124
|
}, [getOptionValue, deriveLabel]);
|
|
132
125
|
const [isOpen, setIsOpen] = (0, react_1.useState)(false);
|
|
133
126
|
const [inputValue, setInputValue] = (0, react_1.useState)('');
|
|
@@ -138,10 +131,13 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
138
131
|
const [selectedValues, setSelectedValues] = (0, react_1.useState)([]);
|
|
139
132
|
const containerRef = (0, react_1.useRef)(null);
|
|
140
133
|
const inputRef = (0, react_1.useRef)(null);
|
|
141
|
-
// Sync external value with internal state
|
|
134
|
+
// Sync external value (ids or option objects) with internal selectedValues state
|
|
142
135
|
(0, react_1.useEffect)(() => {
|
|
143
|
-
if
|
|
136
|
+
// Uncontrolled mode: if value is undefined, do not override internal state
|
|
137
|
+
if (value === undefined) {
|
|
144
138
|
return;
|
|
139
|
+
}
|
|
140
|
+
// Explicit clear from parent
|
|
145
141
|
if (value === null) {
|
|
146
142
|
setSelectedValues([]);
|
|
147
143
|
return;
|
|
@@ -222,7 +218,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
222
218
|
setFilteredOptions(newOptions ?? []);
|
|
223
219
|
}
|
|
224
220
|
catch {
|
|
225
|
-
// Error handling
|
|
226
221
|
}
|
|
227
222
|
finally {
|
|
228
223
|
setInternalLoading(false);
|
|
@@ -284,6 +279,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
284
279
|
}
|
|
285
280
|
}, [isDisabled, isOpen, filteredOptions, highlightedIndex, isCreatable, inputValue, deriveLabel]);
|
|
286
281
|
const emitSelection = (0, react_1.useCallback)((next) => {
|
|
282
|
+
// Backward-compatible callback
|
|
287
283
|
if (onClick) {
|
|
288
284
|
onClick(isMultiSelect ? next ?? [] : next ? next[0] : null);
|
|
289
285
|
}
|
|
@@ -309,7 +305,6 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
309
305
|
setHasSearched(false);
|
|
310
306
|
}
|
|
311
307
|
catch {
|
|
312
|
-
// Error handling
|
|
313
308
|
}
|
|
314
309
|
finally {
|
|
315
310
|
setInternalLoading(false);
|
|
@@ -340,8 +335,10 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
340
335
|
}
|
|
341
336
|
setSelectedValues(next);
|
|
342
337
|
emitSelection(next);
|
|
338
|
+
// In multi-select mode, keep the input open and clear input for next search
|
|
343
339
|
setInputValue('');
|
|
344
340
|
setHasSearched(false);
|
|
341
|
+
// Don't close dropdown in multi-select mode
|
|
345
342
|
}
|
|
346
343
|
else {
|
|
347
344
|
const next = [option];
|
|
@@ -352,6 +349,7 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
352
349
|
setHasSearched(false);
|
|
353
350
|
}
|
|
354
351
|
}, [isMultiSelect, selectedValues, deriveValue, emitSelection]);
|
|
352
|
+
const showLoading = isLoading || internalLoading;
|
|
355
353
|
const handleAddIconClick = (0, react_1.useCallback)((e) => {
|
|
356
354
|
e.preventDefault();
|
|
357
355
|
e.stopPropagation();
|
|
@@ -368,37 +366,36 @@ function CreatableSelect({ options = [], value, onChange, onClick, onValueChange
|
|
|
368
366
|
}
|
|
369
367
|
}
|
|
370
368
|
}, [isDisabled, isOpen]);
|
|
371
|
-
const showLoading = isLoading || internalLoading;
|
|
372
|
-
// Helper function to check if an option is selected
|
|
373
|
-
const isOptionSelected = (0, react_1.useCallback)((option) => {
|
|
374
|
-
return selectedValues.some((val) => deriveValue(val) === deriveValue(option));
|
|
375
|
-
}, [selectedValues, deriveValue]);
|
|
376
369
|
return (react_1.default.createElement("div", { ref: containerRef, className: `relative w-full ${className} ${styles.container}`, onKeyDown: handleKeyDown },
|
|
377
370
|
label && react_1.default.createElement("label", { className: "block text-sm font-medium text-gray-700 mb-1" }, label),
|
|
378
371
|
react_1.default.createElement("div", { className: `${styles.trigger} ${isDisabled ? 'bg-gray-100 cursor-not-allowed' : ''} ${isOpen ? 'border-blue-500 ring-2 ring-blue-100' : 'border-gray-300'}`, onClick: handleTriggerClick },
|
|
379
372
|
react_1.default.createElement("div", { className: "flex-grow flex items-center overflow-x-auto no-scrollbar" },
|
|
380
373
|
react_1.default.createElement("div", { className: "flex items-center gap-2 flex-nowrap" },
|
|
381
|
-
selectedValues.
|
|
382
|
-
react_1.default.createElement("
|
|
383
|
-
|
|
374
|
+
selectedValues.length > 0 &&
|
|
375
|
+
selectedValues.map((val) => (react_1.default.createElement("div", { key: deriveValue(val), className: "flex-shrink-0 flex items-center bg-gray-200 rounded-md px-2 py-1" },
|
|
376
|
+
react_1.default.createElement("span", { className: "truncate" }, deriveLabel(val)),
|
|
377
|
+
react_1.default.createElement("button", { type: "button", onClick: (e) => clearValue(e, val), className: styles.clearButton }, renderIcon(icons.clear, styles.icon))))),
|
|
384
378
|
react_1.default.createElement("input", { ref: inputRef, type: "text", className: `${styles.input} ${isDisabled ? 'bg-gray-100' : ''} min-w-[80px] flex-shrink-0`, placeholder: selectedValues.length > 0 ? '' : placeholder, value: inputValue, onChange: handleInputChange, disabled: isDisabled, onClick: (e) => e.stopPropagation() }))),
|
|
385
379
|
react_1.default.createElement("div", { className: "flex-shrink-0 flex items-center gap-1 ml-2" },
|
|
386
380
|
iconSrc.hasAdd && (react_1.default.createElement("button", { type: "button", onClick: handleAddIconClick, className: styles.clearButton }, renderIcon(iconSrc.hasAdd, styles.icon))),
|
|
387
381
|
styles.separator && react_1.default.createElement("div", { className: styles.separator }),
|
|
388
382
|
react_1.default.createElement("button", { type: "button", onClick: toggleDropdown }, isOpen
|
|
389
|
-
? renderIcon(iconSrc.dropdownOpen, styles.icon)
|
|
383
|
+
? renderIcon(iconSrc.dropdownOpen, `${styles.icon} ${styles.spinAnimation || ''}`)
|
|
390
384
|
: renderIcon(iconSrc.dropdownClosed, styles.icon)))),
|
|
391
385
|
isOpen && (react_1.default.createElement("div", { className: styles.dropdown }, showLoading ? (react_1.default.createElement("div", { className: styles.loadingState },
|
|
392
386
|
renderIcon(iconSrc.loading, `animate-spin mr-2 ${styles.icon}`),
|
|
393
387
|
loadingMessage)) : (react_1.default.createElement(react_1.default.Fragment, null,
|
|
394
|
-
filteredOptions.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null, filteredOptions.map((option, index) => {
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
388
|
+
filteredOptions.length > 0 && (react_1.default.createElement(react_1.default.Fragment, null, filteredOptions.map((option, index) => (react_1.default.createElement("div", { key: deriveValue(option), className: `${styles.option} ${index === highlightedIndex ? styles.highlightedOption : 'hover:bg-gray-50'}`, onClick: () => selectOption(option), onMouseEnter: () => setHighlightedIndex(index) },
|
|
389
|
+
selectedValues.some((val) => deriveValue(val) === deriveValue(option)) &&
|
|
390
|
+
renderIcon(iconSrc.checkmark, 'w-4 h-4 mr-2 text-blue-500'),
|
|
391
|
+
react_1.default.createElement("span", { className: selectedValues.some((val) => deriveValue(val) === deriveValue(option))
|
|
392
|
+
? styles.selectedOption
|
|
393
|
+
: '' }, deriveLabel(option) || deriveValue(option))))))),
|
|
400
394
|
filteredOptions.length === 0 && !inputValue && (react_1.default.createElement("div", { className: styles.noOptions }, noOptionsMessage)),
|
|
401
|
-
filteredOptions.length === 0 &&
|
|
395
|
+
filteredOptions.length === 0 &&
|
|
396
|
+
inputValue &&
|
|
397
|
+
hasSearched &&
|
|
398
|
+
renderNoResults(noResultsFound, styles.noResults ?? '', iconSrc.create),
|
|
402
399
|
isCreatable &&
|
|
403
400
|
inputValue &&
|
|
404
401
|
!options?.some((o) => deriveLabel(o) === inputValue) && (react_1.default.createElement("div", { className: styles.createOption, onClick: handleCreateOption },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DataType } from
|
|
1
|
+
import { DataType } from "../Cards/AutoComplete&DropDown/CardsType";
|
|
2
2
|
export interface AutoCompleteProps {
|
|
3
3
|
data: DataType[];
|
|
4
4
|
placeholder: string;
|
|
@@ -7,7 +7,7 @@ export interface AutoCompleteProps {
|
|
|
7
7
|
required: boolean;
|
|
8
8
|
disable: boolean;
|
|
9
9
|
textError: string | null;
|
|
10
|
-
type:
|
|
10
|
+
type: "courier" | "person" | "item" | "geography" | "simple";
|
|
11
11
|
valueHandler: (value: DataType | null) => void;
|
|
12
12
|
onChangeHandler: (value: string) => void;
|
|
13
13
|
iconSRC: {
|
|
@@ -18,5 +18,6 @@ export interface AutoCompleteProps {
|
|
|
18
18
|
style?: {
|
|
19
19
|
width?: string;
|
|
20
20
|
margin?: string;
|
|
21
|
+
height?: string;
|
|
21
22
|
};
|
|
22
23
|
}
|