AI Loader

Waiting states with character: typing dots, an orbit around a thinking face, and echo bars with a shimmering label.

Installation

Installation

One command adds ai-loader and the shared AI Kit layer it is built on (tokens, faces, marks and brand icons). No animation library, light and dark built in.

$npx shadcn@latest add https://tweenui.dev/r/ai-loader.json
ai-loader-demo
components/ui/ai-loader-demo.tsx
"use client"

import * as React from "react"

import { AiDemo } from "@/lib/ai-demo"
import { useAiLoop } from "@/lib/ai-kit"
import {
  AiEchoLoader,
  AiOrbitLoader,
  AiTypingDots,
} from "@/registry/tween/ai-loader"

const clock = (seconds: number) => `0:${String(seconds).padStart(2, "0")}`

function Dots() {
  return (
    <div style={{ display: "grid", gap: 16, justifyItems: "start" }}>
      <AiTypingDots label="Mira is typing" />
      <AiTypingDots tone="violet" shape="blob" />
      <AiTypingDots face={false} label="Three agents are replying" />
    </div>
  )
}

const THOUGHTS = [
  "Reading the hero section",
  "Comparing three reveals",
  "Checking reduced motion",
  "Writing the plan",
]

function Orbit() {
  const root = React.useRef<HTMLDivElement>(null)
  const [at, setAt] = React.useState(0)

  useAiLoop(
    root,
    async ({ sleep }) => {
      for (let index = 0; index < THOUGHTS.length; index++) {
        setAt(index)
        await sleep(1700)
      }
    },
    { gap: 0, still: () => setAt(1) }
  )

  return (
    <div ref={root} style={{ display: "grid", justifyItems: "center" }}>
      <AiOrbitLoader label={THOUGHTS[at] ?? THOUGHTS[0]} size={60} />
    </div>
  )
}

function Echo() {
  const root = React.useRef<HTMLDivElement>(null)
  const [seconds, setSeconds] = React.useState(3)

  useAiLoop(
    root,
    async ({ sleep }) => {
      for (let tick = 0; tick < 12; tick++) {
        setSeconds(tick)
        await sleep(1000)
      }
    },
    { gap: 0 }
  )

  return (
    <div ref={root} style={{ display: "grid", gap: 14, justifyItems: "start" }}>
      <AiEchoLoader
        label={seconds < 6 ? "Searching the registry" : "Reading 4 components"}
        elapsed={clock(seconds)}
      />
      <AiEchoLoader label="Waiting for the model" bars={3} />
    </div>
  )
}

export function AiLoaderDemo({ only }: { only?: string }) {
  return (
    <AiDemo
      only={only}
      tabs={[
        { name: "Dots", node: <Dots /> },
        { name: "Orbit", node: <Orbit /> },
        { name: "Echo", node: <Echo /> },
      ]}
    />
  )
}

Installation

pnpm dlx shadcn@latest add https://tweenui.dev/r/ai-loader.json

Usage

import {
  AiEchoLoader,
  AiOrbitLoader,
  AiTypingDots,
} from "@/components/ui/ai-loader"
<AiTypingDots label="Mira is typing" />
 
<AiOrbitLoader label="Comparing three reveals" tone="violet" />
 
<AiEchoLoader label="Searching the registry" elapsed="0:04" />

Versions

  • AiTypingDots is three dots in a chat bubble, with an optional face beside it and a short label after the dots.
  • AiOrbitLoader sends a small comet of dots around a thinking face. Its label rolls over in place whenever it changes.
  • AiEchoLoader is a row of bars that rise and fall in turn beside a shimmering label and an elapsed timer.

Each one is a status region with an accessible label. With reduced motion the loops stop and each shows a still frame.

Props

AiTypingDots

PropTypeDefaultDescription
labelstringA short line after the dots.
facebooleantrueShows the agent's face beside the bubble.
tonetone or CSS colour"blue"Face colour.
shapeface shape"orb"Face shape.

AiOrbitLoader

PropTypeDefaultDescription
labelstringWhat the agent is thinking about.
sizenumber56The face's size in pixels. The orbit follows.
moodmood"think"What the face acts out.
tonetone or CSS colour"violet"Face and dot colour.
shapeface shape"blob"Face shape.

AiEchoLoader

PropTypeDefaultDescription
labelstringThe shimmering line.
elapsedstringElapsed time, already formatted.
barsnumber5How many bars to draw.