UNPKG

@easy-shadcn/react

Version:

Use shadcn/ui easy&enhance like component library

218 lines (212 loc) 9.83 kB
'use strict'; var React = require('react'); var DropdownMenuPrimitive = require('@radix-ui/react-dropdown-menu'); var reactIcons = require('@radix-ui/react-icons'); var utils = require('@easy-shadcn/utils'); var jsxRuntime = require('react/jsx-runtime'); function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n.default = e; return Object.freeze(n); } var React__namespace = /*#__PURE__*/_interopNamespace(React); var DropdownMenuPrimitive__namespace = /*#__PURE__*/_interopNamespace(DropdownMenuPrimitive); var DropdownMenu = DropdownMenuPrimitive__namespace.Root; var DropdownMenuTrigger = DropdownMenuPrimitive__namespace.Trigger; var DropdownMenuGroup = DropdownMenuPrimitive__namespace.Group; var DropdownMenuPortal = DropdownMenuPrimitive__namespace.Portal; var DropdownMenuSub = DropdownMenuPrimitive__namespace.Sub; var DropdownMenuSubTrigger = React__namespace.forwardRef(({ className, inset, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs( DropdownMenuPrimitive__namespace.SubTrigger, { ref, className: utils.cn( "flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0", inset && "pl-8", className ), ...props, children: [ children, /* @__PURE__ */ jsxRuntime.jsx(reactIcons.ChevronRightIcon, { className: "ml-auto size-4" }) ] } )); DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive__namespace.SubTrigger.displayName; var DropdownMenuSubContent = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx( DropdownMenuPrimitive__namespace.SubContent, { ref, className: utils.cn( "z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className ), ...props } )); DropdownMenuSubContent.displayName = DropdownMenuPrimitive__namespace.SubContent.displayName; var DropdownMenuContent = React__namespace.forwardRef(({ className, sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx( DropdownMenuPrimitive__namespace.Content, { ref, sideOffset, className: utils.cn( "z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md", "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className ), ...props } ) })); DropdownMenuContent.displayName = DropdownMenuPrimitive__namespace.Content.displayName; var DropdownMenuItem = React__namespace.forwardRef(({ className, inset, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx( DropdownMenuPrimitive__namespace.Item, { ref, className: utils.cn( "relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", inset && "pl-8", className ), ...props } )); DropdownMenuItem.displayName = DropdownMenuPrimitive__namespace.Item.displayName; var DropdownMenuCheckboxItem = React__namespace.forwardRef(({ className, children, checked, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs( DropdownMenuPrimitive__namespace.CheckboxItem, { ref, className: utils.cn( "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className ), checked, ...props, children: [ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute left-2 flex size-3.5 items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.ItemIndicator, { children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.CheckIcon, { className: "size-4" }) }) }), children ] } )); DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive__namespace.CheckboxItem.displayName; var DropdownMenuRadioItem = React__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs( DropdownMenuPrimitive__namespace.RadioItem, { ref, className: utils.cn( "relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50", className ), ...props, children: [ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "absolute left-2 flex size-3.5 items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPrimitive__namespace.ItemIndicator, { children: /* @__PURE__ */ jsxRuntime.jsx(reactIcons.DotFilledIcon, { className: "size-4 fill-current" }) }) }), children ] } )); DropdownMenuRadioItem.displayName = DropdownMenuPrimitive__namespace.RadioItem.displayName; var DropdownMenuLabel = React__namespace.forwardRef(({ className, inset, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx( DropdownMenuPrimitive__namespace.Label, { ref, className: utils.cn( "px-2 py-1.5 text-sm font-semibold", inset && "pl-8", className ), ...props } )); DropdownMenuLabel.displayName = DropdownMenuPrimitive__namespace.Label.displayName; var DropdownMenuSeparator = React__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx( DropdownMenuPrimitive__namespace.Separator, { ref, className: utils.cn("-mx-1 my-1 h-px bg-muted", className), ...props } )); DropdownMenuSeparator.displayName = DropdownMenuPrimitive__namespace.Separator.displayName; var DropdownMenuShortcut = ({ className, ...props }) => { return /* @__PURE__ */ jsxRuntime.jsx( "span", { className: utils.cn("ml-auto text-xs tracking-widest opacity-60", className), ...props } ); }; DropdownMenuShortcut.displayName = "DropdownMenuShortcut"; var DropdownMenu2 = ({ children, menu, contentProps, ...resetProps }) => { const renderNormalItem = (item, idx) => { const { subItems, name, shortcut, prefix, key, ...resetProps2 } = item; if (subItems) { return renderSubItem(item, idx); } return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuItem, { ...resetProps2, children: [ prefix && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "mr-2", children: prefix }), name, shortcut && /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuShortcut, { children: shortcut }) ] }, key || idx); }; const renderSubItem = (menu2, idx) => { if (!menu2.subItems || menu2.subItems.length === 0) { return null; } return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenuSub, { children: [ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSubTrigger, { children: menu2.name }), /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuPortal, { children: /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSubContent, { children: renderMenuItem(menu2.subItems) }) }) ] }, menu2.key || idx); }; const renderGroupItem = (group, groupIdx, separatorConf) => { const { groupName, key, groupNameProps, items, ...resetProps2 } = group; return /* @__PURE__ */ jsxRuntime.jsxs(React.Fragment, { children: [ groupIdx !== 0 && /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}), groupName && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuLabel, { ...groupNameProps, children: groupName }), /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}) ] }), /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuGroup, { ...resetProps2, children: items.map((item, idx) => renderNormalItem(item, idx)) }), separatorConf.nextIsGroup == false && separatorConf.total !== groupIdx + 1 && /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuSeparator, {}) ] }, key || groupIdx); }; const renderMenuItem = (menu2) => { return menu2.map((item, idx) => { if ("name" in item) { return renderNormalItem(item, idx); } if ("items" in item) { return renderGroupItem(item, idx, { total: menu2.length, nextIsGroup: menu2[idx + 1] ? "items" in menu2[idx + 1] : false }); } return null; }); }; return /* @__PURE__ */ jsxRuntime.jsxs(DropdownMenu, { ...resetProps, children: [ /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuTrigger, { asChild: true, children }), /* @__PURE__ */ jsxRuntime.jsx(DropdownMenuContent, { ...contentProps, children: renderMenuItem(menu) }) ] }); }; exports.DropdownMenu = DropdownMenu2;