UNPKG

@vela-ui/react

Version:

Vela UI React components

303 lines (294 loc) 11.3 kB
"use strict"; "use client"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; 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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/components/menu.tsx var menu_exports = {}; __export(menu_exports, { Menu: () => Menu, MenuDescription: () => MenuDescription, MenuItem: () => MenuItem, MenuLabel: () => MenuLabel, MenuPopover: () => MenuPopover, MenuSection: () => MenuSection, MenuSeparator: () => MenuSeparator, MenuShortcut: () => MenuShortcut, MenuTrigger: () => MenuTrigger, SubmenuTrigger: () => import_react_aria_components4.SubmenuTrigger }); module.exports = __toCommonJS(menu_exports); var import_react_aria_components4 = require("react-aria-components"); // src/icons/check.tsx var import_jsx_runtime = require("react/jsx-runtime"); var CheckIcon = (props) => { return /* @__PURE__ */ (0, import_jsx_runtime.jsx)( "svg", { fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", width: "1em", height: "1em", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M20 6 9 17l-5-5" }) } ); }; // src/icons/chevron-right.tsx var import_jsx_runtime2 = require("react/jsx-runtime"); var ChevronRightIcon = (props) => { return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)( "svg", { fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", width: "1em", height: "1em", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m9 18 6-6-6-6" }) } ); }; // src/icons/circle.tsx var import_jsx_runtime3 = require("react/jsx-runtime"); var CircleIcon = (props) => { return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)( "svg", { fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", width: "1em", height: "1em", viewBox: "0 0 24 24", xmlns: "http://www.w3.org/2000/svg", ...props, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("circle", { cx: "12", cy: "12", r: "10" }) } ); }; // src/lib/utils.ts var import_clsx = require("clsx"); var import_react_aria_components = require("react-aria-components"); var import_tailwind_merge = require("tailwind-merge"); var cn = (...inputs) => (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(...inputs)); // src/components/dropdown.tsx var import_react_aria_components2 = require("react-aria-components"); var import_tailwind_merge2 = require("tailwind-merge"); var import_tailwind_variants = require("tailwind-variants"); var import_jsx_runtime4 = require("react/jsx-runtime"); var dropdownItemVariants = (0, import_tailwind_variants.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 DropdownLabel({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_react_aria_components2.Text, { slot: "label", className, ...props }); } function DropdownDescription({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( import_react_aria_components2.Text, { slot: "description", className: (0, import_tailwind_merge2.twMerge)("text-muted-foreground text-sm", className), ...props } ); } function DropdownSeparator({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)( import_react_aria_components2.Separator, { orientation: "horizontal", className: (0, import_tailwind_merge2.twMerge)("bg-border -mx-1 my-1 h-px", className), ...props } ); } // src/components/popover.tsx var import_react_aria_components3 = require("react-aria-components"); var import_tailwind_variants2 = require("tailwind-variants"); var import_jsx_runtime5 = require("react/jsx-runtime"); var popoverVariants = (0, import_tailwind_variants2.tv)({ base: "bg-popover text-popover-foreground z-50 rounded-md border shadow-md outline-hidden transition duration-200", variants: { isEntering: { true: [ "animate-in fade-in-0 zoom-in-95", "data-[placement=left]:slide-in-from-right-2 data-[placement=right]:slide-in-from-left-2 data-[placement=top]:slide-in-from-bottom-2 data-[placement=bottom]:slide-in-from-top-2" ] }, isExiting: { true: [ "animate-out fade-out-0 zoom-out-95", "data-[placement=left]:slide-out-to-right-2 data-[placement=right]:slide-out-to-left-2 data-[placement=top]:slide-out-to-bottom-2 data-[placement=bottom]:slide-out-to-top-2" ] } } }); var Popover = ({ className, showArrow, ...props }) => { const popoverContext = (0, import_react_aria_components3.useSlottedContext)(import_react_aria_components3.PopoverContext); const isSubmenu = (popoverContext == null ? void 0 : popoverContext.trigger) === "SubmenuTrigger"; let offset = showArrow ? 12 : 8; offset = isSubmenu ? offset - 6 : offset; return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( import_react_aria_components3.Popover, { "data-slot": "popover", offset, className: (0, import_react_aria_components3.composeRenderProps)( className, (className2, renderProps) => popoverVariants({ ...renderProps, className: className2 }) ), ...props, children: (0, import_react_aria_components3.composeRenderProps)(props.children, (children) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [ showArrow && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_react_aria_components3.OverlayArrow, { className: "group", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)( "svg", { width: 12, height: 12, viewBox: "0 0 12 12", className: "fill-popover stroke-border block stroke-1 group-data-[placement=bottom]:rotate-180 group-data-[placement=left]:-rotate-90 group-data-[placement=right]:rotate-90", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: "M0 0 L6 6 L12 0" }) } ) }), children ] })) } ); }; // src/components/menu.tsx var import_jsx_runtime6 = require("react/jsx-runtime"); var MenuTrigger = import_react_aria_components4.MenuTrigger; var MenuSeparator = DropdownSeparator; var MenuLabel = DropdownLabel; var MenuDescription = DropdownDescription; function MenuPopover({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)( Popover, { className: (0, import_react_aria_components4.composeRenderProps)(className, (className2) => cn("w-auto", className2)), ...props } ); } function Menu({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)( import_react_aria_components4.Menu, { className: (0, import_react_aria_components4.composeRenderProps)( className, (className2) => cn( "max-h-[inherit] min-w-[8rem] overflow-auto rounded-md p-1 outline-hidden [clip-path:inset(0_0_0_0_round_calc(var(--radius)-2px))]", className2 ) ), ...props } ); } function MenuItem({ className, children, variant, ...props }) { const textValue = props.textValue || (typeof children === "string" ? children : void 0); return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)( import_react_aria_components4.MenuItem, { className: (0, import_react_aria_components4.composeRenderProps)( className, (className2, renderProps) => dropdownItemVariants({ ...renderProps, variant, className: cn("data-[selection-mode]:pr-2 data-[selection-mode]:pl-8", className2, { "data-[open=true]:bg-accent data-[open=true]:text-accent-foreground": renderProps.hasSubmenu }) }) ), textValue, ...props, children: (values) => /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_jsx_runtime6.Fragment, { children: [ values.isSelected && /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: "pointer-events-none absolute left-2 flex size-4 items-center justify-center", children: [ values.selectionMode === "single" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CircleIcon, { className: "size-2 fill-current" }), values.selectionMode === "multiple" && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CheckIcon, { className: "size-4" }) ] }), typeof children === "function" ? children(values) : children, values.hasSubmenu && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(ChevronRightIcon, { className: "ml-auto size-4" }) ] }) } ); } function MenuSection({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(import_react_aria_components4.MenuSection, { className, ...props, children: [ "title" in props && /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_aria_components4.Header, { className: "px-2 py-1.5 text-sm font-medium", children: props.title }), /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_react_aria_components4.Collection, { items: props.items, children: props.children }) ] }); } function MenuShortcut({ className, ...props }) { return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)( import_react_aria_components4.Keyboard, { className: cn("text-muted-foreground ml-auto font-sans text-xs tracking-widest", className), ...props } ); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { Menu, MenuDescription, MenuItem, MenuLabel, MenuPopover, MenuSection, MenuSeparator, MenuShortcut, MenuTrigger, SubmenuTrigger });