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

next-nav

v1.0.4

Published

Add a modern navbar to your next.js app automatically based on your routes.

Downloads

14

Readme

next-nav

Description

Add a modern navbar to your next.js app automatically based on your routes.

Note Only the app directory structure of next.js is currenlty supported. This will NOT work with the pages directory.

Table of Contents

Installation

npm install next-nav

Usage

import Nav from 'next-nav';

export default function Home() {
	return (
		<main>
			<Nav />
		</main>
	);
}
  1. Import the Nav component from next-nav.
  2. Place Nav anywhere inside a React functional component.
  3. Your folders (routes) will automatically be added to the Nav component.

Example


If your file structure looks like this:

your-project
  ├─ app
  │  ├─ about
  │  ├─ contact
  │  ├─ products
  │  ├─ globals.css
  │  ├─ layout.jsx
  │  ├─ page.module.css
  │  └─ page.jsx
  │
  ├─ node_modules
  ├─ .gitignore
  ├─ next.config.js
  ├─ package-lock.json
  ├─ package.json
  └─ README.md

Nav will render this:

<nav class="nav">
	<p>Home</p>
	<p>About</p>
	<p>Products</p>
	<p>Contact</p>
</nav>

Dropdown Menus

Nested folders are automatically rendered as sub menus (dropdowns).

Example


If your file structure looks like this:

app
  ├─ about
  ├─ contact
  ├─ products
  │  ├─ soap
  │  ├─ candles
  │  └─ art
  │
  ├─ globals.css
  ├─ layout.tsx
  ├─ page.module.css
  └─ page.tsx

Nav will render this:

<nav class="nav">
	<p>Home</p>
	<p>About</p>
	<p>Contact</p>
	<div>
		<p>
			Products
			<svg width="10" height="10">
				<polyline points="1,4 5,9 9,4" />
			</svg>
		</p>

		<p>Soap</p>
		<p>Candles</p>
		<p>Art</p>
	</div>
</nav>

Options

The Nav component accepts a single 'options' prop that expects an object.

import Nav from 'next-nav';

export default function Home() {
	const options = {
		style: {
			color: 'lightblue'
		}
	};

	return (
		<main>
			<Nav options={options} />
		</main>
	);
}

The options object accepts two parameters, style and exclude.

Styling

The style parameter is an object that allows you to customize the appearance of the Nav component with any of the following options.

| Key | Value | | :------------ | :----------------------------------------------------------------------- | | gap | 30px 10% 10vw | | color | red #ff0000 #f00 rgb(255, 0, 0) hsl(0, 100%, 50%) | | hoverColor | blue #0000ff #00f rgb(0, 0, 255) hsl(240, 100%, 50%) | | textAlign | start center end | | textTransform | lowercase uppercase capitalize |

Inheritance

There is some default styling applied to the Nav component however most of the text style will be inherited from your existing styling. This is why there are no options to customize the font.

Exclusion

The exclude parameter is an array that allows you to specify routes you don't want in your navigation.

const options = {
    exclude: ['home', 'products'];
}

To exclude a subnav (dropdown) item, you must include the parent route followed by a slash, as it would appear in the url.

const options = {
    exclude: ['products/candles'];
}

Example


If your file structure looks like this:

app
  ├─ about
  ├─ contact
  ├─ products
  │  ├─ soap
  │  ├─ candles
  │  └─ art
  │
  ├─ globals.css
  ├─ layout.tsx
  ├─ page.module.css
  └─ page.tsx

and your options look like this:

const options = {
	style: {
		textTransform: 'uppercase'
	},

	exclude: ['home', 'products']
};

return (
	<main>
		<Nav options={options} />
	</main>
);

Nav will render this:

<nav class="nav options">
	<p>ABOUT</p>
	<p>CONTACT</p>
</nav>

Contributing

Questions

mreliwood on GitHub   |   [email protected]