Skeleton

Placeholders that shimmer with the library's dither, or ripple as fabric, while things load.

MC
Mira ChenProduct designer · Acme Studio

Designing calm interfaces for tools people live in all day. Lately: cloth, dither and very small details.

2,481 followers312 following86 projects
Comments 3Newest
JP
Jon Park2m

Can we keep the dither on the toasts? It makes them feel like part of the same family.

AL
Ada Lee14m

Shipped the new slider. Have a look.

SR
Sam Rivera1h

Tabs feel great with the goo slide, especially going backwards.

Journal4 min read

Three effects, and only three

Fabric for things that drop and open, dither for texture and light, goo for things that slide.

ALAda Lee · Nov 28
Weekly visitorsLast 7 days
12,480+8.2%
vs. 11,534 the week before

Installation

Terminal
npx shadcn@latest add https://fabrickit.org/r/skeleton.json

This copies the component into components/fabricui and its engine into lib/fabricui. It's your code from then on. First time? Add the theme once: see Installation.

Code

components/fabricui/skeleton.tsx
"use client";

import * as React from "react";
import { mount } from "@/lib/fabricui/mount";
import { ClothDrop } from "@/lib/fabricui/cloth-drop";
import { start } from "@/lib/fabricui/skeleton-engine";
import "./skeleton.css";

const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
const cx = (...c: (string | false | undefined)[]) => c.filter(Boolean).join(" ");
const len = (v: number | string | undefined) => (typeof v === "number" ? `${v}px` : v);

export type SkeletonProps = Omit<React.HTMLAttributes<HTMLSpanElement>, "children"> & {
  /** "line" (text, 10px tall), "circle" (avatars) or "block" (anything else: set height). */
  shape?: "line" | "circle" | "block";
  /** Its width (px, or any CSS length like "64%"). 100% by default; a circle's height follows it. */
components/fabricui/skeleton.css
/*
 * Skeleton — placeholders while something loads.
 *
 * The library's dither does the shimmer: a band of 1-bit Bayer dots glints
 * across the grey shapes (skeleton.js), in page space, so one band passes
 * over every shape on the page together. When the content arrives it fades
 * in over the placeholders, which fade out.
 *
 *   <div class="loadable" data-loading>
 *     <div class="loadable__skeleton" aria-hidden="true">
 *       <span class="skeleton skeleton--circle" style="--w:40px"></span>
 *       <span class="skeleton skeleton--line" style="--w:60%"></span>
 *     </div>
 *     <div class="loadable__content">…the real thing…</div>
 *   </div>
 *
lib/fabricui/skeleton-engine.js
/*
 * skeleton-engine.js — the dither glint over every .skeleton on the page. From skeleton.js.
 *
 * Each skeleton gets a canvas. A soft band moves diagonally across the page;
 * where it passes, 2px dots light up through a 4×4 Bayer dither (the same
 * ordered dither as the cloth), so the shimmer is made of the library's dots
 * rather than a smooth gradient. The band crosses the whole .loadable (or the
 * lone skeleton) in one continuous sweep over all its shapes, and its clock
 * starts when the skeleton appears, so the first pass comes right away.
 * Only skeletons that are showing are drawn, at ~30fps; with reduced motion
 * nothing moves. A .loadable[data-fabric] shimmers as cloth instead. Any
 * element with [data-skeleton-area] (a table, say) sweeps as one, too.
 *
 * Changes from skeleton.js, for React: the loop runs while at least one
 * skeleton is mounted (start() returns its stop), instead of from page load.
 */

Usage

Usage
import { Loadable, Skeleton } from "@/components/fabricui/skeleton";

export function Profile({ user }: { user?: { name: string; role: string } }) {
  return (
    <Loadable
      loading={!user}
      skeleton={
        <div style={{ display: "flex", alignItems: "center", gap: 14 }}>
          <Skeleton shape="circle" width={56} />
          <div style={{ flex: 1, display: "grid", gap: 14 }}>
            <Skeleton width={110} />
            <Skeleton width={180} />
          </div>
        </div>
      }
    >
      <h3>{user?.name}</h3>
      <p>{user?.role}</p>
    </Loadable>
  );
}

Props

PropTypeDefault
loading

Loadable: while true the placeholders show; when it turns false the content fades in over them as they fade out.

boolean—
skeleton

Loadable: the placeholders, Skeleton shapes laid out like the content. One glint sweeps across all of them together.

ReactNode—
fabric

Loadable: the whole card ripples as cloth while it loads, and settles flat before the content comes in.

booleanfalse
paused

Loadable, fabric: stop its motion (while it's off screen, say); the placeholders stay.

booleanfalse
skeletonClassName / contentClassName

Loadable: classes for the two layers, to lay them out the same.

string—
shape

Skeleton: a line of text (10px tall), an avatar, or anything else (set height).

"line" | "circle" | "block""line"
width / height

Skeleton: px, or any CSS length ("64%"). Width is 100% by default; a circle's height follows its width.

number | string—