Svelte Loading Spinners

0.3.6 · active · verified Tue Apr 21

This library offers a collection of loading spinner Svelte components. The current stable version is `0.3.6`. It provides a variety of visual spinners, including `Jumper`, `BarLoader`, `Circle`, and `Wave`, each implemented as a standalone Svelte component. Updates are typically released as needed, responding to bug fixes or Svelte ecosystem changes, rather than on a fixed cadence. A key architectural aspect is that these are pure Svelte components, making them reactive and easily integrated into any Svelte application. They are designed to work seamlessly with SvelteKit, particularly demonstrating integration with the `$app/stores.navigating` store for handling page transitions. Each spinner component is highly customizable via common props such as `size`, `color`, `unit`, and `duration`. Specific spinners like `Circle2` and `Circle3` offer additional, unique props for fine-grained control over their appearance. The package includes TypeScript type definitions, providing full type safety for developers using TypeScript in their Svelte projects.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates integrating `svelte-loading-spinners` for SvelteKit page navigation detection and manual task simulation, using `Jumper` and `Wave` components. This example should be placed in a SvelteKit `+layout.svelte` file.

<!-- src/routes/+layout.svelte -->
<script lang="ts">
  import { Jumper, Wave } from 'svelte-loading-spinners';
  import { navigating } from '$app/stores'; // SvelteKit specific store for navigation status

  // Simulate a delay or background task for demonstration if not relying solely on SvelteKit navigation
  let showManualSpinner = false;
  async function simulateLoading() {
    showManualSpinner = true;
    await new Promise(resolve => setTimeout(resolve, 2000)); // Simulate a 2-second load
    showManualSpinner = false;
  }
</script>

<nav>
  <a href="/">Home</a>
  <a href="/about">About</a>
  <button on:click={simulateLoading}>Simulate Task</button>
</nav>

<!-- Show spinner during SvelteKit navigation -->
{#if $navigating}
  <div class="spinner-overlay kit-nav">
    <Jumper size="60" color="#FF3E00" unit="px" duration="1s" />
    <p>Loading page...</p>
  </div>
{/if}

<!-- Show spinner for manual tasks -->
{#if showManualSpinner}
  <div class="spinner-overlay manual-task">
    <Wave size="80" color="blue" />
    <p>Processing data...</p>
  </div>
{/if}

<slot />

<style>
  .spinner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.9);
    z-index: 1000;
  }
  .kit-nav { background-color: rgba(255, 255, 255, 0.9); }
  .manual-task { background-color: rgba(0, 0, 0, 0.7); color: white; }
  nav { padding: 1rem; background: #eee; }
  nav a, nav button { margin-right: 1rem; }
</style>

view raw JSON →