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

@axframe/contextmenu

v0.3.5

Published

@axframe/contextmenu makes menus dynamically added to the "React" project available.

Downloads

9

Readme

@axframe/contextmenu

@axframe/contextmenu makes menus dynamically added to the "React" project available.

NPM version NPM downloads

Install

npm i @axframe/contextmenu

DEMO : https://axframe-contextmenu.vercel.app/

Development

npm i
npm run dev

Open http://localhost:3000 with your browser to see the result.

USE

Add styles to your project

Add a CSS file to suit your project. You can also create your own files by referring to the files provided.

import '@axframe/contextmenu/dist/style.less';
// or
import '@axframe/contextmenu/dist/style.css';
// or
import '@axframe/contextmenu/dist/style.scss';

Contextmenu Example

Open codesandbox example

import React from 'react';
import {
  ArrowLeftOutlined,
  ArrowRightOutlined,
  FacebookOutlined,
  GithubOutlined,
  GooglePlusOutlined,
  MailOutlined,
  ReloadOutlined,
  SlackOutlined,
  TwitterOutlined,
} from '@ant-design/icons';
import { ContextMenu, AXFCMenu } from '@axframe/contextmenu';
import styled from '@emotion/styled';

const ContextMenuSample: React.FC = () => {
  const contextMenu = React.useRef<ContextMenu>(
    new ContextMenu({
      id: 'basic',
      style: { fontSize: '14px', minWidth: '200px' },
    }), // also you can set menu by second parameter
  );

  const onClickMenu: AXFCMenu.OnClickItem = React.useCallback(menuItem => {
    console.log(menuItem);
  }, []);

  const handleContextMenu = React.useCallback((e: React.MouseEvent<HTMLDivElement>) => {
    e.preventDefault();
    contextMenu.current.popup({
      x: e.pageX,
      y: e.pageY,
    });
  }, []);

  React.useEffect(() => {
    contextMenu.current.setMenu([
      {
        label: 'Back (enabled: false)',
        icon: <ArrowLeftOutlined />,
        click: onClickMenu,
        enabled: false,
      },
      {
        label: 'Forward',
        icon: <ArrowRightOutlined />,
        click: onClickMenu,
        accelerator: 'Cmd+F',
      },
      {
        label: 'Reload',
        icon: <ReloadOutlined />,
        click: onClickMenu,
      },
      { type: 'separator' },
      { label: 'Save as', click: onClickMenu, visible: false },
      {
        label: 'Print (enabled: false)',
        click: 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: <GithubOutlined />,
            click: onClickMenu,
          },
          {
            label: 'Gitlab',
            icon: <GithubOutlined />,
            click: onClickMenu,
          },
          {
            label: 'Twitter',
            icon: <TwitterOutlined />,
            click: onClickMenu,
          },
          {
            label: 'Facebook',
            icon: <FacebookOutlined />,
            click: onClickMenu,
          },
          {
            label: 'Google+',
            icon: <GooglePlusOutlined />,
            click: onClickMenu,
            visible: false,
          },
          {
            label: 'Slack (enabled: false)',
            icon: <SlackOutlined />,
            click: onClickMenu,
            enabled: false,
          },
          {
            label: 'Email',
            icon: <MailOutlined />,
            click: onClickMenu,
          },
        ],
      },
      { type: 'separator' },
      { label: 'View Source', click: onClickMenu },
      { label: 'Save', click: onClickMenu },
    ]);
  }, [onClickMenu]);

  return (
    <Container data-testid={'context-menu-sample-div'} onContextMenu={handleContextMenu}>
      Right mouse click here
    </Container>
  );
};

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

export default ContextMenuSample;

MenuBar Example

import React from 'react';
import styled from '@emotion/styled';
import {
  ArrowLeftOutlined,
  ArrowRightOutlined,
  FacebookOutlined,
  GithubOutlined,
  GooglePlusOutlined,
  MailOutlined,
  ReloadOutlined,
  SlackOutlined,
  TwitterOutlined,
} from '@ant-design/icons';
import { MenuBar, AXFCMenu } from '@axframe/contextmenu';

const MenuBarExample: React.FC = () => {
  const onClickMenu: AXFCMenu.OnClickItem = React.useCallback(menuItem => {
    console.log(menuItem);
  }, []);

  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: <ArrowLeftOutlined />,
                  click: onClickMenu,
                  enabled: false,
                },
                {
                  label: 'Forward',
                  icon: <ArrowRightOutlined />,
                  click: onClickMenu,
                  accelerator: 'Cmd+F',
                },
                {
                  label: 'Reload',
                  icon: <ReloadOutlined />,
                  click: onClickMenu,
                },
                { type: 'separator' },
                { label: 'Save as', click: onClickMenu, visible: false },
                {
                  label: 'Print (enabled: false)',
                  click: 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: <GithubOutlined />,
                      click: onClickMenu,
                    },
                    {
                      label: 'Gitlab',
                      icon: <GithubOutlined />,
                      click: onClickMenu,
                    },
                    {
                      label: 'Twitter',
                      icon: <TwitterOutlined />,
                      click: onClickMenu,
                    },
                    {
                      label: 'Facebook',
                      icon: <FacebookOutlined />,
                      click: onClickMenu,
                    },
                    {
                      label: 'Google+',
                      icon: <GooglePlusOutlined />,
                      click: onClickMenu,
                      visible: false,
                    },
                    {
                      label: 'Slack (enabled: false)',
                      icon: <SlackOutlined />,
                      click: onClickMenu,
                      enabled: false,
                    },
                    {
                      label: 'Email',
                      icon: <MailOutlined />,
                      click: onClickMenu,
                    },
                  ],
                },
                { type: 'separator' },
                { label: 'View Source', click: onClickMenu },
                { label: 'Save', click: onClickMenu },
              ],
            },
            {
              label: 'Edit',
              submenu: [
                {
                  label: 'Undo',
                  accelerator: 'Cmd+Z',
                  click: onClickMenu,
                },
                {
                  label: 'Redo',
                  accelerator: 'Cmd++Shift+Z',
                  click: onClickMenu,
                },
              ],
            },
            {
              label: 'Selection',
              submenu: [
                {
                  label: 'Select All',
                  click: onClickMenu,
                },
              ],
            },
          ]}
        />
      </div>
    </Container>
  );
};

const Container = styled.div`
  height: 500px;
  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;
  }
`;

export default MenuBarExample;