@bioturing/components 0.26.2 → 0.28.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/checkbox/component.js.map +1 -1
- package/dist/components/choice-list/component.js +24 -21
- package/dist/components/choice-list/component.js.map +1 -1
- package/dist/components/cmdk/index.js.map +1 -1
- package/dist/components/combobox/component.js +202 -0
- package/dist/components/combobox/component.js.map +1 -0
- package/dist/components/combobox/style.css +1 -0
- package/dist/components/combobox/trigger.js +89 -0
- package/dist/components/combobox/trigger.js.map +1 -0
- package/dist/components/dropdown-menu/component.js +176 -162
- package/dist/components/dropdown-menu/component.js.map +1 -1
- package/dist/components/dropdown-menu/divider.js +16 -0
- package/dist/components/dropdown-menu/divider.js.map +1 -0
- package/dist/components/dropdown-menu/item.css +1 -0
- package/dist/components/dropdown-menu/item.js +131 -0
- package/dist/components/dropdown-menu/item.js.map +1 -0
- package/dist/components/dropdown-menu/style.css +1 -1
- package/dist/components/hooks/useDraggable.js +77 -0
- package/dist/components/hooks/useDraggable.js.map +1 -0
- package/dist/components/hooks/useHover.js +26 -0
- package/dist/components/hooks/useHover.js.map +1 -0
- package/dist/components/hooks/useTransitionStatus.js +52 -0
- package/dist/components/hooks/useTransitionStatus.js.map +1 -0
- package/dist/components/nav/item.js +2 -2
- package/dist/components/popup-panel/component.js +136 -169
- package/dist/components/popup-panel/component.js.map +1 -1
- package/dist/components/popup-panel/style.css +1 -1
- package/dist/components/resizable/component.js +239 -0
- package/dist/components/resizable/component.js.map +1 -0
- package/dist/components/resizable/style.css +1 -0
- package/dist/components/segmented/component.js +3 -3
- package/dist/components/segmented/component.js.map +1 -1
- package/dist/components/select/component.js +160 -91
- package/dist/components/select/component.js.map +1 -1
- package/dist/components/select/item.js +54 -0
- package/dist/components/select/item.js.map +1 -0
- package/dist/components/select/style.css +1 -1
- package/dist/components/spin/component.js +9 -8
- package/dist/components/spin/component.js.map +1 -1
- package/dist/components/splitter/splitter-panel.js +26 -43
- package/dist/components/splitter/splitter-panel.js.map +1 -1
- package/dist/components/splitter/splitter.js +99 -98
- package/dist/components/splitter/splitter.js.map +1 -1
- package/dist/components/splitter/useSizes.js +86 -0
- package/dist/components/splitter/useSizes.js.map +1 -0
- package/dist/components/stack/StackChild.js +9 -9
- package/dist/components/transition/component.js +1 -1
- package/dist/components/transition/component.js.map +1 -1
- package/dist/components/upload/dragger.js +19 -10
- package/dist/components/upload/dragger.js.map +1 -1
- package/dist/components/upload/item.js +21 -18
- package/dist/components/upload/item.js.map +1 -1
- package/dist/components/utils/antdUtils.js +18 -56
- package/dist/components/utils/antdUtils.js.map +1 -1
- package/dist/components/utils/placement.js +58 -0
- package/dist/components/utils/placement.js.map +1 -0
- package/dist/components/utils/reactElement.js +5 -0
- package/dist/components/utils/reactElement.js.map +1 -0
- package/dist/index.d.ts +478 -20
- package/dist/index.js +205 -189
- package/dist/index.js.map +1 -1
- package/dist/metadata.js +39 -5
- package/dist/metadata.js.map +1 -1
- package/package.json +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../../src/components/dropdown-menu/component.tsx"],"sourcesContent":["\"use client\";\nimport { Menu } from \"@base-ui-components/react/menu\";\nimport { useControlled } from \"@base-ui-components/react/utils\";\nimport { Popover } from \"@base-ui-components/react/popover\";\nimport { type PopoverProps } from \"antd/es/popover\";\nimport { Ref, useCallback, useRef } from \"react\";\nimport {\n clsx,\n DROPDOWN_COLLISION_AVOIDANCE,\n parseAntdPlacement,\n useAntdCssVarClassname,\n useCls,\n} from \"../utils\";\nimport { Command } from \"../cmdk\";\nimport { ScrollArea } from \"../scroll-area\";\n\n// Import component-specific styles\nimport { Input } from \"../input\";\nimport { PopupPanelSize } from \"../popup-panel/constants\";\n\nimport \"./style.css\";\n\nexport type DropdownMenuItemType =\n | {\n type: \"item\";\n label?: React.ReactNode;\n disabled?: boolean;\n icon?: React.ReactNode;\n key: React.Key;\n onClick?: React.HTMLAttributes<HTMLElement>[\"onClick\"];\n onMouseEnter?: React.HTMLAttributes<HTMLElement>[\"onMouseEnter\"];\n onMouseLeave?: React.HTMLAttributes<HTMLElement>[\"onMouseLeave\"];\n onMouseOver?: React.HTMLAttributes<HTMLElement>[\"onMouseOver\"];\n onMouseOut?: React.HTMLAttributes<HTMLElement>[\"onMouseOut\"];\n danger?: boolean;\n ref?: React.Ref<HTMLElement>;\n }\n | {\n type: \"divider\";\n }\n | {\n type: \"header\";\n title?: React.ReactNode;\n };\n\nexport interface DropdownMenuProps {\n /** Array of menu items to be displayed in the dropdown */\n items: DropdownMenuItemType[];\n /** Custom render function for the trigger element */\n children?: React.ComponentProps<typeof Menu.Trigger>[\"render\"];\n /**\n * Placement of the dropdown relative to the trigger element\n * @default \"bottomLeft\"\n */\n placement?: PopoverProps[\"placement\"];\n /**\n * Whether to open the dropdown on hover instead of click\n * @default false\n */\n openOnHover?: boolean;\n /**\n * Controlled open state of the dropdown\n */\n open?: boolean;\n /**\n * Callback fired when the dropdown open state changes\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * Additional CSS class for the dropdown component\n */\n className?: string;\n /**\n * Custom class names for different parts of the dropdown\n * @default {}\n */\n classNames?: {\n root?: string;\n trigger?: string;\n popup?: string;\n group?: string;\n groupLabel?: string;\n item?: string;\n itemIcon?: string;\n itemText?: string;\n separator?: string;\n positioner?: string;\n };\n /**\n * Custom render function for menu items\n */\n itemRender?: (\n item: DropdownMenuItemType,\n props: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n /**\n * Whether to show search input\n * @default false\n */\n showSearch?: boolean;\n /**\n * Size of the dropdown menu\n * @default \"auto\"\n */\n size?: \"auto\" | keyof typeof PopupPanelSize;\n /**\n * Search placeholder\n */\n searchProps?: Omit<\n React.ComponentProps<typeof Command.Input>,\n \"size\" | \"ref\"\n >;\n /**\n *\n */\n}\n\ninterface DropdownMenuGroup {\n label: React.ReactNode | null;\n items: DropdownMenuItemType[];\n}\n\nexport const DropdownMenu = ({\n children,\n items,\n placement,\n openOnHover,\n open: outsideOpen,\n onOpenChange: outsideOnOpenChange,\n className,\n itemRender,\n classNames,\n size = \"auto\",\n showSearch,\n searchProps = {\n placeholder: \"Search...\",\n },\n}: DropdownMenuProps) => {\n const [open, setOpen] = useControlled({\n controlled: outsideOpen,\n default: false,\n name: \"open\",\n });\n const onOpenChange = useCallback(\n (newValue: boolean) => {\n setOpen(newValue);\n outsideOnOpenChange?.(newValue);\n },\n [setOpen, outsideOnOpenChange]\n );\n const cls = useCls();\n const antdCssVarClassname = useAntdCssVarClassname();\n const headlessUIPlacement = parseAntdPlacement(placement);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const itemGroups = items.reduce<DropdownMenuGroup[]>((acc, current) => {\n // If no groups exist yet and current item is not a header, create default group\n if (acc.length === 0 && current.type !== \"header\") {\n acc.push({\n label: null,\n items: [],\n });\n }\n\n // If it's a header, create a new group\n if (current.type === \"header\") {\n acc.push({\n label: current.title,\n items: [],\n });\n }\n // If it's an item and we have at least one group, add it to the last group's items\n else if (\n (current.type === \"item\" || current.type === \"divider\") &&\n acc.length > 0\n ) {\n acc[acc.length - 1].items.push(current);\n }\n // Skip dividers\n return acc;\n }, []);\n\n const MenuSeparator = showSearch ? Command.Separator : Menu.Separator;\n\n const renderMenuItem = useCallback(\n (item: DropdownMenuItemType, i: number, j: number) => {\n const MenuItem = showSearch ? Command.Item : Menu.Item;\n\n if (item.type === \"item\") {\n const props = {\n className: clsx(cls(\"dropdown-menu-item\"), classNames?.item),\n disabled: item.disabled,\n \"data-danger\": item.danger,\n ref: item.ref as Ref<HTMLDivElement>,\n onClick: item.onClick,\n onMouseEnter: item.onMouseEnter,\n onMouseLeave: item.onMouseLeave,\n onMouseOver: item.onMouseOver,\n onMouseOut: item.onMouseOut,\n onSelect: showSearch\n ? () => {\n const e = new MouseEvent(\"click\", {\n bubbles: true,\n cancelable: true,\n }) as unknown as React.MouseEvent<HTMLElement, MouseEvent>;\n item.onClick(e);\n onOpenChange?.(false);\n }\n : undefined,\n render: itemRender\n ? (itemProps: React.HTMLAttributes<HTMLElement>) =>\n itemRender(item, itemProps)\n : undefined,\n children: [\n item.icon && (\n <span\n key=\"icon\"\n className={clsx(\n cls(\"dropdown-menu-item-icon\"),\n classNames?.itemIcon\n )}\n >\n {item.icon}\n </span>\n ),\n <span key=\"label\">{item.label}</span>,\n ],\n };\n return showSearch ? (\n <Command.Item key={i + \"-\" + j} {...props}></Command.Item>\n ) : (\n <MenuItem key={i + \"-\" + j} {...props}></MenuItem>\n );\n } else if (item.type === \"divider\") {\n return (\n <MenuSeparator\n key={i + \"-\" + j}\n className={clsx(\n cls(\"dropdown-menu-divider\"),\n classNames?.separator\n )}\n />\n );\n }\n return null;\n },\n [cls, classNames, itemRender, onOpenChange, showSearch, MenuSeparator]\n );\n\n const renderGroup = useCallback(\n (group: DropdownMenuGroup, index: number) => (\n <Menu.Group\n key={\"group\" + index}\n className={clsx(cls(\"dropdown-menu-group\"), classNames?.group)}\n >\n {group.label && (\n <Menu.GroupLabel\n className={clsx(\n cls(\"dropdown-menu-header\"),\n classNames?.groupLabel\n )}\n >\n <span>{group.label}</span>\n </Menu.GroupLabel>\n )}\n {group.items.map((item, j) => renderMenuItem(item, index, j))}\n </Menu.Group>\n ),\n [cls, classNames, renderMenuItem]\n );\n\n const renderGroupShowSearch = useCallback(\n (group: DropdownMenuGroup, index: number) =>\n group.label ? (\n <Command.Group\n key={\"group\" + index}\n className={clsx(cls(\"dropdown-menu-group\"), classNames?.group)}\n heading={\n <Menu.GroupLabel\n className={clsx(\n cls(\"dropdown-menu-header\"),\n classNames?.groupLabel\n )}\n >\n <span>{group.label}</span>\n </Menu.GroupLabel>\n }\n >\n {group.items.map((item, j) => renderMenuItem(item, index, j))}\n </Command.Group>\n ) : (\n group.items.map((item, j) => renderMenuItem(item, index, j))\n ),\n [cls, classNames, renderMenuItem]\n );\n\n const renderMenuInner = useCallback(\n () =>\n showSearch ? (\n <Command className={cls(\"dropdown-menu-container\")}>\n <Command.Input\n {...searchProps}\n key=\"search\"\n render={\n <Input allowClear className={cls(\"dropdown-menu-search\")} />\n }\n />\n <ScrollArea>\n <Command.List className={cls(\"dropdown-menu-list\")}>\n <Command.Empty className={cls(\"dropdown-menu-empty\")}>\n No results found.\n </Command.Empty>\n {itemGroups.map(renderGroupShowSearch)}\n </Command.List>\n </ScrollArea>\n </Command>\n ) : (\n <div className={cls(\"dropdown-menu-container\")}>\n <ScrollArea>{itemGroups.map(renderGroup)}</ScrollArea>\n </div>\n ),\n [\n showSearch,\n itemGroups,\n renderGroupShowSearch,\n renderGroup,\n searchProps,\n cls,\n ]\n );\n\n const BaseComponent = showSearch ? Popover : Menu;\n\n return (\n <BaseComponent.Root\n openOnHover={openOnHover}\n open={open}\n onOpenChange={onOpenChange}\n >\n <BaseComponent.Trigger\n render={children}\n ref={buttonRef}\n className={clsx(\n cls(\"dropdown-menu-trigger\"),\n classNames?.trigger,\n antdCssVarClassname\n )}\n />\n <BaseComponent.Portal>\n <BaseComponent.Positioner\n side={headlessUIPlacement.placement}\n align={headlessUIPlacement.align}\n sideOffset={4}\n className={clsx(cls(\"dropdown-menu-root\"), classNames?.root)}\n collisionAvoidance={DROPDOWN_COLLISION_AVOIDANCE}\n >\n <BaseComponent.Popup\n className={clsx(\n cls(\"dropdown-menu\"),\n className,\n classNames?.popup,\n antdCssVarClassname\n )}\n style={\n {\n \"--size-width\":\n size in PopupPanelSize ? PopupPanelSize[size] : undefined,\n } as React.CSSProperties\n }\n >\n {renderMenuInner()}\n </BaseComponent.Popup>\n </BaseComponent.Positioner>\n </BaseComponent.Portal>\n </BaseComponent.Root>\n );\n};\n"],"names":["DropdownMenu","children","items","placement","openOnHover","outsideOpen","outsideOnOpenChange","className","itemRender","classNames","size","showSearch","searchProps","open","setOpen","useControlled","onOpenChange","useCallback","newValue","cls","useCls","antdCssVarClassname","useAntdCssVarClassname","headlessUIPlacement","parseAntdPlacement","buttonRef","useRef","itemGroups","acc","current","MenuSeparator","Command","Menu","renderMenuItem","item","i","j","MenuItem","props","clsx","e","itemProps","jsx","renderGroup","group","index","jsxs","renderGroupShowSearch","renderMenuInner","createElement","Input","ScrollArea","BaseComponent","Popover","DROPDOWN_COLLISION_AVOIDANCE","PopupPanelSize"],"mappings":";;;;;;;;;;;;;;AA0HO,MAAMA,KAAe,CAAC;AAAA,EAC3B,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAMC;AAAA,EACN,cAAcC;AAAA,EACd,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,YAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,IACZ,aAAa;AAAA,EAAA;AAEjB,MAAyB;AACvB,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAc;AAAA,IACpC,YAAYV;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,EAAA,CACP,GACKW,IAAeC;AAAA,IACnB,CAACC,MAAsB;AACrB,MAAAJ,EAAQI,CAAQ,GAChBZ,KAAA,QAAAA,EAAsBY;AAAA,IACxB;AAAA,IACA,CAACJ,GAASR,CAAmB;AAAA,EAC/B,GACMa,IAAMC,EAAO,GACbC,IAAsBC,EAAuB,GAC7CC,IAAsBC,EAAmBrB,CAAS,GAClDsB,IAAYC,EAA0B,IAAI,GAC1CC,IAAazB,EAAM,OAA4B,CAAC0B,GAAKC,OAErDD,EAAI,WAAW,KAAKC,EAAQ,SAAS,YACvCD,EAAI,KAAK;AAAA,IACP,OAAO;AAAA,IACP,OAAO,CAAA;AAAA,EAAC,CACT,GAICC,EAAQ,SAAS,WACnBD,EAAI,KAAK;AAAA,IACP,OAAOC,EAAQ;AAAA,IACf,OAAO,CAAA;AAAA,EAAC,CACT,KAIAA,EAAQ,SAAS,UAAUA,EAAQ,SAAS,cAC7CD,EAAI,SAAS,KAEbA,EAAIA,EAAI,SAAS,CAAC,EAAE,MAAM,K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AA,MACAgB;AAAA,MACAoB;AAAA,MACAJ;AAAA,MACA/B;AAAA,MACAO;AAAA,IAAA;AAAA,EAEJ,GAEMiC,IAAgBzC,IAAa0C,IAAUrB;AAG3C,SAAA,gBAAAc;AAAA,IAACM,EAAc;AAAA,IAAd;AAAA,MACC,aAAAhD;AAAA,MACA,MAAAS;AAAA,MACA,cAAAG;AAAA,MAEA,UAAA;AAAA,QAAA,gBAAA0B;AAAA,UAACU,EAAc;AAAA,UAAd;AAAA,YACC,QAAQnD;AAAA,YACR,KAAKwB;AAAA,YACL,WAAWc;AAAA,cACTpB,EAAI,uBAAuB;AAAA,cAC3BV,KAAA,gBAAAA,EAAY;AAAA,cACZY;AAAA,YAAA;AAAA,UACF;AAAA,QACF;AAAA,QACA,gBAAAqB,EAACU,EAAc,QAAd,EACC,UAAA,gBAAAV;AAAA,UAACU,EAAc;AAAA,UAAd;AAAA,YACC,MAAM7B,EAAoB;AAAA,YAC1B,OAAOA,EAAoB;AAAA,YAC3B,YAAY;AAAA,YACZ,WAAWgB,EAAKpB,EAAI,oBAAoB,GAAGV,KAAA,gBAAAA,EAAY,IAAI;AAAA,YAC3D,oBAAoB6C;AAAA,YAEpB,UAAA,gBAAAZ;AAAA,cAACU,EAAc;AAAA,cAAd;AAAA,gBACC,WAAWb;AAAA,kBACTpB,EAAI,eAAe;AAAA,kBACnBZ;AAAA,kBACAE,KAAA,gBAAAA,EAAY;AAAA,kBACZY;AAAA,gBACF;AAAA,gBACA,OACE;AAAA,kBACE,gBACEX,KAAQ6C,IAAiBA,EAAe7C,CAAI,IAAI;AAAA,gBACpD;AAAA,gBAGD,UAAgBsC,EAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UACnB;AAAA,QAAA,EAEJ,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../src/components/dropdown-menu/component.tsx"],"sourcesContent":["\"use client\";\nimport { Menu } from \"@base-ui-components/react/menu\";\nimport { useControlled } from \"@base-ui-components/utils/useControlled\";\nimport { Popover } from \"@base-ui-components/react/popover\";\nimport { type PopoverProps } from \"antd/es/popover\";\nimport { useCallback, useRef } from \"react\";\nimport {\n clsx,\n DROPDOWN_COLLISION_AVOIDANCE,\n parseAntdPlacement,\n useAntdCssVarClassname,\n useCls,\n} from \"../utils\";\nimport { Command } from \"../cmdk\";\nimport { ScrollArea } from \"../scroll-area\";\n\n// Import component-specific styles\nimport { Input } from \"../input\";\nimport { PopupPanelSize } from \"../popup-panel/constants\";\nimport { DropdownMenuItem } from \"./item\";\n\nimport \"./style.css\";\nimport { DropdownMenuDivider } from \"./divider\";\n\nexport type DropdownMenuItemType =\n | {\n /**\n * The type of the menu item\n */\n type: \"item\";\n /**\n * The label of the menu item\n */\n label?: React.ReactNode;\n /**\n * Whether the menu item is disabled\n */\n disabled?: boolean;\n /**\n * The icon of the menu item\n */\n icon?: React.ReactNode;\n /**\n * The key of the menu item\n */\n key: React.Key;\n /**\n * The onClick event handler of the menu item\n */\n onClick?: React.HTMLAttributes<HTMLElement>[\"onClick\"];\n /**\n * The onMouseEnter event handler of the menu item\n */\n onMouseEnter?: React.HTMLAttributes<HTMLElement>[\"onMouseEnter\"];\n /**\n * The onMouseLeave event handler of the menu item\n */\n onMouseLeave?: React.HTMLAttributes<HTMLElement>[\"onMouseLeave\"];\n /**\n * The onMouseOver event handler of the menu item\n */\n onMouseOver?: React.HTMLAttributes<HTMLElement>[\"onMouseOver\"];\n /**\n * The onMouseOut event handler of the menu item\n */\n onMouseOut?: React.HTMLAttributes<HTMLElement>[\"onMouseOut\"];\n /**\n * The className of the menu item\n */\n className?: string;\n /**\n * Whether the menu item is a danger item\n */\n danger?: boolean;\n /**\n * The ref of the menu item\n */\n ref?: React.Ref<HTMLElement>;\n }\n | {\n /**\n * The type of the menu item\n */\n type: \"divider\";\n }\n | {\n /**\n * The type of the menu item\n */\n type: \"header\";\n /**\n * The title of the menu item\n */\n title?: React.ReactNode;\n /**\n * The className of the menu item\n */\n className?: string;\n };\n\nexport interface DropdownMenuProps {\n /** Array of menu items to be displayed in the dropdown */\n items: DropdownMenuItemType[];\n /** Custom render function for the trigger element */\n children?: React.ComponentProps<typeof Menu.Trigger>[\"render\"];\n /**\n * Placement of the dropdown relative to the trigger element\n * @default \"bottomLeft\"\n */\n placement?: PopoverProps[\"placement\"];\n /**\n * Whether to open the dropdown on hover instead of click\n * @default false\n */\n openOnHover?: boolean;\n /**\n * Controlled open state of the dropdown\n */\n open?: boolean;\n /**\n * Callback fired when the dropdown open state changes\n */\n onOpenChange?: (open: boolean) => void;\n /**\n * Additional CSS class for the dropdown component\n */\n className?: string;\n /**\n * Custom class names for different parts of the dropdown\n * @default {}\n */\n classNames?: {\n root?: string;\n trigger?: string;\n popup?: string;\n group?: string;\n groupLabel?: string;\n item?: string;\n itemIcon?: string;\n itemText?: string;\n separator?: string;\n positioner?: string;\n };\n /**\n * Custom render function for menu items\n */\n itemRender?: (\n item: DropdownMenuItemType,\n props: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n /**\n * Whether to show search input\n * @default false\n */\n showSearch?: boolean;\n /**\n * Size of the dropdown menu\n * @default \"auto\"\n */\n size?: \"auto\" | keyof typeof PopupPanelSize;\n /**\n * Search placeholder\n */\n searchProps?: Omit<\n React.ComponentProps<typeof Command.Input>,\n \"size\" | \"ref\"\n >;\n /**\n * Whether to match the width of the popup with the trigger\n * @default false\n */\n popupMatchTriggerWidth?: boolean;\n\n /**\n * Content to display before the list\n */\n beforeList?: React.ReactNode;\n /**\n * Content to display after the list\n */\n afterList?: React.ReactNode;\n /**\n * Whether to keep the dropdown open when an item is selected\n * @default false\n */\n keepOpenOnSelect?: boolean;\n /**\n * Control the highlighted state of the menu item\n */\n highlightedItemKey?: React.Key;\n /**\n * Control the selected state of the menu item\n */\n selectedItemKeys?: React.Key[];\n /**\n * Whether to show checkbox\n * @default false\n */\n showCheckbox?: boolean;\n}\n\ninterface DropdownMenuGroup {\n label: React.ReactNode | null;\n items: DropdownMenuItemType[];\n}\n\nexport const DropdownMenu = ({\n children,\n items,\n placement,\n openOnHover,\n open: outsideOpen,\n onOpenChange: outsideOnOpenChange,\n className,\n itemRender,\n classNames,\n size = \"auto\",\n showSearch,\n searchProps = {\n placeholder: \"Search...\",\n },\n popupMatchTriggerWidth,\n beforeList,\n afterList,\n keepOpenOnSelect,\n highlightedItemKey,\n selectedItemKeys,\n showCheckbox,\n}: DropdownMenuProps) => {\n const [open, setOpen] = useControlled({\n controlled: outsideOpen,\n default: false,\n name: \"open\",\n });\n const onOpenChange = useCallback(\n (newValue: boolean) => {\n setOpen(newValue);\n outsideOnOpenChange?.(newValue);\n },\n [setOpen, outsideOnOpenChange]\n );\n const cls = useCls();\n const antdCssVarClassname = useAntdCssVarClassname();\n const baseUIPlacement = parseAntdPlacement(placement);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const itemGroups = items.reduce<DropdownMenuGroup[]>((acc, current) => {\n // If no groups exist yet and current item is not a header, create default group\n if (acc.length === 0 && current.type !== \"header\") {\n acc.push({\n label: null,\n items: [],\n });\n }\n\n // If it's a header, create a new group\n if (current.type === \"header\") {\n acc.push({\n label: current.title,\n items: [],\n });\n }\n // If it's an item and we have at least one group, add it to the last group's items\n else if (\n (current.type === \"item\" || current.type === \"divider\") &&\n acc.length > 0\n ) {\n acc[acc.length - 1].items.push(current);\n }\n // Skip dividers\n return acc;\n }, []);\n\n const renderMenuItem = useCallback(\n (item: DropdownMenuItemType, i: number, j: number) => {\n if (item.type === \"item\") {\n return (\n <DropdownMenuItem\n key={i + \"-\" + j}\n item={item}\n inCombobox={showSearch}\n selected={selectedItemKeys?.includes(item.key)}\n onSelect={\n showSearch\n ? () => {\n const e = new MouseEvent(\"click\", {\n bubbles: true,\n cancelable: true,\n }) as unknown as React.MouseEvent<HTMLElement, MouseEvent>;\n item.onClick(e);\n if (!keepOpenOnSelect) onOpenChange?.(false);\n }\n : undefined\n }\n itemRender={itemRender}\n showCheckbox={showCheckbox}\n />\n );\n } else if (item.type === \"divider\") {\n return (\n <DropdownMenuDivider\n key={i + \"-\" + j}\n inCombobox={showSearch}\n className={classNames?.separator}\n />\n );\n }\n return null;\n },\n [\n classNames,\n itemRender,\n onOpenChange,\n showSearch,\n keepOpenOnSelect,\n selectedItemKeys,\n showCheckbox,\n ]\n );\n\n const renderGroup = useCallback(\n (group: DropdownMenuGroup, index: number) => (\n <Menu.Group\n key={\"group\" + index}\n className={clsx(cls(\"dropdown-menu-group\"), classNames?.group)}\n >\n {group.label && (\n <Menu.GroupLabel\n className={clsx(\n cls(\"dropdown-menu-header\"),\n classNames?.groupLabel\n )}\n >\n <span>{group.label}</span>\n </Menu.GroupLabel>\n )}\n {group.items.map((item, j) => renderMenuItem(item, index, j))}\n </Menu.Group>\n ),\n [cls, classNames, renderMenuItem]\n );\n\n const renderGroupShowSearch = useCallback(\n (group: DropdownMenuGroup, index: number) =>\n group.label ? (\n <Command.Group\n key={\"group\" + index}\n className={clsx(cls(\"dropdown-menu-group\"), classNames?.group)}\n heading={\n <Menu.GroupLabel\n className={clsx(\n cls(\"dropdown-menu-header\"),\n classNames?.groupLabel\n )}\n >\n <span>{group.label}</span>\n </Menu.GroupLabel>\n }\n >\n {group.items.map((item, j) => renderMenuItem(item, index, j))}\n </Command.Group>\n ) : (\n group.items.map((item, j) => renderMenuItem(item, index, j))\n ),\n [cls, classNames, renderMenuItem]\n );\n\n const renderMenuInner = useCallback(\n () =>\n showSearch ? (\n <Command\n className={cls(\"dropdown-menu-container\")}\n disablePointerSelection={showSearch}\n defaultValue={\n highlightedItemKey ? String(highlightedItemKey) : undefined\n }\n >\n <Command.Input\n {...searchProps}\n key=\"search\"\n render={\n <Input allowClear className={cls(\"dropdown-menu-search\")} />\n }\n />\n {beforeList}\n <ScrollArea>\n <Command.List className={cls(\"dropdown-menu-list\")}>\n <Command.Empty className={cls(\"dropdown-menu-empty\")}>\n No results found.\n </Command.Empty>\n {itemGroups.map(renderGroupShowSearch)}\n </Command.List>\n </ScrollArea>\n {afterList}\n </Command>\n ) : (\n <div className={cls(\"dropdown-menu-container\")}>\n {beforeList}\n <ScrollArea>{itemGroups.map(renderGroup)}</ScrollArea>\n {afterList}\n </div>\n ),\n [\n showSearch,\n cls,\n highlightedItemKey,\n searchProps,\n beforeList,\n itemGroups,\n renderGroupShowSearch,\n afterList,\n renderGroup,\n ]\n );\n\n const BaseComponent = showSearch ? Popover : Menu;\n\n return (\n <BaseComponent.Root\n openOnHover={openOnHover}\n open={open}\n onOpenChange={onOpenChange}\n >\n <BaseComponent.Trigger\n render={children}\n ref={buttonRef}\n className={clsx(\n cls(\"dropdown-menu-trigger\"),\n classNames?.trigger,\n antdCssVarClassname\n )}\n />\n <BaseComponent.Portal>\n <BaseComponent.Positioner\n side={baseUIPlacement.side}\n align={baseUIPlacement.align}\n sideOffset={4}\n className={clsx(cls(\"dropdown-menu-root\"), classNames?.root)}\n collisionAvoidance={DROPDOWN_COLLISION_AVOIDANCE}\n >\n <BaseComponent.Popup\n className={clsx(\n cls(\n \"dropdown-menu\",\n showCheckbox && \"dropdown-menu-show-checkbox\",\n popupMatchTriggerWidth && \"dropdown-menu-match-trigger-width\"\n ),\n className,\n classNames?.popup,\n antdCssVarClassname\n )}\n style={\n {\n \"--size-width\":\n size in PopupPanelSize ? PopupPanelSize[size] : undefined,\n } as React.CSSProperties\n }\n >\n {renderMenuInner()}\n </BaseComponent.Popup>\n </BaseComponent.Positioner>\n </BaseComponent.Portal>\n </BaseComponent.Root>\n );\n};\n"],"names":["DropdownMenu","children","items","placement","openOnHover","outsideOpen","outsideOnOpenChange","className","itemRender","classNames","size","showSearch","searchProps","popupMatchTriggerWidth","beforeList","afterList","keepOpenOnSelect","highlightedItemKey","selectedItemKeys","showCheckbox","open","setOpen","useControlled","onOpenChange","useCallback","newValue","cls","useCls","antdCssVarClassname","useAntdCssVarClassname","baseUIPlacement","parseAntdPlacement","buttonRef","useRef","itemGroups","acc","current","renderMenuItem","item","i","j","jsx","DropdownMenuItem","e","DropdownMenuDivider","renderGroup","group","index","jsxs","Menu","clsx","renderGroupShowSearch","Command","renderMenuInner","createElement","Input","ScrollArea","BaseComponent","Popover","DROPDOWN_COLLISION_AVOIDANCE","PopupPanelSize"],"mappings":";;;;;;;;;;;;;;;;;AA8MO,MAAMA,KAAe,CAAC;AAAA,EAC3B,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAMC;AAAA,EACN,cAAcC;AAAA,EACd,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,YAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,IACZ,aAAa;AAAA,EACf;AAAA,EACA,wBAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,cAAAC;AACF,MAAyB;AACvB,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAc;AAAA,IACpC,YAAYjB;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,EAAA,CACP,GACKkB,IAAeC;AAAA,IACnB,CAACC,MAAsB;AACrB,MAAAJ,EAAQI,CAAQ,GAChBnB,KAAA,QAAAA,EAAsBmB;AAAA,IACxB;AAAA,IACA,CAACJ,GAASf,CAAmB;AAAA,EAC/B,GACMoB,IAAMC,EAAO,GACbC,IAAsBC,GAAuB,GAC7CC,IAAkBC,EAAmB5B,CAAS,GAC9C6B,IAAYC,EAA0B,IAAI,GAC1CC,IAAahC,EAAM,OAA4B,CAACiC,GAAKC,OAErDD,EAAI,WAAW,KAAKC,EAAQ,SAAS,YACvCD,EAAI,KAAK;AAAA,IACP,OAAO;AAAA,IACP,OAAO,CAAA;AAAA,EAAC,CACT,GAICC,EAAQ,SAAS,WACnBD,EAAI,KAAK;AAAA,IACP,OAAOC,EAAQ;AAAA,IACf,OAAO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ACZmB;AAAA,YAAA;AAAA,UACF;AAAA,QACF;AAAA,QACA,gBAAAa,EAACgB,EAAc,QAAd,EACC,UAAA,gBAAAhB;AAAA,UAACgB,EAAc;AAAA,UAAd;AAAA,YACC,MAAM3B,EAAgB;AAAA,YACtB,OAAOA,EAAgB;AAAA,YACvB,YAAY;AAAA,YACZ,WAAWoB,EAAKxB,EAAI,oBAAoB,GAAGjB,KAAA,gBAAAA,EAAY,IAAI;AAAA,YAC3D,oBAAoBkD;AAAA,YAEpB,UAAA,gBAAAlB;AAAA,cAACgB,EAAc;AAAA,cAAd;AAAA,gBACC,WAAWP;AAAA,kBACTxB;AAAA,oBACE;AAAA,oBACAP,KAAgB;AAAA,oBAChBN,KAA0B;AAAA,kBAC5B;AAAA,kBACAN;AAAA,kBACAE,KAAA,gBAAAA,EAAY;AAAA,kBACZmB;AAAA,gBACF;AAAA,gBACA,OACE;AAAA,kBACE,gBACElB,KAAQkD,IAAiBA,EAAelD,CAAI,IAAI;AAAA,gBACpD;AAAA,gBAGD,UAAgB2C,EAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UACnB;AAAA,QAAA,EAEJ,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as t } from "react/jsx-runtime";
|
|
2
|
+
import { Command as p } from "../cmdk/index.js";
|
|
3
|
+
import { Menu as n } from "@base-ui-components/react/menu";
|
|
4
|
+
import { useCls as s } from "../utils/antdUtils.js";
|
|
5
|
+
import { clsx as a } from "../utils/cn.js";
|
|
6
|
+
const l = ({
|
|
7
|
+
inCombobox: r,
|
|
8
|
+
className: o
|
|
9
|
+
}) => {
|
|
10
|
+
const m = s(), e = r ? p.Separator : n.Separator;
|
|
11
|
+
return /* @__PURE__ */ t(e, { className: a(m("dropdown-menu-divider"), o) });
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
l as DropdownMenuDivider
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=divider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"divider.js","sources":["../../../src/components/dropdown-menu/divider.tsx"],"sourcesContent":["import { Command } from \"../cmdk\";\nimport { Menu } from \"@base-ui-components/react/menu\";\nimport { clsx, useCls } from \"../utils\";\n\nexport interface DropdownMenuDividerProps {\n inCombobox?: boolean;\n className?: string;\n}\n\nexport const DropdownMenuDivider = ({\n inCombobox,\n className,\n}: DropdownMenuDividerProps) => {\n const cls = useCls();\n const MenuSeparator = inCombobox ? Command.Separator : Menu.Separator;\n\n return (\n <MenuSeparator className={clsx(cls(\"dropdown-menu-divider\"), className)} />\n );\n};\n"],"names":["DropdownMenuDivider","inCombobox","className","cls","useCls","MenuSeparator","Command","Menu","jsx","clsx"],"mappings":";;;;;AASO,MAAMA,IAAsB,CAAC;AAAA,EAClC,YAAAC;AAAA,EACA,WAAAC;AACF,MAAgC;AAC9B,QAAMC,IAAMC,EAAO,GACbC,IAAgBJ,IAAaK,EAAQ,YAAYC,EAAK;AAG1D,SAAA,gBAAAC,EAACH,KAAc,WAAWI,EAAKN,EAAI,uBAAuB,GAAGD,CAAS,GAAG;AAE7E;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@layer components{.ds-dropdown-menu-item{padding:.375rem .75rem;border-radius:var(--ds-border-radius-sm);cursor:pointer;display:flex;align-items:center;transition:all .3s var(--ds-motion-ease-out)}.ds-dropdown-menu-item:focus{outline:none}.ds-dropdown-menu-item:hover,.ds-dropdown-menu-item[data-active=true],.ds-dropdown-menu-item[data-selected=true],.ds-dropdown-menu-item[data-highlighted=true]{background:var(--ds-control-item-bg-hover)}.ds-dropdown-menu-item:active,.ds-dropdown-menu-item:focus,.ds-dropdown-menu-item[data-focus=true]{background:var(--ds-control-item-bg-active);font-weight:500}.ds-dropdown-menu:not(.ds-dropdown-menu-show-checkbox) .ds-dropdown-menu-item[data-actual-selected=true]{background:var(--ds-control-item-bg-active);font-weight:500}.ds-dropdown-menu-item[data-disabled=true]{pointer-events:none;color:var(--ds-color-text-disabled)}.ds-dropdown-menu-item[data-danger=true]{color:var(--ds-color-error)}.ds-dropdown-menu-item[data-danger=true]:hover{background:var(--ds-color-error-bg)}.ds-dropdown-menu-item[data-danger=true]:active,.ds-dropdown-menu-item[data-danger=true]:focus,.ds-dropdown-menu-item[data-danger=true][data-focus=true]{background:var(--ds-color-error-bg-hover)}.ds-dropdown-menu-item .ds-checkbox-wrapper{margin-right:.5rem}.ds-dropdown-menu-item .ds-dropdown-menu-item-icon{display:flex;align-items:center;justify-content:center;margin-right:.5rem;font-size:1rem;color:var(--ds-color-icon)}[data-danger=true] :is(.ds-dropdown-menu-item .ds-dropdown-menu-item-icon){color:var(--ds-color-error)}}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as g, Fragment as k, jsx as r } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo as x } from "react";
|
|
4
|
+
import { Command as E } from "../cmdk/index.js";
|
|
5
|
+
import { Menu as L } from "@base-ui-components/react/menu";
|
|
6
|
+
import './item.css';/* empty css */
|
|
7
|
+
import { Checkbox as h } from "antd";
|
|
8
|
+
import { useCls as b } from "../utils/antdUtils.js";
|
|
9
|
+
import { clsx as p } from "../utils/cn.js";
|
|
10
|
+
const C = ({
|
|
11
|
+
item: o,
|
|
12
|
+
inCombobox: u = !1,
|
|
13
|
+
selected: i = !1,
|
|
14
|
+
itemRender: t,
|
|
15
|
+
itemProps: w = {},
|
|
16
|
+
classNames: n,
|
|
17
|
+
onSelect: I,
|
|
18
|
+
showCheckbox: e,
|
|
19
|
+
indeterminate: M,
|
|
20
|
+
renderAsNativeElement: O
|
|
21
|
+
}) => {
|
|
22
|
+
const d = b(), y = x(
|
|
23
|
+
() => u ? E.Item : L.Item,
|
|
24
|
+
[u]
|
|
25
|
+
), f = x(() => ({
|
|
26
|
+
className: p(
|
|
27
|
+
d("dropdown-menu-item", u && "dropdown-menu-item-combobox"),
|
|
28
|
+
n == null ? void 0 : n.item,
|
|
29
|
+
o.className
|
|
30
|
+
),
|
|
31
|
+
disabled: o.disabled,
|
|
32
|
+
"data-danger": o.danger,
|
|
33
|
+
"data-actual-selected": i,
|
|
34
|
+
ref: o.ref,
|
|
35
|
+
onClick: o.onClick,
|
|
36
|
+
onMouseEnter: o.onMouseEnter,
|
|
37
|
+
onMouseLeave: o.onMouseLeave,
|
|
38
|
+
onMouseOver: o.onMouseOver,
|
|
39
|
+
onMouseOut: o.onMouseOut,
|
|
40
|
+
"data-value": typeof o.label == "string" ? o.label : String(o.key),
|
|
41
|
+
render: t ? (j) => t(o, j) : void 0,
|
|
42
|
+
children: u ? /* @__PURE__ */ g(k, { children: [
|
|
43
|
+
e && /* @__PURE__ */ r(
|
|
44
|
+
h,
|
|
45
|
+
{
|
|
46
|
+
checked: i,
|
|
47
|
+
tabIndex: -1,
|
|
48
|
+
indeterminate: M
|
|
49
|
+
}
|
|
50
|
+
),
|
|
51
|
+
o.icon && /* @__PURE__ */ r(
|
|
52
|
+
"span",
|
|
53
|
+
{
|
|
54
|
+
className: p(
|
|
55
|
+
d("dropdown-menu-item-icon"),
|
|
56
|
+
n == null ? void 0 : n.itemIcon
|
|
57
|
+
),
|
|
58
|
+
children: o.icon
|
|
59
|
+
}
|
|
60
|
+
),
|
|
61
|
+
/* @__PURE__ */ r(
|
|
62
|
+
"span",
|
|
63
|
+
{
|
|
64
|
+
className: p(
|
|
65
|
+
d("dropdown-menu-item-text"),
|
|
66
|
+
n == null ? void 0 : n.itemText
|
|
67
|
+
),
|
|
68
|
+
children: o.label
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
] }) : /* @__PURE__ */ g(k, { children: [
|
|
72
|
+
e && /* @__PURE__ */ r(
|
|
73
|
+
h,
|
|
74
|
+
{
|
|
75
|
+
checked: i,
|
|
76
|
+
tabIndex: -1,
|
|
77
|
+
indeterminate: M
|
|
78
|
+
}
|
|
79
|
+
),
|
|
80
|
+
o.icon && /* @__PURE__ */ r(
|
|
81
|
+
"span",
|
|
82
|
+
{
|
|
83
|
+
className: p(
|
|
84
|
+
d("dropdown-menu-item-icon"),
|
|
85
|
+
n == null ? void 0 : n.itemIcon
|
|
86
|
+
),
|
|
87
|
+
children: o.icon
|
|
88
|
+
}
|
|
89
|
+
),
|
|
90
|
+
/* @__PURE__ */ r(
|
|
91
|
+
"span",
|
|
92
|
+
{
|
|
93
|
+
className: p(
|
|
94
|
+
d("dropdown-menu-item-text"),
|
|
95
|
+
n == null ? void 0 : n.itemText
|
|
96
|
+
),
|
|
97
|
+
children: o.label
|
|
98
|
+
}
|
|
99
|
+
)
|
|
100
|
+
] })
|
|
101
|
+
}), [
|
|
102
|
+
n == null ? void 0 : n.item,
|
|
103
|
+
n == null ? void 0 : n.itemIcon,
|
|
104
|
+
n == null ? void 0 : n.itemText,
|
|
105
|
+
d,
|
|
106
|
+
u,
|
|
107
|
+
M,
|
|
108
|
+
o,
|
|
109
|
+
t,
|
|
110
|
+
i,
|
|
111
|
+
e
|
|
112
|
+
]);
|
|
113
|
+
if (t)
|
|
114
|
+
return t(o, {
|
|
115
|
+
...f,
|
|
116
|
+
...w
|
|
117
|
+
});
|
|
118
|
+
const { render: v, ...T } = f;
|
|
119
|
+
return O ? v ? v(f) : /* @__PURE__ */ r("div", { onClick: I, ...T }) : /* @__PURE__ */ r(
|
|
120
|
+
y,
|
|
121
|
+
{
|
|
122
|
+
value: String(o.key),
|
|
123
|
+
onSelect: I,
|
|
124
|
+
...f
|
|
125
|
+
}
|
|
126
|
+
);
|
|
127
|
+
};
|
|
128
|
+
export {
|
|
129
|
+
C as DropdownMenuItem
|
|
130
|
+
};
|
|
131
|
+
//# sourceMappingURL=item.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item.js","sources":["../../../src/components/dropdown-menu/item.tsx"],"sourcesContent":["\"use client\";\nimport React, { Ref, useMemo } from \"react\";\nimport { clsx, useCls } from \"../utils\";\nimport type { DropdownMenuItemType } from \"./component\";\nimport { Command } from \"../cmdk\";\nimport { Menu } from \"@base-ui-components/react/menu\";\n\nimport \"./item.css\";\nimport { Checkbox } from \"antd\";\n\nexport interface DropdownMenuItemProps {\n /** The menu item data */\n item: DropdownMenuItemType & { type: \"item\" };\n /** Custom render function for the item */\n itemRender?: (\n item: DropdownMenuItemType,\n props: React.HTMLAttributes<HTMLElement>\n ) => React.ReactElement;\n /** Additional props to pass to the item */\n itemProps?: React.HTMLAttributes<HTMLElement>;\n /** Class names from parent DropdownMenu */\n classNames?: {\n item?: string;\n itemIcon?: string;\n itemText?: string;\n };\n onSelect?: () => void;\n /**\n * Whether the menu item is in a combobox\n */\n inCombobox?: boolean;\n /**\n * Whether the menu item is in a menu\n */\n renderAsNativeElement?: boolean;\n /**\n * Whether the menu item is selected (for combobox)\n * @default false\n */\n selected?: boolean;\n /**\n * Whether to show checkbox (only for decoration purpose)\n */\n showCheckbox?: boolean;\n /**\n * Whether the menu item checkbox is indeterminate (for combobox)\n * @default false\n */\n indeterminate?: boolean;\n}\n\nexport const DropdownMenuItem: React.FC<DropdownMenuItemProps> = ({\n item,\n inCombobox = false,\n selected = false,\n itemRender,\n itemProps = {},\n classNames,\n onSelect,\n showCheckbox,\n indeterminate,\n renderAsNativeElement,\n}) => {\n const cls = useCls();\n\n const MenuItem = useMemo(\n () => (inCombobox ? Command.Item : Menu.Item),\n [inCombobox]\n );\n\n const props = useMemo(() => {\n return {\n className: clsx(\n cls(\"dropdown-menu-item\", inCombobox && \"dropdown-menu-item-combobox\"),\n classNames?.item,\n item.className\n ),\n disabled: item.disabled,\n \"data-danger\": item.danger,\n \"data-actual-selected\": selected,\n ref: item.ref as Ref<HTMLDivElement>,\n onClick: item.onClick,\n onMouseEnter: item.onMouseEnter,\n onMouseLeave: item.onMouseLeave,\n onMouseOver: item.onMouseOver,\n onMouseOut: item.onMouseOut,\n \"data-value\":\n typeof item.label === \"string\" ? item.label : String(item.key),\n render: itemRender\n ? (itemProps: React.HTMLAttributes<HTMLElement>) =>\n itemRender(item, itemProps)\n : undefined,\n children: inCombobox ? (\n <>\n {showCheckbox && (\n <Checkbox\n checked={selected}\n tabIndex={-1}\n indeterminate={indeterminate}\n />\n )}\n {item.icon && (\n <span\n className={clsx(\n cls(\"dropdown-menu-item-icon\"),\n classNames?.itemIcon\n )}\n >\n {item.icon}\n </span>\n )}\n <span\n className={clsx(\n cls(\"dropdown-menu-item-text\"),\n classNames?.itemText\n )}\n >\n {item.label}\n </span>\n </>\n ) : (\n <>\n {showCheckbox && (\n <Checkbox\n checked={selected}\n tabIndex={-1}\n indeterminate={indeterminate}\n />\n )}\n {item.icon && (\n <span\n className={clsx(\n cls(\"dropdown-menu-item-icon\"),\n classNames?.itemIcon\n )}\n >\n {item.icon}\n </span>\n )}\n <span\n className={clsx(\n cls(\"dropdown-menu-item-text\"),\n classNames?.itemText\n )}\n >\n {item.label}\n </span>\n </>\n ),\n };\n }, [\n classNames?.item,\n classNames?.itemIcon,\n classNames?.itemText,\n cls,\n inCombobox,\n indeterminate,\n item,\n itemRender,\n selected,\n showCheckbox,\n ]);\n // If custom render function is provided, use it\n if (itemRender) {\n return itemRender(item, {\n ...props,\n ...itemProps,\n });\n }\n const { render, ...restProps } = props;\n // Default rendering\n return renderAsNativeElement ? (\n render ? (\n render(props)\n ) : (\n <div onClick={onSelect} {...restProps} />\n )\n ) : (\n <MenuItem\n value={String(item.key)}\n onSelect={onSelect}\n {...props}\n ></MenuItem>\n );\n};\n"],"names":["DropdownMenuItem","item","inCombobox","selected","itemRender","itemProps","classNames","onSelect","showCheckbox","indeterminate","renderAsNativeElement","cls","useCls","MenuItem","useMemo","Command","Menu","props","clsx","jsxs","Fragment","jsx","Checkbox","render","restProps"],"mappings":";;;;;;;;;AAmDO,MAAMA,IAAoD,CAAC;AAAA,EAChE,MAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,UAAAC,IAAW;AAAA,EACX,YAAAC;AAAA,EACA,W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AAAA,MACtB,UAAAM;AAAA,MACC,GAAGU;AAAA,IAAA;AAAA,EACL;AAEL;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
@layer components{.ds-dropdown-menu-root{z-index:2000}.ds-dropdown-menu{box-shadow:var(--ds-box-shadow-secondary);border-radius:var(--ds-border-radius);background:var(--ds-color-bg-elevated);list-style:none;padding:.25rem;color:var(--ds-color-text);font-size:var(--ds-font-size);font-family:var(--ds-font-family);transition-property:transform,scale,opacity;transition-duration:.2s;transition-timing-function:var(--ds-motion-ease-out);transform-origin:var(--transform-origin);max-width:min(var(--size-width),var(--available-width));max-height:var(--available-height);display:flex;flex-direction:column}.ds-dropdown-menu[data-ending-style],.ds-dropdown-menu[data-starting-style]{transform:scale(.9);opacity:0}.ds-dropdown-menu:focus{outline:none}.ds-dropdown-menu .ds-dropdown-menu-container{flex-shrink:1;min-height:0;display:flex;flex-direction:column}.ds-dropdown-menu .ds-dropdown-menu-search{flex-shrink:0}.ds-dropdown-menu .ds-dropdown-menu-list{flex-shrink:1;min-height:0;display:flex;flex-direction:column}
|
|
1
|
+
@layer components{.ds-dropdown-menu-root{z-index:2000}.ds-dropdown-menu{box-shadow:var(--ds-box-shadow-secondary);border-radius:var(--ds-border-radius);background:var(--ds-color-bg-elevated);list-style:none;padding:.25rem;color:var(--ds-color-text);font-size:var(--ds-font-size);font-family:var(--ds-font-family);transition-property:transform,scale,opacity;transition-duration:.2s;transition-timing-function:var(--ds-motion-ease-out);transform-origin:var(--transform-origin);max-width:min(var(--size-width),var(--available-width));max-height:var(--available-height);display:flex;flex-direction:column}.ds-dropdown-menu[data-ending-style],.ds-dropdown-menu[data-starting-style]{transform:scale(.9);opacity:0}.ds-dropdown-menu:focus{outline:none}.ds-dropdown-menu .ds-dropdown-menu-container{flex-shrink:1;min-height:0;display:flex;flex-direction:column}.ds-dropdown-menu .ds-dropdown-menu-search{flex-shrink:0}.ds-dropdown-menu .ds-dropdown-menu-list{flex-shrink:1;min-height:0;display:flex;flex-direction:column}:is(.ds-dropdown-menu .ds-dropdown-menu-list) [cmdk-list-sizer]{flex-shrink:1;min-height:0;display:flex;flex-direction:column}.ds-dropdown-menu-search{margin-bottom:.25rem}.ds-dropdown-menu-divider{border-bottom:1px solid var(--ds-color-split);margin:.25rem 0}.ds-dropdown-menu-header{font-size:.75rem;font-weight:500;line-height:1rem;text-transform:uppercase;color:var(--ds-color-text-tertiary);padding:.75rem .75rem .25rem}.ds-dropdown-menu-header:first-child{padding-top:.5rem}.ds-dropdown-menu-empty{padding:.375rem .75rem;color:var(--ds-color-text-tertiary)}.ds-dropdown-menu-match-trigger-width{width:min(var(--anchor-width),var(--available-width))}}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useCallback as H } from "react";
|
|
3
|
+
function T(d = !0) {
|
|
4
|
+
return { ref: H((n) => {
|
|
5
|
+
if (!n || !d) return;
|
|
6
|
+
let i = !1, m = 0, f = 0, v = 0, p = 0, o = null;
|
|
7
|
+
n.addEventListener("mousedown", h);
|
|
8
|
+
function z(t) {
|
|
9
|
+
var s, c;
|
|
10
|
+
let e = t;
|
|
11
|
+
for (; e && e !== n; ) {
|
|
12
|
+
if (e.classList.contains("resize-handle") || e.classList.contains("ds-resizable-resize-handle") || e.getAttribute("data-resize-handle") || (s = e.getAttribute("data-testid")) != null && s.includes("resize") || e.getAttribute("data-placement") || // Resizable handles have data-placement
|
|
13
|
+
(c = e.style.cursor) != null && c.includes("resize") || // Check for react-use-resizable specific classes/attributes
|
|
14
|
+
e.classList.contains("resizable-handle") || e.hasAttribute("data-resizable-handle") || // Check for common resize cursor styles
|
|
15
|
+
["n-resize", "s-resize", "e-resize", "w-resize", "ne-resize", "nw-resize", "se-resize", "sw-resize"].includes(e.style.cursor))
|
|
16
|
+
return !0;
|
|
17
|
+
e = e.parentElement;
|
|
18
|
+
}
|
|
19
|
+
return !1;
|
|
20
|
+
}
|
|
21
|
+
function y(t) {
|
|
22
|
+
const e = window.getComputedStyle(t), s = new DOMMatrix(e.transform);
|
|
23
|
+
return {
|
|
24
|
+
x: s.m41 || parseInt(e.left) || 0,
|
|
25
|
+
y: s.m42 || parseInt(e.top) || 0
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function L(t, e, s) {
|
|
29
|
+
t.style.transform = `translate(${e}px, ${s}px)`;
|
|
30
|
+
}
|
|
31
|
+
function h(t) {
|
|
32
|
+
const e = t.target;
|
|
33
|
+
if (z(e))
|
|
34
|
+
return;
|
|
35
|
+
if (n.closest("[data-resizable]")) {
|
|
36
|
+
const r = n.getBoundingClientRect(), E = t.clientX - r.left, b = t.clientY - r.top, l = 8, w = b <= l, x = b >= r.height - l, S = E <= l, A = E >= r.width - l, D = n.querySelector('.ds-resizable-resize-handle[data-placement*="top"]'), X = n.querySelector('.ds-resizable-resize-handle[data-placement*="bottom"]'), Y = n.querySelector('.ds-resizable-resize-handle[data-placement*="left"]'), q = n.querySelector('.ds-resizable-resize-handle[data-placement*="right"]');
|
|
37
|
+
if (w && D || x && X || S && Y || A && q)
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
t.preventDefault(), t.stopPropagation(), i = !0, m = t.clientX, f = t.clientY;
|
|
41
|
+
const s = y(n);
|
|
42
|
+
v = s.x, p = s.y, document.body.style.cursor = "grabbing", document.body.style.userSelect = "none", n.querySelectorAll('button, a, input, select, textarea, [role="button"]').forEach((r) => {
|
|
43
|
+
r.style.pointerEvents = "auto";
|
|
44
|
+
}), document.addEventListener("mousemove", u, { passive: !1 }), document.addEventListener("mouseup", a), document.addEventListener("touchmove", g, { passive: !1 }), document.addEventListener("touchend", a);
|
|
45
|
+
}
|
|
46
|
+
function u(t) {
|
|
47
|
+
!i || !n || (t.preventDefault(), o && cancelAnimationFrame(o), o = requestAnimationFrame(() => {
|
|
48
|
+
const e = t.clientX - m, s = t.clientY - f, c = v + e, r = p + s;
|
|
49
|
+
L(n, c, r);
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
function g(t) {
|
|
53
|
+
if (!i || !n) return;
|
|
54
|
+
t.preventDefault();
|
|
55
|
+
const e = t.touches[0];
|
|
56
|
+
if (!e) return;
|
|
57
|
+
const s = new MouseEvent("mousemove", {
|
|
58
|
+
clientX: e.clientX,
|
|
59
|
+
clientY: e.clientY,
|
|
60
|
+
bubbles: !0
|
|
61
|
+
});
|
|
62
|
+
u(s);
|
|
63
|
+
}
|
|
64
|
+
function a() {
|
|
65
|
+
i && (i = !1, o && (cancelAnimationFrame(o), o = null), document.body.style.cursor = "", document.body.style.userSelect = "", n && n.querySelectorAll('button, a, input, select, textarea, [role="button"]').forEach((e) => {
|
|
66
|
+
e.style.pointerEvents = "";
|
|
67
|
+
}), document.removeEventListener("mousemove", u), document.removeEventListener("mouseup", a), document.removeEventListener("touchmove", g), document.removeEventListener("touchend", a));
|
|
68
|
+
}
|
|
69
|
+
return () => {
|
|
70
|
+
n.removeEventListener("mousedown", h), a();
|
|
71
|
+
};
|
|
72
|
+
}, [d]) };
|
|
73
|
+
}
|
|
74
|
+
export {
|
|
75
|
+
T as useDraggable
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=useDraggable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDraggable.js","sources":["../../../src/components/hooks/useDraggable.ts"],"sourcesContent":["\"use client\";\nimport { useCallback } from \"react\";\n\nexport function useDraggable(enabled: boolean = true) {\n const ref = useCallback((element: HTMLElement | null) => {\n if (!element || !enabled) return;\n \n let isDragging = false;\n let startX = 0;\n let startY = 0;\n let initialLeft = 0;\n let initialTop = 0;\n let rafId: number | null = null;\n\n element.addEventListener(\"mousedown\", dragMouseDown);\n\n function isResizeHandle(target: HTMLElement): boolean {\n // Check if the element or any of its parents is a resize handle\n let current = target;\n while (current && current !== element) {\n // Check for various resize handle indicators\n if (\n current.classList.contains('resize-handle') ||\n current.classList.contains('ds-resizable-resize-handle') ||\n current.getAttribute('data-resize-handle') ||\n current.getAttribute('data-testid')?.includes('resize') ||\n current.getAttribute('data-placement') || // Resizable handles have data-placement\n current.style.cursor?.includes('resize') ||\n // Check for react-use-resizable specific classes/attributes\n current.classList.contains('resizable-handle') ||\n current.hasAttribute('data-resizable-handle') ||\n // Check for common resize cursor styles\n ['n-resize', 's-resize', 'e-resize', 'w-resize', 'ne-resize', 'nw-resize', 'se-resize', 'sw-resize'].includes(current.style.cursor)\n ) {\n return true;\n }\n current = current.parentElement as HTMLElement;\n }\n return false;\n }\n\n function getElementPosition(el: HTMLElement) {\n const style = window.getComputedStyle(el);\n const matrix = new DOMMatrix(style.transform);\n return {\n x: matrix.m41 || parseInt(style.left) || 0,\n y: matrix.m42 || parseInt(style.top) || 0\n };\n }\n\n function setElementPosition(el: HTMLElement, x: number, y: number) {\n // Use transform for better performance and smoother animation\n el.style.transform = `translate(${x}px, ${y}px)`;\n }\n\n function dragMouseDown(e: MouseEvent) {\n const target = e.target as HTMLElement;\n \n // Check if the click is on a resize handle\n if (isResizeHandle(target)) {\n return; // Don't start dragging\n }\n \n // Let resize handles take priority - if we reach this point and there's a resizable container,\n // we should check if there are actual resize handles present before preventing drag\n if (element.closest('[data-resizable]')) {\n const rect = element.getBoundingClientRect();\n const x = e.clientX - rect.left;\n const y = e.clientY - rect.top;\n const handleSize = 8;\n \n // Only prevent drag if we're near an edge AND there are actual resize handles\n const nearTopEdge = y <= handleSize;\n const nearBottomEdge = y >= rect.height - handleSize;\n const nearLeftEdge = x <= handleSize;\n const nearRightEdge = x >= rect.width - handleSize;\n \n // Check if resize handles exist for the edges we're near\n const hasTopHandle = element.querySelector('.ds-resizable-resize-handle[data-placement*=\"top\"]');\n const hasBottomHandle = element.querySelector('.ds-resizable-resize-handle[data-placement*=\"bottom\"]');\n const hasLeftHandle = element.querySelector('.ds-resizable-resize-handle[data-placement*=\"left\"]');\n const hasRightHandle = element.querySelector('.ds-resizable-resize-handle[data-placement*=\"right\"]');\n \n if (\n (nearTopEdge && hasTopHandle) ||\n (nearBottomEdge && hasBottomHandle) ||\n (nearLeftEdge && hasLeftHandle) ||\n (nearRightEdge && hasRightHandle)\n ) {\n return; // Let resize handle it\n }\n }\n \n e.preventDefault();\n e.stopPropagation();\n \n isDragging = true;\n \n // Store initial mouse position\n startX = e.clientX;\n startY = e.clientY;\n \n // Get initial element position\n const pos = getElementPosition(element);\n initialLeft = pos.x;\n initialTop = pos.y;\n \n // Set initial cursor style and prevent text selection\n document.body.style.cursor = 'grabbing';\n document.body.style.userSelect = 'none';\n \n // Only disable pointer events on content areas, not buttons/interactive elements\n const interactiveElements = element.querySelectorAll('button, a, input, select, textarea, [role=\"button\"]');\n interactiveElements.forEach(el => {\n (el as HTMLElement).style.pointerEvents = 'auto';\n });\n \n // Add move and up listeners\n document.addEventListener(\"mousemove\", elementDrag, { passive: false });\n document.addEventListener(\"mouseup\", closeDragElement);\n \n // Add touch events for mobile support\n document.addEventListener(\"touchmove\", handleTouchMove, { passive: false });\n document.addEventListener(\"touchend\", closeDragElement);\n }\n\n function elementDrag(e: MouseEvent) {\n if (!isDragging || !element) return;\n \n e.preventDefault();\n \n // Cancel any previous animation frame\n if (rafId) {\n cancelAnimationFrame(rafId);\n }\n \n // Use requestAnimationFrame for smooth animation\n rafId = requestAnimationFrame(() => {\n const deltaX = e.clientX - startX;\n const deltaY = e.clientY - startY;\n \n const newX = initialLeft + deltaX;\n const newY = initialTop + deltaY;\n \n // Apply position directly without bounds checking\n setElementPosition(element, newX, newY);\n });\n }\n\n function handleTouchMove(e: TouchEvent) {\n if (!isDragging || !element) return;\n \n e.preventDefault();\n \n const touch = e.touches[0];\n if (!touch) return;\n \n // Convert touch event to mouse-like event\n const mouseEvent = new MouseEvent('mousemove', {\n clientX: touch.clientX,\n clientY: touch.clientY,\n bubbles: true\n });\n \n elementDrag(mouseEvent);\n }\n\n function closeDragElement() {\n if (!isDragging) return;\n \n isDragging = false;\n \n // Cancel any pending animation frame\n if (rafId) {\n cancelAnimationFrame(rafId);\n rafId = null;\n }\n \n // Restore styles\n document.body.style.cursor = '';\n document.body.style.userSelect = '';\n \n // Restore pointer events for interactive elements\n if (element) {\n const interactiveElements = element.querySelectorAll('button, a, input, select, textarea, [role=\"button\"]');\n interactiveElements.forEach(el => {\n (el as HTMLElement).style.pointerEvents = '';\n });\n }\n \n // Remove event listeners\n document.removeEventListener(\"mousemove\", elementDrag);\n document.removeEventListener(\"mouseup\", closeDragElement);\n document.removeEventListener(\"touchmove\", handleTouchMove);\n document.removeEventListener(\"touchend\", closeDragElement);\n }\n\n // Cleanup function\n return () => {\n element.removeEventListener(\"mousedown\", dragMouseDown);\n closeDragElement();\n };\n }, [enabled]);\n \n return { ref };\n}\n"],"names":["useDraggable","enabled","useCallback","element","isDragging","startX","startY","initialLeft","initialTop","rafId","dragMouseDown","isResizeHandle","target","current","_a","_b","getElementPosition","el","style","matrix","setElementPosition","x","y","e","rect","handleSize","nearTopEdge","nearBottomEdge","nearLeftEdge","nearRightEdge","hasTopHandle","hasBottomHandle","hasLeftHandle","hasRightHandle","pos","elementDrag","closeDragElement","handleTouchMove","deltaX","deltaY","newX","newY","touch","mouseEvent"],"mappings":";;AAGgB,SAAAA,EAAaC,IAAmB,IAAM;AAyMpD,SAAO,EAAE,KAxMGC,EAAY,CAACC,MAAgC;AACnD,QAAA,CAACA,KAAW,CAACF,EAAS;AAE1B,QAAIG,IAAa,IACbC,IAAS,GACTC,IAAS,GACTC,IAAc,GACdC,IAAa,GACbC,IAAuB;AAEnB,IAAAN,EAAA,iBAAiB,aAAaO,CAAa;AAEnD,aAASC,EAAeC,GAA8B;;AAEpD,UAAIC,IAAUD;AACP,aAAAC,KAAWA,MAAYV,KAAS;AAGnC,YAAAU,EAAQ,UAAU,SAAS,eAAe,KAC1CA,EAAQ,UAAU,SAAS,4BAA4B,KACvDA,EAAQ,aAAa,oBAAoB,MACzCC,IAAAD,EAAQ,aAAa,aAAa,MAAlC,QAAAC,EAAqC,SAAS,aAC9CD,EAAQ,aAAa,gBAAgB;AAAA,SACrCE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IAAA;AAGxB,aAASP,IAAmB;AAC1B,MAAKhC,MAEQA,IAAA,IAGTK,MACF,qBAAqBA,CAAK,GAClBA,IAAA,OAID,SAAA,KAAK,MAAM,SAAS,IACpB,SAAA,KAAK,MAAM,aAAa,IAG7BN,KAC0BA,EAAQ,iBAAiB,qDAAqD,EACtF,QAAQ,CAAMc,MAAA;AAC/B,QAAAA,EAAmB,MAAM,gBAAgB;AAAA,MAAA,CAC3C,GAIM,SAAA,oBAAoB,aAAakB,CAAW,GAC5C,SAAA,oBAAoB,WAAWC,CAAgB,GAC/C,SAAA,oBAAoB,aAAaC,CAAe,GAChD,SAAA,oBAAoB,YAAYD,CAAgB;AAAA,IAAA;AAI3D,WAAO,MAAM;AACH,MAAAjC,EAAA,oBAAoB,aAAaO,CAAa,GACrC0B,EAAA;AAAA,IACnB;AAAA,EAAA,GACC,CAACnC,CAAO,CAAC,EAEC;AACf;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState as v, useRef as E, useCallback as n } from "react";
|
|
3
|
+
function l() {
|
|
4
|
+
const [c, u] = v(!1), t = E(null), r = n(() => {
|
|
5
|
+
u(!0);
|
|
6
|
+
}, []), s = n(() => {
|
|
7
|
+
u(!1);
|
|
8
|
+
}, []);
|
|
9
|
+
return [n(
|
|
10
|
+
(e) => {
|
|
11
|
+
var o;
|
|
12
|
+
((o = t.current) == null ? void 0 : o.nodeType) === Node.ELEMENT_NODE && (t.current.removeEventListener(
|
|
13
|
+
"mouseenter",
|
|
14
|
+
r
|
|
15
|
+
), t.current.removeEventListener(
|
|
16
|
+
"mouseleave",
|
|
17
|
+
s
|
|
18
|
+
)), (e == null ? void 0 : e.nodeType) === Node.ELEMENT_NODE && (e.addEventListener("mouseenter", r), e.addEventListener("mouseleave", s)), t.current = e;
|
|
19
|
+
},
|
|
20
|
+
[r, s]
|
|
21
|
+
), c];
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
l as useHover
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=useHover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHover.js","sources":["../../../src/components/hooks/useHover.ts"],"sourcesContent":["\"use client\";\n\nimport { useState, useCallback, useRef } from \"react\";\n\nexport function useHover<T extends HTMLElement>(): [\n (node: T) => void,\n boolean\n] {\n const [hovering, setHovering] = useState(false);\n const previousNode = useRef(null);\n\n const handleMouseEnter = useCallback(() => {\n setHovering(true);\n }, []);\n\n const handleMouseLeave = useCallback(() => {\n setHovering(false);\n }, []);\n\n const customRef = useCallback(\n (node: T) => {\n if (previousNode.current?.nodeType === Node.ELEMENT_NODE) {\n previousNode.current.removeEventListener(\n \"mouseenter\",\n handleMouseEnter\n );\n previousNode.current.removeEventListener(\n \"mouseleave\",\n handleMouseLeave\n );\n }\n\n if (node?.nodeType === Node.ELEMENT_NODE) {\n node.addEventListener(\"mouseenter\", handleMouseEnter);\n node.addEventListener(\"mouseleave\", handleMouseLeave);\n }\n\n previousNode.current = node;\n },\n [handleMouseEnter, handleMouseLeave]\n );\n\n return [customRef, hovering];\n}\n"],"names":["useHover","hovering","setHovering","useState","previousNode","useRef","handleMouseEnter","useCallback","handleMouseLeave","node","_a"],"mappings":";;AAIO,SAASA,IAGd;AACA,QAAM,CAACC,GAAUC,CAAW,IAAIC,EAAS,EAAK,GACxCC,IAAeC,EAAO,IAAI,GAE1BC,IAAmBC,EAAY,MAAM;AACzC,IAAAL,EAAY,EAAI;AAAA,EAClB,GAAG,EAAE,GAECM,IAAmBD,EAAY,MAAM;AACzC,IAAAL,EAAY,EAAK;AAAA,EACnB,GAAG,EAAE;AAyBE,SAAA,CAvBWK;AAAA,IAChB,CAACE,MAAY;;AACX,QAAIC,IAAAN,EAAa,YAAb,gBAAAM,EAAsB,cAAa,KAAK,iBAC1CN,EAAa,QAAQ;AAAA,QACnB;AAAA,QACAE;AAAA,MACF,GACAF,EAAa,QAAQ;AAAA,QACnB;AAAA,QACAI;AAAA,MACF,KAGEC,KAAA,gBAAAA,EAAM,cAAa,KAAK,iBACrBA,EAAA,iBAAiB,cAAcH,CAAgB,GAC/CG,EAAA,iBAAiB,cAAcD,CAAgB,IAGtDJ,EAAa,UAAUK;AAAA,IACzB;AAAA,IACA,CAACH,GAAkBE,CAAgB;AAAA,EACrC,GAEmBP,CAAQ;AAC7B;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as c from "react";
|
|
3
|
+
import * as m from "react-dom";
|
|
4
|
+
import { useIsoLayoutEffect as e } from "@base-ui-components/utils/useIsoLayoutEffect";
|
|
5
|
+
import { AnimationFrame as u } from "@base-ui-components/utils/useAnimationFrame";
|
|
6
|
+
function g(t, n = !1, f = !1) {
|
|
7
|
+
const [r, s] = c.useState(
|
|
8
|
+
t && n ? "idle" : void 0
|
|
9
|
+
), [i, a] = c.useState(t);
|
|
10
|
+
return t && !i && (a(!0), s("starting")), !t && i && r !== "ending" && !f && s("ending"), !t && !i && r === "ending" && s(void 0), e(() => {
|
|
11
|
+
if (!t && i && r !== "ending" && f) {
|
|
12
|
+
const o = u.request(() => {
|
|
13
|
+
s("ending");
|
|
14
|
+
});
|
|
15
|
+
return () => {
|
|
16
|
+
u.cancel(o);
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}, [t, i, r, f]), e(() => {
|
|
20
|
+
if (!t || n)
|
|
21
|
+
return;
|
|
22
|
+
const o = u.request(() => {
|
|
23
|
+
m.flushSync(() => {
|
|
24
|
+
s(void 0);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return () => {
|
|
28
|
+
u.cancel(o);
|
|
29
|
+
};
|
|
30
|
+
}, [n, t]), e(() => {
|
|
31
|
+
if (!t || !n)
|
|
32
|
+
return;
|
|
33
|
+
t && i && r !== "idle" && s("starting");
|
|
34
|
+
const o = u.request(() => {
|
|
35
|
+
s("idle");
|
|
36
|
+
});
|
|
37
|
+
return () => {
|
|
38
|
+
u.cancel(o);
|
|
39
|
+
};
|
|
40
|
+
}, [n, t, i, s, r]), c.useMemo(
|
|
41
|
+
() => ({
|
|
42
|
+
mounted: i,
|
|
43
|
+
setMounted: a,
|
|
44
|
+
transitionStatus: r
|
|
45
|
+
}),
|
|
46
|
+
[i, r]
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
g as useTransitionStatus
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=useTransitionStatus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useTransitionStatus.js","sources":["../../../src/components/hooks/useTransitionStatus.ts"],"sourcesContent":["\"use client\";\nimport * as React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { useIsoLayoutEffect } from \"@base-ui-components/utils/useIsoLayoutEffect\";\nimport { AnimationFrame } from \"@base-ui-components/utils/useAnimationFrame\";\n\nexport type TransitionStatus = \"starting\" | \"ending\" | \"idle\" | undefined;\n\n/**\n * Provides a status string for CSS animations.\n * @param open - a boolean that determines if the element is open.\n * @param enableIdleState - a boolean that enables the `'idle'` state between `'starting'` and `'ending'`\n */\nexport function useTransitionStatus(\n open: boolean,\n enableIdleState: boolean = false,\n deferEndingState: boolean = false\n) {\n const [transitionStatus, setTransitionStatus] =\n React.useState<TransitionStatus>(\n open && enableIdleState ? \"idle\" : undefined\n );\n const [mounted, setMounted] = React.useState(open);\n\n if (open && !mounted) {\n setMounted(true);\n setTransitionStatus(\"starting\");\n }\n\n if (!open && mounted && transitionStatus !== \"ending\" && !deferEndingState) {\n setTransitionStatus(\"ending\");\n }\n\n if (!open && !mounted && transitionStatus === \"ending\") {\n setTransitionStatus(undefined);\n }\n\n useIsoLayoutEffect(() => {\n if (!open && mounted && transitionStatus !== \"ending\" && deferEndingState) {\n const frame = AnimationFrame.request(() => {\n setTransitionStatus(\"ending\");\n });\n\n return () => {\n AnimationFrame.cancel(frame);\n };\n }\n\n return undefined;\n }, [open, mounted, transitionStatus, deferEndingState]);\n\n useIsoLayoutEffect(() => {\n if (!open || enableIdleState) {\n return undefined;\n }\n\n const frame = AnimationFrame.request(() => {\n ReactDOM.flushSync(() => {\n setTransitionStatus(undefined);\n });\n });\n\n return () => {\n AnimationFrame.cancel(frame);\n };\n }, [enableIdleState, open]);\n\n useIsoLayoutEffect(() => {\n if (!open || !enableIdleState) {\n return undefined;\n }\n\n if (open && mounted && transitionStatus !== \"idle\") {\n setTransitionStatus(\"starting\");\n }\n\n const frame = AnimationFrame.request(() => {\n setTransitionStatus(\"idle\");\n });\n\n return () => {\n AnimationFrame.cancel(frame);\n };\n }, [enableIdleState, open, mounted, setTransitionStatus, transitionStatus]);\n\n return React.useMemo(\n () => ({\n mounted,\n setMounted,\n transitionStatus,\n }),\n [mounted, transitionStatus]\n );\n}\n"],"names":["useTransitionStatus","open","enableIdleState","deferEndingState","transitionStatus","setTransitionStatus","React","mounted","setMounted","useIsoLayoutEffect","frame","AnimationFrame","ReactDOM"],"mappings":";;;;;AAaO,SAASA,EACdC,GACAC,IAA2B,IAC3BC,IAA4B,IAC5B;AACA,QAAM,CAACC,GAAkBC,CAAmB,IAC1CC,EAAM;AAAA,IACJL,KAAQC,IAAkB,SAAS;AAAA,EACrC,GACI,CAACK,GAASC,CAAU,IAAIF,EAAM,SAASL,CAAI;AAE7C,SAAAA,KAAQ,CAACM,MACXC,EAAW,EAAI,GACfH,EAAoB,UAAU,IAG5B,CAACJ,KAAQM,KAAWH,MAAqB,YAAY,CAACD,KACxDE,EAAoB,QAAQ,GAG1B,CAACJ,KAAQ,CAACM,KAAWH,MAAqB,YAC5CC,EAAoB,MAAS,GAG/BI,EAAmB,MAAM;AACvB,QAAI,CAACR,KAAQM,KAAWH,MAAqB,YAAYD,GAAkB;AACnE,YAAAO,IAAQC,EAAe,QAAQ,MAAM;AACzC,QAAAN,EAAoB,QAAQ;AAAA,MAAA,CAC7B;AAED,aAAO,MAAM;AACX,QAAAM,EAAe,OAAOD,CAAK;AAAA,M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