@vela-ui/react
Version:
Vela UI React components
99 lines (96 loc) • 3.03 kB
JavaScript
import {
CheckIcon
} from "./chunk-6SWBNV6A.mjs";
// src/components/dropdown.tsx
import {
ListBoxItem as AriaListBoxItem,
Text as AriaText,
Collection,
composeRenderProps,
Header,
ListBoxSection,
Separator
} from "react-aria-components";
import { twMerge } from "tailwind-merge";
import { tv } from "tailwind-variants";
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
var dropdownItemVariants = tv({
base: "relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[selection-mode]:pr-8 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
variants: {
variant: {
default: "",
destructive: "text-destructive *:[svg]:!text-destructive"
},
isFocused: {
true: "bg-accent text-accent-foreground"
},
isHovered: {
true: "bg-accent text-accent-foreground"
},
isDisabled: {
true: "pointer-events-none opacity-50"
}
},
compoundVariants: [
{
variant: "destructive",
isFocused: true,
className: "bg-destructive/10 dark:bg-destructive/20 text-destructive"
}
]
});
function DropdownSection({ className, ...props }) {
return /* @__PURE__ */ jsxs(ListBoxSection, { className, children: [
"title" in props && /* @__PURE__ */ jsx(Header, { className: "text-muted-foreground px-2 py-1.5 text-xs", children: props.title }),
/* @__PURE__ */ jsx(Collection, { items: props.items, children: props.children })
] });
}
function DropdownItem({ className, variant, ...props }) {
const textValue = props.textValue || (typeof props.children === "string" ? props.children : void 0);
return /* @__PURE__ */ jsx(
AriaListBoxItem,
{
textValue,
className: composeRenderProps(
className,
(className2, renderProps) => dropdownItemVariants({ ...renderProps, variant, className: className2 })
),
...props,
children: composeRenderProps(props.children, (children, { isSelected }) => /* @__PURE__ */ jsxs(Fragment, { children: [
isSelected && /* @__PURE__ */ jsx("span", { className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center", children: /* @__PURE__ */ jsx(CheckIcon, {}) }),
children
] }))
}
);
}
function DropdownLabel({ className, ...props }) {
return /* @__PURE__ */ jsx(AriaText, { slot: "label", className, ...props });
}
function DropdownDescription({ className, ...props }) {
return /* @__PURE__ */ jsx(
AriaText,
{
slot: "description",
className: twMerge("text-muted-foreground text-sm", className),
...props
}
);
}
function DropdownSeparator({ className, ...props }) {
return /* @__PURE__ */ jsx(
Separator,
{
orientation: "horizontal",
className: twMerge("bg-border -mx-1 my-1 h-px", className),
...props
}
);
}
export {
dropdownItemVariants,
DropdownSection,
DropdownItem,
DropdownLabel,
DropdownDescription,
DropdownSeparator
};