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

@porrametict/react-context-menu

v1.0.9

Published

A React component for creating menus with ease.

Downloads

5

Readme

React ContextMenu

A React component for creating menus with ease.

Installation

npm i @porrametict/react-context-menu

Usage

import { ContextMenu, CallbackProps } from "@porrametict/react-context-menu";

export const Example1 = () => {
  const menuItems = [
    { id: "menu1", label: "Menu 1" },
    {
      id: "menu2",
      label: "Menu 2",

      submenu: [
        {
          id: "submenu-2-1",
          parentId: "menu2",
          label: "Submenu 2-1",
        },
        {
          id: "submenu-2-2",
          parentId: "menu2",
          label: "Submenu 2-2",
        },
      ],
    },
  ];

  const handleOnClick = ({ data, menuItem }: CallbackProps) => {
    console.log(data);
    console.log(menuItem);
    alert(`Data is: ${data} \nMenuItem is: ${JSON.stringify(menuItem)}`);
  };
  return (
    <ContextMenu
      menuItems={menuItems}
      onMenuClick={(_data) => handleOnClick(_data)}
    >
      <div
        style={{
          height: "100px",
          width: "100px",
          display: "flex",
          alignItems: "center",
          justifyContent: "center",
          border: "1px solid black",
        }}
      >
        Right Click Me
      </div>
    </ContextMenu>
  );
};

Props

  • menuItems (required): An array of menu items that define the structure and behavior of the context menu.
  • onMenuClick (required): A callback function that is called when a menu item is clicked. It receives two parameters: data (the associated data) and menuItem (the clicked menu item). Use this callback to handle different actions based on the clicked menu item.
  • data (optional): The data associated with the context menu. This is passed to the onMenuClick callback when a menu item is clicked.
  • menuItemWidth (optional): The width of each menu item in pixels. (Default: 200)
  • menuItemHeight (optional): The height of each menu item in pixels. (Default: 30)
  • containerStyle (optional): Custom styling for the container that wraps the context menu.
  • menuContainerClass (optional): Additional CSS class for the menu container.
  • menuItemClass (optional): Additional CSS class for each menu item.

MenuItem

  • id (required): A unique identifier for the menu item.
  • parentId (required): The identifier of the parent menu item. Not set or use null for top-level items.
  • label (required): The text label displayed for the menu item.
  • submenu (optional): An array of submenu items, defining nested menus.
  • prependIcon (optional): React node to prepend an icon to the menu item.
  • appendIcon (optional): React node to append an icon to the menu item.
  • disabledFunc (optional): A function that, when provided with CallbackProps, returns a boolean indicating whether the menu item should be disabled.
  • hiddenFunc (optional): A function that, when provided with CallbackProps, returns a boolean indicating whether the menu item should be hidden.
  • ... (additional properties): Any additional properties can be added as needed.
[
  { id: "menu1", label: "Menu 1" },
  {
    id: "menu2",
    label: "Menu 2",

    submenu: [
      {
        id: "submenu-2-1",
        parentId: "menu2",
        label: "Submenu 2-1",
      },
      {
        id: "submenu-2-2",
        parentId: "menu2",
        label: "Submenu 2-2",
      },
    ],
  },
  {
    id: "disable-menu",
    parentId: null,
    label: "Disabled menu",
    action: "delete",
    disabledFunc: (_data) => {
      const { data, menuItem } = _data;
      return true;
    },
  },
  {
    id: "hide-menu",
    parentId: null,
    label: "Hide Me",
    action: "delete",
    hiddenFunc: (_data) => {
      const { data, menuItem } = _data;
      return true;
    },
  },
];