{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "scroll-to-bottom",
  "registryDependencies": [
    "utils",
    "https://turnui.xyz/r/turn-button.json"
  ],
  "files": [
    {
      "path": "src/registry/ui/scroll-to-bottom.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { Button } from \"./turn-button\";\n\n/**\n * A \"jump to latest\" button that appears when a scroll container is not at the bottom.\n * Place it inside a `relative` wrapper around the container; it centers itself near the bottom edge.\n */\nexport function ScrollToBottom({\n  target,\n  threshold = 120,\n  label = \"Scroll to latest message\",\n  className,\n}: {\n  /** The scrolling element, e.g. the ref returned by useAutoScroll. */\n  target: React.RefObject<HTMLElement | null>;\n  /** How far from the bottom, in pixels, before the button appears. */\n  threshold?: number;\n  /** Accessible name. Keep the word \"latest\" so it contains the visible text. */\n  label?: string;\n  className?: string;\n}) {\n  const [away, setAway] = React.useState(false);\n\n  React.useEffect(() => {\n    const el = target.current;\n    if (!el) return;\n    const update = () => setAway(el.scrollHeight - el.scrollTop - el.clientHeight > threshold);\n    const first = requestAnimationFrame(update);\n    el.addEventListener(\"scroll\", update, { passive: true });\n    const resize = typeof ResizeObserver !== \"undefined\" ? new ResizeObserver(update) : undefined;\n    resize?.observe(el);\n    const mutate = new MutationObserver(update);\n    mutate.observe(el, { childList: true, subtree: true, characterData: true });\n    return () => {\n      cancelAnimationFrame(first);\n      el.removeEventListener(\"scroll\", update);\n      resize?.disconnect();\n      mutate.disconnect();\n    };\n  }, [target, threshold]);\n\n  function jump() {\n    const el = target.current;\n    if (!el) return;\n    const reduce = window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches;\n    el.scrollTo({ top: el.scrollHeight, behavior: reduce ? \"auto\" : \"smooth\" });\n    // The button unmounts once the container is at the bottom, so hand focus to the container.\n    if (!el.hasAttribute(\"tabindex\")) el.setAttribute(\"tabindex\", \"-1\");\n    el.focus({ preventScroll: true });\n  }\n\n  if (!away) return null;\n  return (\n    <Button\n      type=\"button\"\n      variant=\"outline\"\n      size=\"sm\"\n      aria-label={label}\n      onClick={jump}\n      className={cn(\"absolute bottom-3 left-1/2 -translate-x-1/2 gap-1.5 bg-background font-mono text-xs\", className)}\n    >\n      <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden>\n        <path d=\"M8 3v10M3.5 8.5 8 13l4.5-4.5\" />\n      </svg>\n      latest\n    </Button>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}