@trail-ui/react
Version:
782 lines (775 loc) • 29.4 kB
JavaScript
;
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/select/customSelect.tsx
var customSelect_exports = {};
__export(customSelect_exports, {
default: () => customSelect_default
});
module.exports = __toCommonJS(customSelect_exports);
var import_theme = require("@trail-ui/theme");
var import_react4 = __toESM(require("react"));
var import_icons = require("@trail-ui/icons");
// src/overlay/overlay.tsx
var import_react = require("react");
var import_jsx_runtime = require("react/jsx-runtime");
var Positions = {
top: "top",
topLeft: "topLeft",
topRight: "topRight",
bottom: "bottom",
bottomLeft: "bottomLeft",
bottomRight: "bottomRight",
left: "left",
leftTop: "leftTop",
leftBottom: "leftBottom",
right: "right",
rightTop: "rightTop",
rightBottom: "rightBottom"
};
function Overlay(props) {
const [style, setStyle] = (0, import_react.useState)({
top: 0,
left: 0,
transform: "",
position: "fixed"
});
const overlayRef = (0, import_react.useRef)(null);
const getMaxHeight = () => {
var _a, _b, _c, _d, _e;
const refEl = props.referenceElement.current;
if (!refEl) {
return;
}
const refRect = refEl.getBoundingClientRect();
let maxAvailableHeight = 0;
const windowHeight = window.innerHeight;
switch (props.position) {
case Positions.bottom:
case Positions.bottomLeft:
case Positions.bottomRight:
maxAvailableHeight = windowHeight - refRect.bottom - (((_a = props.offset) == null ? void 0 : _a.y) || 0) * 2;
break;
case Positions.top:
case Positions.topLeft:
case Positions.topRight:
maxAvailableHeight = refRect.top - (((_b = props.offset) == null ? void 0 : _b.y) || 0) * 2;
break;
default:
return "100%";
}
if ((_c = props.style) == null ? void 0 : _c.maxHeight) {
maxAvailableHeight = maxAvailableHeight < ((_d = props.style) == null ? void 0 : _d.maxHeight) ? maxAvailableHeight : (_e = props.style) == null ? void 0 : _e.maxHeight;
}
return maxAvailableHeight;
};
const getMaxWidth = () => {
var _a, _b, _c, _d, _e;
const refEl = props.referenceElement.current;
if (!refEl) {
return;
}
const refRect = refEl.getBoundingClientRect();
let maxAvailableWidth = 0;
const windowWidth = window.innerWidth;
switch (props.position) {
case Positions.right:
case Positions.rightBottom:
case Positions.rightTop:
maxAvailableWidth = windowWidth - refRect.right - (((_a = props.offset) == null ? void 0 : _a.x) || 0) * 2;
break;
case Positions.left:
case Positions.leftBottom:
case Positions.leftTop:
maxAvailableWidth = refRect.left - (((_b = props.offset) == null ? void 0 : _b.x) || 0) * 2;
break;
default:
return null;
}
if ((_c = props.style) == null ? void 0 : _c.maxWidth) {
maxAvailableWidth = maxAvailableWidth < ((_d = props.style) == null ? void 0 : _d.maxWidth) ? maxAvailableWidth : (_e = props.style) == null ? void 0 : _e.maxWidth;
}
return maxAvailableWidth;
};
const getUpdatedPositions = () => {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
const refEl = props.referenceElement.current;
if (!refEl) {
return;
}
const refRect = refEl.getBoundingClientRect();
let top = 0;
let left = 0;
let transform = "";
switch (props.position) {
case Positions.top:
top = refRect.top - (((_a = props.offset) == null ? void 0 : _a.y) || 0);
left = refRect.left + refRect.width / 2;
transform = "translate(-50%, -100%)";
break;
case Positions.topLeft:
top = refRect.top - (((_b = props.offset) == null ? void 0 : _b.y) || 0);
left = refRect.left;
transform = "translateY(-100%)";
break;
case Positions.topRight:
top = refRect.top - (((_c = props.offset) == null ? void 0 : _c.y) || 0);
left = refRect.right;
transform = "translate(-100%, -100%)";
break;
case Positions.bottom:
top = refRect.bottom + (((_d = props.offset) == null ? void 0 : _d.y) || 0);
left = refRect.left + refRect.width / 2;
transform = "translateX(-50%)";
break;
case Positions.bottomLeft:
top = refRect.bottom + (((_e = props.offset) == null ? void 0 : _e.y) || 0);
left = refRect.left;
break;
case Positions.bottomRight:
top = refRect.bottom + (((_f = props.offset) == null ? void 0 : _f.y) || 0);
left = refRect.right;
transform = "translateX(-100%)";
break;
case Positions.left:
top = refRect.top + refRect.height / 2;
left = refRect.left - (((_g = props.offset) == null ? void 0 : _g.x) || 0);
transform = "translate(-100%,-50%)";
break;
case Positions.leftTop:
top = refRect.top;
left = refRect.left - (((_h = props.offset) == null ? void 0 : _h.x) || 0);
transform = "translateX(-100%)";
break;
case Positions.leftBottom:
top = refRect.bottom;
left = refRect.left - (((_i = props.offset) == null ? void 0 : _i.x) || 0);
transform = "translate(-100%, -100%)";
break;
case Positions.right:
top = refRect.top + refRect.height / 2;
left = refRect.right + (((_j = props.offset) == null ? void 0 : _j.x) || 0);
transform = "translateY(-50%)";
break;
case Positions.rightTop:
top = refRect.top;
left = refRect.right + (((_k = props.offset) == null ? void 0 : _k.x) || 0);
break;
case Positions.rightBottom:
top = refRect.bottom;
left = refRect.right + (((_l = props.offset) == null ? void 0 : _l.x) || 0);
transform = "translateY(-100%)";
break;
}
const maxHeight = getMaxHeight();
const maxWidth = getMaxWidth();
setStyle((prevState) => ({
...prevState,
top,
left,
transform,
width: refRect.width,
...maxHeight && { maxHeight },
...maxWidth && { maxWidth }
}));
};
(0, import_react.useLayoutEffect)(() => {
if (!props.referenceElement.current) {
return;
}
getUpdatedPositions();
const updatePositions = () => getUpdatedPositions();
const observer = new ResizeObserver(updatePositions);
if (props.referenceElement.current) {
observer.observe(props.referenceElement.current);
}
if (overlayRef.current) {
observer.observe(overlayRef.current);
}
window.addEventListener("resize", updatePositions);
window.addEventListener("scroll", updatePositions, true);
return () => {
observer.disconnect();
window.removeEventListener("resize", updatePositions);
window.removeEventListener("scroll", updatePositions, true);
};
}, [props.referenceElement.current]);
if ((0, import_react.isValidElement)(props.children)) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
props.onOverlayClick && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
"div",
{
role: "button",
className: "z-2 fixed left-[0] top-[0] h-[100vh] w-[100vw]",
onClick: props.onOverlayClick,
onKeyDown: props.onOverlayClick,
"aria-label": "Close dropdown",
tabIndex: -1
}
),
(0, import_react.cloneElement)(props.children, { style })
] });
} else {
return props.children;
}
}
// src/multiselect/tw-field.tsx
var import_react3 = __toESM(require("react"));
var import_react_aria_components = require("react-aria-components");
var import_tailwind_merge2 = require("tailwind-merge");
// src/multiselect/tw-text.tsx
var import_tailwind_merge = require("tailwind-merge");
var import_react2 = __toESM(require("react"));
var import_jsx_runtime2 = require("react/jsx-runtime");
function Text({ className, elementType, children, ...props }) {
return import_react2.default.createElement(
elementType != null ? elementType : "p",
{
...props,
className: (0, import_tailwind_merge.twMerge)("flex gap-1 pt-1.5 text-xs text-neutral-700", className)
},
children
);
}
// src/multiselect/tw-field.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
var LabeledGroup = import_react3.default.forwardRef(function(props, ref) {
const labelId = import_react3.default.useId();
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_aria_components.LabelContext.Provider, { value: { id: labelId, elementType: "span" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react_aria_components.GroupContext.Provider, { value: { "aria-labelledby": labelId }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components.Group,
{
...props,
ref,
className: (0, import_react_aria_components.composeRenderProps)(props.className, (className) => {
return (0, import_tailwind_merge2.twMerge)("relative flex flex-col", className);
})
}
) }) });
});
function Label({
requiredHint,
isDisabled,
...props
}) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components.Label,
{
...props,
"data-slot": "label",
className: (0, import_tailwind_merge2.twMerge)(
requiredHint && "after:ml-0.5 after:text-red-800 after:content-['*']",
isDisabled && "opacity-50",
props.className
)
}
);
}
var DescriptionContext = import_react3.default.createContext(null);
var InputFieldGroup = import_react3.default.forwardRef(
function InputFieldGroup2(props, ref) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components.Group,
{
...props,
"data-slot": "control",
ref,
className: (0, import_react_aria_components.composeRenderProps)(props.className, (className) => {
return (0, import_tailwind_merge2.twMerge)(
"group relative flex w-full items-center overflow-hidden rounded-md border bg-inherit shadow-sm",
"[&_svg]:text-muted",
"group-invalid:border-destructive",
// Disabled and readonly style
"[&:has(_[data-disabled=true])]:opacity-50",
"[&:has([readonly])]:opacity-50",
// Prevent double opacity
"[&:has(_[data-disabled=true])_[class*=opacity-]]:opacity-100",
"[&:has([readonly])_[class*=opacity-]]:opacity-100",
// Remove inside input/data-input border style
"[&_:is(input,[data-slot=control])]:border-none",
"[&_:is(input,[data-slot=control])]:shadow-none",
"[&_:is(input,[data-slot=control])]:ring-0",
className
);
})
}
);
}
);
var Input = import_react3.default.forwardRef(function Input2(props, ref) {
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
import_react_aria_components.Input,
{
...props,
ref,
className: (0, import_react_aria_components.composeRenderProps)(props.className, (className, { isDisabled, isInvalid }) => {
return (0, import_tailwind_merge2.twMerge)(
"flex w-full rounded-md border-none bg-inherit px-2 py-[5px] shadow-none outline-none",
"text-sm placeholder:text-neutral-600",
"[&[readonly]]:opacity-50",
isInvalid && "border-destructive",
isDisabled && "opacity-50",
className
);
})
}
);
});
// src/select/customSelect.tsx
var import_react_aria_components2 = require("react-aria-components");
var import_jsx_runtime4 = require("react/jsx-runtime");
var Keys = {
Backspace: "Backspace",
Clear: "Clear",
Down: "ArrowDown",
End: "End",
Enter: "Enter",
Escape: "Escape",
Home: "Home",
Left: "ArrowLeft",
PageDown: "PageDown",
PageUp: "PageUp",
Right: "ArrowRight",
Space: " ",
Tab: "Tab",
Up: "ArrowUp"
};
var MenuActions = {
Close: "Close",
CloseSelect: "CloseSelect",
First: "First",
Last: "Last",
Next: "Next",
Open: "Open",
Previous: "Previous",
Select: "Select",
Space: "Space",
Type: "Type"
};
function getActionFromKey(key, menuOpen) {
if (!menuOpen && key === Keys.Down)
return MenuActions.Open;
if (!menuOpen && key === Keys.Enter)
return MenuActions.Open;
if (key === Keys.Down)
return MenuActions.Next;
if (key === Keys.Up)
return MenuActions.Previous;
if (key === Keys.Home)
return MenuActions.First;
if (key === Keys.End)
return MenuActions.Last;
if (key === Keys.Escape)
return MenuActions.Close;
if (key === Keys.Enter)
return MenuActions.CloseSelect;
if (key === Keys.Backspace || key === Keys.Clear || key.length === 1)
return MenuActions.Type;
return void 0;
}
var CustomSelect = (0, import_react4.forwardRef)(
({
options,
label,
labelKey = "value",
valueKey = "id",
id = "select",
onChange,
onBlur,
defaultValue,
classNames,
errorMessage,
description,
errorIcon = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_icons.ErrorIcon,
{
className: "h-4 w-4 text-red-800 dark:text-red-600",
role: "img",
"aria-label": "Error",
"aria-hidden": false
}
),
errorId,
isRequired,
isDisabled,
isInvalid,
placeholder = "Select items",
value: selectedValue,
form,
name,
maxOptionsBeforeConversionToComboBox = 6,
isCombobox,
...otherprops
}, ref) => {
const [isOpen, setIsOpen] = (0, import_react4.useState)(false);
const [searchValue, setSearchValue] = (0, import_react4.useState)("");
const [activeIndex, setActiveIndex] = (0, import_react4.useState)(-1);
const [value, setValue] = (0, import_react4.useState)({ label: "", value: "" });
const listboxRef = (0, import_react4.useRef)(null);
const inputRef = (0, import_react4.useRef)(null);
const localRef = (0, import_react4.useRef)(null);
const buttonRef = (0, import_react4.useRef)(null);
const optionRefs = (0, import_react4.useRef)([]);
const hiddenInputRef = (0, import_react4.useRef)(null);
const refElementForOverlay = (0, import_react4.useRef)(null);
const slots = (0, import_react4.useMemo)(() => (0, import_theme.multiselect)(), []);
const isComponentCombobox = (0, import_react4.useMemo)(() => {
if (isCombobox !== void 0) {
return isCombobox;
} else {
return options.length > maxOptionsBeforeConversionToComboBox;
}
}, [isCombobox, options, maxOptionsBeforeConversionToComboBox]);
const getOptionLabel = (option) => {
if (typeof option === "string")
return option;
return option[labelKey] || option.label || "";
};
const getOptionValue = (option) => {
if (typeof option === "string")
return option;
return option[valueKey] || option.value || "";
};
const resetIndex = () => setActiveIndex(-1);
const filteredOptions = (0, import_react4.useMemo)(
() => options.filter((option) => {
return getOptionLabel(option).toString().toLowerCase().includes(searchValue.toLowerCase());
}),
[searchValue, options]
);
const toggleDropdown = () => setIsOpen((prevState) => !prevState);
const toggleItem = (option) => {
if (isDisabled)
return;
onChange(option.value);
setSearchValue("");
toggleDropdown();
if (inputRef.current) {
inputRef.current.focus();
inputRef.current.value = getOptionLabel(option);
}
if (buttonRef.current) {
buttonRef.current.focus();
}
if (hiddenInputRef.current) {
hiddenInputRef.current.value = getOptionLabel(option);
}
};
const handleInputChange = (e) => {
if (isDisabled)
return;
setSearchValue(e.target.value);
if (!isOpen)
toggleDropdown();
if (activeIndex === -1) {
setActiveIndex(0);
}
};
function getUpdatedIndex(current, action) {
switch (action) {
case MenuActions.First:
return 0;
case MenuActions.Last:
return filteredOptions.length;
case MenuActions.Previous:
return (activeIndex - 1 + filteredOptions.length) % filteredOptions.length;
case MenuActions.Next:
return (activeIndex + 1) % filteredOptions.length;
default:
return current;
}
}
const handleKeyDown = (e) => {
var _a, _b;
const action = getActionFromKey(e.key, isOpen);
if (isDisabled) {
e.preventDefault();
e.stopPropagation();
return;
}
if (e.key === Keys.Tab) {
if (isOpen) {
toggleDropdown();
resetIndex();
setSearchValue("");
}
return;
}
if (!action)
return;
if (MenuActions.Type !== action)
e.preventDefault();
switch (action) {
case MenuActions.Next:
case MenuActions.Last:
case MenuActions.First:
case MenuActions.Previous:
const nextIndex = getUpdatedIndex(activeIndex, action);
setActiveIndex(nextIndex);
(_a = optionRefs.current[nextIndex].current) == null ? void 0 : _a.focus();
break;
case MenuActions.Type:
if (inputRef.current)
inputRef.current.focus();
break;
case MenuActions.CloseSelect:
if (activeIndex >= 0) {
(_b = optionRefs.current[activeIndex].current) == null ? void 0 : _b.click();
}
break;
case MenuActions.Close:
handleOnClick({ detail: 1 });
setSearchValue("");
resetIndex();
break;
case MenuActions.Open:
handleOnClick({ detail: 1 });
break;
}
};
const handleOnClick = (e) => {
if (!isDisabled && (e == null ? void 0 : e.detail) === 1) {
toggleDropdown();
if (isOpen) {
resetIndex();
}
}
};
(0, import_react4.useEffect)(() => {
const handleClickOutside = (event) => {
if (localRef.current && !localRef.current.contains(event.target)) {
setIsOpen(false);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () => document.removeEventListener("mousedown", handleClickOutside);
}, []);
(0, import_react4.useEffect)(() => {
if (!ref)
return;
if (typeof ref === "function") {
ref(localRef.current);
} else {
ref.current = localRef.current;
}
}, [ref]);
(0, import_react4.useEffect)(() => {
const index = options.findIndex((item) => item.value === selectedValue);
setValue(index !== -1 ? options[index] : { label: "", value: "" });
}, [selectedValue, options]);
(0, import_react4.useEffect)(() => {
var _a;
if (isOpen) {
(_a = buttonRef.current) == null ? void 0 : _a.setAttribute("role", "combobox");
optionRefs.current = filteredOptions.map(
(_, i) => optionRefs.current[i] || import_react4.default.createRef()
);
if (filteredOptions.length > 1 && !isCombobox) {
setActiveIndex(0);
}
}
}, [isOpen]);
(0, import_react4.useEffect)(() => {
if (filteredOptions.length > 0) {
resetIndex();
}
}, [filteredOptions]);
(0, import_react4.useEffect)(() => {
var _a, _b;
if (isOpen && activeIndex >= 0) {
requestAnimationFrame(() => {
var _a2, _b2;
(_b2 = (_a2 = optionRefs.current[activeIndex]) == null ? void 0 : _a2.current) == null ? void 0 : _b2.scrollIntoView({ block: "nearest" });
});
}
if (isOpen)
(_a = buttonRef.current) == null ? void 0 : _a.setAttribute("aria-activedescendant", `${id}-option-${activeIndex}`);
else
(_b = buttonRef.current) == null ? void 0 : _b.removeAttribute("aria-activedescendant");
}, [activeIndex]);
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
"div",
{
ref: localRef,
className: "group relative flex w-full max-w-xs flex-col transition-opacity duration-200 data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 motion-reduce:transition-none",
children: [
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
Label,
{
id: `${id}-label`,
isDisabled,
requiredHint: isRequired,
className: slots.label({ class: classNames == null ? void 0 : classNames.label }),
children: label
}
),
/* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { ref: refElementForOverlay, className: "relative", children: [
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
"input",
{
ref: hiddenInputRef,
type: "hidden",
name,
value: getOptionValue(value),
form,
required: isRequired
}
),
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: slots.control({ class: classNames == null ? void 0 : classNames.control }), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "flex flex-1 items-center gap-2", children: [
isComponentCombobox ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
Input,
{
ref: inputRef,
autoComplete: "off",
"aria-autocomplete": "list",
"aria-labelledby": `${id}-label`,
onBlur,
className: slots.input({ class: classNames == null ? void 0 : classNames.input }),
onChange: handleInputChange,
onKeyDown: handleKeyDown,
onClick: handleOnClick,
placeholder: !getOptionValue(value) ? `${placeholder}` : "",
"aria-expanded": isOpen,
"aria-controls": isOpen ? "select-combobox" : void 0,
"aria-activedescendant": isOpen && activeIndex >= 0 ? `${id}-option-${activeIndex}` : void 0,
disabled: isDisabled,
required: isRequired && !getOptionValue(value) && !searchValue,
"aria-invalid": isInvalid,
"aria-required": isRequired,
role: "combobox",
"aria-describedby": errorId || "",
"aria-haspopup": "listbox",
...otherprops
}
) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_react_aria_components2.Button,
{
ref: buttonRef,
onKeyDown: handleKeyDown,
onClick: handleOnClick,
className: slots.input({ class: classNames == null ? void 0 : classNames.label }) + ` text-left`,
"aria-expanded": isOpen,
"aria-controls": isOpen ? "select-listbox" : void 0,
"aria-activedescendant": isOpen && activeIndex >= 0 ? `${id}-option-${activeIndex}` : void 0,
"aria-invalid": isInvalid,
"aria-required": isRequired,
"aria-describedby": errorId || "",
"aria-labelledby": `${id}-label`,
isDisabled,
"aria-haspopup": "listbox",
...otherprops,
children: getOptionLabel(value) || placeholder
}
),
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_icons.ChevronDownIcon,
{
height: 24,
width: 24,
onKeyDown: handleKeyDown,
onClick: (e) => {
var _a, _b;
handleOnClick(e);
(_a = inputRef.current) == null ? void 0 : _a.focus();
(_b = buttonRef.current) == null ? void 0 : _b.focus();
},
className: `${isOpen ? "rotate-180" : ""} cursor-pointer`
}
)
] }) }),
errorMessage ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
Text,
{
id: errorId,
slot: "errorMessage",
elementType: "div",
className: slots.errorMessage({
class: classNames == null ? void 0 : classNames.errorMessage
}),
children: [
errorIcon,
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: errorMessage })
]
}
) : description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
Text,
{
slot: "description",
elementType: "div",
className: slots.description({ class: classNames == null ? void 0 : classNames.description }),
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: description })
}
) : null
] }),
isOpen && filteredOptions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
Overlay,
{
referenceElement: refElementForOverlay,
position: Positions.bottom,
style: { maxHeight: 240 },
offset: { x: 8, y: 8 },
children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
"ul",
{
ref: listboxRef,
role: "listbox",
id: `select-${isComponentCombobox ? "combobox " : "listbox"}`,
"aria-label": label,
className: "absolute z-30 max-h-60 w-full overflow-auto rounded-md bg-neutral-50 py-2 text-base shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none",
children: filteredOptions.map((option, index) => {
const isActive = index === activeIndex;
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
"li",
{
ref: optionRefs.current[index],
role: "option",
id: `${id}-option-${index}`,
"aria-selected": getOptionValue(value) === getOptionValue(option),
tabIndex: isActive ? 0 : -1,
className: `relative flex cursor-pointer justify-between border-l-[3px] p-2 hover:bg-purple-50 focus:bg-purple-50 ${isActive ? "border-purple-600 bg-purple-50" : "border-transparent"} ${getOptionValue(value) === getOptionValue(option) ? "font-medium" : ""}`,
onClick: () => toggleItem(option),
onKeyDown: handleKeyDown,
onMouseEnter: () => setActiveIndex(index),
children: [
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: `block truncate text-sm text-neutral-900`, children: getOptionLabel(option) }),
getOptionValue(value) === getOptionValue(option) && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "flex items-center pl-1.5", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_icons.CheckIcon, { className: "h-5 w-5 text-purple-600" }) })
]
},
getOptionValue(option)
);
})
}
)
}
)
]
}
);
}
);
CustomSelect.displayName = "CustomSelectComponent";
var customSelect_default = CustomSelect;