{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "skeleton",
  "title": "Skeleton",
  "description": "A loading placeholder with shimmer or fade variants, plus a transition that crossfades into real content once loading finishes.",
  "registryDependencies": ["utils"],
  "files": [
    {
      "path": "registry/primitives/effects/skeleton/index.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport { useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, HTMLAttributes, ReactNode, Ref } from \"react\";\n\nimport { usePrefersReducedMotion } from \"@/hooks/use-prefers-reduced-motion\";\n\n// Skeleton only reads --sk-muted (surface fill) and --sk-foreground (shimmer\n// highlight). Both default to the app's own shadcn tokens when present, so\n// the skeleton matches the surrounding theme out of the box — override\n// either var directly (className or style) to use different colors.\nconst componentThemeClassName =\n  \"[--sk-muted:var(--muted,#f5f7fa)] [--sk-foreground:var(--foreground,#111111)]\";\n\nconst STYLE_ID = \"sk-styles\";\n\nconst SKELETON_CSS = `\n@keyframes sk-shimmer {\n  to {\n    transform: translateX(200%);\n  }\n}\n\n.sk-surface {\n  background-color: #f5f7fa;\n  background-color: var(--sk-muted);\n}\n\n.sk-shimmer {\n  background: linear-gradient(\n    90deg,\n    transparent 0%,\n    rgba(17, 17, 17, 0.06) 50%,\n    transparent 100%\n  );\n  background: linear-gradient(\n    90deg,\n    transparent 0%,\n    color-mix(in srgb, var(--sk-foreground) 6%, transparent) 50%,\n    transparent 100%\n  );\n  animation: sk-shimmer var(--sk-duration, 1.6s)\n    ease-in-out infinite;\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .sk-shimmer {\n    animation: none;\n  }\n}\n`;\n\ntype SkeletonRounded = \"none\" | \"sm\" | \"md\" | \"lg\" | \"full\";\ntype SkeletonVariant = \"shimmer\" | \"fade\";\n\nconst skeletonRoundedClasses = {\n  none: \"rounded-none\",\n  sm: \"rounded-sm\",\n  md: \"rounded-md\",\n  lg: \"rounded-lg\",\n  full: \"rounded-full\",\n} as const satisfies Record<SkeletonRounded, string>;\n\nconst skeletonVariantDefaultDuration: Record<SkeletonVariant, number> = {\n  shimmer: 1.6,\n  fade: 2.4,\n};\n\nfunction getSkeletonVariantDuration(\n  variant: SkeletonVariant,\n  duration?: number\n) {\n  return duration ?? skeletonVariantDefaultDuration[variant];\n}\n\nfunction ensureSkeletonStyles() {\n  if (typeof document === \"undefined\") {\n    return;\n  }\n\n  let style = document.querySelector(`#${STYLE_ID}`) as HTMLStyleElement | null;\n\n  if (!style) {\n    style = document.createElement(\"style\");\n    style.id = STYLE_ID;\n    document.head.append(style);\n  }\n\n  style.textContent = SKELETON_CSS;\n}\n\nfunction resolveSkeletonA11yProps({\n  animate = true,\n  decorative = true,\n  label,\n}: {\n  animate?: boolean;\n  decorative?: boolean;\n  label?: string | null;\n}) {\n  if (decorative || label === null) {\n    return { \"aria-hidden\": true as const };\n  }\n\n  return {\n    \"aria-label\": label ?? (animate ? \"Loading\" : \"Placeholder\"),\n    \"aria-live\": \"polite\" as const,\n    role: \"status\" as const,\n  };\n}\n\ninterface SkeletonProps extends HTMLAttributes<HTMLDivElement> {\n  animate?: boolean;\n  decorative?: boolean;\n  duration?: number;\n  label?: string | null;\n  ref?: Ref<HTMLDivElement>;\n  rounded?: SkeletonRounded;\n  variant?: SkeletonVariant;\n}\n\nfunction Skeleton({\n  animate = true,\n  className,\n  decorative = true,\n  duration,\n  label,\n  ref,\n  rounded = \"md\",\n  style,\n  variant = \"shimmer\",\n  ...props\n}: SkeletonProps) {\n  const variantDuration = getSkeletonVariantDuration(variant, duration);\n  const showShimmer = animate && variant === \"shimmer\";\n  const showFade = animate && variant === \"fade\";\n\n  useEffect(() => {\n    if (showShimmer) {\n      ensureSkeletonStyles();\n    }\n  }, [showShimmer]);\n\n  let animatedStyle = style;\n  if (showShimmer) {\n    animatedStyle = {\n      ...style,\n      \"--sk-duration\": `${variantDuration}s`,\n    } as CSSProperties;\n  } else if (showFade) {\n    animatedStyle = { ...style, animationDuration: `${variantDuration}s` };\n  }\n\n  return (\n    <div\n      className={cn(\n        componentThemeClassName,\n        \"sk-surface relative block h-4 w-full overflow-hidden\",\n        showFade && \"animate-pulse motion-reduce:animate-none\",\n        skeletonRoundedClasses[rounded],\n        className\n      )}\n      ref={ref}\n      style={animatedStyle}\n      {...resolveSkeletonA11yProps({ animate, decorative, label })}\n      {...props}\n    >\n      {showShimmer ? (\n        <span\n          aria-hidden=\"true\"\n          className=\"sk-shimmer pointer-events-none absolute inset-0 -translate-x-full\"\n        />\n      ) : null}\n    </div>\n  );\n}\n\nfunction SkeletonAvatar({\n  className,\n  ...props\n}: Omit<SkeletonProps, \"rounded\">) {\n  return (\n    <Skeleton\n      className={cn(\"size-10\", className)}\n      decorative\n      rounded=\"full\"\n      {...props}\n    />\n  );\n}\n\nfunction SkeletonText({ className, ...props }: SkeletonProps) {\n  return <Skeleton className={cn(\"h-3\", className)} decorative {...props} />;\n}\n\nfunction SkeletonButton({\n  className,\n  ...props\n}: Omit<SkeletonProps, \"rounded\">) {\n  return (\n    <Skeleton\n      className={cn(\"h-9 w-24\", className)}\n      decorative\n      rounded=\"lg\"\n      {...props}\n    />\n  );\n}\n\nconst ShimmerSkeleton = Skeleton;\n\ntype SkeletonTransitionPhase = \"done\" | \"loading\" | \"revealing\" | \"settling\";\n\nconst SKELETON_TRANSITION_DEFAULT_SETTLE_DURATION = 0.4;\nconst SKELETON_TRANSITION_DEFAULT_FADE_DURATION = 0.15;\n\ninterface SkeletonTransitionProps {\n  children: ReactNode;\n  className?: string;\n  /**\n   * Crossfade duration between skeleton and content, in seconds.\n   * @default 0.15\n   */\n  fadeDuration?: number;\n  /** While true, only `skeleton` is shown. Flipping to false plays the reveal. */\n  loading: boolean;\n  /**\n   * How long the skeleton lingers after `loading` turns false, before the\n   * crossfade starts, in seconds. Gives the shimmer a beat to settle instead\n   * of cutting away mid-cycle.\n   * @default 0.4\n   */\n  settleDuration?: number;\n  /** Placeholder shown while `loading` is true — typically `Skeleton` or its variants. */\n  skeleton: ReactNode;\n}\n\n/**\n * Swaps a skeleton placeholder for real content once loading finishes: the\n * shimmer settles for a beat, then skeleton and content crossfade.\n *\n * While both are mounted, `children` is absolutely positioned (so it overlays\n * `skeleton`, which drives the wrapper's height). If the two differ a lot in\n * size, the layout snaps to the content's real height the instant the\n * crossfade finishes — size `skeleton` close to the expected content to\n * avoid a visible jump.\n */\nfunction SkeletonTransition({\n  children,\n  className,\n  fadeDuration = SKELETON_TRANSITION_DEFAULT_FADE_DURATION,\n  loading,\n  settleDuration = SKELETON_TRANSITION_DEFAULT_SETTLE_DURATION,\n  skeleton,\n}: SkeletonTransitionProps) {\n  const [phase, setPhase] = useState<SkeletonTransitionPhase>(\n    loading ? \"loading\" : \"done\"\n  );\n  const prefersReducedMotion = usePrefersReducedMotion();\n  // Reveal only on a real loading → ready transition. The effect also re-runs\n  // when prefersReducedMotion resolves after mount, which must not replay it.\n  const wasLoadingRef = useRef(loading);\n\n  useEffect(() => {\n    const wasLoading = wasLoadingRef.current;\n    wasLoadingRef.current = loading;\n\n    if (loading) {\n      setPhase(\"loading\");\n      return;\n    }\n    if (!wasLoading) {\n      return;\n    }\n    setPhase(prefersReducedMotion ? \"done\" : \"settling\");\n  }, [loading, prefersReducedMotion]);\n\n  useEffect(() => {\n    if (phase !== \"settling\") {\n      return;\n    }\n    const timer = window.setTimeout(\n      () => setPhase(\"revealing\"),\n      settleDuration * 1000\n    );\n    return () => window.clearTimeout(timer);\n  }, [phase, settleDuration]);\n\n  useEffect(() => {\n    if (phase !== \"revealing\") {\n      return;\n    }\n    const timer = window.setTimeout(\n      () => setPhase(\"done\"),\n      fadeDuration * 1000\n    );\n    return () => window.clearTimeout(timer);\n  }, [phase, fadeDuration]);\n\n  const showSkeleton = phase !== \"done\";\n  const showContent = phase !== \"loading\";\n  const crossfading = phase === \"revealing\" || phase === \"done\";\n  const fadeStyle: CSSProperties = { transitionDuration: `${fadeDuration}s` };\n\n  return (\n    <div className={cn(\"relative\", className)}>\n      {showSkeleton && (\n        <div\n          aria-hidden=\"true\"\n          className={cn(\n            \"transition-opacity ease-out\",\n            crossfading ? \"pointer-events-none opacity-0\" : \"opacity-100\"\n          )}\n          style={fadeStyle}\n        >\n          {skeleton}\n        </div>\n      )}\n      {showContent && (\n        <div\n          className={cn(\n            showSkeleton && \"absolute inset-0\",\n            \"transition-opacity ease-out\",\n            crossfading ? \"opacity-100\" : \"opacity-0\"\n          )}\n          style={fadeStyle}\n        >\n          {children}\n        </div>\n      )}\n    </div>\n  );\n}\n\nexport {\n  getSkeletonVariantDuration,\n  resolveSkeletonA11yProps,\n  ShimmerSkeleton,\n  Skeleton,\n  SkeletonAvatar,\n  SkeletonButton,\n  SkeletonText,\n  SkeletonTransition,\n  skeletonRoundedClasses,\n  skeletonVariantDefaultDuration,\n};\nexport default Skeleton;\nexport type {\n  SkeletonProps,\n  SkeletonProps as ShimmerSkeletonProps,\n  SkeletonRounded,\n  SkeletonTransitionProps,\n  SkeletonVariant,\n};\n",
      "type": "registry:ui",
      "target": "components/sora-ui/effects/skeleton.tsx"
    }
  ],
  "meta": {
    "keywords": [
      "skeleton",
      "loading",
      "placeholder",
      "shimmer",
      "shimmer-effect"
    ]
  },
  "type": "registry:ui"
}
