@bioturing/components 0.29.2 → 0.31.0
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/choice-list/component.js +26 -28
- package/dist/components/choice-list/component.js.map +1 -1
- package/dist/components/code-block/component.js +10 -10
- package/dist/components/combobox/component.js +113 -112
- package/dist/components/combobox/component.js.map +1 -1
- package/dist/components/command-palette/component.js +79 -0
- package/dist/components/command-palette/component.js.map +1 -0
- package/dist/components/command-palette/style.css +1 -0
- package/dist/components/dropdown-menu/component.js +117 -189
- package/dist/components/dropdown-menu/component.js.map +1 -1
- package/dist/components/dropdown-menu/item.css +1 -1
- package/dist/components/dropdown-menu/item.js +50 -37
- package/dist/components/dropdown-menu/item.js.map +1 -1
- package/dist/components/dropdown-menu/style.css +1 -1
- package/dist/components/dropdown-menu/useDropdownMenu.js +124 -0
- package/dist/components/dropdown-menu/useDropdownMenu.js.map +1 -0
- package/dist/components/hooks/antd.js +9 -11
- package/dist/components/hooks/antd.js.map +1 -1
- package/dist/components/hooks/useBreakpoint.js +50 -0
- package/dist/components/hooks/useBreakpoint.js.map +1 -0
- package/dist/components/hooks/useResizeObserver.js +52 -0
- package/dist/components/hooks/useResizeObserver.js.map +1 -0
- package/dist/components/hooks/useWindowSize.js +23 -0
- package/dist/components/hooks/useWindowSize.js.map +1 -0
- package/dist/components/keyboard-shortcut/component.js +72 -0
- package/dist/components/keyboard-shortcut/component.js.map +1 -0
- package/dist/components/keyboard-shortcut/style.css +1 -0
- package/dist/components/loader/component.js +15 -0
- package/dist/components/loader/component.js.map +1 -0
- package/dist/components/loader/style.css +1 -0
- package/dist/components/modal/index.js.map +1 -1
- package/dist/components/popup-panel/style.css +1 -1
- package/dist/components/resizable/component.js +107 -90
- package/dist/components/resizable/component.js.map +1 -1
- package/dist/components/theme-provider/style.css +1 -1
- package/dist/components/toast/style.css +1 -1
- package/dist/index.d.ts +240 -59
- package/dist/index.js +204 -191
- package/dist/index.js.map +1 -1
- package/dist/metadata.js +47 -2
- package/dist/metadata.js.map +1 -1
- package/package.json +1 -1
|
@@ -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/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\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\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 * Function to extract keywords from the item for search filtering\n * @default (item) => [String(item.key), reactNodeToString(item.label)]\n */\n getItemKeywords?: (item: DropdownMenuItemType & { type: \"item\" }) => string[];\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 getItemKeywords,\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 getItemKeywords={getItemKeywords}\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 <FormItemInputContext.Provider value={{}}>\n <Command.Input\n {...searchProps}\n key=\"search\"\n render={\n <Input\n allowClear\n className={cls(\"dropdown-menu-search\")}\n placeholder=\"Search\"\n />\n }\n />\n </FormItemInputContext.Provider>\n {beforeList}\n <ScrollArea fadeEdges>\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 fadeEdges>{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","getItemKeywords","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","FormItemInputContext","createElement","Input","ScrollArea","BaseComponent","Popover","DROPDOWN_COLLISION_AVOIDANCE","PopupPanelSize"],"mappings":";;;;;;;;;;;;;;;;;;AAoNO,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;AAAA,EACA,iBAAAC;AACF,MAAyB;AACvB,QAAM,CAACC,GAAMC,CAAO,IAAIC,EAAc;AAAA,IACpC,YAAYlB;AAAA,IACZ,SAAS;AAAA,IACT,MAAM;AAAA,EAAA,CACP,GACKmB,IAAe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gBACEnB,KAAQoD,IAAiBA,EAAepD,CAAI,IAAI;AAAA,gBACpD;AAAA,gBAGD,UAAgB4C,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 { 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\";\nimport { FormItemInputContext } from \"antd/es/form/context\";\n\n// Import component-specific styles\nimport { Input } from \"../input\";\nimport { PopupPanelSize } from \"../popup-panel/constants\";\n\nimport { DropdownMenuItemType } from \"./types\";\nimport { useDropdownMenu, UseDropdownMenuProps } from \"./useDropdownMenu\";\nimport { useControlledState } from \"../hooks\";\n\nimport \"./style.css\";\n\nexport interface DropdownMenuProps\n extends Omit<UseDropdownMenuProps, \"classNames\"> {\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 * Default open state of the dropdown\n */\n defaultOpen?: boolean;\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 itemIcon?: string;\n itemText?: string;\n positioner?: string;\n } & UseDropdownMenuProps[\"classNames\"];\n\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 * 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\nexport const DropdownMenu = ({\n children,\n items,\n placement,\n openOnHover,\n open: outsideOpen,\n onOpenChange: outsideOnOpenChange,\n defaultOpen,\n className,\n itemRender,\n classNames,\n size = \"auto\",\n showSearch,\n inCombobox: inComboboxProp,\n searchProps = {\n placeholder: \"Search...\",\n },\n popupMatchTriggerWidth,\n beforeList,\n afterList,\n keepOpenOnSelect,\n highlightedItemKey,\n selectedItemKeys,\n getItemKeywords,\n showCheckbox,\n}: DropdownMenuProps) => {\n const inCombobox =\n typeof inComboboxProp === \"boolean\" ? inComboboxProp : showSearch;\n const [open, onOpenChange] = useControlledState(\n outsideOpen,\n outsideOnOpenChange,\n defaultOpen,\n );\n const cls = useCls();\n const antdCssVarClassname = useAntdCssVarClassname();\n const baseUIPlacement = parseAntdPlacement(placement);\n const buttonRef = useRef<HTMLButtonElement>(null);\n const { itemGroups, renderGroup } = useDropdownMenu({\n items,\n keepOpenOnSelect,\n highlightedItemKey,\n selectedItemKeys,\n showCheckbox,\n getItemKeywords,\n itemRender,\n inCombobox,\n onOpenChange,\n classNames: {\n item: classNames?.item,\n itemIcon: classNames?.itemIcon,\n itemSuffix: classNames?.itemSuffix,\n group: classNames?.group,\n groupLabel: classNames?.groupLabel,\n divider: classNames?.divider,\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 <FormItemInputContext.Provider value={{}}>\n <Command.Input\n {...searchProps}\n key=\"search\"\n render={\n <Input\n allowClear\n className={cls(\"dropdown-menu-search\")}\n placeholder=\"Search\"\n />\n }\n />\n </FormItemInputContext.Provider>\n {beforeList}\n <ScrollArea fadeEdges>\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(renderGroup)}\n </Command.List>\n </ScrollArea>\n {afterList}\n </Command>\n ) : (\n <div className={cls(\"dropdown-menu-container\")}>\n {beforeList}\n <ScrollArea fadeEdges>{itemGroups.map(renderGroup)}</ScrollArea>\n {afterList}\n </div>\n ),\n [\n showSearch,\n cls,\n highlightedItemKey,\n searchProps,\n beforeList,\n itemGroups,\n afterList,\n renderGroup,\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","defaultOpen","className","itemRender","classNames","size","showSearch","inComboboxProp","searchProps","popupMatchTriggerWidth","beforeList","afterList","keepOpenOnSelect","highlightedItemKey","selectedItemKeys","getItemKeywords","showCheckbox","inCombobox","open","onOpenChange","useControlledState","cls","useCls","antdCssVarClassname","useAntdCssVarClassname","baseUIPlacement","parseAntdPlacement","buttonRef","useRef","itemGroups","renderGroup","useDropdownMenu","renderMenuInner","useCallback","jsxs","Command","jsx","FormItemInputContext","createElement","Input","ScrollArea","BaseComponent","Popover","Menu","clsx","DROPDOWN_COLLISION_AVOIDANCE","PopupPanelSize"],"mappings":";;;;;;;;;;;;;;;;;AAuGO,MAAMA,KAAe,CAAC;AAAA,EAC3B,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,WAAAC;AAAA,EACA,aAAAC;AAAA,EACA,MAAMC;AAAA,EACN,cAAcC;AAAA,EACd,aAAAC;AAAA,EACA,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,YAAAC;AAAA,EACA,YAAYC;AAAA,EACZ,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,iBAAAC;AAAA,EACA,cAAAC;AACF,MAAyB;AACvB,QAAMC,IACJ,OAAOV,KAAmB,YAAYA,IAAiBD,GACnD,CAACY,GAAMC,CAAY,IAAIC;AAAA,IAC3BrB;AAAA,IACAC;AAAA,IACAC;AAAA,EACF,GACMoB,IAAMC,EAAO,GACbC,IAAsBC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AAA,kBACTvB;AAAA,oBACE;AAAA,oBACAL,KAAgB;AAAA,oBAChBP,KAA0B;AAAA,kBAC5B;AAAA,kBACAP;AAAA,kBACAE,KAAA,gBAAAA,EAAY;AAAA,kBACZmB;AAAA,gBACF;AAAA,gBACA,OACE;AAAA,kBACE,gBACElB,KAAQyC,IAAiBA,EAAezC,CAAI,IAAI;AAAA,gBACpD;AAAA,gBAGD,UAAgB2B,EAAA;AAAA,cAAA;AAAA,YAAA;AAAA,UACnB;AAAA,QAAA,EAEJ,CAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
@@ -1 +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)
|
|
1
|
+
@layer components{.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))}.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);color:var(--ds-color-text)}.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)}.ds-dropdown-menu:not(.ds-dropdown-menu-show-checkbox) .ds-dropdown-menu-item[data-actual-selected=true]{background:var(--ds-control-item-bg-active)}.ds-dropdown-menu-item[data-disabled=true]{pointer-events:none;color:var(--ds-color-text-disabled)}.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)}.ds-dropdown-menu-item .ds-dropdown-menu-item-text{flex-grow:1}.ds-dropdown-menu-item .ds-dropdown-menu-item-suffix{margin-left:.75rem;font-size:.75rem;line-height:1.25rem;color:var(--color-ds-color-text-tertiary);display:flex;flex-grow:0;flex-shrink:0;align-items:flex-end}.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[data-danger=true] .ds-dropdown-menu-item-icon{color:var(--ds-color-error)}}
|
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as I, Fragment as
|
|
3
|
-
import { useMemo as
|
|
2
|
+
import { jsxs as I, Fragment as h, jsx as r } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo as e } from "react";
|
|
4
4
|
import { Command as j } from "../cmdk/index.js";
|
|
5
5
|
import { Menu as E } from "@base-ui-components/react/menu";
|
|
6
6
|
import './item.css';/* empty css */
|
|
7
7
|
import { Checkbox as w } from "antd";
|
|
8
8
|
import { reactNodeToString as L } from "../utils/reactToString.js";
|
|
9
9
|
import { useCls as D } from "../utils/antdUtils.js";
|
|
10
|
-
import { clsx as
|
|
10
|
+
import { clsx as u } from "../utils/cn.js";
|
|
11
11
|
const J = ({
|
|
12
12
|
item: o,
|
|
13
|
-
inCombobox:
|
|
13
|
+
inCombobox: p = !1,
|
|
14
14
|
selected: f = !1,
|
|
15
|
-
itemRender:
|
|
16
|
-
itemProps:
|
|
15
|
+
itemRender: t,
|
|
16
|
+
itemProps: S = {},
|
|
17
17
|
classNames: n,
|
|
18
18
|
onSelect: k,
|
|
19
|
-
showCheckbox:
|
|
20
|
-
indeterminate:
|
|
21
|
-
renderAsNativeElement:
|
|
19
|
+
showCheckbox: x,
|
|
20
|
+
indeterminate: M,
|
|
21
|
+
renderAsNativeElement: y,
|
|
22
22
|
getItemKeywords: g
|
|
23
23
|
}) => {
|
|
24
|
-
const d = D(),
|
|
25
|
-
() =>
|
|
26
|
-
[
|
|
27
|
-
), i =
|
|
28
|
-
className:
|
|
29
|
-
d("dropdown-menu-item",
|
|
24
|
+
const d = D(), O = e(
|
|
25
|
+
() => p ? j.Item : E.Item,
|
|
26
|
+
[p]
|
|
27
|
+
), i = e(() => ({
|
|
28
|
+
className: u(
|
|
29
|
+
d("dropdown-menu-item", p && "dropdown-menu-item-combobox"),
|
|
30
30
|
n == null ? void 0 : n.item,
|
|
31
31
|
o.className
|
|
32
32
|
),
|
|
@@ -40,20 +40,20 @@ const J = ({
|
|
|
40
40
|
onMouseOver: o.onMouseOver,
|
|
41
41
|
onMouseOut: o.onMouseOut,
|
|
42
42
|
"data-value": typeof o.label == "string" ? o.label : String(o.key),
|
|
43
|
-
render:
|
|
44
|
-
children:
|
|
45
|
-
|
|
43
|
+
render: t ? (b) => t(o, b) : void 0,
|
|
44
|
+
children: p ? /* @__PURE__ */ I(h, { children: [
|
|
45
|
+
x && /* @__PURE__ */ r(
|
|
46
46
|
w,
|
|
47
47
|
{
|
|
48
48
|
checked: f,
|
|
49
49
|
tabIndex: -1,
|
|
50
|
-
indeterminate:
|
|
50
|
+
indeterminate: M
|
|
51
51
|
}
|
|
52
52
|
),
|
|
53
53
|
o.icon && /* @__PURE__ */ r(
|
|
54
54
|
"span",
|
|
55
55
|
{
|
|
56
|
-
className:
|
|
56
|
+
className: u(
|
|
57
57
|
d("dropdown-menu-item-icon"),
|
|
58
58
|
n == null ? void 0 : n.itemIcon
|
|
59
59
|
),
|
|
@@ -63,26 +63,26 @@ const J = ({
|
|
|
63
63
|
/* @__PURE__ */ r(
|
|
64
64
|
"span",
|
|
65
65
|
{
|
|
66
|
-
className:
|
|
66
|
+
className: u(
|
|
67
67
|
d("dropdown-menu-item-text"),
|
|
68
68
|
n == null ? void 0 : n.itemText
|
|
69
69
|
),
|
|
70
70
|
children: o.label
|
|
71
71
|
}
|
|
72
72
|
)
|
|
73
|
-
] }) : /* @__PURE__ */ I(
|
|
74
|
-
|
|
73
|
+
] }) : /* @__PURE__ */ I(h, { children: [
|
|
74
|
+
x && /* @__PURE__ */ r(
|
|
75
75
|
w,
|
|
76
76
|
{
|
|
77
77
|
checked: f,
|
|
78
78
|
tabIndex: -1,
|
|
79
|
-
indeterminate:
|
|
79
|
+
indeterminate: M
|
|
80
80
|
}
|
|
81
81
|
),
|
|
82
82
|
o.icon && /* @__PURE__ */ r(
|
|
83
83
|
"span",
|
|
84
84
|
{
|
|
85
|
-
className:
|
|
85
|
+
className: u(
|
|
86
86
|
d("dropdown-menu-item-icon"),
|
|
87
87
|
n == null ? void 0 : n.itemIcon
|
|
88
88
|
),
|
|
@@ -92,38 +92,51 @@ const J = ({
|
|
|
92
92
|
/* @__PURE__ */ r(
|
|
93
93
|
"span",
|
|
94
94
|
{
|
|
95
|
-
className:
|
|
95
|
+
className: u(
|
|
96
96
|
d("dropdown-menu-item-text"),
|
|
97
97
|
n == null ? void 0 : n.itemText
|
|
98
98
|
),
|
|
99
99
|
children: o.label
|
|
100
100
|
}
|
|
101
|
+
),
|
|
102
|
+
o.suffix && /* @__PURE__ */ r(
|
|
103
|
+
"span",
|
|
104
|
+
{
|
|
105
|
+
className: u(
|
|
106
|
+
d("dropdown-menu-item-suffix"),
|
|
107
|
+
n == null ? void 0 : n.itemSuffix
|
|
108
|
+
),
|
|
109
|
+
children: o.suffix
|
|
110
|
+
}
|
|
101
111
|
)
|
|
102
112
|
] })
|
|
103
113
|
}), [
|
|
104
114
|
n == null ? void 0 : n.item,
|
|
105
115
|
n == null ? void 0 : n.itemIcon,
|
|
106
116
|
n == null ? void 0 : n.itemText,
|
|
117
|
+
n == null ? void 0 : n.itemSuffix,
|
|
107
118
|
d,
|
|
108
|
-
u,
|
|
109
|
-
e,
|
|
110
|
-
o,
|
|
111
119
|
p,
|
|
120
|
+
M,
|
|
121
|
+
o,
|
|
122
|
+
t,
|
|
112
123
|
f,
|
|
113
|
-
|
|
124
|
+
x
|
|
114
125
|
]);
|
|
115
|
-
if (
|
|
116
|
-
return
|
|
126
|
+
if (t)
|
|
127
|
+
return t(o, {
|
|
117
128
|
...i,
|
|
118
|
-
...
|
|
129
|
+
...S
|
|
119
130
|
});
|
|
120
|
-
const { render: v, ...
|
|
121
|
-
return
|
|
122
|
-
|
|
131
|
+
const { render: v, ...T } = i;
|
|
132
|
+
return y ? v ? v(i) : /* @__PURE__ */ r("div", { onClick: k, ...T }) : /* @__PURE__ */ r(
|
|
133
|
+
O,
|
|
123
134
|
{
|
|
124
135
|
value: String(o.key),
|
|
125
136
|
keywords: g ? g(o) : [String(o.key), L(o.label)],
|
|
126
|
-
onSelect:
|
|
137
|
+
onSelect: () => {
|
|
138
|
+
k(o);
|
|
139
|
+
},
|
|
127
140
|
...i
|
|
128
141
|
}
|
|
129
142
|
);
|
|
@@ -1 +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, reactNodeToString, useCls } from \"../utils\";\nimport type { DropdownMenuItemType } from \"./
|
|
1
|
+
{"version":3,"file":"item.js","sources":["../../../src/components/dropdown-menu/item.tsx"],"sourcesContent":["\"use client\";\nimport React, { Ref, useMemo } from \"react\";\nimport { clsx, reactNodeToString, useCls } from \"../utils\";\nimport type { DropdownMenuItemType } from \"./types\";\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 itemSuffix?: string;\n };\n onSelect?: (item: DropdownMenuItemType & { type: \"item\" }) => 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 * Function to extract keywords from the item for search filtering\n * @default (item) => [String(item.key), reactNodeToString(item.label)]\n */\n getItemKeywords?: (item: DropdownMenuItemType & { type: \"item\" }) => string[];\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 getItemKeywords,\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 {item.suffix && (\n <span\n className={clsx(\n cls(\"dropdown-menu-item-suffix\"),\n classNames?.itemSuffix,\n )}\n >\n {item.suffix}\n </span>\n )}\n </>\n ),\n };\n }, [\n classNames?.item,\n classNames?.itemIcon,\n classNames?.itemText,\n classNames?.itemSuffix,\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 keywords={\n getItemKeywords\n ? getItemKeywords(item)\n : [String(item.key), reactNodeToString(item.label)]\n }\n onSelect={() => {\n onSelect(item);\n }}\n {...props}\n ></MenuItem>\n );\n};\n"],"names":["DropdownMenuItem","item","inCombobox","selected","itemRender","itemProps","classNames","onSelect","showCheckbox","indeterminate","renderAsNativeElement","getItemKeywords","cls","useCls","MenuItem","useMemo","Command","Menu","props","clsx","jsxs","Fragment","jsx","Checkbox","render","restProps","reactNodeToString"],"mappings":";;;;;;;;;;AAyDO,MAAMA,IAAoD,CAAC;AAAA,EAChE,MAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,UAAAC,IAAW;AAAA,EACX,YAAAC;AAAA,EACA,WAAAC,IAAY,CAAC;AAAA,EACb,YAAAC;AAAA,EACA,UAAAC;AAAA,EACA,cAAAC;AAAA,EACA,eAAAC;AAAA,EACA,uBAAAC;AAAA,EACA,iBAAAC;AACF,MAAM;AACJ,QAAMC,IAAMC,EAAO,GAEbC,IAAWC;AAAA,IACf,MAAOb,IAAac,EAAQ,OAAOC,EAAK;AAAA,IACxC,CAACf,CAAU;AAAA,EACb,GAEMgB,IAAQH,EAAQ,OACb;AAAA,IACL,WAAWI;AAAA,MACTP,EAAI,sBAAsBV,KAAc,6BAA6B;AAAA,MACrEI,KAAA,gBAAAA,EAAY;AAAA,MACZL,EAAK;AAAA,IACP;AAAA,IACA,UAAUA,EAAK;AAAA,IACf,eAAeA,EAAK;AAAA,IACpB,wBAAwBE;AAAA,IACxB,KAAKF,EAAK;AAAA,IACV,SAASA,EAAK;AAAA,IACd,cAAcA,EAAK;AAAA,IACnB,cAAcA,EAAK;AAAA,IACnB,aAAaA,EAAK;AAAA,IAClB,YAAYA,EAAK;AAAA,IACjB,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,UAAKL,EAAA;AAAA,QAAA;AAAA,MACR;AAAA,MACCA,EAAK,UACJ,gBAAAqB;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,WAAWH;AAAA,YACTP,EAAI,2BAA2B;AAAA,YAC/BN,KAAA,gBAAAA,EAAY;AAAA,UACd;AAAA,UAEC,UAAKL,EAAA;AAAA,QAAA;AAAA,MAAA;AAAA,IACR,EAEJ,CAAA;AAAA,EAEJ,IACC;AAAA,IACDK,KAAA,gBAAAA,EAAY;AAAA,IACZA,KAAA,gBAAAA,EAAY;AAAA,IACZA,KAAA,gBAAAA,EAAY;AAAA,IACZA,KAAA,gBAAAA,EAAY;AAAA,IACZM;AAAA,IACAV;AAAA,IACAO;AAAA,IACAR;AAAA,IACAG;AAAA,IACAD;AAAA,IACAK;AAAA,EAAA,CACD;AAED,MAAIJ;AACF,WAAOA,EAAWH,GAAM;AAAA,MACtB,GAAGiB;AAAA,MACH,GAAGb;AAAA,IAAA,CACJ;AAEH,QAAM,EAAE,QAAAmB,GAAQ,GAAGC,EAAA,IAAcP;AAE1B,SAAAR,IACLc,IACEA,EAAON,CAAK,IAEX,gBAAAI,EAAA,OAAA,EAAI,SAASf,GAAW,GAAGkB,EAAA,CAAW,IAGzC,gBAAAH;AAAA,IAACR;AAAA,IAAA;AAAA,MACC,OAAO,OAAOb,EAAK,GAAG;AAAA,MACtB,UACEU,IACIA,EAAgBV,CAAI,IACpB,CAAC,OAAOA,EAAK,GAAG,GAAGyB,EAAkBzB,EAAK,KAAK,CAAC;AAAA,MAEtD,UAAU,MAAM;AACd,QAAAM,EAASN,CAAI;AAAA,MACf;AAAA,MACC,GAAGiB;AAAA,IAAA;AAAA,EACL;AAEL;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
@layer components{.ds-dropdown-menu-root{z-index:
|
|
1
|
+
@layer components{.ds-dropdown-menu-root{z-index:var(--ds-z-index-dropdown)}.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,.ds-dropdown-menu .ds-dropdown-menu-list [cmdk-list-sizer]{flex-shrink:1;min-height:0;display:flex;flex-direction:column}}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { jsx as e, jsxs as D } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback as b, useMemo as L } from "react";
|
|
3
|
+
import { DropdownMenuItem as y } from "./item.js";
|
|
4
|
+
import { DropdownMenuDivider as j } from "./divider.js";
|
|
5
|
+
import { Menu as G } from "@base-ui-components/react";
|
|
6
|
+
import { Command as E } from "../cmdk/index.js";
|
|
7
|
+
import { useCls as T } from "../utils/antdUtils.js";
|
|
8
|
+
import { reactNodeToString as q } from "../utils/reactToString.js";
|
|
9
|
+
import { clsx as h } from "../utils/cn.js";
|
|
10
|
+
const W = ({
|
|
11
|
+
items: M,
|
|
12
|
+
inCombobox: n = !1,
|
|
13
|
+
classNames: o = {},
|
|
14
|
+
selectedItemKeys: f,
|
|
15
|
+
keepOpenOnSelect: v,
|
|
16
|
+
showCheckbox: w = !1,
|
|
17
|
+
getItemKeywords: S = (u) => [String(u.key), q(u.label)],
|
|
18
|
+
onOpenChange: l,
|
|
19
|
+
itemRender: g
|
|
20
|
+
}) => {
|
|
21
|
+
const u = T(), d = b(
|
|
22
|
+
(r, i, p) => r.type === "item" ? /* @__PURE__ */ e(
|
|
23
|
+
y,
|
|
24
|
+
{
|
|
25
|
+
item: r,
|
|
26
|
+
inCombobox: n,
|
|
27
|
+
selected: f == null ? void 0 : f.includes(r.key),
|
|
28
|
+
onSelect: n ? r.onSelect ? r.onSelect : () => {
|
|
29
|
+
const t = new MouseEvent("click", {
|
|
30
|
+
bubbles: !0,
|
|
31
|
+
cancelable: !0
|
|
32
|
+
});
|
|
33
|
+
r.onClick(t), v || l == null || l(!1);
|
|
34
|
+
} : void 0,
|
|
35
|
+
itemRender: g,
|
|
36
|
+
showCheckbox: w,
|
|
37
|
+
getItemKeywords: S,
|
|
38
|
+
classNames: {
|
|
39
|
+
item: o.item,
|
|
40
|
+
itemIcon: o.itemIcon,
|
|
41
|
+
itemSuffix: o.itemSuffix
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
i + "-" + p
|
|
45
|
+
) : r.type === "divider" ? /* @__PURE__ */ e(
|
|
46
|
+
j,
|
|
47
|
+
{
|
|
48
|
+
inCombobox: n,
|
|
49
|
+
className: o == null ? void 0 : o.divider
|
|
50
|
+
},
|
|
51
|
+
i + "-" + p
|
|
52
|
+
) : null,
|
|
53
|
+
[
|
|
54
|
+
o,
|
|
55
|
+
g,
|
|
56
|
+
l,
|
|
57
|
+
n,
|
|
58
|
+
v,
|
|
59
|
+
f,
|
|
60
|
+
w,
|
|
61
|
+
S
|
|
62
|
+
]
|
|
63
|
+
), k = b(
|
|
64
|
+
(r, i) => /* @__PURE__ */ D(
|
|
65
|
+
G.Group,
|
|
66
|
+
{
|
|
67
|
+
className: h(u("dropdown-menu-group"), o == null ? void 0 : o.group),
|
|
68
|
+
children: [
|
|
69
|
+
r.label && /* @__PURE__ */ e(
|
|
70
|
+
G.GroupLabel,
|
|
71
|
+
{
|
|
72
|
+
className: h(
|
|
73
|
+
u("dropdown-menu-header"),
|
|
74
|
+
o == null ? void 0 : o.groupLabel
|
|
75
|
+
),
|
|
76
|
+
children: /* @__PURE__ */ e("span", { children: r.label })
|
|
77
|
+
}
|
|
78
|
+
),
|
|
79
|
+
r.items.map((p, t) => d(p, i, t))
|
|
80
|
+
]
|
|
81
|
+
},
|
|
82
|
+
"group" + i
|
|
83
|
+
),
|
|
84
|
+
[u, o, d]
|
|
85
|
+
), m = b(
|
|
86
|
+
(r, i) => r.label ? /* @__PURE__ */ e(
|
|
87
|
+
E.Group,
|
|
88
|
+
{
|
|
89
|
+
className: h(u("dropdown-menu-group"), o == null ? void 0 : o.group),
|
|
90
|
+
heading: /* @__PURE__ */ e(
|
|
91
|
+
G.GroupLabel,
|
|
92
|
+
{
|
|
93
|
+
className: h(
|
|
94
|
+
u("dropdown-menu-header"),
|
|
95
|
+
o == null ? void 0 : o.groupLabel
|
|
96
|
+
),
|
|
97
|
+
children: /* @__PURE__ */ e("span", { children: r.label })
|
|
98
|
+
}
|
|
99
|
+
),
|
|
100
|
+
children: r.items.map((p, t) => d(p, i, t))
|
|
101
|
+
},
|
|
102
|
+
"group" + i
|
|
103
|
+
) : r.items.map((p, t) => d(p, i, t)),
|
|
104
|
+
[u, o, d]
|
|
105
|
+
);
|
|
106
|
+
return {
|
|
107
|
+
itemGroups: L(
|
|
108
|
+
() => M.reduce((r, i) => (r.length === 0 && i.type !== "header" && r.push({
|
|
109
|
+
label: null,
|
|
110
|
+
items: []
|
|
111
|
+
}), i.type === "header" ? r.push({
|
|
112
|
+
label: i.title,
|
|
113
|
+
items: []
|
|
114
|
+
}) : (i.type === "item" || i.type === "divider") && r.length > 0 && r[r.length - 1].items.push(i), r), []),
|
|
115
|
+
[M]
|
|
116
|
+
),
|
|
117
|
+
renderMenuItem: d,
|
|
118
|
+
renderGroup: n ? m : k
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
export {
|
|
122
|
+
W as useDropdownMenu
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=useDropdownMenu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDropdownMenu.js","sources":["../../../src/components/dropdown-menu/useDropdownMenu.tsx"],"sourcesContent":["import { useMemo, useCallback } from \"react\";\nimport { DropdownMenuItemType, DropdownMenuGroup } from \"./types\";\nimport { DropdownMenuItem } from \"./item\";\nimport { DropdownMenuDivider } from \"./divider\";\nimport { reactNodeToString, clsx, useCls } from \"../utils\";\nimport { Menu } from \"@base-ui-components/react\";\nimport { Command } from \"../cmdk\";\n\nexport interface UseDropdownMenuProps {\n /**\n * Callback function to handle the open state change of the dropdown menu.\n */\n onOpenChange?: (open: boolean) => void;\n items: DropdownMenuItemType[];\n inCombobox?: boolean;\n classNames?: {\n item?: string;\n itemIcon?: string;\n itemSuffix?: string;\n group?: string;\n groupLabel?: string;\n divider?: 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 /**\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 * Function to extract keywords from the item for search filtering\n * @default (item) => [String(item.key), reactNodeToString(item.label)]\n */\n getItemKeywords?: (item: DropdownMenuItemType & { type: \"item\" }) => string[];\n}\n\nexport const useDropdownMenu = ({\n items,\n inCombobox = false,\n classNames = {},\n selectedItemKeys,\n keepOpenOnSelect,\n showCheckbox = false,\n getItemKeywords = (item) => [String(item.key), reactNodeToString(item.label)],\n onOpenChange,\n itemRender,\n}: UseDropdownMenuProps) => {\n const cls = useCls();\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={inCombobox}\n selected={selectedItemKeys?.includes(item.key)}\n onSelect={\n inCombobox\n ? item.onSelect\n ? item.onSelect\n : () => {\n const e = new MouseEvent(\"click\", {\n bubbles: true,\n cancelable: true,\n }) as unknown as React.MouseEvent<\n HTMLElement,\n MouseEvent\n >;\n item.onClick(e);\n if (!keepOpenOnSelect) onOpenChange?.(false);\n }\n : undefined\n }\n itemRender={itemRender}\n showCheckbox={showCheckbox}\n getItemKeywords={getItemKeywords}\n classNames={{\n item: classNames.item,\n itemIcon: classNames.itemIcon,\n itemSuffix: classNames.itemSuffix,\n }}\n />\n );\n } else if (item.type === \"divider\") {\n return (\n <DropdownMenuDivider\n key={i + \"-\" + j}\n inCombobox={inCombobox}\n className={classNames?.divider}\n />\n );\n }\n return null;\n },\n [\n classNames,\n itemRender,\n onOpenChange,\n inCombobox,\n keepOpenOnSelect,\n selectedItemKeys,\n showCheckbox,\n getItemKeywords,\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 renderGroupCombobox = 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 itemGroups = useMemo(\n () =>\n 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 [items],\n );\n return {\n itemGroups,\n renderMenuItem,\n renderGroup: inCombobox ? renderGroupCombobox : renderGroup,\n };\n};\n"],"names":["useDropdownMenu","items","inCombobox","classNames","selectedItemKeys","keepOpenOnSelect","showCheckbox","getItemKeywords","item","reactNodeToString","onOpenChange","itemRender","cls","useCls","renderMenuItem","useCallback","j","jsx","DropdownMenuItem","e","DropdownMenuDivider","renderGroup","group","index","jsxs","Menu","clsx","renderGroupCombobox","Command","useMemo","acc","current"],"mappings":";;;;;;;;;AAwDO,MAAMA,IAAkB,CAAC;AAAA,EAC9B,OAAAC;AAAA,EACA,YAAAC,IAAa;AAAA,EACb,YAAAC,IAAa,CAAC;AAAA,EACd,kBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,cAAAC,IAAe;AAAA,EACf,iBAAAC,IAAkB,CAACC,MAAS,CAAC,OAAOA,EAAK,GAAG,GAAGC,EAAkBD,EAAK,KAAK,CAAC;AAAA,EAC5E,cAAAE;AAAA,EACA,YAAAC;AACF,MAA4B;AAC1B,QAAMC,IAAMC,EAAO,GACbC,IAAiBC;AAAA,IACrB,CAACP,GAA4B,GAAWQ,MAClCR,EAAK,SAAS,SAEd,gBAAAS;AAAA,MAACC;AAAA,MAAA;AAAA,QAEC,MAAAV;AAAA,QACA,YAAAN;AAAA,QACA,UAAUE,KAAA,gBAAAA,EAAkB,SAASI,EAAK;AAAA,QAC1C,UACEN,IACIM,EAAK,WACHA,EAAK,WACL,MAAM;AACE,gBAAAW,IAAI,I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ACR;AAAA,IAGE,gBAAAa;AAAA,IACA,aAAaZ,IAAayB,IAAsBN;AAAA,EAClD;AACF;"}
|
|
@@ -1,23 +1,21 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import s from "antd/es/theme";
|
|
3
|
-
import t from "antd/es/grid";
|
|
4
3
|
import o from "antd/es/app/useApp";
|
|
5
|
-
import { default as
|
|
6
|
-
import { useForm as l, useWatch as
|
|
7
|
-
const
|
|
4
|
+
import { default as c } from "antd/es/app/useApp";
|
|
5
|
+
import { useForm as l, useWatch as d } from "antd/es/form/Form";
|
|
6
|
+
const u = s.useToken, m = () => {
|
|
8
7
|
const { message: e } = o();
|
|
9
8
|
return e;
|
|
10
|
-
},
|
|
9
|
+
}, n = () => {
|
|
11
10
|
const { modal: e } = o();
|
|
12
11
|
return e;
|
|
13
12
|
};
|
|
14
13
|
export {
|
|
15
|
-
|
|
16
|
-
p as useBreakpoint,
|
|
14
|
+
c as useApp,
|
|
17
15
|
l as useForm,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
16
|
+
m as useMessage,
|
|
17
|
+
n as useModal,
|
|
18
|
+
u as useToken,
|
|
19
|
+
d as useWatch
|
|
22
20
|
};
|
|
23
21
|
//# sourceMappingURL=antd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"antd.js","sources":["../../../src/components/hooks/antd.ts"],"sourcesContent":["\"use client\";\nimport theme from \"antd/es/theme\";\
|
|
1
|
+
{"version":3,"file":"antd.js","sources":["../../../src/components/hooks/antd.ts"],"sourcesContent":["\"use client\";\nimport theme from \"antd/es/theme\";\n// import Grid from \"antd/es/grid\";\nimport useApp from \"antd/es/app/useApp\";\n\nexport const useToken = theme.useToken;\n// export const useBreakpoint = Grid.useBreakpoint;\n\nexport { useForm, useWatch } from \"antd/es/form/Form\";\n\nexport const useMessage = () => {\n const { message } = useApp();\n return message;\n};\n\nexport const useModal = () => {\n const { modal } = useApp();\n return modal;\n};\n\nexport { useApp };\n"],"names":["useToken","theme","useMessage","message","useApp","useModal","modal"],"mappings":";;;;;AAKO,MAAMA,IAAWC,EAAM,UAKjBC,IAAa,MAAM;AACxB,QAAA,EAAE,SAAAC,EAAQ,IAAIC,EAAO;AACpB,SAAAD;AACT,GAEaE,IAAW,MAAM;AACtB,QAAA,EAAE,OAAAC,EAAM,IAAIF,EAAO;AAClB,SAAAE;AACT;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useState as r, useMemo as M, useEffect as x, useCallback as w } from "react";
|
|
3
|
+
const e = {
|
|
4
|
+
sm: 640,
|
|
5
|
+
md: 768,
|
|
6
|
+
lg: 1024,
|
|
7
|
+
xl: 1280,
|
|
8
|
+
"2xl": 1536
|
|
9
|
+
}, q = (h = "lg") => {
|
|
10
|
+
const [i, l] = r(h), [d, u] = r(!1), a = M(() => {
|
|
11
|
+
const t = {};
|
|
12
|
+
return typeof window < "u" && (t.sm = window.matchMedia(`(max-width: ${e.md - 1}px)`), t.md = window.matchMedia(`(min-width: ${e.md}px) and (max-width: ${e.lg - 1}px)`), t.lg = window.matchMedia(`(min-width: ${e.lg}px) and (max-width: ${e.xl - 1}px)`), t.xl = window.matchMedia(`(min-width: ${e.xl}px) and (max-width: ${e["2xl"] - 1}px)`), t["2xl"] = window.matchMedia(`(min-width: ${e["2xl"]}px)`)), t;
|
|
13
|
+
}, []);
|
|
14
|
+
x(() => {
|
|
15
|
+
u(!0);
|
|
16
|
+
}, []), x(() => {
|
|
17
|
+
if (typeof window > "u" || !d) return;
|
|
18
|
+
const t = () => {
|
|
19
|
+
var m, o, s, c;
|
|
20
|
+
let n = "sm";
|
|
21
|
+
(m = a["2xl"]) != null && m.matches ? n = "2xl" : (o = a.xl) != null && o.matches ? n = "xl" : (s = a.lg) != null && s.matches ? n = "lg" : (c = a.md) != null && c.matches ? n = "md" : n = "sm", l(n);
|
|
22
|
+
};
|
|
23
|
+
return t(), Object.values(a).forEach((n) => {
|
|
24
|
+
n && n.addEventListener("change", t);
|
|
25
|
+
}), () => {
|
|
26
|
+
Object.values(a).forEach((n) => {
|
|
27
|
+
n && n.removeEventListener("change", t);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
}, [a, d]);
|
|
31
|
+
const f = w((t) => typeof window > "u" || !d ? e[i] >= e[t] : window.matchMedia(`(min-width: ${e[t]}px)`).matches, [d, i]), p = w((t) => typeof window > "u" || !d ? e[i] < e[t] : window.matchMedia(`(max-width: ${e[t] - 1}px)`).matches, [d, i]), $ = w((t, n) => typeof window > "u" || !d ? e[i] >= e[t] && e[i] < e[n] : window.matchMedia(`(min-width: ${e[t]}px) and (max-width: ${e[n] - 1}px)`).matches, [d, i]), y = w((t) => {
|
|
32
|
+
if (typeof window > "u" || !d)
|
|
33
|
+
return i === t;
|
|
34
|
+
const n = Object.keys(e), m = n.indexOf(t), o = n[m + 1];
|
|
35
|
+
let s;
|
|
36
|
+
return m === 0 ? s = `(max-width: ${e.md - 1}px)` : o ? s = `(min-width: ${e[t]}px) and (max-width: ${e[o] - 1}px)` : s = `(min-width: ${e[t]}px)`, window.matchMedia(s).matches;
|
|
37
|
+
}, [d, i]);
|
|
38
|
+
return {
|
|
39
|
+
breakpoint: i,
|
|
40
|
+
up: f,
|
|
41
|
+
down: p,
|
|
42
|
+
between: $,
|
|
43
|
+
only: y
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
export {
|
|
47
|
+
e as BREAKPOINTS,
|
|
48
|
+
q as useBreakpoint
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=useBreakpoint.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBreakpoint.js","sources":["../../../src/components/hooks/useBreakpoint.ts"],"sourcesContent":["\"use client\";\nimport { useEffect, useState, useCallback, useMemo } from \"react\";\n\ntype Breakpoint = \"sm\" | \"md\" | \"lg\" | \"xl\" | \"2xl\" | \"3xl\";\n\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};\n\n/**\n * A responsive breakpoint hook using window.matchMedia for optimal performance.\n *\n * @param ssrBreakpoint - The breakpoint to use during SSR and before hydration.\n * Defaults to \"lg\" for better SEO (search engines typically use desktop viewports).\n *\n * @example\n * ```tsx\n * // Default: uses \"lg\" for SSR\n * const bp = useBreakpoint();\n *\n * // Custom SSR breakpoint\n * const bp = useBreakpoint(\"md\");\n *\n * // Usage\n * bp.breakpoint // Current breakpoint: \"sm\" | \"md\" | \"lg\" | \"xl\" | \"2xl\"\n * bp.up(\"md\") // true if screen >= 768px\n * bp.down(\"lg\") // true if screen < 1024px\n * bp.between(\"md\", \"xl\") // true if 768px <= screen < 1280px\n * bp.only(\"lg\") // true if screen is exactly in \"lg\" range\n * ```\n */\nexport const useBreakpoint = (ssrBreakpoint: Breakpoint = \"lg\") => {\n const [breakpoint, setBreakpoint] = useState<Breakpoint>(ssrBreakpoint);\n const [isHydrated, setIsHydrated] = useState(false);\n\n // Generate media queries\n const mediaQueries = useMemo(() => {\n const queries: Record<Breakpoint, MediaQueryList> = {} as any;\n if (typeof window !== 'undefined') {\n queries.sm = window.matchMedia(`(max-width: ${BREAKPOINTS.md - 1}px)`);\n queries.md = window.matchMedia(`(min-width: ${BREAKPOINTS.md}px) and (max-width: ${BREAKPOINTS.lg - 1}px)`);\n queries.lg = window.matchMedia(`(min-width: ${BREAKPOINTS.lg}px) and (max-width: ${BREAKPOINTS.xl - 1}px)`);\n queries.xl = window.matchMedia(`(min-width: ${BREAKPOINTS.xl}px) and (max-width: ${BREAKPOINTS[\"2xl\"] - 1}px)`);\n queries[\"2xl\"] = window.matchMedia(`(min-width: ${BREAKPOINTS[\"2xl\"]}px)`);\n }\n return queries;\n }, []);\n\n useEffect(() => {\n setIsHydrated(true);\n }, []);\n\n useEffect(() => {\n if (typeof window === 'undefined' || !isHydrated) return;\n\n const updateBreakpoint = () => {\n let currentBp: Breakpoint = \"sm\";\n\n if (mediaQueries[\"2xl\"]?.matches) currentBp = \"2xl\";\n else if (mediaQueries.xl?.matches) currentBp = \"xl\";\n else if (mediaQueries.lg?.matches) currentBp = \"lg\";\n else if (mediaQueries.md?.matches) currentBp = \"md\";\n else currentBp = \"sm\";\n\n setBreakpoint(currentBp);\n };\n\n // Initial check\n updateBreakpoint();\n\n // Add listeners\n Object.values(mediaQueries).forEach(mq => {\n if (mq) mq.addEventListener('change', updateBreakpoint);\n });\n\n return () => {\n Object.values(mediaQueries).forEach(mq => {\n if (mq) mq.removeEventListener('change', updateBreakpoint);\n });\n };\n }, [mediaQueries, isHydrated]);\n\n // Min width check: is current width >= breakpoint\n const up = useCallback((bp: Breakpoint) => {\n if (typeof window === 'undefined' || !isHydrated) {\n // SSR fallback: check if ssrBreakpoint >= bp\n return BREAKPOINTS[breakpoint] >= BREAKPOINTS[bp];\n }\n const mq = window.matchMedia(`(min-width: ${BREAKPOINTS[bp]}px)`);\n return mq.matches;\n }, [isHydrated, breakpoint]);\n\n // Max width check: is current width < breakpoint\n const down = useCallback((bp: Breakpoint) => {\n if (typeof window === 'undefined' || !isHydrated) {\n // SSR fallback: check if ssrBreakpoint < bp\n return BREAKPOINTS[breakpoint] < BREAKPOINTS[bp];\n }\n const mq = window.matchMedia(`(max-width: ${BREAKPOINTS[bp] - 1}px)`);\n return mq.matches;\n }, [isHydrated, breakpoint]);\n\n // Range check: is current width between min and max breakpoints\n const between = useCallback((minBp: Breakpoint, maxBp: Breakpoint) => {\n if (typeof window === 'undefined' || !isHydrated) {\n // SSR fallback: check if minBp <= ssrBreakpoint < maxBp\n return BREAKPOINTS[breakpoint] >= BREAKPOINTS[minBp] && BREAKPOINTS[breakpoint] < BREAKPOINTS[maxBp];\n }\n const mq = window.matchMedia(`(min-width: ${BREAKPOINTS[minBp]}px) and (max-width: ${BREAKPOINTS[maxBp] - 1}px)`);\n return mq.matches;\n }, [isHydrated, breakpoint]);\n\n // Only check: is current width only within this breakpoint range\n const only = useCallback((bp: Breakpoint) => {\n if (typeof window === 'undefined' || !isHydrated) {\n // SSR fallback: check if ssrBreakpoint === bp\n return breakpoint === bp;\n }\n\n const breakpointKeys = Object.keys(BREAKPOINTS) as Breakpoint[];\n const currentIndex = breakpointKeys.indexOf(bp);\n const nextBp = breakpointKeys[currentIndex + 1];\n\n let query: string;\n if (currentIndex === 0) {\n // For 'sm', check if width < md\n query = `(max-width: ${BREAKPOINTS.md - 1}px)`;\n } else if (!nextBp) {\n // For highest breakpoint, check if width >= current\n query = `(min-width: ${BREAKPOINTS[bp]}px)`;\n } else {\n // For middle breakpoints, check range\n query = `(min-width: ${BREAKPOINTS[bp]}px) and (max-width: ${BREAKPOINTS[nextBp] - 1}px)`;\n }\n\n const mq = window.matchMedia(query);\n return mq.matches;\n }, [isHydrated, breakpoint]);\n\n return {\n breakpoint,\n up,\n down,\n between,\n only,\n };\n};\n"],"names":["BREAKPOINTS","useBreakpoint","ssrBreakpoint","breakpoint","setBreakpoint","useState","isHydrated","setIsHydrated","mediaQueries","useMemo","queries","useEffect","updateBreakpoint","currentBp","_a","_b","_c","_d","mq","up","useCallback","bp","down","between","minBp","maxBp","only","breakpointKeys","currentIndex","nextBp","query"],"mappings":";;AAKO,MAAMA,IAAc;AAAA,EACzB,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,OAAO;AACT,GAwBaC,IAAgB,CAACC,IAA4B,SAAS;AACjE,QAAM,CAACC,GAAYC,CAAa,IAAIC,EAAqBH,CAAa,GAChE,CAACI,GAAYC,CAAa,IAAIF,EAAS,EAAK,GAG5CG,IAAeC,EAAQ,MAAM;AACjC,UAAMC,IAA8C,CAAC;AACjD,WAAA,OAAO,SAAW,QACpBA,EAAQ,KAAK,OAAO,WAAW,eAAeV,EAAY,KAAK,CAAC,KAAK,GAC7DU,EAAA,KAAK,OAAO,WAAW,eAAeV,EAAY,EAAE,uBAAuBA,EAAY,KAAK,CAAC,KAAK,GAClG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const S = {
|
|
4
|
+
x: 0,
|
|
5
|
+
y: 0,
|
|
6
|
+
width: 0,
|
|
7
|
+
height: 0,
|
|
8
|
+
top: 0,
|
|
9
|
+
left: 0,
|
|
10
|
+
bottom: 0,
|
|
11
|
+
right: 0
|
|
12
|
+
};
|
|
13
|
+
function x(o) {
|
|
14
|
+
const n = l(0), e = l(null), [r, u] = R(S), c = d(
|
|
15
|
+
() => typeof window < "u" ? new ResizeObserver((m) => {
|
|
16
|
+
const t = m[0];
|
|
17
|
+
t && (cancelAnimationFrame(n.current), n.current = requestAnimationFrame(() => {
|
|
18
|
+
var s, f;
|
|
19
|
+
if (e.current) {
|
|
20
|
+
const i = ((s = t.borderBoxSize) == null ? void 0 : s[0]) || ((f = t.contentBoxSize) == null ? void 0 : f[0]);
|
|
21
|
+
if (i) {
|
|
22
|
+
const a = i.inlineSize, h = i.blockSize;
|
|
23
|
+
u({
|
|
24
|
+
width: a,
|
|
25
|
+
height: h,
|
|
26
|
+
x: t.contentRect.x,
|
|
27
|
+
y: t.contentRect.y,
|
|
28
|
+
top: t.contentRect.top,
|
|
29
|
+
left: t.contentRect.left,
|
|
30
|
+
bottom: t.contentRect.bottom,
|
|
31
|
+
right: t.contentRect.right
|
|
32
|
+
});
|
|
33
|
+
} else
|
|
34
|
+
u(t.contentRect);
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
}) : null,
|
|
38
|
+
[]
|
|
39
|
+
);
|
|
40
|
+
return z(() => (e.current && (c == null || c.observe(e.current, o)), () => {
|
|
41
|
+
c == null || c.disconnect(), n.current && cancelAnimationFrame(n.current);
|
|
42
|
+
}), [e.current]), [e, r];
|
|
43
|
+
}
|
|
44
|
+
function g(o) {
|
|
45
|
+
const [n, { width: e, height: r }] = x(o);
|
|
46
|
+
return { ref: n, width: e, height: r };
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
g as useElementSize,
|
|
50
|
+
x as useResizeObserver
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=useResizeObserver.js.map
|