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 🙏

© 2025 – Pkg Stats / Ryan Hefner

nextjs-top-scroll-progress-bar

v0.0.8

Published

A Next.js npm package that adds a top scroll progress bar to your Next.js apps, compatible with both Pages Router and App Router.

Readme

nextjs-top-scroll-progress-bar

A lightweight Next.js component that adds a customizable scroll progress bar at the top of your page. The progress bar indicates how far the user has scrolled through the content, providing a better user experience.

Features

  • Automatic scroll progress tracking
  • Customizable appearance (height and color)
  • Works with Next.js App Router
  • Zero dependencies
  • TypeScript support

See CHANGELOG.md for release history and updates.

Installation

npm install nextjs-top-scroll-progress-bar
# or
yarn add nextjs-top-scroll-progress-bar
# or
pnpm add nextjs-top-scroll-progress-bar

Usage

The component can be used with both the App Router (Next.js 13+) and the Pages Router. Choose the appropriate setup based on your project.

With App Router (Next.js 13+)

  1. Create a client component for the progress bar (since it uses browser APIs):
// app/components/ClientTopScrollProgressBar.tsx
'use client'

import { TopScrollProgressBar } from 'nextjs-top-scroll-progress-bar'

interface TopScrollProgressBarProps {
  height?: number;
  color?: string;
}

export default function ClientTopScrollProgressBar({ height, color }: TopScrollProgressBarProps) {
  return <TopScrollProgressBar height={height} color={color}/>
}
  1. Use the component in your root layout:
// app/layout.tsx
import ClientTopScrollProgressBar from './components/ClientTopScrollProgressBar'

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        <ClientTopScrollProgressBar color="#F00" height={4} />
        {children}
      </body>
    </html>
  )
}

With Pages Router

  1. Create a client component for the progress bar:
// components/ClientTopScrollProgressBar.tsx
import { TopScrollProgressBar } from 'nextjs-top-scroll-progress-bar'

interface TopScrollProgressBarProps {
  height?: number;
  color?: string;
}

export default function ClientTopScrollProgressBar({ height, color }: TopScrollProgressBarProps) {
  return <TopScrollProgressBar height={height} color={color}/>
}
  1. Add it to your _app.tsx:
// pages/_app.tsx
import type { AppProps } from 'next/app'
import ClientTopScrollProgressBar from '../components/ClientTopScrollProgressBar'

export default function App({ Component, pageProps }: AppProps) {
  return (
    <>
      <ClientTopScrollProgressBar color="#F00" height={4} />
      <Component {...pageProps} />
    </>
  )
}

Props

The component accepts the following props:

| Prop | Type | Default | Description | |------|------|---------|-------------| | color | string | '#FF0000' | Color of the progress bar. Accepts any valid CSS color value (hex, rgb, hsl, etc.) | | height | number | 4 | Height of the progress bar in pixels |

Examples

// Default appearance
<ClientTopScrollProgressBar />

// Custom red color with 4px height
<ClientTopScrollProgressBar color="#FF0000" height={4} />

// Using RGB color
<ClientTopScrollProgressBar color="rgb(0, 128, 255)" height={3} />

Development

Project Structure

├── src/                    # Source code
│   ├── TopScrollProgressBar.tsx  # Main component
│   └── index.ts           # Entry point
├── dist/                   # Built files (generated)
├── __tests__/             # Test files
└── package.json           # Project configuration

Setup Development Environment

  1. Clone the repository:
git clone https://github.com/renjith100/nextjs-top-scroll-progress-bar.git
cd nextjs-top-scroll-progress-bar
  1. Install dependencies:
npm install
  1. Start development:
npm run build # Build the package

Testing with a Local Next.js Project

To test the package locally before publishing:

  1. In your package directory, create a local package:
npm pack

This will create a file like nextjs-top-scroll-progress-bar-0.0.2.tgz

  1. In your Next.js project's package.json, add the local package:
{
  "dependencies": {
    "nextjs-top-scroll-progress-bar": "file:/path/to/nextjs-top-scroll-progress-bar-0.0.2.tgz"
  }
}
  1. Install the package in your Next.js project:
npm install
  1. Use the component as described in the Usage section above.

Whenever you make changes to the package:

  1. Rebuild the package: npm run build
  2. Create a new package: npm pack
  3. Reinstall in your Next.js project: npm install

Running Tests

The project uses Jest and React Testing Library for testing. Tests are located in the src/__tests__ directory.

# Run tests once
npm test

# Run tests in watch mode (for development)
npm run test:watch

The test suite includes:

  • Component rendering tests
  • Props validation tests
  • Scroll behavior tests

Building

The package uses Rollup for building and generates both ESM and CommonJS formats:

npm run build

This will create:

  • dist/index.cjs.js - CommonJS format
  • dist/index.esm.js - ES Module format
  • dist/index.d.ts - TypeScript declarations

License

MIT