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-nested-menu

v1.0.9

Published

React JS component for rendering nested navigation menus

Downloads

290

Readme

React Nested Menu

React JS component for rendering nested navigation menus

Example

Installation

npm install react-nested-menu --save

Usage

React Nested Menu renders HTML of a multi-level navigation menu. The structure of the menu is generated from an array of objects

import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import ReactDOM from 'react-dom';
import { ReactNestedMenu } from 'react-nested-menu';


class App extends Component {
    linkTransformer = (menuItem) => {

        return (
            <Link to={menuItem.url}>{ menuItem.title }</Link>
        )
    }

    render() {

        const menu = [
            {
                id: 1,
                title: "Home",
                url: "/"
            },
            {
                id: 2,
                title: "About Us",
                url: "/about-us"
            },
            {
                title: "Team",
                url: "/team",
                children: [
                    {
                        id: 8,
                        title: "Tim Drake",
                        url: "/tim-drake"
                    },
                    {
                        id: 9,
                        title: "Jason Todd",
                        url: "/jason-todd"
                    },
                    {
                        id: 10,
                        title: "Richard Grayson",
                        url: "/richard-grayson"
                    }
                ]
            },
            {
                title: "Services",
                url: "/services",
                children: [
                    {
                        id: 5,
                        title: "Web Development",
                        url: "/web-development"
                    },
                    {
                        id: 6,
                        title: "UI Design",
                        url: "/ui-design"
                    },
                    {
                        id: 7,
                        title: "Copywriting",
                        url: "/copywriting"
                    }
                ]
            },
            {
                id: 4,
                title: "Contact",
                url: "/contact"
            },
            {
                title: "Social",
                url: "/social",
                children: [
                    {
                        id: 11,
                        title: "Twitter",
                        url: "/twitter"
                    },
                    {
                        id: 12,
                        title: "Facebook",
                        url: "/facebook"
                    }
                ]
            },
        ];

        return (
            <div className="App">
                <ReactNestedMenu
                    navParentClassname="vertical menu nested"
                    navTopLevelParentClassname="vertical menu"
                    navChildClassname="child"
                    linkTransformer={this.linkTransformer}
                    menuData={menu}/>
            </div>
        );
    }
}

ReactDOM.render(<App />, document.getElementById('root'));

Props

  • navParentElement: HTML tag name of elements that wrap nav menu elements
    • type: string
    • default: ul
  • navChildElement: HTML tag name of elements wrapped by parent elements
    • type: string
    • default: li
  • navParentClassname: class of nav parent elements
    • type: string
  • navTopLevelParentClassname: class of top level nav parent elements
    • type: string
  • navChildClassname: class of nav child elements
    • type: string
  • navUrlProperty: the key name to use as the href attribute of the anchor tags
    • type: string
    • default: url
  • navTitleProperty: the key name to use as the title wrapped by the anchor tags
    • type: string
    • default: title
  • childMenuProperty: the key name of the array of child nav items
    • type: string
    • default: children
  • arrayKey: the key to use as the key attribute in React array elements
    • type: string
    • default: id
  • linkTransformer: function that accepts an object in the menuData array and returns a React element; this can be used to render something besides an anchor tag such as a React Router Link element
    • type: function
  • menuData: an array of objects
    • type: array