{"version":3,"file":"MenuSub.cjs","names":["useProps","SubMenuContext","useDelayedHover","Popover","MenuSubTarget","MenuSubDropdown","MenuSubItem"],"sources":["../../../../src/components/Menu/MenuSub/MenuSub.tsx"],"sourcesContent":["import { use } from 'react';\nimport { useDisclosure, useId } from '@mantine/hooks';\nimport { ExtendComponent, Factory, useProps } from '../../../core';\nimport { FloatingAxesOffsets, FloatingPosition, useDelayedHover } from '../../../utils/Floating';\nimport { __PopoverProps, Popover } from '../../Popover';\nimport { TransitionOverride } from '../../Transition';\nimport { MenuSubDropdown } from '../MenuSubDropdown/MenuSubDropdown';\nimport { MenuSubItem } from '../MenuSubItem/MenuSubItem';\nimport { MenuSubTarget } from '../MenuSubTarget/MenuSubTarget';\nimport { SubMenuContext } from './MenuSub.context';\n\nexport type MenuSubFactory = Factory<{\n  props: MenuSubProps;\n}>;\n\nexport interface MenuSubProps extends __PopoverProps {\n  children: React.ReactNode;\n\n  /** Called with current state when dropdown opens or closes */\n  onChange?: (opened: boolean) => void;\n\n  /** Open delay in ms, applicable when hover trigger is used */\n  openDelay?: number;\n\n  /** Close delay in ms, applicable when hover trigger is used */\n  closeDelay?: number;\n\n  /** Dropdown position relative to the target element @default 'right-start' */\n  position?: FloatingPosition;\n\n  /** Offset of the dropdown element @default 0 */\n  offset?: number | FloatingAxesOffsets;\n\n  /** Props passed down to the `Transition` component that used to animate dropdown presence, use to configure duration and animation type @default { duration: 0 } */\n  transitionProps?: TransitionOverride;\n}\n\nconst defaultProps = {\n  offset: 0,\n  position: 'right-start',\n  transitionProps: { duration: 0 },\n  openDelay: 0,\n  middlewares: {\n    shift: {\n      // Enable crossAxis shift to keep submenu dropdown within viewport bounds when positioned horizontally\n      crossAxis: true,\n    },\n  },\n} satisfies Partial<MenuSubProps>;\n\nexport function MenuSub(_props: MenuSubProps) {\n  const { children, closeDelay, openDelay, ...others } = useProps('MenuSub', defaultProps, _props);\n  const id = useId();\n  const [opened, { open, close }] = useDisclosure(false);\n  const ctx = use(SubMenuContext);\n\n  const { openDropdown, closeDropdown } = useDelayedHover({\n    open,\n    close,\n    closeDelay,\n    openDelay,\n  });\n\n  const focusFirstItem = () =>\n    window.setTimeout(() => {\n      document\n        .getElementById(`${id}-dropdown`)\n        ?.querySelectorAll<HTMLButtonElement>('[data-menu-item]:not([data-disabled])')[0]\n        ?.focus();\n    }, 16);\n\n  const focusParentItem = () =>\n    window.setTimeout(() => {\n      document.getElementById(`${id}-target`)?.focus();\n    }, 16);\n\n  return (\n    <SubMenuContext\n      value={{\n        opened,\n        close: closeDropdown,\n        open: openDropdown,\n        focusFirstItem,\n        focusParentItem,\n        parentContext: ctx,\n      }}\n    >\n      <Popover opened={opened} withinPortal={false} withArrow={false} id={id} {...others}>\n        {children}\n      </Popover>\n    </SubMenuContext>\n  );\n}\n\nMenuSub.extend = (input: ExtendComponent<MenuSubFactory>) => input;\nMenuSub.displayName = '@mantine/core/MenuSub';\nMenuSub.Target = MenuSubTarget;\nMenuSub.Dropdown = MenuSubDropdown;\nMenuSub.Item = MenuSubItem;\n"],"mappings":";;;;;;;;;;;;;AAqCA,MAAM,eAAe;CACnB,QAAQ;CACR,UAAU;CACV,iBAAiB,EAAE,UAAU,GAAG;CAChC,WAAW;CACX,aAAa,EACX,OAAO,EAEL,WAAW,MACZ,EACF;CACF;AAED,SAAgB,QAAQ,QAAsB;CAC5C,MAAM,EAAE,UAAU,YAAY,WAAW,GAAG,WAAWA,kBAAAA,SAAS,WAAW,cAAc,OAAO;CAChG,MAAM,MAAA,GAAA,eAAA,QAAY;CAClB,MAAM,CAAC,QAAQ,EAAE,MAAM,YAAA,GAAA,eAAA,eAAyB,MAAM;CACtD,MAAM,OAAA,GAAA,MAAA,KAAUC,wBAAAA,eAAe;CAE/B,MAAM,EAAE,cAAc,kBAAkBC,0BAAAA,gBAAgB;EACtD;EACA;EACA;EACA;EACD,CAAC;CAEF,MAAM,uBACJ,OAAO,iBAAiB;AACtB,WACG,eAAe,GAAG,GAAG,WAAW,EAC/B,iBAAoC,wCAAwC,CAAC,IAC7E,OAAO;IACV,GAAG;CAER,MAAM,wBACJ,OAAO,iBAAiB;AACtB,WAAS,eAAe,GAAG,GAAG,SAAS,EAAE,OAAO;IAC/C,GAAG;AAER,QACE,iBAAA,GAAA,kBAAA,KAACD,wBAAAA,gBAAD;EACE,OAAO;GACL;GACA,OAAO;GACP,MAAM;GACN;GACA;GACA,eAAe;GAChB;YAED,iBAAA,GAAA,kBAAA,KAACE,gBAAAA,SAAD;GAAiB;GAAQ,cAAc;GAAO,WAAW;GAAW;GAAI,GAAI;GACzE;GACO,CAAA;EACK,CAAA;;AAIrB,QAAQ,UAAU,UAA2C;AAC7D,QAAQ,cAAc;AACtB,QAAQ,SAASC,sBAAAA;AACjB,QAAQ,WAAWC,wBAAAA;AACnB,QAAQ,OAAOC,oBAAAA"}