mantine-contextmenu 7.0.0-alpha.6 → 7.1.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/README.md +2 -2
- package/dist/cjs/ContextMenu.js +2 -2
- package/dist/cjs/ContextMenu.js.map +1 -1
- package/dist/cjs/ContextMenuPortal.js +1 -0
- package/dist/cjs/ContextMenuPortal.js.map +1 -1
- package/dist/cjs/ContextMenuProvider.js +2 -2
- package/dist/cjs/ContextMenuProvider.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/ContextMenu.js +2 -2
- package/dist/esm/ContextMenu.js.map +1 -1
- package/dist/esm/ContextMenuPortal.js +2 -1
- package/dist/esm/ContextMenuPortal.js.map +1 -1
- package/dist/esm/ContextMenuProvider.js +2 -2
- package/dist/esm/ContextMenuProvider.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/types/ContextMenuProvider.d.ts +20 -0
- package/dist/types/types.d.ts +6 -3
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -14,8 +14,8 @@ The "dark-theme aware" **context-menu** for your Mantine UI applications, built
|
|
|
14
14
|
|
|
15
15
|
[](https://icflorescu.github.io/mantine-contextmenu/)
|
|
16
16
|
|
|
17
|
-
**⚠️ NOTE: Mantine ContextMenu V7 is compatible with Mantine V7.**
|
|
18
|
-
**💡 If you're looking for
|
|
17
|
+
**⚠️ NOTE: Mantine ContextMenu V7.1 is compatible with Mantine V7.1.**
|
|
18
|
+
**💡 If you're looking for the old version that works with Mantine V6, head over to [Mantine ContextMenu V6](https://icflorescu.github.io/mantine-contextmenu-v6).**
|
|
19
19
|
|
|
20
20
|
## Features
|
|
21
21
|
|
package/dist/cjs/ContextMenu.js
CHANGED
|
@@ -48,8 +48,6 @@ function ContextMenu(_a) {
|
|
|
48
48
|
(windowWidth = window.innerWidth, windowHeight = window.innerHeight);
|
|
49
49
|
var dir = (0, core_1.useDirection)().dir;
|
|
50
50
|
return ((0, jsx_runtime_1.jsx)(core_1.Paper, { ref: paperRef, shadow: shadow, radius: borderRadius, className: (0, clsx_1.default)('mantine-contextmenu', className, classNames === null || classNames === void 0 ? void 0 : classNames.root), style: [
|
|
51
|
-
styles === null || styles === void 0 ? void 0 : styles.root,
|
|
52
|
-
style,
|
|
53
51
|
function (_a) {
|
|
54
52
|
var md = _a.spacing.md;
|
|
55
53
|
var mdSpacing = (0, core_1.px)(md);
|
|
@@ -63,6 +61,8 @@ function ContextMenu(_a) {
|
|
|
63
61
|
: windowWidth - mdSpacing - (x - width - mdSpacing < 0 ? width + mdSpacing : x),
|
|
64
62
|
};
|
|
65
63
|
},
|
|
64
|
+
style,
|
|
65
|
+
styles === null || styles === void 0 ? void 0 : styles.root,
|
|
66
66
|
], children: Array.isArray(content)
|
|
67
67
|
? content.map(function (_a) {
|
|
68
68
|
var key = _a.key, className = _a.className, style = _a.style, onClick = _a.onClick, items = _a.items, title = _a.title, otherOptions = __rest(_a, ["key", "className", "style", "onClick", "items", "title"]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../package/ContextMenu.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,sCAAwD;AACxD,wCAAmD;AACnD,8CAAwB;AACxB,+BAAmC;AACnC,2DAA0D;AAC1D,qDAAoD;AACpD,6DAA+D;AAE/D,iCAAmC;AAanC,SAAgB,WAAW,CAAC,EAAyF;;QAAvF,CAAC,OAAA,EAAE,CAAC,OAAA,EAAE,OAAO,aAAA,EAAE,MAAM,YAAA,EAAE,MAAM,YAAA,EAAE,SAAS,eAAA,EAAE,KAAK,WAAA,EAAE,UAAU,gBAAA,EAAE,MAAM,YAAA;IACzF,IAAA,KAA2B,IAAA,kBAAU,EAAC,4CAAsB,CAAC,EAA3D,MAAM,YAAA,EAAE,YAAY,kBAAuC,CAAC;IAC7D,IAAA,QAAQ,GAAI,IA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cesContent":["'use client';\n\nimport { Paper, px, useDirection } from '@mantine/core';\nimport { useResizeObserver } from '@mantine/hooks';\nimport clsx from 'clsx';\nimport { useContext } from 'react';\nimport { ContextMenuDivider } from './ContextMenuDivider';\nimport { ContextMenuItem } from './ContextMenuItem';\nimport { ContextMenuSettingsCtx } from './ContextMenuProvider';\nimport type { ContextMenuContent, ContextMenuOptions } from './types';\nimport { humanize } from './utils';\n\nexport type ContextMenuInstanceOptions = {\n x: number;\n y: number;\n content: ContextMenuContent;\n};\n\nexport type ContextMenuProps = ContextMenuOptions &\n ContextMenuInstanceOptions & {\n onHide: () => void;\n };\n\nexport function ContextMenu({ x, y, content, zIndex, onHide, className, style, classNames, styles }: ContextMenuProps) {\n const { shadow, borderRadius } = useContext(ContextMenuSettingsCtx);\n const [paperRef] = useResizeObserver<HTMLDivElement>();\n const { width, height } = paperRef.current?.getBoundingClientRect() || { width: 0, height: 0 };\n\n let windowWidth = 0;\n let windowHeight = 0;\n if (typeof window !== 'undefined') ({ innerWidth: windowWidth, innerHeight: windowHeight } = window);\n\n const { dir } = useDirection();\n\n return (\n <Paper\n ref={paperRef}\n shadow={shadow}\n radius={borderRadius}\n className={clsx('mantine-contextmenu', className, classNames?.root)}\n style={[\n ({ spacing: { md } }) => {\n const mdSpacing = px(md) as number;\n return {\n zIndex,\n top: y + height + mdSpacing > windowHeight ? windowHeight - height - mdSpacing : y,\n left:\n dir === 'ltr'\n ? x + width + mdSpacing > windowWidth\n ? windowWidth - width - mdSpacing\n : x\n : windowWidth - mdSpacing - (x - width - mdSpacing < 0 ? width + mdSpacing : x),\n };\n },\n style,\n styles?.root,\n ]}\n >\n {Array.isArray(content)\n ? content.map(({ key, className, style, onClick, items, title, ...otherOptions }) =>\n onClick || items ? (\n <ContextMenuItem\n key={key}\n className={clsx(classNames?.item, className)}\n style={[styles?.item, style]}\n title={title ?? humanize(key)}\n onClick={onClick}\n onHide={onHide}\n items={items}\n {...otherOptions}\n />\n ) : (\n <ContextMenuDivider\n key={key}\n className={clsx(classNames?.divider, className)}\n style={[styles?.divider, style]}\n />\n )\n )\n : content(onHide)}\n </Paper>\n );\n}\n"]}
|
|
@@ -32,6 +32,7 @@ function ContextMenuPortal(_a) {
|
|
|
32
32
|
var onHide = _a.onHide, otherProps = __rest(_a, ["onHide"]);
|
|
33
33
|
(0, hooks_1.useWindowEvent)('resize', onHide);
|
|
34
34
|
(0, hooks_1.useWindowEvent)('scroll', onHide);
|
|
35
|
+
(0, hooks_1.useHotkeys)([['Escape', onHide]]);
|
|
35
36
|
var ref = (0, hooks_1.useClickOutside)(onHide);
|
|
36
37
|
return ((0, jsx_runtime_1.jsx)(core_1.Portal, { ref: ref, children: (0, jsx_runtime_1.jsx)(ContextMenu_1.ContextMenu, __assign({}, otherProps, { onHide: onHide })) }));
|
|
37
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenuPortal.js","sourceRoot":"","sources":["../../package/ContextMenuPortal.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,sCAAuC;AACvC,
|
|
1
|
+
{"version":3,"file":"ContextMenuPortal.js","sourceRoot":"","sources":["../../package/ContextMenuPortal.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEb,sCAAuC;AACvC,wCAA6E;AAC7E,6CAAmE;AAEnE,SAAgB,iBAAiB,CAAC,EAA2C;IAAzC,IAAA,MAAM,YAAA,EAAK,UAAU,cAAvB,UAAyB,CAAF;IACvD,IAAA,sBAAc,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjC,IAAA,sBAAc,EAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjC,IAAA,kBAAU,EAAC,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACjC,IAAM,GAAG,GAAG,IAAA,uBAAe,EAAC,MAAM,CAAC,CAAC;IAEpC,OAAO,CACL,uBAAC,aAAM,IAAC,GAAG,EAAE,GAAG,YACd,uBAAC,yBAAW,eAAK,UAAU,IAAE,MAAM,EAAE,MAAM,IAAI,GACxC,CACV,CAAC;AACJ,CAAC;AAXD,8CAWC","sourcesContent":["'use client';\n\nimport { Portal } from '@mantine/core';\nimport { useClickOutside, useHotkeys, useWindowEvent } from '@mantine/hooks';\nimport { ContextMenu, type ContextMenuProps } from './ContextMenu';\n\nexport function ContextMenuPortal({ onHide, ...otherProps }: ContextMenuProps) {\n useWindowEvent('resize', onHide);\n useWindowEvent('scroll', onHide);\n useHotkeys([['Escape', onHide]]);\n const ref = useClickOutside(onHide);\n\n return (\n <Portal ref={ref}>\n <ContextMenu {...otherProps} onHide={onHide} />\n </Portal>\n );\n}\n"]}
|
|
@@ -23,7 +23,7 @@ var DEFAULT_SETTINGS = {
|
|
|
23
23
|
submenuDelay: 500,
|
|
24
24
|
};
|
|
25
25
|
exports.ContextMenuSettingsCtx = (0, react_1.createContext)(DEFAULT_SETTINGS);
|
|
26
|
-
exports.ContextMenuCtx = (0, react_1.createContext)({ showContextMenu: function () { return function () { return undefined; }; }, hideContextMenu: function () { return undefined; } });
|
|
26
|
+
exports.ContextMenuCtx = (0, react_1.createContext)({ showContextMenu: function () { return function () { return undefined; }; }, hideContextMenu: function () { return undefined; }, isContextMenuVisible: false });
|
|
27
27
|
/**
|
|
28
28
|
* Provider that allows to show a context menu anywhere in your application.
|
|
29
29
|
* If you wrap your application with this provider, you can use the `useContextMenu` hook
|
|
@@ -49,7 +49,7 @@ function ContextMenuProvider(_a) {
|
|
|
49
49
|
styles: options === null || options === void 0 ? void 0 : options.styles,
|
|
50
50
|
});
|
|
51
51
|
}; };
|
|
52
|
-
return ((0, jsx_runtime_1.jsx)(exports.ContextMenuSettingsCtx.Provider, { value: { shadow: shadow, borderRadius: borderRadius, submenuDelay: submenuDelay }, children: (0, jsx_runtime_1.jsxs)(exports.ContextMenuCtx.Provider, { value: { showContextMenu: showContextMenu, hideContextMenu: hideContextMenu }, children: [children, (0, jsx_runtime_1.jsx)(core_1.MantineProvider, { children: data && (0, jsx_runtime_1.jsx)(ContextMenuPortal_1.ContextMenuPortal, __assign({ onHide: hideContextMenu }, data)) })] }) }));
|
|
52
|
+
return ((0, jsx_runtime_1.jsx)(exports.ContextMenuSettingsCtx.Provider, { value: { shadow: shadow, borderRadius: borderRadius, submenuDelay: submenuDelay }, children: (0, jsx_runtime_1.jsxs)(exports.ContextMenuCtx.Provider, { value: { showContextMenu: showContextMenu, hideContextMenu: hideContextMenu, isContextMenuVisible: !!data }, children: [children, (0, jsx_runtime_1.jsx)(core_1.MantineProvider, { children: data && (0, jsx_runtime_1.jsx)(ContextMenuPortal_1.ContextMenuPortal, __assign({ onHide: hideContextMenu }, data)) })] }) }));
|
|
53
53
|
}
|
|
54
54
|
exports.ContextMenuProvider = ContextMenuProvider;
|
|
55
55
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenuProvider.js","sourceRoot":"","sources":["../../package/ContextMenuProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;AAEb,sCAAgD;AAChD,+BAA4D;AAE5D,yDAAwD;AAUxD,IAAM,gBAAgB,GAA0F;IAC9G,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,GAAG;CAClB,CAAC;AAEW,QAAA,sBAAsB,GAAG,IAAA,qBAAa,EAAC,gBAAgB,CAAC,CAAC;AACzD,QAAA,cAAc,GAAG,IAAA,qBAAa,
|
|
1
|
+
{"version":3,"file":"ContextMenuProvider.js","sourceRoot":"","sources":["../../package/ContextMenuProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;;;;AAEb,sCAAgD;AAChD,+BAA4D;AAE5D,yDAAwD;AAUxD,IAAM,gBAAgB,GAA0F;IAC9G,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;IAClB,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YACrB,UAAU,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,UAAU;YAC/B,MAAM,EAAE,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM;SACxB,CAAC,CAAC;IACL,CAAC,EAbsE,CAatE,CAAC;IAEF,OAAO,CACL,uBAAC,8BAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,QAAA,EAAE,YAAY,cAAA,EAAE,YAAY,cAAA,EAAE,YAC5E,wBAAC,sBAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,eAAe,iBAAA,EAAE,eAAe,iBAAA,EAAE,oBAAoB,EAAE,CAAC,CAAC,IAAI,EAAE,aAC/F,QAAQ,EACT,uBAAC,sBAAe,cAAE,IAAI,IAAI,uBAAC,qCAAiB,aAAC,MAAM,EAAE,eAAe,IAAM,IAAI,EAAI,GAAmB,IAC7E,GACM,CACnC,CAAC;AACJ,CAAC;AApCD,kDAoCC;AAED;;GAEG;AACH,SAAgB,cAAc;IAC5B,OAAO,IAAA,kBAAU,EAAC,sBAAc,CAAC,CAAC;AACpC,CAAC;AAFD,wCAEC","sourcesContent":["'use client';\n\nimport { MantineProvider } from '@mantine/core';\nimport { createContext, useContext, useState } from 'react';\nimport type { ContextMenuInstanceOptions } from './ContextMenu';\nimport { ContextMenuPortal } from './ContextMenuPortal';\nimport type {\n ContextMenuOptions,\n ContextMenuProviderProps,\n ContextMenuSettings,\n HideContextMenuFunction,\n ShowContextMenuFunction,\n WithRequiredProperty,\n} from './types';\n\nconst DEFAULT_SETTINGS: WithRequiredProperty<ContextMenuSettings, 'shadow' | 'borderRadius' | 'submenuDelay'> = {\n shadow: 'sm',\n borderRadius: 'xs',\n submenuDelay: 500,\n};\n\nexport const ContextMenuSettingsCtx = createContext(DEFAULT_SETTINGS);\nexport const ContextMenuCtx = createContext<{\n /**\n * Function that shows the context menu.\n */\n showContextMenu: ShowContextMenuFunction;\n\n /**\n * Function that hides the context menu.\n */\n hideContextMenu: HideContextMenuFunction;\n\n /**\n * Boolean indicating whether the context menu is currently visible.\n */\n isContextMenuVisible: boolean;\n}>({ showContextMenu: () => () => undefined, hideContextMenu: () => undefined, isContextMenuVisible: false });\n\n/**\n * Provider that allows to show a context menu anywhere in your application.\n * If you wrap your application with this provider, you can use the `useContextMenu` hook\n * anywhere in the component tree to access a function that shows the context menu.\n */\nexport function ContextMenuProvider({\n zIndex = 9999,\n shadow = DEFAULT_SETTINGS.shadow,\n borderRadius = DEFAULT_SETTINGS.borderRadius,\n submenuDelay = DEFAULT_SETTINGS.submenuDelay,\n children,\n}: ContextMenuProviderProps) {\n const [data, setData] = useState<(ContextMenuInstanceOptions & ContextMenuOptions) | null>(null);\n\n const hideContextMenu = () => {\n setData(null);\n };\n\n const showContextMenu: ShowContextMenuFunction = (content, options) => (e) => {\n e.preventDefault();\n e.stopPropagation();\n setData({\n x: e.clientX,\n y: e.clientY,\n content,\n zIndex: options?.zIndex || zIndex,\n className: options?.className,\n style: options?.style,\n classNames: options?.classNames,\n styles: options?.styles,\n });\n };\n\n return (\n <ContextMenuSettingsCtx.Provider value={{ shadow, borderRadius, submenuDelay }}>\n <ContextMenuCtx.Provider value={{ showContextMenu, hideContextMenu, isContextMenuVisible: !!data }}>\n {children}\n <MantineProvider>{data && <ContextMenuPortal onHide={hideContextMenu} {...data} />}</MantineProvider>\n </ContextMenuCtx.Provider>\n </ContextMenuSettingsCtx.Provider>\n );\n}\n\n/**\n * Hook returning functions that show and hide the context menu.\n */\nexport function useContextMenu() {\n return useContext(ContextMenuCtx);\n}\n"]}
|
package/dist/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../package/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MantineColor, MantineRadius, MantineShadow, MantineStyleProp, StylesRecord } from '@mantine/core';\n\n/**\n * Utility type that makes a property required\n */\nexport type WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\n/**\n * Utility type that makes a property optional\n */\nexport type WithOptionalProperty<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/**\n * Context menu options\n */\nexport type ContextMenuOptions = {\n /**\n * The z-index of context menu.\n * @default 9999\n */\n zIndex?: number;\n\n /**\n * Context menu container
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../package/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MantineColor, MantineRadius, MantineShadow, MantineStyleProp, StylesRecord } from '@mantine/core';\n\n/**\n * Utility type that makes a property required\n */\nexport type WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\n/**\n * Utility type that makes a property optional\n */\nexport type WithOptionalProperty<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/**\n * Context menu options\n */\nexport type ContextMenuOptions = {\n /**\n * The z-index of context menu.\n * @default 9999\n */\n zIndex?: number;\n\n /**\n * Context menu container class name.\n */\n className?: string;\n\n /**\n * Context menu container style.\n */\n style?: MantineStyleProp;\n\n /**\n * Context menu elements class names.\n */\n classNames?: Partial<Record<'root' | 'item' | 'divider', string>>;\n\n /**\n * Context menu styles.\n * Can be an object with `root`, `item` and `divider` keys and style objects as values,\n * or a function that accepts the current theme and returns a similarly structured object.\n */\n styles?: StylesRecord<'root' | 'item' | 'divider', MantineStyleProp>;\n};\n\n/**\n * Generic context menu settings\n */\nexport type ContextMenuSettings = {\n /**\n * Context menu shadow.\n * @default 'sm'\n */\n shadow?: MantineShadow;\n\n /**\n * Context menu border radius.\n * @default 'xs'\n */\n borderRadius?: MantineRadius;\n\n /**\n * Delay in ms to use when showing and hiding submenus.\n * @default 500\n */\n submenuDelay?: number;\n};\n\n/**\n * Context menu provider props\n */\nexport type ContextMenuProviderProps = ContextMenuSettings &\n ContextMenuOptions & {\n children: React.ReactNode;\n };\n\n/**\n * Context menu item options\n */\nexport type ContextMenuItemOptions = {\n /**\n * Unique key of the context menu item or divider.\n */\n key: string;\n /**\n * Context menu item or divider className.\n */\n className?: string;\n\n /**\n * Context menu item or divider style.\n */\n style?: MantineStyleProp;\n} & (\n | ({\n /**\n * Optional context menu item icon.\n */\n icon?: React.ReactNode;\n\n /**\n * Optional context menu item title.\n * If not provided, one will be generated automatically by \"humanizing\" the key.\n * @default humanize(key)\n */\n title?: React.ReactNode;\n\n /**\n * Optional context menu item color.\n */\n color?: MantineColor;\n\n /**\n * Boolean indicating whether the context menu item is disabled.\n */\n disabled?: boolean;\n } & (\n | {\n /**\n * Optional context menu item `onClick` handler.\n * If not provided, a divider will be rendered instead.\n */\n onClick: React.MouseEventHandler<HTMLButtonElement>;\n\n items?: never;\n }\n | {\n onClick?: never;\n\n /**\n * Optional items.\n * If provided, a submenu will be rendered.\n */\n items: ContextMenuItemOptions[];\n }\n ))\n | {\n icon?: never;\n title?: never;\n color?: never;\n disabled?: never;\n onClick?: never;\n items?: never;\n }\n);\n\n/**\n * Context menu content.\n * Either an array of context menu items, or a function that accepts a close callback and returns context menu content.\n */\nexport type ContextMenuContent = ContextMenuItemOptions[] | ((close: () => void) => JSX.Element);\n\n/**\n * Show context menu function\n */\nexport type ShowContextMenuFunction = (\n /**\n * Context menu content.\n * Either an array of context menu items or a function that accepts a close callback and returns context menu content.\n */\n content: ContextMenuContent,\n\n /**\n * Context menu options (overrides provider props).\n */\n options?: ContextMenuOptions\n) => React.MouseEventHandler;\n\n/**\n * Hide context menu function\n */\nexport type HideContextMenuFunction = () => void;\n"]}
|
package/dist/esm/ContextMenu.js
CHANGED
|
@@ -18,8 +18,6 @@ export function ContextMenu({ x, y, content, zIndex, onHide, className, style, c
|
|
|
18
18
|
({ innerWidth: windowWidth, innerHeight: windowHeight } = window);
|
|
19
19
|
const { dir } = useDirection();
|
|
20
20
|
return (_jsx(Paper, { ref: paperRef, shadow: shadow, radius: borderRadius, className: clsx('mantine-contextmenu', className, classNames?.root), style: [
|
|
21
|
-
styles?.root,
|
|
22
|
-
style,
|
|
23
21
|
({ spacing: { md } }) => {
|
|
24
22
|
const mdSpacing = px(md);
|
|
25
23
|
return {
|
|
@@ -32,6 +30,8 @@ export function ContextMenu({ x, y, content, zIndex, onHide, className, style, c
|
|
|
32
30
|
: windowWidth - mdSpacing - (x - width - mdSpacing < 0 ? width + mdSpacing : x),
|
|
33
31
|
};
|
|
34
32
|
},
|
|
33
|
+
style,
|
|
34
|
+
styles?.root,
|
|
35
35
|
], children: Array.isArray(content)
|
|
36
36
|
? content.map(({ key, className, style, onClick, items, title, ...otherOptions }) => onClick || items ? (_jsx(ContextMenuItem, { className: clsx(classNames?.item, className), style: [styles?.item, style], title: title ?? humanize(key), onClick: onClick, onHide: onHide, items: items, ...otherOptions }, key)) : (_jsx(ContextMenuDivider, { className: clsx(classNames?.divider, className), style: [styles?.divider, style] }, key)))
|
|
37
37
|
: content(onHide) }));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenu.js","sourceRoot":"","sources":["../../package/ContextMenu.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAanC,MAAM,UAAU,WAAW,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,MAA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mantine/core';\nimport { useResizeObserver } from '@mantine/hooks';\nimport clsx from 'clsx';\nimport { useContext } from 'react';\nimport { ContextMenuDivider } from './ContextMenuDivider';\nimport { ContextMenuItem } from './ContextMenuItem';\nimport { ContextMenuSettingsCtx } from './ContextMenuProvider';\nimport type { ContextMenuContent, ContextMenuOptions } from './types';\nimport { humanize } from './utils';\n\nexport type ContextMenuInstanceOptions = {\n x: number;\n y: number;\n content: ContextMenuContent;\n};\n\nexport type ContextMenuProps = ContextMenuOptions &\n ContextMenuInstanceOptions & {\n onHide: () => void;\n };\n\nexport function ContextMenu({ x, y, content, zIndex, onHide, className, style, classNames, styles }: ContextMenuProps) {\n const { shadow, borderRadius } = useContext(ContextMenuSettingsCtx);\n const [paperRef] = useResizeObserver<HTMLDivElement>();\n const { width, height } = paperRef.current?.getBoundingClientRect() || { width: 0, height: 0 };\n\n let windowWidth = 0;\n let windowHeight = 0;\n if (typeof window !== 'undefined') ({ innerWidth: windowWidth, innerHeight: windowHeight } = window);\n\n const { dir } = useDirection();\n\n return (\n <Paper\n ref={paperRef}\n shadow={shadow}\n radius={borderRadius}\n className={clsx('mantine-contextmenu', className, classNames?.root)}\n style={[\n ({ spacing: { md } }) => {\n const mdSpacing = px(md) as number;\n return {\n zIndex,\n top: y + height + mdSpacing > windowHeight ? windowHeight - height - mdSpacing : y,\n left:\n dir === 'ltr'\n ? x + width + mdSpacing > windowWidth\n ? windowWidth - width - mdSpacing\n : x\n : windowWidth - mdSpacing - (x - width - mdSpacing < 0 ? width + mdSpacing : x),\n };\n },\n style,\n styles?.root,\n ]}\n >\n {Array.isArray(content)\n ? content.map(({ key, className, style, onClick, items, title, ...otherOptions }) =>\n onClick || items ? (\n <ContextMenuItem\n key={key}\n className={clsx(classNames?.item, className)}\n style={[styles?.item, style]}\n title={title ?? humanize(key)}\n onClick={onClick}\n onHide={onHide}\n items={items}\n {...otherOptions}\n />\n ) : (\n <ContextMenuDivider\n key={key}\n className={clsx(classNames?.divider, className)}\n style={[styles?.divider, style]}\n />\n )\n )\n : content(onHide)}\n </Paper>\n );\n}\n"]}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
3
|
import { Portal } from '@mantine/core';
|
|
4
|
-
import { useClickOutside, useWindowEvent } from '@mantine/hooks';
|
|
4
|
+
import { useClickOutside, useHotkeys, useWindowEvent } from '@mantine/hooks';
|
|
5
5
|
import { ContextMenu } from './ContextMenu';
|
|
6
6
|
export function ContextMenuPortal({ onHide, ...otherProps }) {
|
|
7
7
|
useWindowEvent('resize', onHide);
|
|
8
8
|
useWindowEvent('scroll', onHide);
|
|
9
|
+
useHotkeys([['Escape', onHide]]);
|
|
9
10
|
const ref = useClickOutside(onHide);
|
|
10
11
|
return (_jsx(Portal, { ref: ref, children: _jsx(ContextMenu, { ...otherProps, onHide: onHide }) }));
|
|
11
12
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenuPortal.js","sourceRoot":"","sources":["../../package/ContextMenuPortal.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"ContextMenuPortal.js","sourceRoot":"","sources":["../../package/ContextMenuPortal.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAyB,MAAM,eAAe,CAAC;AAEnE,MAAM,UAAU,iBAAiB,CAAC,EAAE,MAAM,EAAE,GAAG,UAAU,EAAoB;IAC3E,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjC,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;IACjC,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;IACjC,MAAM,GAAG,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IAEpC,OAAO,CACL,KAAC,MAAM,IAAC,GAAG,EAAE,GAAG,YACd,KAAC,WAAW,OAAK,UAAU,EAAE,MAAM,EAAE,MAAM,GAAI,GACxC,CACV,CAAC;AACJ,CAAC","sourcesContent":["'use client';\n\nimport { Portal } from '@mantine/core';\nimport { useClickOutside, useHotkeys, useWindowEvent } from '@mantine/hooks';\nimport { ContextMenu, type ContextMenuProps } from './ContextMenu';\n\nexport function ContextMenuPortal({ onHide, ...otherProps }: ContextMenuProps) {\n useWindowEvent('resize', onHide);\n useWindowEvent('scroll', onHide);\n useHotkeys([['Escape', onHide]]);\n const ref = useClickOutside(onHide);\n\n return (\n <Portal ref={ref}>\n <ContextMenu {...otherProps} onHide={onHide} />\n </Portal>\n );\n}\n"]}
|
|
@@ -9,7 +9,7 @@ const DEFAULT_SETTINGS = {
|
|
|
9
9
|
submenuDelay: 500,
|
|
10
10
|
};
|
|
11
11
|
export const ContextMenuSettingsCtx = createContext(DEFAULT_SETTINGS);
|
|
12
|
-
export const ContextMenuCtx = createContext({ showContextMenu: () => () => undefined, hideContextMenu: () => undefined });
|
|
12
|
+
export const ContextMenuCtx = createContext({ showContextMenu: () => () => undefined, hideContextMenu: () => undefined, isContextMenuVisible: false });
|
|
13
13
|
/**
|
|
14
14
|
* Provider that allows to show a context menu anywhere in your application.
|
|
15
15
|
* If you wrap your application with this provider, you can use the `useContextMenu` hook
|
|
@@ -34,7 +34,7 @@ export function ContextMenuProvider({ zIndex = 9999, shadow = DEFAULT_SETTINGS.s
|
|
|
34
34
|
styles: options?.styles,
|
|
35
35
|
});
|
|
36
36
|
};
|
|
37
|
-
return (_jsx(ContextMenuSettingsCtx.Provider, { value: { shadow, borderRadius, submenuDelay }, children: _jsxs(ContextMenuCtx.Provider, { value: { showContextMenu, hideContextMenu }, children: [children, _jsx(MantineProvider, { children: data && _jsx(ContextMenuPortal, { onHide: hideContextMenu, ...data }) })] }) }));
|
|
37
|
+
return (_jsx(ContextMenuSettingsCtx.Provider, { value: { shadow, borderRadius, submenuDelay }, children: _jsxs(ContextMenuCtx.Provider, { value: { showContextMenu, hideContextMenu, isContextMenuVisible: !!data }, children: [children, _jsx(MantineProvider, { children: data && _jsx(ContextMenuPortal, { onHide: hideContextMenu, ...data }) })] }) }));
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Hook returning functions that show and hide the context menu.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContextMenuProvider.js","sourceRoot":"","sources":["../../package/ContextMenuProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAUxD,MAAM,gBAAgB,GAA0F;IAC9G,MAAM,EAAE,IAAI;IACZ,YAAY,EAAE,IAAI;IAClB,YAAY,EAAE,GAAG;CAClB,CAAC;AAEF,MAAM,CAAC,MAAM,sBAAsB,GAAG,aAAa,CAAC,gBAAgB,CAAC,CAAC;AACtE,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,
|
|
1
|
+
{"version":3,"file":"ContextMenuProvider.js","sourceRoot":"","sources":["../../package/ContextMenuProvider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAUxD,MAA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,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,sBAAsB,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,YAC5E,MAAC,cAAc,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,eAAe,EAAE,eAAe,EAAE,oBAAoB,EAAE,CAAC,CAAC,IAAI,EAAE,aAC/F,QAAQ,EACT,KAAC,eAAe,cAAE,IAAI,IAAI,KAAC,iBAAiB,IAAC,MAAM,EAAE,eAAe,KAAM,IAAI,GAAI,GAAmB,IAC7E,GACM,CACnC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,cAAc;IAC5B,OAAO,UAAU,CAAC,cAAc,CAAC,CAAC;AACpC,CAAC","sourcesContent":["'use client';\n\nimport { MantineProvider } from '@mantine/core';\nimport { createContext, useContext, useState } from 'react';\nimport type { ContextMenuInstanceOptions } from './ContextMenu';\nimport { ContextMenuPortal } from './ContextMenuPortal';\nimport type {\n ContextMenuOptions,\n ContextMenuProviderProps,\n ContextMenuSettings,\n HideContextMenuFunction,\n ShowContextMenuFunction,\n WithRequiredProperty,\n} from './types';\n\nconst DEFAULT_SETTINGS: WithRequiredProperty<ContextMenuSettings, 'shadow' | 'borderRadius' | 'submenuDelay'> = {\n shadow: 'sm',\n borderRadius: 'xs',\n submenuDelay: 500,\n};\n\nexport const ContextMenuSettingsCtx = createContext(DEFAULT_SETTINGS);\nexport const ContextMenuCtx = createContext<{\n /**\n * Function that shows the context menu.\n */\n showContextMenu: ShowContextMenuFunction;\n\n /**\n * Function that hides the context menu.\n */\n hideContextMenu: HideContextMenuFunction;\n\n /**\n * Boolean indicating whether the context menu is currently visible.\n */\n isContextMenuVisible: boolean;\n}>({ showContextMenu: () => () => undefined, hideContextMenu: () => undefined, isContextMenuVisible: false });\n\n/**\n * Provider that allows to show a context menu anywhere in your application.\n * If you wrap your application with this provider, you can use the `useContextMenu` hook\n * anywhere in the component tree to access a function that shows the context menu.\n */\nexport function ContextMenuProvider({\n zIndex = 9999,\n shadow = DEFAULT_SETTINGS.shadow,\n borderRadius = DEFAULT_SETTINGS.borderRadius,\n submenuDelay = DEFAULT_SETTINGS.submenuDelay,\n children,\n}: ContextMenuProviderProps) {\n const [data, setData] = useState<(ContextMenuInstanceOptions & ContextMenuOptions) | null>(null);\n\n const hideContextMenu = () => {\n setData(null);\n };\n\n const showContextMenu: ShowContextMenuFunction = (content, options) => (e) => {\n e.preventDefault();\n e.stopPropagation();\n setData({\n x: e.clientX,\n y: e.clientY,\n content,\n zIndex: options?.zIndex || zIndex,\n className: options?.className,\n style: options?.style,\n classNames: options?.classNames,\n styles: options?.styles,\n });\n };\n\n return (\n <ContextMenuSettingsCtx.Provider value={{ shadow, borderRadius, submenuDelay }}>\n <ContextMenuCtx.Provider value={{ showContextMenu, hideContextMenu, isContextMenuVisible: !!data }}>\n {children}\n <MantineProvider>{data && <ContextMenuPortal onHide={hideContextMenu} {...data} />}</MantineProvider>\n </ContextMenuCtx.Provider>\n </ContextMenuSettingsCtx.Provider>\n );\n}\n\n/**\n * Hook returning functions that show and hide the context menu.\n */\nexport function useContextMenu() {\n return useContext(ContextMenuCtx);\n}\n"]}
|
package/dist/esm/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../package/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MantineColor, MantineRadius, MantineShadow, MantineStyleProp, StylesRecord } from '@mantine/core';\n\n/**\n * Utility type that makes a property required\n */\nexport type WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\n/**\n * Utility type that makes a property optional\n */\nexport type WithOptionalProperty<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/**\n * Context menu options\n */\nexport type ContextMenuOptions = {\n /**\n * The z-index of context menu.\n * @default 9999\n */\n zIndex?: number;\n\n /**\n * Context menu container
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../package/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MantineColor, MantineRadius, MantineShadow, MantineStyleProp, StylesRecord } from '@mantine/core';\n\n/**\n * Utility type that makes a property required\n */\nexport type WithRequiredProperty<Type, Key extends keyof Type> = Type & {\n [Property in Key]-?: Type[Property];\n};\n\n/**\n * Utility type that makes a property optional\n */\nexport type WithOptionalProperty<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\n\n/**\n * Context menu options\n */\nexport type ContextMenuOptions = {\n /**\n * The z-index of context menu.\n * @default 9999\n */\n zIndex?: number;\n\n /**\n * Context menu container class name.\n */\n className?: string;\n\n /**\n * Context menu container style.\n */\n style?: MantineStyleProp;\n\n /**\n * Context menu elements class names.\n */\n classNames?: Partial<Record<'root' | 'item' | 'divider', string>>;\n\n /**\n * Context menu styles.\n * Can be an object with `root`, `item` and `divider` keys and style objects as values,\n * or a function that accepts the current theme and returns a similarly structured object.\n */\n styles?: StylesRecord<'root' | 'item' | 'divider', MantineStyleProp>;\n};\n\n/**\n * Generic context menu settings\n */\nexport type ContextMenuSettings = {\n /**\n * Context menu shadow.\n * @default 'sm'\n */\n shadow?: MantineShadow;\n\n /**\n * Context menu border radius.\n * @default 'xs'\n */\n borderRadius?: MantineRadius;\n\n /**\n * Delay in ms to use when showing and hiding submenus.\n * @default 500\n */\n submenuDelay?: number;\n};\n\n/**\n * Context menu provider props\n */\nexport type ContextMenuProviderProps = ContextMenuSettings &\n ContextMenuOptions & {\n children: React.ReactNode;\n };\n\n/**\n * Context menu item options\n */\nexport type ContextMenuItemOptions = {\n /**\n * Unique key of the context menu item or divider.\n */\n key: string;\n /**\n * Context menu item or divider className.\n */\n className?: string;\n\n /**\n * Context menu item or divider style.\n */\n style?: MantineStyleProp;\n} & (\n | ({\n /**\n * Optional context menu item icon.\n */\n icon?: React.ReactNode;\n\n /**\n * Optional context menu item title.\n * If not provided, one will be generated automatically by \"humanizing\" the key.\n * @default humanize(key)\n */\n title?: React.ReactNode;\n\n /**\n * Optional context menu item color.\n */\n color?: MantineColor;\n\n /**\n * Boolean indicating whether the context menu item is disabled.\n */\n disabled?: boolean;\n } & (\n | {\n /**\n * Optional context menu item `onClick` handler.\n * If not provided, a divider will be rendered instead.\n */\n onClick: React.MouseEventHandler<HTMLButtonElement>;\n\n items?: never;\n }\n | {\n onClick?: never;\n\n /**\n * Optional items.\n * If provided, a submenu will be rendered.\n */\n items: ContextMenuItemOptions[];\n }\n ))\n | {\n icon?: never;\n title?: never;\n color?: never;\n disabled?: never;\n onClick?: never;\n items?: never;\n }\n);\n\n/**\n * Context menu content.\n * Either an array of context menu items, or a function that accepts a close callback and returns context menu content.\n */\nexport type ContextMenuContent = ContextMenuItemOptions[] | ((close: () => void) => JSX.Element);\n\n/**\n * Show context menu function\n */\nexport type ShowContextMenuFunction = (\n /**\n * Context menu content.\n * Either an array of context menu items or a function that accepts a close callback and returns context menu content.\n */\n content: ContextMenuContent,\n\n /**\n * Context menu options (overrides provider props).\n */\n options?: ContextMenuOptions\n) => React.MouseEventHandler;\n\n/**\n * Hide context menu function\n */\nexport type HideContextMenuFunction = () => void;\n"]}
|
|
@@ -2,8 +2,18 @@
|
|
|
2
2
|
import type { ContextMenuProviderProps, ContextMenuSettings, HideContextMenuFunction, ShowContextMenuFunction, WithRequiredProperty } from './types';
|
|
3
3
|
export declare const ContextMenuSettingsCtx: import("react").Context<WithRequiredProperty<ContextMenuSettings, "shadow" | "borderRadius" | "submenuDelay">>;
|
|
4
4
|
export declare const ContextMenuCtx: import("react").Context<{
|
|
5
|
+
/**
|
|
6
|
+
* Function that shows the context menu.
|
|
7
|
+
*/
|
|
5
8
|
showContextMenu: ShowContextMenuFunction;
|
|
9
|
+
/**
|
|
10
|
+
* Function that hides the context menu.
|
|
11
|
+
*/
|
|
6
12
|
hideContextMenu: HideContextMenuFunction;
|
|
13
|
+
/**
|
|
14
|
+
* Boolean indicating whether the context menu is currently visible.
|
|
15
|
+
*/
|
|
16
|
+
isContextMenuVisible: boolean;
|
|
7
17
|
}>;
|
|
8
18
|
/**
|
|
9
19
|
* Provider that allows to show a context menu anywhere in your application.
|
|
@@ -15,6 +25,16 @@ export declare function ContextMenuProvider({ zIndex, shadow, borderRadius, subm
|
|
|
15
25
|
* Hook returning functions that show and hide the context menu.
|
|
16
26
|
*/
|
|
17
27
|
export declare function useContextMenu(): {
|
|
28
|
+
/**
|
|
29
|
+
* Function that shows the context menu.
|
|
30
|
+
*/
|
|
18
31
|
showContextMenu: ShowContextMenuFunction;
|
|
32
|
+
/**
|
|
33
|
+
* Function that hides the context menu.
|
|
34
|
+
*/
|
|
19
35
|
hideContextMenu: HideContextMenuFunction;
|
|
36
|
+
/**
|
|
37
|
+
* Boolean indicating whether the context menu is currently visible.
|
|
38
|
+
*/
|
|
39
|
+
isContextMenuVisible: boolean;
|
|
20
40
|
};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export type ContextMenuOptions = {
|
|
|
20
20
|
*/
|
|
21
21
|
zIndex?: number;
|
|
22
22
|
/**
|
|
23
|
-
* Context menu container
|
|
23
|
+
* Context menu container class name.
|
|
24
24
|
*/
|
|
25
25
|
className?: string;
|
|
26
26
|
/**
|
|
@@ -28,12 +28,12 @@ export type ContextMenuOptions = {
|
|
|
28
28
|
*/
|
|
29
29
|
style?: MantineStyleProp;
|
|
30
30
|
/**
|
|
31
|
-
* Context menu elements
|
|
31
|
+
* Context menu elements class names.
|
|
32
32
|
*/
|
|
33
33
|
classNames?: Partial<Record<'root' | 'item' | 'divider', string>>;
|
|
34
34
|
/**
|
|
35
35
|
* Context menu styles.
|
|
36
|
-
* Can be an object with `root`, `item` and `divider` keys and
|
|
36
|
+
* Can be an object with `root`, `item` and `divider` keys and style objects as values,
|
|
37
37
|
* or a function that accepts the current theme and returns a similarly structured object.
|
|
38
38
|
*/
|
|
39
39
|
styles?: StylesRecord<'root' | 'item' | 'divider', MantineStyleProp>;
|
|
@@ -139,4 +139,7 @@ content: ContextMenuContent,
|
|
|
139
139
|
* Context menu options (overrides provider props).
|
|
140
140
|
*/
|
|
141
141
|
options?: ContextMenuOptions) => React.MouseEventHandler;
|
|
142
|
+
/**
|
|
143
|
+
* Hide context menu function
|
|
144
|
+
*/
|
|
142
145
|
export type HideContextMenuFunction = () => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mantine-contextmenu",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Enhance your Mantine UI applications usability with customizable context menus",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ui",
|
|
@@ -75,13 +75,13 @@
|
|
|
75
75
|
"@mantine/notifications": "^7.1.5",
|
|
76
76
|
"@tabler/icons-react": "^2.39.0",
|
|
77
77
|
"@types/lodash": "^4.14.200",
|
|
78
|
-
"@types/node": "^20.8.
|
|
78
|
+
"@types/node": "^20.8.8",
|
|
79
79
|
"@types/react": "^18.2.31",
|
|
80
80
|
"@types/react-dom": "^18.2.14",
|
|
81
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
82
|
-
"@typescript-eslint/parser": "^6.
|
|
81
|
+
"@typescript-eslint/eslint-plugin": "^6.9.0",
|
|
82
|
+
"@typescript-eslint/parser": "^6.9.0",
|
|
83
83
|
"clsx": "^2.0.0",
|
|
84
|
-
"eslint": "^8.
|
|
84
|
+
"eslint": "^8.52.0",
|
|
85
85
|
"eslint-config-next": "^13.5.6",
|
|
86
86
|
"eslint-config-prettier": "^9.0.0",
|
|
87
87
|
"lodash": "^4.17.21",
|
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
"webpack": "^5.89.0"
|
|
101
101
|
},
|
|
102
102
|
"peerDependencies": {
|
|
103
|
-
"@mantine/core": ">=7",
|
|
104
|
-
"@mantine/hooks": ">=7",
|
|
103
|
+
"@mantine/core": ">=7.1",
|
|
104
|
+
"@mantine/hooks": ">=7.1",
|
|
105
105
|
"clsx": ">=2"
|
|
106
106
|
}
|
|
107
107
|
}
|