UIMotion

Loader

Ladeanzeige mit 13 Varianten, von Spinner über Dot-Matrix bis ASCII. Eine Größe, currentColor, reduzierte Bewegung.

KostenlosMITv1.0.0Aktualisiert 01.12.2026Als Markdown ansehen

Vorschau

  • spinner
  • dots
  • bars
  • dot-matrix
  • comet
  • morph
  • orbit
  • pulse
  • !OAD+NGscramble
  • 0%percent
  • |ascii
  • ⠋ascii-braille
  • ▁ascii-blocks

Eine einzelne React-Komponente für Ladezustände: Spinner, Dots, Bars, Dot-Matrix, Comet, Morph, Orbit, Pulse, Scramble, Percent und drei ASCII-Spinner wie in Terminal- und KI-Oberflächen. Alles skaliert über eine size-Prop und übernimmt die Textfarbe. Bei reduzierter Bewegung wird jede Variante zu einem ruhigen Puls.

Installation

shadcn CLI
npx shadcn@latest add https://schindlertom.com/r/loader.json

Oder manuell: Abhängigkeiten installieren und den Quellcode kopieren.

npm
npm install motion
Quellcode anzeigen (components/ui/loader.tsx)
components/ui/loader.tsx
/**
 * Loader by Tom Schindler
 * https://schindlertom.com/ui/loader
 *
 * MIT License, Copyright (c) 2026 Tom Schindler
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software,
 * to deal in it without restriction, provided this notice is kept in all copies.
 * Full license text: https://opensource.org/licenses/MIT
 */
"use client";

import { useEffect, useState } from "react";
import { motion, useReducedMotion } from "motion/react";

export type LoaderVariant =
  | "spinner"
  | "dots"
  | "bars"
  | "dot-matrix"
  | "comet"
  | "morph"
  | "orbit"
  | "pulse"
  | "scramble"
  | "percent"
  | "ascii"
  | "ascii-braille"
  | "ascii-blocks";

export type LoaderProps = {
  variant?: LoaderVariant;
  size?: number;
  speed?: number;
  label?: string;
  className?: string;
};

const ASCII_FRAMES: Record<"ascii" | "ascii-braille" | "ascii-blocks", string[]> = {
  ascii: ["|", "/", "-", "\\"],
  "ascii-braille": ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"],
  "ascii-blocks": ["▁", "▂", "▃", "▄", "▅", "▆", "▇", "█", "▇", "▆", "▅", "▄", "▃", "▂"],
};

const SCRAMBLE_CHARS = "!<>-_\\/[]{}=+*^?#";

function useTicker(active: boolean, interval: number) {
  const [tick, setTick] = useState(0);

  useEffect(() => {
    if (!active) return;
    const id = window.setInterval(() => setTick((value) => value + 1), interval);
    return () => window.clearInterval(id);
  }, [active, interval]);

  return tick;
}

function join(...classes: (string | undefined | false)[]) {
  return classes.filter(Boolean).join(" ");
}

const loop = (duration: number, delay = 0) => ({
  duration,
  delay,
  repeat: Infinity,
  ease: "easeInOut" as const,
});

export function Loader({ variant = "spinner", size = 32, speed = 1, label = "Loading", className }: LoaderProps) {
  const reduce = useReducedMotion() ?? false;
  const isText = variant === "scramble" || variant === "percent" || variant.startsWith("ascii");
  const frames = variant.startsWith("ascii") ? ASCII_FRAMES[variant as keyof typeof ASCII_FRAMES] : null;
  const tick = useTicker(isText && !reduce, variant === "percent" ? (speed * 1000) / 100 : (speed * 1000) / (frames?.length ?? 10));

  const root = join("inline-flex shrink-0 items-center justify-center text-current", className);
  const box = { width: size, height: size };

  if (reduce) {
    return (
      <motion.span
        role="status"
        aria-label={label}
        className={root}
        style={box}
        animate={{ opacity: [0.35, 1, 0.35] }}
        transition={loop(speed * 1.6)}
      >
        <span className="block rounded-full bg-current" style={{ width: size * 0.4, height: size * 0.4 }} />
      </motion.span>
    );
  }

  const dot = size / 5;

  const content = (() => {
    switch (variant) {
      case "spinner":
        return (
          <motion.svg
            viewBox="0 0 24 24"
            width={size}
            height={size}
            fill="none"
            animate={{ rotate: 360 }}
            transition={{ duration: speed, repeat: Infinity, ease: "linear" }}
          >
            <circle cx="12" cy="12" r="9.5" stroke="currentColor" strokeOpacity="0.2" strokeWidth="2.5" />
            <path d="M21.5 12a9.5 9.5 0 0 0-9.5-9.5" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" />
          </motion.svg>
        );
      case "dots":
        return (
          <span className="flex items-center" style={{ gap: dot * 0.6 }}>
            {[0, 1, 2].map((index) => (
              <motion.span
                key={index}
                className="block rounded-full bg-current"
                style={{ width: dot, height: dot }}
                animate={{ y: [0, -dot, 0], opacity: [0.4, 1, 0.4] }}
                transition={loop(speed * 0.9, index * speed * 0.15)}
              />
            ))}
          </span>
        );
      case "bars":
        return (
          <span className="flex items-center" style={{ gap: size / 12, height: size }}>
            {[0, 1, 2, 3].map((index) => (
              <motion.span
                key={index}
                className="block rounded-full bg-current"
                style={{ width: size / 8, height: size * 0.75, originY: 0.5 }}
                animate={{ scaleY: [0.35, 1, 0.35] }}
                transition={loop(speed, index * speed * 0.12)}
              />
            ))}
          </span>
        );
      case "dot-matrix":
        return (
          <span className="grid grid-cols-3" style={{ gap: size / 10 }}>
            {Array.from({ length: 9 }, (_, index) => {
              const wave = (index % 3) + Math.floor(index / 3);
              return (
                <motion.span
                  key={index}
                  className="block rounded-full bg-current"
                  style={{ width: size / 4.5, height: size / 4.5 }}
                  animate={{ opacity: [0.15, 1, 0.15], scale: [0.7, 1, 0.7] }}
                  transition={loop(speed, wave * speed * 0.12)}
                />
              );
            })}
          </span>
        );
      case "comet":
        return (
          <motion.span
            className="block rounded-full"
            style={{
              ...box,
              background: "conic-gradient(from 0deg, transparent 0deg, currentColor 300deg, transparent 360deg)",
              WebkitMask: `radial-gradient(farthest-side, transparent calc(100% - ${size / 8}px), #000 calc(100% - ${size / 8 - 1}px))`,
              mask: `radial-gradient(farthest-side, transparent calc(100% - ${size / 8}px), #000 calc(100% - ${size / 8 - 1}px))`,
            }}
            animate={{ rotate: 360 }}
            transition={{ duration: speed, repeat: Infinity, ease: "linear" }}
          />
        );
      case "morph":
        return (
          <motion.span
            className="block bg-current"
            style={{ width: size * 0.6, height: size * 0.6 }}
            animate={{ borderRadius: ["12%", "50%", "12%"], rotate: [0, 180, 360], scale: [1, 0.75, 1] }}
            transition={loop(speed * 1.6)}
          />
        );
      case "orbit":
        return (
          <motion.span
            className="relative block"
            style={box}
            animate={{ rotate: 360 }}
            transition={{ duration: speed * 1.2, repeat: Infinity, ease: "linear" }}
          >
            {[0, 1].map((index) => (
              <span
                key={index}
                className="absolute left-1/2 block rounded-full bg-current"
                style={{
                  width: dot,
                  height: dot,
                  marginLeft: -dot / 2,
                  top: index === 0 ? 0 : size - dot,
                  opacity: index === 0 ? 1 : 0.45,
                }}
              />
            ))}
          </motion.span>
        );
      case "pulse":
        return (
          <span className="relative block" style={box}>
            {[0, 1].map((index) => (
              <motion.span
                key={index}
                className="absolute inset-0 block rounded-full border-current"
                style={{ borderWidth: Math.max(1.5, size / 16) }}
                animate={{ scale: [0.2, 1], opacity: [1, 0] }}
                transition={{ duration: speed * 1.4, delay: index * speed * 0.7, repeat: Infinity, ease: "easeOut" }}
              />
            ))}
          </span>
        );
      case "scramble": {
        const word = label.toUpperCase();
        const text = word
          .split("")
          .map((char, index) => ((tick + index) % 4 === 0 ? SCRAMBLE_CHARS[(tick * 7 + index * 3) % SCRAMBLE_CHARS.length] : char))
          .join("");
        return (
          <span className="font-mono tabular-nums" style={{ fontSize: size * 0.4, letterSpacing: "0.08em" }}>
            {text}
          </span>
        );
      }
      case "percent":
        return (
          <span className="font-mono tabular-nums" style={{ fontSize: size * 0.45 }}>
            {String(tick % 101).padStart(3, " ")}%
          </span>
        );
      default: {
        const list = frames ?? ASCII_FRAMES.ascii;
        return (
          <span className="font-mono leading-none" style={{ fontSize: size * 0.75 }}>
            {list[tick % list.length]}
          </span>
        );
      }
    }
  })();

  return (
    <span role="status" aria-label={label} className={join(root, isText && "w-auto")} style={isText ? { height: size } : box}>
      {content}
    </span>
  );
}

Verwendung

example.tsx
import { Loader } from "@/components/ui/loader";

export function Example() {
return (
  <div className="flex items-center gap-6 text-neutral-400">
    <Loader />
    <Loader variant="dot-matrix" size={28} />
    <Loader variant="ascii-braille" label="Thinking" />
  </div>
);
}

API

PropTypeDefaultBeschreibung
variant"spinner" | "dots" | "bars" | "dot-matrix" | "comet" | "morph" | "orbit" | "pulse" | "scramble" | "percent" | "ascii" | "ascii-braille" | "ascii-blocks""spinner"Welche Animation gezeigt wird.
sizenumber32Grundgröße in px, alles skaliert davon.
speednumber1Sekunden pro Animationszyklus.
labelstring"Loading"Text für Screenreader, auch für Scramble genutzt.
classNamestringZusätzliche Klassen, z. B. für die Farbe.

Häufige Fragen

  • Wie ändere ich die Farbe?

    Setz eine Textfarbe auf den Loader oder ein Elternelement, zum Beispiel mit einer Tailwind-Klasse wie text-emerald-400. Alle Varianten zeichnen in currentColor.

  • Welche Abhängigkeiten brauche ich?

    Nur React, Tailwind CSS und motion. Die ASCII-Varianten sind reine Text-Frames ohne Schriften oder Bilder.

  • Darf ich ihn kommerziell nutzen?

    Ja, die Komponente steht unter der MIT-Lizenz.

Lizenz

Kostenlos nutzbar, auch kommerziell. Einzige Bedingung: Der Lizenzhinweis oben in der Datei bleibt erhalten. Ein Link zu schindlertom.com freut mich, ist aber keine Pflicht.

LICENSE
MIT License

Copyright (c) 2026 Tom Schindler (https://schindlertom.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Kontakt

Bereit für eine Website, die für dich arbeitet?

Lass uns in einem kostenlosen Erstgespräch klären, was du brauchst.

Oder per E-Mail:info@schindlertom.com
Cookies

Cookies auf dieser Website

Ich verwende essenzielle Cookies für Sprache, grundlegende Funktionen und datenschutzfreundliche Nutzungsanalyse. Mehr in der Datenschutzerklärung.