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-simple-side-menu

v1.0.0

Published

A lightweight side menu based on pure React and CSS.

Downloads

17

Readme

react-simple-side-menu

A lightweight side menu based on pure React and CSS.

Usage

To install, simply run the following:

npm install --save react-simple-side-menu

Import the component and the default styling(optional) into your into your React app:

import ReactSimpleSideMenu from "react-simple-side-menu";
import "react-simple-side-menu/styles/react-simple-side-menu-colors.css";

Example

The ReactSimpleSideMenu component has a few props that can be fed into it. However, the menu prop is the main one. You should define the menu as an array of objects and pass it as a prop to the component. For instance,

const menu = [
  {
    title: "Level 0 - 0",
    menuType: "submenu",
    item: [
      {
        title: "Level 1b",
        menuType: "endlink",
        item: () => {console.log("Level 1b")}
      },
      {
        title: "Level 1a",
        menuType: "submenu",
        item: [
          {
            title: "Level 2a",
            menuType: "endlink",
            item: () => {console.log("Level 2a")}
          }
        ]
      }
    ]
  }
]

The objects within the array consists of the following keys:

| key | type | description | |---|---|---| | "title" | string | The string that will be displayed as the label for the button | | "menuType" | string | "submenu" | "endlink" - determines what happens when clicked | | "item" | array | string | func | When menuType is submenu, the item should be an array of this object. When menuType is endlink, the item should be either the string "inherit" or a function that is to be passed to the button upon render. The function passed will trigger upon an onClick event on the button. |

Note: When you enter "inherit" for the item key, you will need to pass a callback function to the component.

You can then pass the menu array into the component as follows:

function App() {
  return (
    <ReactSimpleSideMenu menu={menu}/>
  );
}

Using the callback prop

Using the callback prop will make all the endlink buttons trigger the same function upon an onClick event. It is up to you to decide what parameters goes into this function or how this function operates. The item values for the endlink menuType can still be "inherit" or a function. If a function is defined, it will be called instead of the callback prop function.

For example, the following will cause all of the endlink buttons to log "test" into the console.

function App() {
  return (
    <ReactSimpleSideMenu menu={menu} callback={function(){console.log("test")}}/>
  );
}

If you define the menu array to be as follows:

const menu = [
  {
    title: "Level 0 - 0",
    menuType: "submenu",
    item: [
      {
        title: "Level 1b",
        menuType: "endlink",
        item: "inherit"
      },
      {
        title: "Level 1a",
        menuType: "submenu",
        item: [
          {
            title: "Level 2a",
            menuType: "endlink",
            item: () => {console.log("Level 2a")}
          }
        ]
      }
    ]
  }
]

Level 1b button will log as "test" but level 2a will log as "Level 2a".

Styling

You can use the default styling or create your own custom styles. You have to define the following classes in your main CSS file in order for the component to be styled properly.

Below contains the default classes, but please go ahead and style then to your liking :)

/* Determines the font color of the entire side menu */
.root-node-color {
    color: white;
}

/* Determines the left border color when a submenu is active */
.root-node.active {
    border-left: 4px solid lightblue;
}

/* Determines the background color of the entire side menu */
.overall-background {
    background-color: #3F51B5;
}

License

MIT