prgm-dev / sveltekit-progress-bar

A SvelteKit progress bar that shows on navigation
MIT License
35 stars 2 forks source link

sveltekit-progress-bar

A SvelteKit component that displays a progress bar when the page is loading.

This component is based on the svelte-progress-bar component for Svelte. It has been adapted to integrate with SvelteKit.

If you are looking for a standalone component, check out the original component.

Demo

Please refer to the svelte-progress-bar package for a demo.

Installation

In a SvelteKit project:

npm install --save-dev @prgm/sveltekit-progress-bar

Using pnpm:

pnpm add --save-dev @prgm/sveltekit-progress-bar

Usage

In a SvelteKit page or layout where you would like to use the component, for instance in the src/routes/+layout.svelte file:

<!-- +layout.svelte -->
<script lang="ts">
    import { ProgressBar } from "@prgm/sveltekit-progress-bar";
</script>

<ProgressBar color="#7F57F1" />
<!-- Or, if you're using Tailwind/Windi: -->
<ProgressBar class="text-green-500" />

<slot />

Bar Color

The progress bar does not have a default color, so you will need to set one. You can either set the color as a data property, as a text- class if you're using Tailwind/WindiCSS, or override the CSS.

Svelte component:

<!-- Set the CSS color through an attribute: -->
<ProgressBar color="#0366d6" />
<!-- Or, if you're using Tailwind/Windi: -->
<ProgressBar class="text-green-500" />

Other Styles

If you are using some type of navbar at the top of the page, like Bootstrap's, it is likely that you will need to change the z-index to get the progress bar to appear over the navbar:

<ProgressBar color="#7F57F1" zIndex={100} />

Options

You shouldn't need to play with these, they've been selected based on UX design expertise, but they're available if you need them:

Methods

These additional methods are available on an instantiated progress bar: