@megha-ui/react 1.2.439 → 1.2.441
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.
|
@@ -13,6 +13,7 @@ interface DropdownProps {
|
|
|
13
13
|
options: DropdownOption[];
|
|
14
14
|
selectedValues: (string | number | any)[];
|
|
15
15
|
onChange: (values: (string | number)[]) => void;
|
|
16
|
+
closeOnSelect?: boolean;
|
|
16
17
|
placeholder?: string;
|
|
17
18
|
className?: string;
|
|
18
19
|
style?: React.CSSProperties;
|
|
@@ -58,6 +59,8 @@ interface DropdownProps {
|
|
|
58
59
|
isCreatable?: boolean;
|
|
59
60
|
onCreate?: (value: string) => void;
|
|
60
61
|
isGrouping?: boolean;
|
|
62
|
+
isIcon?: boolean;
|
|
63
|
+
withValue?: boolean;
|
|
61
64
|
}
|
|
62
65
|
declare const Dropdown: React.FC<DropdownProps>;
|
|
63
66
|
export default Dropdown;
|
|
@@ -8,7 +8,7 @@ import Text from "../text";
|
|
|
8
8
|
import Button from "../button";
|
|
9
9
|
import { HiChevronDown } from "react-icons/hi";
|
|
10
10
|
import { FaChevronDown, FaChevronUp } from "react-icons/fa";
|
|
11
|
-
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, onMenuOpen, 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
|
+
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, onMenuOpen, isClear, ClearIcon, clearId, selectedDisplay, checkboxWrapper, isSort = true, onSelectChange, isLoading = false, onApplyChange, withTooltip = false, isCreatable = false, onCreate = () => { }, autoPosition = false, compactDisplay = false, ultraCompactDisplay = false, isGrouping = false, isIcon = false, withValue = false, closeOnSelect = true, }) => {
|
|
12
12
|
var _a, _b;
|
|
13
13
|
const { density } = useDensity();
|
|
14
14
|
const [isOpen, setIsOpen] = useState(false);
|
|
@@ -182,7 +182,8 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
182
182
|
}
|
|
183
183
|
else {
|
|
184
184
|
onApplyChange ? setIntermediateValues([value]) : onChange([value]);
|
|
185
|
-
|
|
185
|
+
if (closeOnSelect)
|
|
186
|
+
setIsOpen(false);
|
|
186
187
|
}
|
|
187
188
|
};
|
|
188
189
|
const handleItemSelect = (item, isDisabled) => {
|
|
@@ -196,7 +197,8 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
196
197
|
}
|
|
197
198
|
else {
|
|
198
199
|
onSelectChange && onSelectChange([item]);
|
|
199
|
-
|
|
200
|
+
if (closeOnSelect)
|
|
201
|
+
setIsOpen(false);
|
|
200
202
|
}
|
|
201
203
|
};
|
|
202
204
|
const handleAllSelect = () => {
|
|
@@ -313,12 +315,12 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
313
315
|
return text;
|
|
314
316
|
};
|
|
315
317
|
return (_jsxs("div", { style: {
|
|
316
|
-
width: width !== null && width !== void 0 ? width : "100%",
|
|
318
|
+
width: width !== null && width !== void 0 ? width : (isIcon ? "max-content" : "100%"),
|
|
317
319
|
marginBottom,
|
|
318
320
|
marginTop,
|
|
319
321
|
marginRight,
|
|
320
322
|
marginLeft,
|
|
321
|
-
}, children: [label && (_jsxs("p", { style: labelStyle, children: [label, required && _jsx("span", { style: asteriskStyle, children: " *" })] })), _jsxs("div", { ref: wrapperRef, className: `${className}`, style: Object.assign({ border, borderRadius: 4, padding: "0 0.5rem", alignItems: "center", display: "flex", minHeight: `var(--control-min-height, ${ultraCompactDisplay
|
|
323
|
+
}, children: [label && (_jsxs("p", { style: labelStyle, children: [label, required && _jsx("span", { style: asteriskStyle, children: " *" })] })), _jsxs("div", { ref: wrapperRef, className: `${className}`, style: Object.assign(Object.assign(Object.assign({ border, borderRadius: 4 }, (isIcon ? { padding: "0 0.5rem" } : {})), { alignItems: "center", display: "flex", minHeight: `var(--control-min-height, ${ultraCompactDisplay
|
|
322
324
|
? "1.5rem"
|
|
323
325
|
: compactDisplay
|
|
324
326
|
? "2rem"
|
|
@@ -326,13 +328,19 @@ const Dropdown = ({ options, selectedValues, onChange, placeholder = "Select..."
|
|
|
326
328
|
? "1.5rem"
|
|
327
329
|
: density === "compact"
|
|
328
330
|
? "2rem"
|
|
329
|
-
: "2.5rem"})`, position: "relative" }, style), children: [_jsxs("div", { style: {
|
|
331
|
+
: "2.5rem"})`, position: "relative" }), style), children: [_jsxs("div", { style: {
|
|
330
332
|
display: "flex",
|
|
331
333
|
alignItems: "center",
|
|
332
334
|
justifyContent: "space-between",
|
|
333
335
|
cursor: "pointer",
|
|
334
336
|
width: "100%",
|
|
335
|
-
}, ref: clearIconRef, onClick: handleClick, children: [_jsx("span", {
|
|
337
|
+
}, ref: clearIconRef, onClick: handleClick, children: [_jsx("span", { style: {
|
|
338
|
+
display: isIcon
|
|
339
|
+
? withValue
|
|
340
|
+
? "inline-block"
|
|
341
|
+
: "none"
|
|
342
|
+
: "inline-block",
|
|
343
|
+
}, children: selectedDisplay
|
|
336
344
|
? selectedDisplay
|
|
337
345
|
: displayValue
|
|
338
346
|
? wrapMiddle(displayValue, selectedCharLength)
|
package/package.json
CHANGED