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

@agjs/react-right-click-menu

v0.0.8

Published

React context menu.

Downloads

168

Readme

react-right-click-menu

Minimalistic provider built around native Contextmenu Event.

Unlike many similar libraries, react-right-click-menu simply provides a context environment, where consumer provides an actual DOM node (a reference) to an element that should trigger the menu and the component that should be rendered when the event occurs.

This makes it easy to intergrate your own UI library and show your own UI Components when a context menu is triggered. That being said, react-right-click-menu doesn't carry over any content or styling, nor it installs any additional dependencies.

CodeSandbox Demo

Install

NPM

npm i @agjs/react-right-click-menu

YARN

yarn add @agjs/react-right-click-menu

Props

| Props | Description | Default | | ---------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- | | trigger | A react reference to an element that will trigger the menu on right click | null | | component | A component to show when trigger is right clicked | null | | isOpenAfterInteraction | Determines if a menu should remain open after user interacts with it. For instance, maybe you will render a list of checkboxes that user has to interact with, and you don't want menu to close it after each interaction (click) | true | | className | A custom className in case you want to apply custom styling to the context wrapper | null | | isOpen | Self-explanatory | false | | setIsOpen | Self-explanatory | - |

Use

import React, { useRef, useState } from "react";
import ContextMenu from "@agjs/react-right-click-menu";
import SomeUiComponent from "somewhere";

export const ExampleComponent = () => {
  const [isMenuShown, setIsMenuShown] = useState(false);
  const ref = useRef();
  return (
    <>
      <ContextMenu
        isOpenAfterInteraction={false}
        trigger={ref}
        component={<SomeUiComponent />}
        isOpen={isMenuShown}
        setIsOpen={setIsMenuShown}
      />
      <div className="foo" ref={ref}>
        Once someone right-clicks inside of me, I will trigger some content!
      </div>
    </>
  );
};

Transitions

Example using react-motion

To keep the minimal footprint, react-right-click-menu doesn't apply any transitions to the component triggered. This decision was made in order to keep minimal amount of external dependencies and to allow a consumer to add them if they wish.

In the showcase below, we can see how we used a render-prop from react-motion to generate some inline-styles and pass them down to the ContextMenu.

import React, { useRef, useState } from "react";
import ContextMenu from "@agjs/react-right-click-menu";
import { Motion, spring } from "react-motion";
import ContextMenu from "./index";
import Foo from "somewhere";

export const ExampleComponent = () => {
  const [isMenuShown, setIsMenuShown] = useState(false);
  const ref = useRef();
  return (
    <>
      <Motion
        defaultStyle={{ opacity: 0 }}
        style={{
          opacity: !isMenuShown ? spring(0) : spring(1),
        }}
      >
        {(interpolatedStyle) => {
          return (
            <ContextMenu
              trigger={ref}
              component={<Foo />}
              isOpen={isMenuShown}
              setIsOpen={setIsMenuShown}
              style={{ opacity: interpolatedStyle.opacity }}
            />
          );
        }}
      </Motion>
      <div ref={ref} style={customStyles}>
        Right click inside of me!
      </div>
    </>
  );
};