@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 2.35 kB
Source Map (JSON)
{"version":3,"file":"MenuContextMenu.mjs","names":[],"sources":["../../../../src/components/Menu/MenuContextMenu/MenuContextMenu.tsx"],"sourcesContent":["import { cloneElement } from 'react';\nimport { getSingleElementChild, useProps } from '../../../core';\nimport { useContextMenuHandlers } from '../../../utils/Floating/use-context-menu-handlers';\nimport { usePopoverContext } from '../../Popover';\nimport { useMenuContext } from '../Menu.context';\n\nexport interface MenuContextMenuProps {\n /** Element that opens the menu when right-clicked. Menu dropdown is positioned at the cursor. The trigger element must not call `event.preventDefault()` in its own `onContextMenu` handler, otherwise the native context menu is not suppressed. */\n children: React.ReactNode;\n\n /** If set, the right-click trigger is disabled and the browser's default context menu is shown */\n disabled?: boolean;\n\n /** Delay in ms before a touch long-press opens the dropdown on touch devices, `500` by default */\n longPressDelay?: number;\n}\n\nexport function MenuContextMenu(props: MenuContextMenuProps) {\n const { children, disabled, longPressDelay } = useProps('MenuContextMenu', null, props);\n\n const child = getSingleElementChild(children);\n if (!child) {\n throw new Error(\n 'Menu.ContextMenu component children should be an element or a component that accepts ref. Fragments, strings, numbers and other primitive values are not supported'\n );\n }\n\n const ctx = useMenuContext();\n const popoverCtx = usePopoverContext();\n\n const handlers = useContextMenuHandlers({\n childProps: child.props as any,\n disabled: disabled || popoverCtx.disabled,\n opened: ctx.opened,\n longPressDelay,\n setReference: popoverCtx.reference as unknown as (node: object) => void,\n open: () => ctx.openDropdown(),\n });\n\n return cloneElement(child, handlers as any);\n}\n\nMenuContextMenu.displayName = '@mantine/core/MenuContextMenu';\n"],"mappings":";;;;;;;;AAiBA,SAAgB,gBAAgB,OAA6B;CAC3D,MAAM,EAAE,UAAU,UAAU,mBAAmB,SAAS,mBAAmB,MAAM,KAAK;CAEtF,MAAM,QAAQ,sBAAsB,QAAQ;CAC5C,IAAI,CAAC,OACH,MAAM,IAAI,MACR,oKACF;CAGF,MAAM,MAAM,eAAe;CAC3B,MAAM,aAAa,kBAAkB;CAWrC,OAAO,aAAa,OATH,uBAAuB;EACtC,YAAY,MAAM;EAClB,UAAU,YAAY,WAAW;EACjC,QAAQ,IAAI;EACZ;EACA,cAAc,WAAW;EACzB,YAAY,IAAI,aAAa;CAC/B,CAEkC,CAAQ;AAC5C;AAEA,gBAAgB,cAAc"}