Skip to content

Dev dependencies, prop changes, and js project interoperability #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions context-menu-area.tsx

This file was deleted.

23 changes: 16 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{
"name": "react-electron-contextmenu",
"version": "0.1.1",
"version": "0.1.2",
"description": "Makes it super easy to create context menus in your React powered Electron apps",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build-library": "npm run clean-build && tsc && cp package.json ./dist/ && cp Readme.md ./dist/ && Echo Build completed!",
"publish-library": "cd ./dist && npm publish && echo Package published!",
"clean-build": "rm -rf dist"
"build": "npm run clean && tsc && cp package.json ./dist/ && cp Readme.md ./dist/ && Echo Build completed!",
"publish": "cd ./dist && npm publish && echo Package published!",
"clean": "rm -rf dist"
},
"repository": {
"type": "git",
Expand All @@ -16,7 +15,17 @@
"author": "johot",
"license": "MIT",
"peerDependencies": {
"react": "*",
"electron": "*"
"electron": "*",
"react": "*"
},
"devDependencies": {
"@types/react": "^17.0.0",
"@types/react-dom": "^17.0.0",
"electron": "^11.2.0",
"react": "^17.0.1",
"typescript": "^4.1.3"
},
"dependencies": {
"tslib": "^2.1.0"
}
}
26 changes: 26 additions & 0 deletions src/ContextMenuArea.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useState, useEffect, useCallback } from 'react';
import { remote } from 'electron';
const { Menu } = remote;

export interface ContextMenuAreaProps extends React.BaseHTMLAttributes<HTMLDivElement> {
menuItems: Electron.MenuItemConstructorOptions[];
}

export function ContextMenuArea(props: ContextMenuAreaProps) {
const { menuItems, ...rest } = props;
const [menu, setMenu] = useState(new Menu());

useEffect(() => {
setMenu(Menu.buildFromTemplate(menuItems));
}, [menuItems]);

const contextMenuCallback = useCallback((event: React.MouseEvent) => {
menu?.popup();
}, [menu]);

return (
<div {...rest} onContextMenu={contextMenuCallback} >
{props.children}
</div>
);
}
2 changes: 1 addition & 1 deletion index.ts → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ContextMenuArea from "./context-menu-area";
import { ContextMenuArea } from "./ContextMenuArea";

export { ContextMenuArea };
export default ContextMenuArea;
2 changes: 2 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
"jsx": "react",
"lib": ["dom", "es2015", "es2016"],
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"moduleResolution": "node",
"noEmitHelpers": true,
"importHelpers": true,
"strict": true,
"noImplicitReturns": true,
"declaration": true
},
"include": ["src"],
"exclude": ["node_modules", "build", "scripts", "acceptance-tests", "webpack", "jest", "src/setupTests.ts"]
}