@alice-ui/react
Version:
68 lines (65 loc) • 2.62 kB
JavaScript
import {
ListBoxSelectedIcon
} from "./chunk-3RNOB27D.mjs";
import {
InternalListBoxContext
} from "./chunk-7CNHZW6F.mjs";
// src/listbox/listbox-item.tsx
import { clsx } from "@alice-ui/shared-utils";
import { menuItem } from "@alice-ui/theme";
import { useContext, useMemo } from "react";
import { ListBoxItem as AriaListBoxItem, Text } from "react-aria-components";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
function ListBoxItem(props) {
const context = useContext(InternalListBoxContext);
const {
children,
description,
startContent,
endContent,
selectedIcon,
className,
classNames = context.itemClasses,
color = context.color,
variant = context.variant,
...otherProps
} = props;
const slots = useMemo(() => menuItem({ variant, color }), [color, variant]);
const baseStyles = clsx(classNames == null ? void 0 : classNames.base, className);
return /* @__PURE__ */ jsx(AriaListBoxItem, { ...otherProps, className: slots.base({ class: baseStyles }), children: ({ isSelected, isDisabled, selectionMode }) => {
const selectedContent = () => {
const defaultIcon = /* @__PURE__ */ jsx(ListBoxSelectedIcon, { isSelected });
if (typeof selectedIcon === "function") {
return selectedIcon({ icon: defaultIcon, isSelected, isDisabled });
}
if (selectedIcon) return selectedIcon;
return defaultIcon;
};
return /* @__PURE__ */ jsxs(Fragment, { children: [
startContent,
description ? /* @__PURE__ */ jsxs("div", { className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }), children: [
/* @__PURE__ */ jsx(Text, { slot: "label", className: slots.title({ class: classNames == null ? void 0 : classNames.title }), children: /* @__PURE__ */ jsx(Fragment, { children }) }),
/* @__PURE__ */ jsx(
Text,
{
slot: "description",
className: slots.description({ class: classNames == null ? void 0 : classNames.description }),
children: description
}
)
] }) : /* @__PURE__ */ jsx(Text, { slot: "label", className: slots.title({ class: classNames == null ? void 0 : classNames.title }), children: /* @__PURE__ */ jsx(Fragment, { children }) }),
selectionMode !== "none" && /* @__PURE__ */ jsx(
"span",
{
"aria-hidden": "true",
className: slots.selectedIcon({ class: classNames == null ? void 0 : classNames.selectedIcon }),
children: selectedContent()
}
),
endContent
] });
} });
}
export {
ListBoxItem
};