All files / src/components/detail Skeleton.tsx

100% Statements 5/5
100% Branches 4/4
100% Functions 3/3
100% Lines 5/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53                                    105x     6669x                                   105x         426x   1271x            
import React from "react";
 
/**
 * A grey placeholder block, sized by the caller.
 *
 * Every viewer page renders one of these while its query is in flight, and
 * before this existed all 22 of them declared the same six-line component at
 * the top of the file. The size is the only thing a call site ever varied, so
 * that is the only thing it passes.
 *
 * ```tsx
 * {isLoading ? <Skeleton className="h-7 w-48" /> : agent.name}
 * ```
 *
 * For a whole card or row of placeholders, prefer `SkeletonCard` /
 * `SkeletonRow` from `components/collection` — they match the real card and
 * row layouts rather than approximating them with loose blocks.
 */
export const Skeleton: React.FC<{ className?: string }> = ({
  className = "",
}) => (
  <div
    className={`animate-pulse rounded bg-gray-200 dark:bg-gray-700 ${className}`}
  />
);
 
export interface SkeletonLinesProps {
  /** How many placeholder lines to draw. */
  count?: number;
  /** Applied to each line — height and width. */
  className?: string;
  /** Wrapper classes, for spacing or a grid. */
  wrapperClassName?: string;
}
 
/**
 * A run of identical placeholder lines — the `Array.from({ length: n })` loop
 * that every loading branch was rebuilding inline.
 */
export const SkeletonLines: React.FC<SkeletonLinesProps> = ({
  count = 3,
  className = "h-12 rounded-xl",
  wrapperClassName = "space-y-4",
}) => (
  <div className={wrapperClassName}>
    {Array.from({ length: count }).map((_, i) => (
      <Skeleton key={i} className={className} />
    ))}
  </div>
);
 
export default Skeleton;