JSPM

@jamalofficial/top-progress-bar

1.0.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q35743F
  • License MIT

Lightweight customizable top progress bar for React (global with hook support)

Package Exports

  • @jamalofficial/top-progress-bar
  • @jamalofficial/top-progress-bar/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@jamalofficial/top-progress-bar) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

๐ŸŸฆ Top Progress Bar

A lightweight, customizable top-loading progress bar for React apps. Designed to be globally accessible with the useTopBar() hook and no external dependencies. Ideal for showing loading states during async operations like route transitions, API calls, or dynamic UI rendering.


๐Ÿš€ Features

  • ๐Ÿ” Global control with useTopBar()
  • โฑ Continuous, step, and manual percentage modes
  • ๐ŸŽจ Customizable color, height, and animation speed
  • ๐Ÿ’ก Zero dependencies โ€” pure React + CSS
  • ๐ŸŒ SSR-friendly and easy to integrate into any React project

๐Ÿ“ฆ Installation

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

๐Ÿ› ๏ธ Usage

1๏ธโƒฃ Wrap your app in the TopProgressBarProvider

// App.jsx or Layout.jsx
import { TopProgressBarProvider } from 'top-progress-bar';

function App() {
  return (
    <TopProgressBarProvider color="#1d4ed8" height="3px" speed={300}>
      <YourApp />
    </TopProgressBarProvider>
  );
}

2๏ธโƒฃ Use the useTopBar hook anywhere

import { useTopBar } from 'top-progress-bar';

function ExampleComponent() {
  const { start, step, set, complete } = useTopBar();

  const handleLoad = async () => {
    start();                  // auto-starts at 5%, increases automatically
    await delay(1000);
    step(20);                 // add 20%
    await delay(500);
    set(80);                  // jump to 80%
    await delay(500);
    complete();               // fill to 100% then hide
  };

  return <button onClick={handleLoad}>Load Something</button>;
}

function delay(ms) {
  return new Promise((res) => setTimeout(res, ms));
}

โš™๏ธ API

TopProgressBarProvider Props

Prop Type Default Description
color string #2563eb The color of the progress bar
height string 4px Height of the bar (e.g., "3px", "5px")
speed number 300 Auto-progress speed (ms interval)

useTopBar() Hook

Provides access to control functions:

Method Description
start() Starts auto-incrementing progress bar
step(n) Increases progress by n percent (e.g., step(10))
set(n) Sets the exact progress (e.g., set(80))
complete() Finishes the bar at 100%, then hides after a delay

โ— The bar is automatically hidden when complete() is called or set(100) is reached.


๐Ÿงช Example

const bar = useTopBar();

useEffect(() => {
  bar.start();

  fetchData().then(() => {
    bar.complete();
  });
}, []);

๐Ÿงฑ Built With

  • โœ… React 17+ or 18+
  • โœ… Pure CSS transitions
  • โœ… React Context + useRef + forwardRef
  • โŒ No third-party animation libraries

๐Ÿ“ License

MIT ยฉ jamalofficial


๐Ÿง‘โ€๐Ÿ’ป Contributing

Contributions are welcome! Please open an issue or submit a PR.