@megha-ui/react 1.2.218 → 1.2.220
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.
|
@@ -7,6 +7,7 @@ interface DropdownOption {
|
|
|
7
7
|
isDelete?: boolean;
|
|
8
8
|
isAdd?: boolean;
|
|
9
9
|
onDelete?: () => void;
|
|
10
|
+
group?: string;
|
|
10
11
|
}
|
|
11
12
|
interface DropdownProps {
|
|
12
13
|
options: DropdownOption[];
|
|
@@ -55,6 +56,7 @@ interface DropdownProps {
|
|
|
55
56
|
withTooltip?: boolean;
|
|
56
57
|
isCreatable?: boolean;
|
|
57
58
|
onCreate?: (value: string) => void;
|
|
59
|
+
isGrouping?: boolean;
|
|
58
60
|
}
|
|
59
61
|
declare const Dropdown: React.FC<DropdownProps>;
|
|
60
62
|
export default Dropdown;
|
|
@@ -7,12 +7,13 @@ import Block from "../block";
|
|
|
7
7
|
import Text from "../text";
|
|
8
8
|
import Button from "../button";
|
|
9
9
|
import { HiChevronDown } from "react-icons/hi";
|
|
10
|
-
const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select...", isMultiple = false, isSelectAll = false, className, style, labelFontSize, labelFontWeight, labelMarginBottom, asteriskColor, label, disabled = false, width, searchEnabled = true, dropdownListWidth, marginBottom, marginTop, marginRight, marginLeft, required, dropdownListBG, searchBorderColor = "#2377ba", maxDropdownHeight = "12rem", border = "1px solid #dbdfe9", selectedCharLength = 0, menuFrom = "left", Tooltip, DropDownIcon, onMenuClose, isClear, ClearIcon, clearId, selectedDisplay, checkboxWrapper, isSort = true, onSelectChange, isLoading = false, onApplyChange, withTooltip = false, isCreatable = false, onCreate = () => { }, autoPosition = false, compactDisplay = false, ultraCompactDisplay = false, }) => {
|
|
10
|
+
const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select...", isMultiple = false, isSelectAll = false, className, style, labelFontSize, labelFontWeight, labelMarginBottom, asteriskColor, label, disabled = false, width, searchEnabled = true, dropdownListWidth, marginBottom, marginTop, marginRight, marginLeft, required, dropdownListBG, searchBorderColor = "#2377ba", maxDropdownHeight = "12rem", border = "1px solid #dbdfe9", selectedCharLength = 0, menuFrom = "left", Tooltip, DropDownIcon, onMenuClose, isClear, ClearIcon, clearId, selectedDisplay, checkboxWrapper, isSort = true, onSelectChange, isLoading = false, onApplyChange, withTooltip = false, isCreatable = false, onCreate = () => { }, autoPosition = false, compactDisplay = false, ultraCompactDisplay = false, isGrouping = false, }) => {
|
|
11
11
|
var _a, _b;
|
|
12
12
|
const { density } = useDensity();
|
|
13
13
|
const [isOpen, setIsOpen] = useState(false);
|
|
14
14
|
const [searchTerm, setSearchTerm] = useState("");
|
|
15
15
|
const [filteredOptions, setFilteredOptions] = useState(options);
|
|
16
|
+
const [groupedOptions, setGroupedOptions] = useState([]);
|
|
16
17
|
const wrapperRef = useRef(null);
|
|
17
18
|
const clearIconRef = useRef(null);
|
|
18
19
|
const searchInputRef = useRef(null);
|
|
@@ -145,8 +146,27 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
145
146
|
.sort((a, b) => (a.label > b.label ? 1 : -1))
|
|
146
147
|
.filter((option) => option.label.toLowerCase().includes(searchTerm.toLowerCase()))
|
|
147
148
|
: options.filter((option) => option.label.toLowerCase().includes(searchTerm.toLowerCase()));
|
|
148
|
-
|
|
149
|
-
|
|
149
|
+
const grouped = [];
|
|
150
|
+
if (isGrouping) {
|
|
151
|
+
const groups = options.map((opt) => opt.group);
|
|
152
|
+
if (groups.length > 0) {
|
|
153
|
+
groups.forEach((group) => {
|
|
154
|
+
if (group) {
|
|
155
|
+
const filteredOptions = options.filter((item) => item.group === group);
|
|
156
|
+
grouped.push({ groupedValue: group, options: filteredOptions });
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
grouped.push({
|
|
162
|
+
groupedValue: "",
|
|
163
|
+
options: [..._options],
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
setGroupedOptions(grouped);
|
|
167
|
+
}
|
|
168
|
+
setFilteredOptions(options);
|
|
169
|
+
}, [searchTerm, options, isSort, isGrouping]);
|
|
150
170
|
const handleSelect = (value, isDisabled) => {
|
|
151
171
|
if (isDisabled)
|
|
152
172
|
return;
|
|
@@ -314,7 +334,10 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
314
334
|
: placeholder }), _jsxs("div", { style: {
|
|
315
335
|
display: "flex",
|
|
316
336
|
alignItems: "center",
|
|
317
|
-
}, children: [isClear && (displayValue || selectedDisplay) && (_jsx("div", { style: { marginRight: "0.5rem" }, onClick: handleClear, id: clearId, title: "Click to clear the value", children: ClearIcon ? (ClearIcon) : (_jsx("span", { style: {
|
|
337
|
+
}, children: [isClear && (displayValue || selectedDisplay) && (_jsx("div", { style: { marginRight: "0.5rem" }, onClick: handleClear, id: clearId, title: "Click to clear the value", children: ClearIcon ? (ClearIcon) : (_jsx("span", { style: {
|
|
338
|
+
color: "var(--form-border-color, #dbdfe9)",
|
|
339
|
+
fontSize: "1rem",
|
|
340
|
+
}, children: "X" })) })), disabled ? (Tooltip && Tooltip) : DropDownIcon ? (DropDownIcon) : (_jsx(HiChevronDown, { fontSize: "1rem" })), withTooltip && Tooltip && Tooltip] })] }), _jsxs("ul", { style: Object.assign(Object.assign({ width: dropdownListWidth || "100%", position: "absolute", backgroundColor: dropdownListBG || "var(--dropdown-bg)", boxShadow: "0 4px 6px rgba(0, 0, 0, 0.1)", border: "1px solid var(--divider, #f5f5f5)", zIndex: 10, marginTop: 4, borderRadius: 4, overflow: "hidden" }, clickStyle), { display: !isOpen ? "none" : "" }), children: [searchEnabled && (_jsx("li", { style: { padding: "0.5rem" }, children: _jsx("input", { ref: searchInputRef, type: "text", placeholder: "Search...", value: searchTerm, onChange: (e) => setSearchTerm(e.target.value), disabled: disabled, style: {
|
|
318
341
|
width: "100%",
|
|
319
342
|
padding: "0.5rem",
|
|
320
343
|
boxSizing: "border-box",
|
|
@@ -337,7 +360,26 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
337
360
|
display: "flex",
|
|
338
361
|
alignItems: "start",
|
|
339
362
|
width: "100%",
|
|
340
|
-
}, children: _jsxs("span", { style: { marginLeft: "0.5rem" }, children: ["+ Create ", searchTerm] }) })] }, String(searchTerm))) : (
|
|
363
|
+
}, children: _jsxs("span", { style: { marginLeft: "0.5rem" }, children: ["+ Create ", searchTerm] }) })] }, String(searchTerm))) : groupedOptions.length > 0 ? (groupedOptions.map((groupOption, gIndex) => (_jsxs("div", { children: [_jsx("div", { children: groupOption.groupedValue }), groupOption.options.map((option, index) => (_jsxs("li", { ref: (el) => {
|
|
364
|
+
const refIndex = gIndex > 0 ? groupedOptions[gIndex - 1].options.length + index : index;
|
|
365
|
+
optionRefs.current[refIndex] = el;
|
|
366
|
+
}, onClick: (e) => onSelectChange
|
|
367
|
+
? handleItemSelect(option, option.disabled || false)
|
|
368
|
+
: handleSelect(option.value, option.disabled || false), style: Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, listItemStyle), { display: "flex", alignItems: "center" }), (index === highlightIndex ? listItemHoverStyle : {})), (option.disabled ? listItemDisabledStyle : {})), (index !== highlightIndex &&
|
|
369
|
+
!isMultiple &&
|
|
370
|
+
intermediateValues.includes(option.value)
|
|
371
|
+
? selectedItemStyle
|
|
372
|
+
: {})), { borderBottom: index === filteredOptions.length - 1
|
|
373
|
+
? "none"
|
|
374
|
+
: "1px solid var(--divider-strong, #dddddd)", wordWrap: "break-word", textWrap: "wrap", justifyContent: "space-between" }), onMouseEnter: (e) => {
|
|
375
|
+
if (!option.disabled) {
|
|
376
|
+
setHighlightIndex(index);
|
|
377
|
+
}
|
|
378
|
+
}, children: [isMultiple && (_jsx("div", { style: { marginRight: "0.5rem" }, children: _jsx(Checkbox, { selected: intermediateValues.includes(option.value), onChange: () => { }, style: { pointerEvents: "none" }, noLabel: true, wrapperClass: checkboxWrapper }) })), _jsxs("div", { style: {
|
|
379
|
+
display: "flex",
|
|
380
|
+
alignItems: "start",
|
|
381
|
+
width: "100%",
|
|
382
|
+
}, children: [option.icon && option.isDelete && !option.isDelete && (_jsx("span", { style: { margin: "0 0.5rem" }, children: option.icon })), _jsx("span", { children: option.label })] }), option.icon && option.isDelete && option.icon] }, String(option.value))))] })))) : (filteredOptions.map((option, index) => (_jsxs("li", { ref: (el) => {
|
|
341
383
|
optionRefs.current[index] = el;
|
|
342
384
|
}, onClick: (e) => onSelectChange
|
|
343
385
|
? handleItemSelect(option, option.disabled || false)
|
package/package.json
CHANGED