Skip to content
Motion · Feedback

Split-flap board

Each flap steps through the alphabet until it lands, like an old departure board.

Installation

  1. Run the CLI

    Run pnpm dlx asta-ui@latest init once, then this. The file lands in components/astabyte/ and the colour tokens go into your CSS.

    $ pnpm dlx asta-ui@latest add split-flap

    Or with the shadcn CLI: pnpm dlx shadcn@latest add https://ui.astabyte.com/r/split-flap.json

  2. Or install the package

    Don’t want the file? Import from asta-ui/split-flap and update with pnpm update asta-ui. Add the stylesheet once. More.

    $ pnpm add asta-ui
    import { SplitFlap } from "asta-ui/split-flap";
  3. Or copy it by hand

    Copy these files. Keep the paths, or fix the @/ imports. Then add the tokens from globals.css.

    "use client";
    
    import { useEffect, useLayoutEffect, useRef, useState } from "react";
    import { useInView } from "../lab-hooks";
    
    const CHARS = " ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-";
    const WORDS = ["ASTABYTE", "LAB-2026", "SHIPPING", "JAKARTA ", "ON TIME "];
    const EASE = "cubic-bezier(.16,1,.3,1)";
    
    let motionQuery: MediaQueryList | null = null;
    const reducedMotion = () => {
      if (typeof matchMedia === "undefined") return false;
      motionQuery ??= matchMedia("(prefers-reduced-motion: reduce)");
      return motionQuery.matches;
    };
    
    /** One flap. It flips only when its own character changes, not on every board render. */
    function Flap({ c }: { c: string }) {
      const ref = useRef<HTMLSpanElement>(null);
      useLayoutEffect(() => {
        if (reducedMotion()) return;
        ref.current?.animate([{ transform: "rotateX(-80deg)", opacity: 0.4 }, { transform: "rotateX(0)", opacity: 1 }], { duration: 120, easing: EASE });
      }, [c]);
      return (
        <span className="relative grid h-12 w-8 place-items-center overflow-hidden bg-paper-2 font-mono text-[22px] font-medium text-ink sm:h-14 sm:w-9">
          <span ref={ref} className="block">
            {c === " " ? " " : c}
          </span>
          <span className="absolute inset-x-0 top-1/2 h-px bg-paper" />
        </span>
      );
    }
    
    /** A departure board: each flap steps through the alphabet until it lands. */
    export default function SplitFlap() {
      const [cells, setCells] = useState(WORDS[0].split(""));
      const root = useRef<HTMLDivElement>(null);
      const visible = useInView(root);
      const word = useRef(0);
      const timer = useRef<ReturnType<typeof setInterval>>(undefined);
    
      const go = () => {
        word.current = (word.current + 1) % WORDS.length;
        const target = WORDS[word.current].split("");
        clearInterval(timer.current);
        // Reduced motion: land on the word at once.
        if (reducedMotion()) {
          setCells(target);
          return;
        }
        timer.current = setInterval(() => {
          setCells((cur) => {
            let moving = false;
            const next = cur.map((c, i) => {
              if (c === target[i]) return c;
              moving = true;
              return CHARS[(CHARS.indexOf(c) + 1) % CHARS.length];
            });
            if (!moving) {
              clearInterval(timer.current);
              return cur;
            }
            return next;
          });
        }, 45);
      };
    
      // Rest while off screen or in a hidden tab.
      useEffect(() => {
        if (!visible) return;
        const auto = setInterval(go, 4200);
        return () => {
          clearInterval(auto);
          clearInterval(timer.current);
        };
      }, [visible]);
    
      return (
        <div ref={root} className="flex h-full w-full flex-col items-center justify-center gap-5 p-4">
          <button type="button" onClick={go} aria-label="Next word" className="flex gap-[3px] [perspective:400px]">
            {cells.map((c, i) => (
              <Flap key={i} c={c} />
            ))}
          </button>
          <span className="font-mono text-[11px] uppercase tracking-[0.08em] text-mute">Click to flip</span>
        </div>
      );
    }
    
  4. Or ask your AI agent

    Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.

    Add the Astabyte UI Split-flap board component to my project.
    
    Each flap steps through the alphabet until it lands, like an old departure board.
    It fills its parent, so give the wrapper a size. It is designed on a dark surface: put it inside an element with the `dark` class.
    
    Install it:
    ```sh
    pnpm dlx asta-ui@latest add split-flap --radix
    ```
    Or with the shadcn CLI:
    ```sh
    pnpm dlx shadcn@latest add https://ui.astabyte.com/r/split-flap.json
    ```
    If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4).
    
    Import it like this:
    ```tsx
    import SplitFlap from "@/components/astabyte/split-flap";
    ```
    
    Usage example and props: https://ui.astabyte.com/split-flap
    Full catalogue for context: https://ui.astabyte.com/llms.txt
    
    Rules:
    - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS.
    - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback.
    - Keep keyboard, focus and ARIA behaviour.
    - Use fake data and fake brand names in examples.
    
    Use it to: [describe where it goes and what it should do]

Usage

It fills its parent. Give the wrapper a size.

import SplitFlap from "@/components/astabyte/split-flap";

export default function Page() {
  // Split-flap board
  return (
    <div className="relative h-96 w-full">
      <SplitFlap />
    </div>
  );
}