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-priority-plus-nav

v1.0.3

Published

Accessible Priority Plus responsive web navigation React Component

Downloads

35

Readme

react-priority-plus-nav

Build Status npm version Coverage Status

Need a robust React responsive menu for your site? Look no further than the priority plus pattern. The pattern has been well described by Brad Frost and CSS Tricks.

Features

Take a horizontal menu…

Wide horizontal menu

…squish it…

Mid-size horizontal menu showing wrapped menu

…and some more…

Narrow horizontal menu showing collapse down to one item

…and the menu doesn't break!

  • Robust, resposive and acessible navigation.
  • Ideal when you don't have control of menu content.
  • Overflow switches from default "More" to "Menu" when there's only one menu item left.
  • Supports localised "More" and "Menu" labels.
  • Tabbing and keyboard menu activation work as you would hope.
  • Intelligent wrapping - if there is only one item that can't fit, the previous sibling is also wrapped. Launching a menu for one item isn't a great experience.
  • All this and less than 2KB gzipped.

Installation

$ npm i react-priority-plus-nav

Import into your react project:

import PriorityPlusNav from "react-priority-plus-nav";

Import the base styles and then set your custom menu styles. The demo styles should act as a good starting point.

@import "~react-priority-plus-nav/es/ppnav";

Demo

Clone this repo and run npm install && npm start on your localhost to see it in action.

Parameters

menuItems

Array of menu item objects. If you override renderMenuItem below, you can set any custom properties in here.

{
  uri: "", // path
  label: "", // menu item label
  isActive: true, // indicates the current menu item is active i.e. we're on this page
}

menuText [optional]

String label for the collapsed menu. Override for localisation purposes.

moreText [optional]

String label for the overflowed menu. Override for localisation purposes.

className [optional]

Class to sit at the top level of the rendered <nav> element. Helpful if you want class overrides outside the default cdl-ppnav namespace.

renderMenuItem [optional]

Override the default menu item render function. You'll want to do this if you're using React Router or similar.

const defaultRenderMenuItem = props => {
  const { itemDetails, captureRef, clickHandler, activeClass } = props;
  const { uri, label, isActive } = itemDetails;

  console.log("rendering");

  return (
    <li className={isActive ? activeClass : ""} key={uri} ref={captureRef} onClick={clickHandler}>
      <a href={uri}>{label}</a>
    </li>
  );
};