Skip to content

Commit 39e5e97

Browse files
committed
Abstract hooks away from ContextMenuWrapper
1 parent bb07cf4 commit 39e5e97

File tree

14 files changed

+280
-194
lines changed

14 files changed

+280
-194
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ module.exports = {
6060
'prettier/prettier': 'off',
6161
},
6262
settings: {
63+
react: {
64+
pragma: 'React', // Pragma to use, default to "React"
65+
version: 'detect',
66+
},
6367
'import/extensions': ['.js', '.jsx', '.ts', '.tsx'],
6468
},
6569
};

docs/components/BasicLocalMenu.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const LocalMenuExample = () => {
55
const menuId = 'my-component-local-menu';
66
const bannerRef = useRef();
77

8-
// This method attaches relevant DOM event listeners to `bannerRef`.
8+
// This hook attaches relevant DOM event listeners to `bannerRef`.
99
useContextMenuHandlers(bannerRef, { id: menuId });
1010

1111
return (

docs/markdown/2-Basic-menus.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ This section talks about context menus that always display the same content.
44

55
To make a context menu global, simply set the `global` prop to `true`. The simplest global menu could look like this:
66
```jsx
7-
<ContextMenuWrapper global={true}>
8-
<div className="context-menu">
9-
<p>I am a global context menu!</p>
10-
</div>
11-
</ContextMenuWrapper>
7+
import React from 'react';
8+
import { ContextMenuWrapper } from 'react-context-menu-wrapper';
9+
10+
export const GlobalMenuExample = () => {
11+
return (
12+
<ContextMenuWrapper global={true}>
13+
<div className="context-menu">
14+
<p>I am a global context menu!</p>
15+
</div>
16+
</ContextMenuWrapper>
17+
);
18+
};
1219
```
1320

1421
This component will automatically replace the default context menu of your browser. Try right-clicking (or
@@ -33,11 +40,12 @@ export const LocalMenuExample = () => {
3340
const menuId = 'my-component-local-menu';
3441
const bannerRef = useRef();
3542

36-
// This method attaches relevant DOM event listeners to `bannerRef`.
43+
// This hook attaches relevant DOM event listeners to `bannerRef`.
3744
useContextMenuHandlers(bannerRef, { id: menuId });
3845

3946
return (
4047
<React.Fragment>
48+
// We attach `bannerRef` to the component that will trigger the context menu:
4149
<div ref={bannerRef} className="banner">Right click or long-press this box</div>
4250

4351
<ContextMenuWrapper id={menuId}>

lib/ContextMenuWrapper.js

Lines changed: 8 additions & 76 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/ContextMenuWrapper.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/hooks.d.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
import React from 'react';
22
import { Nullable } from 'tsdef';
3-
import { ContextMenuEvent, DataAttributes } from './handlers';
3+
import { ContextMenuEvent } from './handlers';
44
export declare const useLazyValue: <T>(factory: () => T) => T;
55
export declare const ContextMenuEventContext: React.Context<Nullable<ContextMenuEvent>>;
66
export declare const useContextMenuEvent: () => Nullable<ContextMenuEvent>;
7-
export interface ContextMenuHandlerObject {
8-
onContextMenu: (event: React.MouseEvent) => void;
9-
[DataAttributes.MenuId]?: string;
10-
[DataAttributes.DataId]?: string;
11-
}
127
export declare const useContextMenuHandlers: (ref: React.RefObject<HTMLElement>, { id, data }: {
138
id?: string | undefined;
149
data?: any;
1510
}) => void;
11+
export declare const useMenuToggleMethods: (lastShowMenuEvent: Nullable<ContextMenuEvent>, setShowMenuEvent: (event: Nullable<ContextMenuEvent>) => void, onShow?: ((event: ContextMenuEvent) => void) | undefined, onHide?: (() => void) | undefined) => [(event: ContextMenuEvent) => void, () => void];
12+
export declare const useMenuPlacementStyle: (lastShowMenuEvent: Nullable<ContextMenuEvent>, setMenuPlacementStyle: (style: Nullable<React.CSSProperties>) => void, wrapperRef: React.RefObject<HTMLElement>) => void;
13+
export declare const useInternalHandlers: (showMenu: (event: ContextMenuEvent) => void, hideMenu: () => void, id?: string | undefined, global?: boolean | undefined, hideOnSelfClick?: boolean | undefined, hideOnOutsideClick?: boolean | undefined, hideOnEscape?: boolean | undefined, hideOnScroll?: boolean | undefined, hideOnWindowResize?: boolean | undefined) => void;

lib/hooks.js

Lines changed: 50 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/hooks.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)