Skeletons

Table

Cells delay by row + column, so the placeholder fills in on a diagonal instead of flashing the whole grid at once.

  • table
  • grid
  • diagonal

Preview

Usage

<SkeletonTable rows={6} columns={4} stagger={45} />
import { Skeleton, type SkeletonAnimation } from "./Skeleton";
import { cn } from "@/lib/cn";

export interface SkeletonTableProps {
  rows?: number;
  columns?: number;
  animation?: SkeletonAnimation;
  header?: boolean;
  /** Diagonal ripple: each cell waits (row + column) * stagger. */
  stagger?: number;
  className?: string;
}

export function SkeletonTable({
  rows = 5,
  columns = 4,
  animation = "shimmer",
  header = true,
  stagger = 45,
  className,
}: SkeletonTableProps) {
  return (
    <div className={cn("w-full overflow-hidden rounded-xl border border-line", className)}>
      {header && (
        <div
          className="grid gap-4 border-b border-line bg-surface px-4 py-3"
          style={{ gridTemplateColumns: `repeat(${columns}, minmax(0,1fr))` }}
        >
          {Array.from({ length: columns }, (_, c) => (
            <Skeleton key={c} animation={animation} height={8} width="60%" delay={c * stagger} />
          ))}
        </div>
      )}
      <div className="divide-y divide-line">
        {Array.from({ length: rows }, (_, r) => (
          <div
            key={r}
            className="grid gap-4 px-4 py-3.5"
            style={{ gridTemplateColumns: `repeat(${columns}, minmax(0,1fr))` }}
          >
            {Array.from({ length: columns }, (_, c) => (
              <Skeleton
                key={c}
                animation={animation}
                height={10}
                width={c === 0 ? "80%" : `${45 + ((r * 7 + c * 11) % 40)}%`}
                delay={(r + c) * stagger}
              />
            ))}
          </div>
        ))}
      </div>
    </div>
  );
}

export default SkeletonTable;