npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-electron-window-menu

v0.6.2

Published

:octocat: React Component that render a menu with 'Electron Menu' in the Windows environment.

Downloads

9

Readme

npm version

react-electron-window-menu

Install

$ npm i react-electron-window-menu

MenuBar

View Demo : https://codesandbox.io/s/qlz936p539

import * as React from 'react';
import { MenuBar, IREWMenu } from 'react-electron-window-menu';
import 'react-electron-window-menu/style.scss';
import { styled } from 'styledComponents';
import { Icon } from 'antd';

const Container = styled.div`
  height: 200px;
  background: #467bff;
  padding: 10px;
  overflow: auto;
  .menubar-container {
    padding: 0 10px;
    height: 25px;
    background: #eee;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.3);

    font-size: 12px;
  }
`;

interface IProps {}
interface IState {}

class MenuBarExample extends React.Component<IProps, IState> {
  state = {};

  constructor(props: IProps) {
    super(props);
  }

  onClickMenu: IREWMenu.OnClickItem = (menuItem, w, e) => {
    console.log(menuItem);
  };

  render() {
    return (
      <Container>
        <div className="menubar-container">
          <MenuBar
            style={{ height: '25px' }}
            submenu={{
              style: { minWidth: '150px' },
              placement: 'bottom',
            }}
            items={[
              {
                label: 'File',
                submenu: [
                  {
                    label: 'Back (enabled: false)',
                    icon: <Icon type="arrow-left" />,
                    click: this.onClickMenu,
                    enabled: false,
                  },
                  {
                    label: 'Forward',
                    icon: <Icon type="arrow-right" />,
                    click: this.onClickMenu,
                    accelerator: 'Cmd+F',
                  },
                  {
                    label: 'Reload',
                    icon: <Icon type="caret-right" />,
                    click: this.onClickMenu,
                  },
                  { type: 'separator' },
                  { label: 'Save as', click: this.onClickMenu, visible: false },
                  {
                    label: 'Print (enabled: false)',
                    click: this.onClickMenu,
                    enabled: false,
                  },
                  {
                    type: 'checkbox',
                    label: 'Action option 1',
                    click: (menuItem, w, e) => {
                      console.log(menuItem);
                    },
                  },
                  {
                    type: 'checkbox',
                    label: 'Action option 2 (enabled: false)',
                    checked: true,
                    enabled: false,
                    click: (menuItem, w, e) => {
                      console.log(menuItem);
                    },
                  },
                  {
                    label: 'send to...',
                    submenu: [
                      {
                        label: 'Github',
                        icon: <Icon type="github" />,
                        click: this.onClickMenu,
                      },
                      {
                        label: 'Gitlab',
                        icon: <Icon type="gitlab" />,
                        click: this.onClickMenu,
                      },
                      {
                        label: 'Twitter',
                        icon: <Icon type="twitter" />,
                        click: this.onClickMenu,
                      },
                      {
                        label: 'Facebook',
                        icon: <Icon type="facebook" />,
                        click: this.onClickMenu,
                      },
                      {
                        label: 'Google+',
                        icon: <Icon type="google-plus" />,
                        click: this.onClickMenu,
                        visible: false,
                      },
                      {
                        label: 'Slack (enabled: false)',
                        icon: <Icon type="slack-square" />,
                        click: this.onClickMenu,
                        enabled: false,
                      },
                      {
                        label: 'Email',
                        icon: <Icon type="mail" />,
                        click: this.onClickMenu,
                      },
                    ],
                  },
                  { type: 'separator' },
                  { label: 'View Source', click: this.onClickMenu },
                  { label: 'Save', click: this.onClickMenu },
                ],
              },
              {
                label: 'Edit',
                submenu: [
                  {
                    label: 'Undo',
                    accelerator: 'Cmd+Z',
                    click: this.onClickMenu,
                  },
                  {
                    label: 'Redo',
                    accelerator: 'Cmd++Shift+Z',
                    click: this.onClickMenu,
                  },
                ],
              },
              {
                label: 'Selection',
                submenu: [
                  {
                    label: 'Select All',
                    click: this.onClickMenu,
                  },
                ],
              },
            ]}
          />
        </div>
      </Container>
    );
  }
}

export default MenuBarExample;

ContextMenu

View Demo : https://codesandbox.io/s/9j6m3ojo3o

import * as React from 'react';
import { ContextMenu, IREWMenu } from 'react-electron-window-menu';
import 'react-electron-window-menu/style.scss';
import { styled } from 'styledComponents';
import { Icon } from 'antd';

const Container = styled.div`
  height: 300px;
  background: #eee;
  display: flex;
  justify-content: center;
  align-items: center;
`;

interface IProps {}
interface IState {}

class ContextMenuExample extends React.Component<IProps, IState> {
  menu: IREWMenu.IContextMenu;
  state = {};

  constructor(props: IProps) {
    super(props);

    this.menu = new ContextMenu({
      id: 'basic',
      style: { fontSize: '14px', minWidth: '200px' },
    });
  }

  onClickMenu: IREWMenu.OnClickItem = (menuItem, w, e) => {
    console.log(menuItem);
  };

  handleContextMenu = (e: React.MouseEvent<HTMLDivElement>) => {
    e.preventDefault();
    this.menu.popup({ x: e.pageX, y: e.pageY });
  };

  render() {
    return (
      <Container onContextMenu={this.handleContextMenu}>
        Right mouse click here
      </Container>
    );
  }

  componentDidMount() {
    this.menu.setMenu([
      {
        label: 'Back (enabled: false)',
        icon: <Icon type="arrow-left" />,
        click: this.onClickMenu,
        enabled: false,
      },
      {
        label: 'Forward',
        icon: <Icon type="arrow-right" />,
        click: this.onClickMenu,
        accelerator: 'Cmd+F',
      },
      {
        label: 'Reload',
        icon: <Icon type="caret-right" />,
        click: this.onClickMenu,
      },
      { type: 'separator' },
      { label: 'Save as', click: this.onClickMenu, visible: false },
      {
        label: 'Print (enabled: false)',
        click: this.onClickMenu,
        enabled: false,
      },
      {
        type: 'checkbox',
        label: 'Action option 1',
        click: (menuItem, w, e) => {
          console.log(menuItem);
        },
      },
      {
        type: 'checkbox',
        label: 'Action option 2 (enabled: false)',
        checked: true,
        enabled: false,
        click: (menuItem, w, e) => {
          console.log(menuItem);
        },
      },
      {
        label: 'send to...',
        submenu: [
          {
            label: 'Github',
            icon: <Icon type="github" />,
            click: this.onClickMenu,
          },
          {
            label: 'Gitlab',
            icon: <Icon type="gitlab" />,
            click: this.onClickMenu,
          },
          {
            label: 'Twitter',
            icon: <Icon type="twitter" />,
            click: this.onClickMenu,
          },
          {
            label: 'Facebook',
            icon: <Icon type="facebook" />,
            click: this.onClickMenu,
          },
          {
            label: 'Google+',
            icon: <Icon type="google-plus" />,
            click: this.onClickMenu,
            visible: false,
          },
          {
            label: 'Slack (enabled: false)',
            icon: <Icon type="slack-square" />,
            click: this.onClickMenu,
            enabled: false,
          },
          {
            label: 'Email',
            icon: <Icon type="mail" />,
            click: this.onClickMenu,
          },
        ],
      },
      { type: 'separator' },
      { label: 'View Source', click: this.onClickMenu },
      { label: 'Save', click: this.onClickMenu },
    ]);
  }
}

export default ContextMenuExample;

Version history

  • v0.2.0 : Implement submenu
  • v0.3.0 : Add properties "check, enable, visible" on MenuItem
  • v0.3.1 : update readme
  • v0.4.0 : Add property "accelerator" on MenuItem
  • v0.5.1 : Rename to react-electron-window-menu
  • v0.6.1 : Update dependencies