{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spinner",
  "title": "Spinner",
  "description": "The spinner every Kino component shows while something loads. It looks the same whichever icon library a project uses.",
  "files": [
    {
      "path": "registry/components/kino/spinner.tsx",
      "content": "'use client'\n\nimport { type ComponentProps, useEffect, useState } from 'react'\n\nimport { cn } from '@/lib/utils'\n\nfunction Spinner({ className, ...props }: ComponentProps<'svg'>) {\n  return (\n    <svg\n      data-slot='spinner'\n      role='img'\n      aria-label='Loading'\n      viewBox='0 0 16 16'\n      fill='none'\n      // `h-4 w-4`, not `size-4`: a parent sizes its icons with\n      // `[&_svg:not([class*='size-'])]`, which a `size-` class here would opt out of.\n      className={cn('h-4 w-4 animate-spin motion-reduce:animate-pulse', className)}\n      {...props}\n    >\n      <circle\n        cx='8'\n        cy='8'\n        r='6'\n        stroke='currentColor'\n        strokeOpacity='0.25'\n        strokeWidth='2'\n      />\n      <path\n        d='M14 8a6 6 0 0 0-6-6'\n        stroke='currentColor'\n        strokeWidth='2'\n        strokeLinecap='round'\n      />\n    </svg>\n  )\n}\n\nconst SPINNER_DELAY_MS = 200\nconst SPINNER_MIN_MS = 300\n\n/** The spinner is hidden, or shown since a time from `performance.now()`. */\ntype SpinnerState = { phase: 'hidden' } | { phase: 'shown'; since: number }\n\n/**\n * How long until the spinner should change to match `loading`, in ms, or null\n * when it already matches: it shows only once loading has lasted, and then\n * stays long enough to be read, so a fast request never flashes one.\n */\nfunction spinnerWait(state: SpinnerState, loading: boolean, now: number): number | null {\n  if (state.phase === 'hidden') return loading ? SPINNER_DELAY_MS : null\n  return loading ? null : Math.max(0, SPINNER_MIN_MS - (now - state.since))\n}\n\n/**\n * Whether to show a spinner while `loading`: after 200ms, then for at least\n * 300ms. Loading from the first render shows it at once, since no action\n * waits on it and a late spinner would move the page after load.\n */\nfunction useSpinner(loading: boolean): boolean {\n  const [state, setState] = useState<SpinnerState>(() =>\n    loading ? { phase: 'shown', since: performance.now() } : { phase: 'hidden' },\n  )\n  useEffect(() => {\n    const wait = spinnerWait(state, loading, performance.now())\n    if (wait === null) return\n    const timeout = setTimeout(() => {\n      setState(\n        loading ? { phase: 'shown', since: performance.now() } : { phase: 'hidden' },\n      )\n    }, wait)\n    return () => clearTimeout(timeout)\n  }, [loading, state])\n  return state.phase === 'shown'\n}\n\nexport { Spinner, spinnerWait, useSpinner }\n",
      "type": "registry:component",
      "target": "@components/kino/spinner.tsx"
    }
  ],
  "type": "registry:component"
}