Thinking UI

Typing Indicator

Three dots bouncing in a staggered wave.

Code

components/thinking-ui/typing-indicator.tsx
"use client";

import type { CSSProperties } from "react";
import { useMotion } from "@/lib/motion";
import { cn } from "@/lib/utils";

/* The wave is a CSS animation rather than a Motion loop: Motion can collapse a
   repeating transform-keyframe loop into a near-zero transform that Chrome
   doesn't paint, which left the dots invisible under some personalities. CSS
   runs it on the compositor, and every value still comes from the active
   personality. Reduced motion is chosen in CSS too, so the server and the
   browser render the same markup. */
const KEYFRAMES = `
@keyframes tui-typing-wave { 0%, 100% { translate: 0 0; opacity: .4 } 50% { translate: 0 calc(var(--tui-lift) * -1); opacity: 1 } }
@keyframes tui-typing-pulse { 0%, 100% { opacity: .35 } 50% { opacity: 1 } }
.tui-typing-dot { animation: tui-typing-wave var(--tui-pace) ease-in-out var(--tui-delay) infinite both }
@media (prefers-reduced-motion: reduce) { .tui-typing-dot { animation-name: tui-typing-pulse } }
`;

export type TypingIndicatorProps = {
  label?: string;
  className?: string;
  dotClassName?: string;
};

export function TypingIndicator({ label = "Assistant is typing", className, dotClassName }: TypingIndicatorProps) {
  const m = useMotion();
  const p = m.personality;
  const pace = (p.loop ?? p.duration.slower * 2.6) * m.scale;
  const step = Math.max(p.stagger, 0.06) * 2 * m.scale;

  return (
    <span role="status" aria-label={label} className={cn("inline-flex items-center gap-1", className)}>
      <style href="tui-typing-indicator" precedence="default">
        {KEYFRAMES}
      </style>
      {[0, 1, 2].map((i) => (
        <span
          key={i}
          aria-hidden
          className={cn("tui-typing-dot size-1.5 rounded-full bg-fg-muted", dotClassName)}
          style={
            {
              "--tui-lift": `${p.distance.sm}px`,
              "--tui-pace": `${pace}s`,
              "--tui-delay": `${i * step}s`,
            } as CSSProperties
          }
        />
      ))}
    </span>
  );
}

Motion notes

  • A 140ms stagger makes the dots read as a wave rather than three separate blinks.
  • Only 4px of lift, so it stays calm in a dense chat.
  • With reduced motion, the bounce becomes an opacity pulse.

Installation

  1. 1

    Install dependencies

    Terminal
    npm install motion clsx tailwind-merge
  2. 2

    Add the design tokens and motion system (once per project)

    Copy styles/tokens/*, lib/motion.tsx and lib/utils.ts from Get started.

  3. 3

    Paste the source into components/thinking-ui/typing-indicator.tsx

    Copy it from the Code tab, or use Copy prompt to let your coding agent do all of this.

Usage

Example
<TypingIndicator />

Props

PropTypeDefaultDescription
labelstring"Assistant is typing"Accessible status label.
dotClassNamestring—Classes for each dot.