Spinner

An indicator that can be used to show a loading state.

Basic
In Buttons
In Badges
Badge Badge Badge Badge
In Input Group
In Empty State
No projects yet
You haven't created any projects yet. Get started by creating your first project.

Installation

Install the dependencies

pnpm add cn

Copy the component

Copy the following files into src/lib/components/ui/spinner.

src/lib/components/ui/spinner/Spinner.svelte
<script lang="ts">
  import type { SpinnerProps } from './types.js';
  import { cn } from 'cn';
  import Loader2Icon from '@lucide/svelte/icons/loader-2';
  let { class: classProp, ...props }: SpinnerProps = $props();
</script>
<Loader2Icon
  data-slot="spinner"
  role="status"
  aria-label="Loading"
  class={cn('size-4 animate-spin', classProp)}
  {...props}
/>
src/lib/components/ui/spinner/types.ts
import type { SVGAttributes } from 'svelte/elements';

export type SpinnerProps = Omit<SVGAttributes<SVGSVGElement>, 'children'>;
src/lib/components/ui/spinner/index.ts
export { default as Spinner } from './Spinner.svelte';
export type { SpinnerProps } from './types.js';

Update the import paths

Change the imports to match your project setup.

Usage

<script lang="ts">
  import { Spinner } from '$lib/components/ui/spinner';
</script>
<Spinner class="size-6" />