UNPKG

@trail-ui/react

Version:
198 lines (194 loc) 7.64 kB
"use strict"; 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/multiselect/tw-listbox.tsx var tw_listbox_exports = {}; __export(tw_listbox_exports, { DropdownItem: () => DropdownItem, DropdownSection: () => DropdownSection, ListBox: () => ListBox, ListBoxItem: () => ListBoxItem }); module.exports = __toCommonJS(tw_listbox_exports); var import_react = __toESM(require("react")); var import_react_aria_components2 = require("react-aria-components"); // src/multiselect/tw-utils.ts var import_react_aria_components = require("react-aria-components"); var import_tailwind_merge = require("tailwind-merge"); function composeTailwindRenderProps(className, tw) { return (0, import_react_aria_components.composeRenderProps)(className, (className2) => (0, import_tailwind_merge.twMerge)(tw, className2)); } // src/multiselect/tw-listbox.tsx var import_tailwind_merge2 = require("tailwind-merge"); var import_jsx_runtime = require("react/jsx-runtime"); function ListBox({ children, ...props }) { const ref = import_react.default.useRef(null); import_react.default.useEffect(() => { if (ref.current) { const selectedItem = ref.current.querySelector("[aria-selected=true]"); if (selectedItem) { const timer = setTimeout(() => { selectedItem.scrollIntoView({ block: "nearest", behavior: "smooth" }); }, 50); return () => { clearTimeout(timer); }; } } }, []); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_react_aria_components2.ListBox, { ...props, className: composeTailwindRenderProps(props.className, "outline-none"), ref, children } ); } function ListBoxItem(props) { const textValue = props.textValue || (typeof props.children === "string" ? props.children : void 0); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_react_aria_components2.ListBoxItem, { ...props, textValue, className: (0, import_react_aria_components2.composeRenderProps)( props.className, (className, { isDisabled, isFocusVisible }) => { return (0, import_tailwind_merge2.twMerge)( "group relative flex cursor-pointer border-l-[3px] border-transparent px-2 py-1.5 hover:border-purple-600 hover:bg-purple-50", isDisabled && "opacity-50", isFocusVisible && "border-l-[3px] border-purple-600 bg-purple-50", className ); } ), children: props.children } ); } function DropdownItem({ destructive, ...props }) { const textValue = props.textValue || (typeof props.children === "string" ? props.children : void 0); return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_react_aria_components2.ListBoxItem, { ...props, textValue, className: (0, import_react_aria_components2.composeRenderProps)(props.className, (className, { isDisabled, isFocused }) => { return (0, import_tailwind_merge2.twMerge)([ "group flex cursor-default select-none items-center gap-x-1 outline-none", "has-submenu:pe-0 px-1.5 py-2.5 sm:py-1.5", "text-base/6 sm:text-sm/6 [&:has(_[slot=description])_[slot=label]]:leading-5", "[&:not(:has([slot=description]))_[role=img]]:size-5", "[&:has([slot=description])_[role=img]]:size-7", "[&:has([slot=description])_[role=img]]:self-start", "[&:has([slot=description])_[role=img]]:mt-0.5", "[&:has([slot=description])_[role=img]]:me-0.5", isDisabled && "opacity-50", isFocused && "bg-hover", destructive && "text-destructive", className ]); }), children: (0, import_react_aria_components2.composeRenderProps)(props.children, (children, { isSelected }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: (0, import_tailwind_merge2.twMerge)("flex w-4 shrink-0 self-start", isSelected && "mt-[5px]"), children: isSelected && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Check, { className: "size-4" }) }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "span", { className: (0, import_tailwind_merge2.twMerge)( "flex min-w-0 flex-1 items-center gap-x-2", "[&>svg:not([class^=text-])]:text-muted", "[&>svg:not([class^=size-])]:size-4" ), children } ) ] })) } ); } function DropdownSection({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)( import_react_aria_components2.Section, { className: (0, import_tailwind_merge2.twMerge)( "[&:first-child]:-mt-[1px]", "[&:not(:first-child)]:my-1.5", "[&:not(:first-child)]:border-t-border/40 [&:not(:first-child)]:border-t", className ), children: [ /* @__PURE__ */ (0, import_jsx_runtime.jsx)( import_react_aria_components2.Header, { className: (0, import_tailwind_merge2.twMerge)( "bg-background text-muted sticky z-10 truncate px-2 pt-2 text-xs/4", "top-[0px] -mx-[1px] rounded-md backdrop-blur-md" ), children: props.title } ), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react_aria_components2.Collection, { items: props.items, children: props.children }) ] } ); } function Check(props) { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { "data-slot": "icon-internal", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 16 16", fill: "currentColor", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "path", { fillRule: "evenodd", d: "M12.416 3.376a.75.75 0 0 1 .208 1.04l-5 7.5a.75.75 0 0 1-1.154.114l-3-3a.75.75 0 0 1 1.06-1.06l2.353 2.353 4.493-6.74a.75.75 0 0 1 1.04-.207Z", clipRule: "evenodd" } ) } ); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { DropdownItem, DropdownSection, ListBox, ListBoxItem });