|
| 1 | +# Next Js TopLoader |
| 2 | + |
| 3 | +- A Next.js Top Loading Bar component made using nprogress, works with Next.js 14 and React. |
| 4 | + |
| 5 | +[](https://www.npmjs.com/package/nextjs-toploader) |
| 6 | +[](https://www.npmjs.com/package/nextjs-toploader) |
| 7 | +[](https://jsr.io/badges/@thesgj/nextjs-toploader) |
| 8 | + |
| 9 | +For using npm package manager instead see: (https://www.npmjs.com/package/nextjs-toploader) |
| 10 | + |
| 11 | +## Install |
| 12 | + |
| 13 | +using jsr with npm: |
| 14 | + |
| 15 | +```bash |
| 16 | +npx jsr add @thesgj/nextjs-toploader |
| 17 | +``` |
| 18 | + |
| 19 | +using jsr with yarn: |
| 20 | + |
| 21 | +```bash |
| 22 | +yarn dlx jsr add @thesgj/nextjs-toploader |
| 23 | +``` |
| 24 | + |
| 25 | +using deno: |
| 26 | + |
| 27 | +```bash |
| 28 | +deno add @thesgj/nextjs-toploader |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +import using: |
| 34 | + |
| 35 | +```js |
| 36 | +import NextTopLoader from '@thesgj/nextjs-toploader'; |
| 37 | +``` |
| 38 | + |
| 39 | +### Usage with `app/layout.js` for `app` folder structure |
| 40 | + |
| 41 | +For rendering add `<NextTopLoader />` to your `return()` inside the `<body></body>` of `RootLayout()`: |
| 42 | + |
| 43 | +```js |
| 44 | +import NextTopLoader from '@thesgj/nextjs-toploader'; |
| 45 | + |
| 46 | +export default function RootLayout({ children }) { |
| 47 | + return ( |
| 48 | + <html lang="en"> |
| 49 | + <body> |
| 50 | + <NextTopLoader /> |
| 51 | + {children} |
| 52 | + </body> |
| 53 | + </html> |
| 54 | + ); |
| 55 | +} |
| 56 | +``` |
| 57 | + |
| 58 | +### Usage with `pages/_app.js` for `pages` folder structure |
| 59 | + |
| 60 | +For rendering add `<NextTopLoader />` to your `return()` in `MyApp()`: |
| 61 | + |
| 62 | +```js |
| 63 | +import NextTopLoader from '@thesgj/nextjs-toploader'; |
| 64 | + |
| 65 | +export default function MyApp({ Component, pageProps }) { |
| 66 | + return ( |
| 67 | + <> |
| 68 | + <NextTopLoader /> |
| 69 | + <Component {...pageProps} />; |
| 70 | + </> |
| 71 | + ); |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### Usage with React, Vite React or any other React Based Framework |
| 76 | + |
| 77 | +For rendering add `<NextTopLoader />` to your `return()` inside the <Router><Router/> component in `App()` in your App.js: |
| 78 | + |
| 79 | + |
| 80 | +```js |
| 81 | +import NextTopLoader from '@thesgj/nextjs-toploader'; |
| 82 | +const App = () => { |
| 83 | + return ( |
| 84 | + <div> |
| 85 | + <Router> |
| 86 | + <NextTopLoader /> |
| 87 | + <Routes> |
| 88 | + {/* Your Routes Here */} |
| 89 | + </Routes> |
| 90 | + </Router> |
| 91 | + </div> |
| 92 | + ) |
| 93 | +} |
| 94 | + |
| 95 | +export default App; |
| 96 | +``` |
| 97 | + |
| 98 | +### Default Configuration |
| 99 | + |
| 100 | +If no props are passed to `<NextTopLoader />`, below is the default configuration applied. |
| 101 | + |
| 102 | +```jsx |
| 103 | +<NextTopLoader |
| 104 | + color="#2299DD" |
| 105 | + initialPosition={0.08} |
| 106 | + crawlSpeed={200} |
| 107 | + height={3} |
| 108 | + crawl={true} |
| 109 | + showSpinner={true} |
| 110 | + easing="ease" |
| 111 | + speed={200} |
| 112 | + shadow="0 0 10px #2299DD,0 0 5px #2299DD" |
| 113 | + template='<div class="bar" role="bar"><div class="peg"></div></div> |
| 114 | + <div class="spinner" role="spinner"><div class="spinner-icon"></div></div>' |
| 115 | + zIndex={1600} |
| 116 | + showAtBottom={false} |
| 117 | +/> |
| 118 | +``` |
| 119 | + |
| 120 | +- `color`: to change the default color of TopLoader. |
| 121 | +- `initialPosition`: to change initial position for the TopLoader in percentage, : `0.08 = 8%`. |
| 122 | +- `crawlSpeed`: increment delay speed in `ms`. |
| 123 | +- `speed`: animation speed for the TopLoader in `ms` |
| 124 | +- `easing`: animation settings using easing (a CSS easing string). |
| 125 | +- `height`: height of TopLoader in `px`. |
| 126 | +- `crawl`: auto incrementing behavior for the TopLoader. |
| 127 | +- `showSpinner`: to show spinner or not. |
| 128 | +- `shadow`: a smooth shadow for the TopLoader. (set to `false` to disable it) |
| 129 | +- `template`: to include custom HTML attributes for the TopLoader. |
| 130 | +- `zIndex`: defines zIndex for the TopLoader. |
| 131 | +- `showAtBottom`: To show the TopLoader at bottom. (increase height for the TopLoader to ensure it's visibility at the mobile devices) |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +UPI ID: thesgj@sbi |
| 136 | + |
| 137 | +[](https://github.com/sponsors/TheSGJ) |
| 138 | + |
| 139 | +[](https://www.buymeacoffee.com/thesgj) |
0 commit comments