{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "skeleton",
  "title": "Skeleton",
  "description": "Placeholders for content that hasn’t loaded, breathing slowly: shapes at a part’s own size and lines at their text’s height, so the content lands in the same rows. SkeletonContent crossfades them with the content after 200ms of loading and keeps them at least 300ms, so a fast request never flashes them.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/placeholder.json",
    "https://kinoui.com/r/resize.json",
    "https://kinoui.com/r/spinner.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/skeleton.tsx",
      "content": "'use client'\n\nimport { useSpinner } from '@/registry/components/kino/spinner'\nimport {\n  placeholderBreatheClassName,\n  placeholderFillClassName,\n} from '@/registry/lib/placeholder'\nimport { transitionsSettled } from '@/registry/lib/resize'\nimport { mergeProps, type PartProps, renderElement } from '@ui-sdk/react/primitive'\nimport { type ReactNode, type RefObject, useEffect, useRef, useState } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * Placeholders for content that hasn't loaded yet. Nothing about the data is\n * known, so they take the sizes the layout sets before it arrives: a shape at\n * a part's own size (an avatar, a badge, an image), and lines of text at the\n * height of the text's line, each as wide as a typical value. When the content\n * arrives it takes the same rows, so nothing moves.\n *\n * `SkeletonContent` swaps the placeholder for the content as the Spinner\n * shows: at once when it mounts loading, otherwise once loading has lasted\n * 200ms, and then for at least 300ms, so a fast request never flashes it.\n */\n\nconst shapeClassName = cn(\n  'rounded-(--control-radius-capped)',\n  placeholderFillClassName,\n  placeholderBreatheClassName,\n)\n\n/** A shape sized by its classes, such as `size-8 rounded-full` for an avatar. */\nfunction Skeleton({\n  className,\n  render,\n  ...props\n}: Omit<PartProps<'div'>, 'className'> & { className?: string }) {\n  return renderElement(\n    'div',\n    mergeProps(\n      {\n        'data-slot': 'skeleton',\n        'aria-hidden': true,\n        className: cn(shapeClassName, className),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\n/**\n * Lines of text still loading, each the height of the line it sits in, so a\n * placeholder inside a title or a paragraph is as tall as its text will be.\n * Its width is the line's; the last of several is shorter, as a paragraph's is.\n */\nfunction SkeletonText({\n  className,\n  lines = 1,\n  render,\n  ...props\n}: Omit<PartProps<'span'>, 'className'> & {\n  className?: string\n  /** How many lines of text it stands in for. */\n  lines?: number\n}) {\n  return renderElement(\n    'span',\n    mergeProps(\n      {\n        'data-slot': 'skeleton-text',\n        'aria-hidden': true,\n        className: cn('flex max-w-full flex-col', className),\n        children: Array.from({ length: lines }, (_, line) => (\n          <span key={line} className='flex h-lh items-center'>\n            {/* About as tall as the letters, so lines stand apart as text does. */}\n            <span\n              className={cn(\n                'h-[0.8em] w-full',\n                lines > 1 && line === lines - 1 && 'w-3/5',\n                shapeClassName,\n              )}\n            />\n          </span>\n        )),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\n/**\n * Shows its `placeholder` while `loading`, and its children once they arrive.\n * Each swap crossfades: the side that leaves fades out on the `exit` role\n * over the one that arrives, which fades in on the `enter` role.\n */\nfunction SkeletonContent({\n  loading,\n  placeholder,\n  children,\n  ...props\n}: Omit<PartProps<'div'>, 'className'> & {\n  className?: string\n  /** Whether the content is still loading. */\n  loading: boolean\n  /** What stands in for the content while it loads: skeletons laid out as it will be. */\n  placeholder: ReactNode\n}) {\n  const shown = useSpinner(loading)\n  const [side, setSide] = useState(shown)\n  // Which side is fading out, by whether it is the placeholder.\n  const [leaving, setLeaving] = useState<boolean | null>(null)\n  // Nothing fades on first paint: only once it has swapped (motion rule 6).\n  const [swapped, setSwapped] = useState(false)\n  if (side !== shown) {\n    setSide(shown)\n    setLeaving(side)\n    setSwapped(true)\n  }\n  const leavingRef = useRef<HTMLDivElement>(null)\n  useEffect(() => {\n    const element = leavingRef.current\n    if (leaving === null || element === null) return\n    let current = true\n    void transitionsSettled(element, { property: 'opacity' }).then(() => {\n      if (current) setLeaving(null)\n    })\n    return () => {\n      current = false\n    }\n  }, [leaving])\n  const sides = leaving === null ? [shown] : [leaving, shown]\n  return (\n    // Both sides share one cell while one leaves, so neither moves.\n    <div data-slot='skeleton-content-stack' className='grid *:[grid-area:1/1]'>\n      {sides.map((isPlaceholder) => (\n        <SkeletonContentSide\n          // One element per side, so a swap cut short turns back from where it is.\n          key={isPlaceholder ? 'placeholder' : 'content'}\n          sideRef={isPlaceholder === leaving ? leavingRef : undefined}\n          placeholder={isPlaceholder}\n          leaving={isPlaceholder === leaving}\n          busy={loading || shown}\n          fades={swapped}\n          {...props}\n        >\n          {isPlaceholder ? placeholder : children}\n        </SkeletonContentSide>\n      ))}\n    </div>\n  )\n}\n\nfunction SkeletonContentSide({\n  sideRef,\n  placeholder,\n  leaving,\n  busy,\n  fades,\n  className,\n  render,\n  ...props\n}: Omit<PartProps<'div'>, 'className'> & {\n  className?: string\n  sideRef: RefObject<HTMLDivElement | null> | undefined\n  placeholder: boolean\n  leaving: boolean\n  busy: boolean\n  fades: boolean\n}) {\n  return renderElement(\n    'div',\n    mergeProps(\n      {\n        'data-slot': 'skeleton-content',\n        ref: sideRef,\n        'data-loading': placeholder ? '' : undefined,\n        // The placeholder says nothing to a screen reader; a status region says what loads.\n        'aria-hidden': placeholder || leaving || undefined,\n        'aria-busy': (busy && !leaving) || undefined,\n        inert: leaving || undefined,\n        className: cn(\n          fades &&\n            'transition-opacity duration-(--motion-enter-duration) ease-(--motion-enter-easing) starting:opacity-0',\n          leaving &&\n            'pointer-events-none opacity-0 duration-(--motion-exit-duration) ease-(--motion-exit-easing)',\n          className,\n        ),\n      },\n      props,\n    ),\n    render,\n  )\n}\n\nexport { Skeleton, SkeletonContent, SkeletonText }\n",
      "type": "registry:component",
      "target": "@components/kino/skeleton.tsx"
    }
  ],
  "type": "registry:component"
}