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

nextjs13-progress

v1.3.3

Published

An implementation of n-progress for use with the Next.js 13 app router.

Downloads

1,691

Readme

nextjs13-progress

npm All Contributors

Description

An implementation of n-progress for use with the Next.js 13 app router. This project is based on the Nextjs Progressbar

project and the props are 100% compatible.

Installation


npm i nextjs13-progress

Usage

In your layout.tsx:

import './globals.css';
import type { Metadata } from 'next';
import { Inter } from 'next/font/google';

import { Next13NProgress, Link } from 'nextjs13-progress';

const inter = Inter({ subsets: ['latin'] });

export const metadata: Metadata = {
	title: 'Create Next App',
	description: 'Generated by create next app',
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
	return (
		<html lang="en">
			<body className={inter.className}>
				<main className="min-h-screen flex flex-col">
					<header className="flex items-center gap-6 justify-center text-2xl text-white bg-slate-800 py-4">
						<Link href="/">Home</Link>
						<Link href="/page2">Page2</Link>
					</header>
					{children}
				</main>
				<Next13NProgress color="red" height={5} />
			</body>
		</html>
	);
}

NOTE: You must use the Link component from this package in order to initiate the start of n-progress. This component is a wrapper for Next/Link.

Default Config

If no props are passed to <Next13NProgress />, below is the default configuration applied.

<Next13NProgress color="#29D" startPosition={0.3} stopDelayMs={200} height={3} showOnShallow={true} />
  • color: to change the default color of progressbar. You can also use rgb(,,) or rgba(,,,).
  • startPosition: to set the default starting position : 0.3 = 30%.
  • stopDelayMs: time for delay to stop progressbar in ms.
  • height: height of progressbar in px.
  • showOnShallow: You can choose whether you want the progressbar to be displayed if you're using shallow routing. It takes a boolean. Learn more about shallow routing in Next.js docs.

Advanced usage

Link

The provided Link component adds an onClick event to the links it generates. This handler will:

  1. Verify the href attribute of the link, and the characteristics of the click event. Depending on both conditions, it will start the progress bar.
  2. Fire any additional onClick event that you provided

In some cases, you might need a greater level of control over the onClick event. For that reason, the handler can be imported so as to create your own Link component as needed.

Example 1:

Don't attach the progressbar onClick event if we've already supplied an onClick event of our own.

'use client';

import NextLink, { LinkProps } from 'next/link';
import { forwardRef } from 'react';
import { linkClicked as progressBarLinkClicked } from 'nextjs13-progress';

export const Link = forwardRef<HTMLAnchorElement, LinkProps>((
	{ onClick, ...rest },
	ref,
) => (
	<NextLink
		onClick={event => {
			if (onClick) {
				// fire only the existing event only
				onClick(event);
			} else {
				// fire the progressbar event
				progressBarLinkClicked(event);
			}
		}}
		{...rest}
		ref={ref}
	/>
));

Example 2:

Clicking a link triggers a browser prompt. Since the link only clicks through if the user confirms, we need to also assure that the progress bar also only starts if that condition is met.

'use client';

import NextLink, { LinkProps } from 'next/link';
import { forwardRef } from 'react';
import { linkClicked as progressBarLinkClicked } from 'nextjs13-progress';

export const Link = forwardRef<HTMLAnchorElement, LinkProps>((
	{ ...rest },
	ref,
) => (
	<NextLink
		onClick={event => {
			const confirm = window.confirm("Are you sure?");
			if (confirm) {
				// proceed as normal
				progressBarLinkClicked(event);
			} else {
				// cancel the click
				event.preventDefault();
			}
		}}
		{...rest}
		ref={ref}
	/>
));

Demo

Click Here for a full working Next.js demo site.

Contributors

Contributing

Contributions are always welcome! To contribute, simply fork, make your change and issue a PR.

Thanks

Special thanks to # Vũ Văn Dũng for his nextjs13-appdir-router-events demo Next.js project. I borrowed much of the code from that project to make this package.

License

MIT