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-skeletal-nav

v0.4.1

Published

Build recursive navigation UIs with React

Downloads

237

Readme

react-skeletal-nav 🦴🧭

A set of React components for building recursive navigation UIs for the web

NPM JavaScript Style Guide

Intro

Makes defining recursive navs as simple as this

const Header = () => (
  <Nav>
    <NavItem title="Item 1" href="/" />
    <NavItem title="Item 2" href="/" />
    <NavItem title="Sub Nav">
      <Nav>
        <NavItem title="Subitem 1" href="/" />
        <NavItem title="Subitem 2" href="/" />
      </Nav>
    </NavItem>
  </Nav>
);

It's also possible to render from JSON by taking advantage from the react-from-json library.

Install

npm install --save react-skeletal-nav

Usage

react-skeletal-nav provides 3 skeleton components:

  1. <Nav /> - The root navigation component.
  2. <NavItem /> - A navigation item, such as a link to a page, or link to a nested <Nav />
  3. <NavList /> - A group of <NavItem /> components. Useful for segmenting your items. Optional.

You need to extend these components for use in your app. It's easiest to use the HOCs provided, but you can also use render props.

Nav.js

import React from 'react';
import { withNav } from 'react-skeletal-nav';

export const Nav = withNav(
  ({ children, goBack, route, isStack, isVisible }) =>
    // Only render stack nav
    isStack && (
      // Hide if not visible, but don't unmount so nested Navs stay mounted
      <div style={{ display: isVisible ? 'block' : 'none' }}>
        {/* Never render the back button on the "root" nav */}
        {route !== 'root' && <button onClick={goBack}>Back</button>}

        {/* Render children, including nested Navs */}
        {children}
      </div>
    )
);

NavItem.js

import React from 'react';
import { withNavItem } from 'react-skeletal-nav';

export const NavItem = withNavItem(({ children, href, onClick, title }) => (
  <div>
    {href && <a href="">{title}</a>}
    {!href && <button onClick={onClick}>{title}</button>}

    {/* Render nested navs */}
    {children}
  </div>
));

App.js

import Nav from './Nav';
import NavItem from './NavItem';

export default () => (
  <Nav>
    <NavItem title="Item 1" href="/" />
    <NavItem title="Item 2" href="/" />
    <NavItem title="Sub Nav">
      <Nav>
        <NavItem title="Subitem 1" href="/" />
        <NavItem title="Subitem 2" href="/" />
      </Nav>
    </NavItem>
  </Nav>
);

Rendering from JSON

We can also render complex navigation UI from JSON, using the react-from-json library. This is particularly useful when working with a headless CMS.

import React from 'react';
import ReactFromJSON from 'react-from-json';
import Nav from './Nav';
import NavItem from './NavItem';

const componentMapping = {
  Nav,
  NavItem
};

const data = {
  type: 'Nav',
  props: {
    children: [
      { type: 'NavItem', props: { href: '/', title: 'Item 1' } },
      { type: 'NavItem', props: { href: '/', title: 'Item 2' } },
      {
        type: 'NavItem',
        props: {
          children: {
            type: 'Nav',
            props: {
              children: [
                {
                  type: 'NavItem',
                  props: { href: '/', title: 'Subitem 1' }
                },
                {
                  type: 'NavItem',
                  props: { href: '/', title: 'Subitem 2' }
                }
              ]
            }
          },
          title: 'SubNav'
        }
      }
    ]
  }
};

export default () => <ReactFromJSON mapping={componentMapping} entry={data} />;

API

TBD

Contributing & Releasing

Follow the angular verison of conventional commits when committing to this repo, as this generates the CHANGELOG.md and ensures we follow semver.

To bump version, generate changelog and prep for release, run:

yarn release

then to publish

npm publish

License

MIT © chrisvxd