@trail-ui/react
Version:
279 lines (270 loc) • 11.1 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/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_react3 = __toESM(require("react"));
var import_react_aria_components3 = 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_merge3 = require("tailwind-merge");
// src/multiselect/tw-text.tsx
var import_tailwind_merge2 = require("tailwind-merge");
var import_react = __toESM(require("react"));
var import_jsx_runtime = require("react/jsx-runtime");
function Text({ className, elementType, children, ...props }) {
return import_react.default.createElement(
elementType != null ? elementType : "p",
{
...props,
className: (0, import_tailwind_merge2.twMerge)("flex gap-1 pt-1.5 text-xs text-neutral-700", className)
},
children
);
}
// src/multiselect/tw-listbox.tsx
var import_shared_utils2 = require("@trail-ui/shared-utils");
var import_theme2 = require("@trail-ui/theme");
// src/listbox/listbox.tsx
var import_shared_utils = require("@trail-ui/shared-utils");
var import_theme = require("@trail-ui/theme");
var import_react2 = require("react");
var import_react_aria_components2 = require("react-aria-components");
var import_jsx_runtime2 = require("react/jsx-runtime");
var InternalListBoxContext = (0, import_react2.createContext)(
{}
);
// src/listbox/listbox-selected-icon.tsx
var import_jsx_runtime3 = require("react/jsx-runtime");
function ListBoxSelectedIcon(props) {
const { isSelected, ...otherProps } = props;
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
"svg",
{
"aria-hidden": "true",
"data-selected": isSelected,
role: "presentation",
viewBox: "0 0 16 16",
...otherProps,
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
"polyline",
{
fill: "none",
points: "1 9 7 14 15 4",
stroke: "currentColor",
strokeDasharray: 22,
strokeDashoffset: isSelected ? 44 : 66,
strokeWidth: 2,
style: {
transition: "stroke-dashoffset 200ms ease"
}
}
)
}
);
}
// src/multiselect/tw-listbox.tsx
var import_jsx_runtime4 = require("react/jsx-runtime");
function ListBox({ children, ...props }) {
const ref = import_react3.default.useRef(null);
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_react_aria_components3.ListBox,
{
...props,
className: composeTailwindRenderProps(props.className, "outline-none"),
ref,
children
}
);
}
function ListBoxItem(props) {
const context = (0, import_react3.useContext)(InternalListBoxContext);
const {
children,
description,
startContent,
endContent,
selectedIcon,
className,
classNames = context.itemClasses,
...otherProps
} = props;
const baseStyles = (0, import_shared_utils2.clsx)(classNames == null ? void 0 : classNames.base, className);
const slots = (0, import_react3.useMemo)(() => (0, import_theme2.selectComboboxItem)(), []);
const textValue = props.textValue || (typeof props.children === "string" ? props.children : void 0);
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_react_aria_components3.ListBoxItem,
{
...otherProps,
textValue,
className: slots.base({ class: baseStyles }),
children: ({ isSelected, isDisabled, selectionMode }) => {
const selectedContent = () => {
const defaultIcon = /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ListBoxSelectedIcon, { isSelected });
if (typeof selectedIcon === "function") {
return selectedIcon({ icon: defaultIcon, isSelected, isDisabled });
}
if (selectedIcon)
return selectedIcon;
return defaultIcon;
};
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { "aria-selected": isSelected, className: "flex flex-1", children: [
startContent,
description ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: slots.wrapper({ class: classNames == null ? void 0 : classNames.wrapper }), children: [
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { slot: "label", className: slots.title({ class: classNames == null ? void 0 : classNames.title }), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children }) }),
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
Text,
{
slot: "description",
className: slots.description({ class: classNames == null ? void 0 : classNames.description }),
children: description
}
)
] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Text, { slot: "label", className: slots.title({ class: classNames == null ? void 0 : classNames.title }), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children }) }),
selectionMode !== "none" && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
"span",
{
"aria-hidden": "true",
className: slots.selectedIcon({ class: classNames == null ? void 0 : classNames.selectedIcon }),
children: selectedContent()
}
),
endContent
] });
}
}
);
}
function DropdownItem({ destructive, ...props }) {
const textValue = props.textValue || (typeof props.children === "string" ? props.children : void 0);
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
import_react_aria_components3.ListBoxItem,
{
...props,
textValue,
className: (0, import_react_aria_components3.composeRenderProps)(props.className, (className, { isDisabled, isFocused }) => {
return (0, import_tailwind_merge3.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_components3.composeRenderProps)(props.children, (children, { isSelected }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: (0, import_tailwind_merge3.twMerge)("flex w-4 shrink-0 self-start", isSelected && "mt-[5px]"), children: isSelected && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Check, { className: "size-4" }) }),
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
"span",
{
className: (0, import_tailwind_merge3.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_runtime4.jsxs)(
import_react_aria_components3.Section,
{
className: (0, import_tailwind_merge3.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_runtime4.jsx)(
import_react_aria_components3.Header,
{
className: (0, import_tailwind_merge3.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_runtime4.jsx)(import_react_aria_components3.Collection, { items: props.items, children: props.children })
]
}
);
}
function Check(props) {
return /* @__PURE__ */ (0, import_jsx_runtime4.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_runtime4.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
});