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

push-menu-mec

v1.0.4

Published

react multi level push menu

Downloads

2

Readme

react-push-menu

Notice: There are breaking changes. Do not upgrade from v1.* if you do not intend to adjust the interfaces seen below. The interface to manage the menu has changed. Please see the examples below

npm version

Prerequisites

Install peer dependencies

npm install react react-dom styled-components --save

Install

npm install --save react-push-menu

How to use

import { PushMenu, usePushMenu } from 'react-push-menu';
import { FaChevronRight, FaChevronLeft } from 'react-icons/fa';

function Content() {
  const { toggleMenu } = usePushMenu();
  return (
    <div
      onClick={() => {
        toggleMenu();
      }}
    >
      trigger
    </div>
  );
}

/* ... */

function App() {
  return (
    <PushMenu
      backIcon={<FaChevronLeft />}
      expanderComponent={FaChevronRight}
      nodes={menuData}
      propMap={{ url: 'link' }}
    >
      <Content />
    </PushMenu>
  );
}

See example for more details

Properties

openOnMount (boolean)

This option allows you to initialize the push menu as open on load.

nodes (Object)

This property accepts an object with the definition for the menu. see the example for a sample menu definition

propMap (Object)

APIs can define/give a different structure or property names for required fields. This give the user the option to tell react-push-menu which property on the node/menu item to find the value it's looking for.

| Mapping | Description | | ------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | id | the id property of the node | | displayName | This is the text that will appear in the menu option. | | linkClasses | These are class names that will be added to the menu option. | | expanderClasses | These are class names that will be added to the menu option's expander given it has defined children. | | url | This tells the library which prop the url for the menu item is located. will default to a hash (#) if none is found | | childPropName | This is the property name that holds the children of each menu item node. We realize that data driven menu may differ and it is important to customize the properties that may hold the required data. default: children |

eg.

<PushMenu
  propMap={{
    displayName: 'title',
    id: 'id',
    linkClasses: 'classes',
    expanderClasses: 'expClasses',
    childPropName: 'children',
    url: 'url',
  }}
></PushMenu>

onNodeClick (function)

This is an onClick callback fired when you click the link of a menu item. Please note it won't be fired when you click the expand component for a menu item.

eg.

<PushMenu
  onNodeClick={(e, context) => {
    /**
      {
        // state
        node: Record<string, any>; // the current node
        nodes: Record<string, any>; // full menu tree
        propMap: PropMap;
        visibleMenus: Array;

        // actions
        addMenu: (node) => {};
        removeLastMenu: Function;
        closeMenu: Function;
        openMenu: Function;
        openSubMenu: (node) => {};
        toggleMenu: Function;
      }
     **/
    console.log(context);

    // following line will close the menu completely
    context.closeMenu();
  }}
></PushMenu>

onMenuExpand (function)

This function triggered when a sub menu is expanded.

<PushMenu
  onMenuExpand={(e, context) => {
    // do something
    // return false to prevent default behaviour
  }}
></PushMenu>

linkComponent (React.Component)

You can fully customize the link of the menu by passing in a React Component to this property. It will be instantiated with the data object which contains the current node being interacted with. (props.data). To see an example please see LinkComponent.js

backComponent (React.Component)

You can fully customize the back link of the sub menus by passing in a React Component to this property. It will be instantiated with the data object which contains the current node being interacted with. (props.data).

backIcon (ReactNode)

If you don't specify a backComponent, you can at least need specify an icon to use for the back component

<FaChevronLeft />

expanderComponent (React.Component) (Required)

You can fully customize the expander link of the sub menus by passing in a React Component to this property. The expander is the chevron-right that appears when a menu item has children. It will be instantiated with the data object which contains the current node being interacted with. (props.data).

Notes/Todos

  • add task to deploy to gh-pages
  • add more event handlers

Pull requests are welcome

Credits