{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bottom-sheet",
  "title": "Bottom Sheet",
  "description": "A mobile bottom sheet that slides up over a dimmed backdrop, rests at snap points you drag between from its handle, closes on a downward flick, and keeps its own content scrollable.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/bottom-sheet/bottom-sheet.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { motion, AnimatePresence, animate, useDragControls, useMotionValue, useReducedMotion, useTransform, type PanInfo } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\nexport interface BottomSheetProps {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** Heights it rests at, as fractions of the screen (or container), smallest first. */\n  snapPoints?: number[];\n  /** Which snap point it opens to (index into snapPoints). */\n  defaultSnap?: number;\n  onSnapChange?: (index: number) => void;\n  title?: string;\n  description?: string;\n  children?: React.ReactNode;\n  /** A button that opens the sheet. Leave out and control it with open / onOpenChange. */\n  triggerLabel?: string;\n  /** Drag down, tap the backdrop or press Escape to close. */\n  dismissible?: boolean;\n  /** Place the sheet inside the nearest positioned ancestor instead of over the whole page. */\n  contained?: boolean;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.55)\", sheet: \"#121212\", border: \"rgba(255,255,255,0.1)\", handle: \"rgba(255,255,255,0.22)\", hover: \"rgba(255,255,255,0.08)\", focus: \"rgba(245,244,241,0.85)\", backdrop: \"#000000\", trigger: \"#F5F4F1\", triggerText: \"#0A0A0A\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.55)\", sheet: \"#FFFFFF\", border: \"rgba(10,10,10,0.1)\", handle: \"rgba(10,10,10,0.2)\", hover: \"rgba(10,10,10,0.06)\", focus: \"rgba(10,10,10,0.85)\", backdrop: \"#0A0A0A\", trigger: \"#0A0A0A\", triggerText: \"#FFFFFF\" },\n};\n\nexport function BottomSheet({\n  open,\n  defaultOpen = false,\n  onOpenChange,\n  snapPoints = [0.45, 0.92],\n  defaultSnap = 0,\n  onSnapChange,\n  title,\n  description,\n  children,\n  triggerLabel,\n  dismissible = true,\n  contained = false,\n  theme = \"dark\",\n  className,\n}: BottomSheetProps) {\n  const p = PALETTES[theme];\n  const uid = React.useId();\n  const reduce = Boolean(useReducedMotion());\n  const anchorRef = React.useRef<HTMLDivElement>(null);\n  const sheetRef = React.useRef<HTMLDivElement>(null);\n  const returnFocus = React.useRef<HTMLElement | null>(null);\n  const dragControls = useDragControls();\n  const [internalOpen, setInternalOpen] = React.useState(defaultOpen);\n  const isOpen = open ?? internalOpen;\n  const [snap, setSnap] = React.useState(defaultSnap);\n  const [areaH, setAreaH] = React.useState(800);\n\n  const points = [...snapPoints].sort((a, b) => a - b);\n  const top = points[points.length - 1];\n  const sheetH = Math.round(areaH * top);\n  // y is how far the sheet is pushed down from fully open: 0 at the top snap, sheetH off-screen.\n  const yFor = React.useCallback((i: number) => Math.round(sheetH - areaH * points[i]), [sheetH, areaH, points]);\n  const y = useMotionValue(sheetH);\n  const backdrop = useTransform(y, [0, sheetH], [0.55, 0]);\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (open === undefined) setInternalOpen(next);\n      onOpenChange?.(next);\n    },\n    [open, onOpenChange],\n  );\n\n  // Height of the area the sheet lives in: its container, or the window.\n  React.useLayoutEffect(() => {\n    const area = contained ? anchorRef.current?.parentElement : null;\n    const read = () => setAreaH(area ? area.clientHeight : window.innerHeight);\n    read();\n    if (area) {\n      const ro = new ResizeObserver(read);\n      ro.observe(area);\n      return () => ro.disconnect();\n    }\n    window.addEventListener(\"resize\", read);\n    return () => window.removeEventListener(\"resize\", read);\n  }, [contained]);\n\n  const goTo = React.useCallback(\n    (i: number) => {\n      setSnap(i);\n      onSnapChange?.(i);\n      animate(y, yFor(i), reduce ? { duration: 0 } : { type: \"spring\", stiffness: 380, damping: 40 });\n    },\n    [y, yFor, onSnapChange, reduce],\n  );\n\n  // Slide to the chosen snap point on open (and after the area resizes).\n  React.useEffect(() => {\n    if (!isOpen) return;\n    animate(y, yFor(snap), reduce ? { duration: 0 } : { type: \"spring\", stiffness: 380, damping: 40 });\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [isOpen, sheetH]);\n\n  React.useEffect(() => {\n    if (!isOpen) return;\n    returnFocus.current = document.activeElement as HTMLElement | null;\n    sheetRef.current?.focus({ preventScroll: true });\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\" && dismissible) setOpen(false);\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      document.removeEventListener(\"keydown\", onKey);\n      returnFocus.current?.focus?.({ preventScroll: true });\n    };\n  }, [isOpen, dismissible, setOpen]);\n\n  const onDragEnd = (_: unknown, info: PanInfo) => {\n    // Project where a flick would carry it, then settle on the nearest snap point (or close).\n    const projected = y.get() + info.velocity.y * 0.18;\n    if (dismissible && projected > yFor(0) + (sheetH - yFor(0)) * 0.45) {\n      setOpen(false);\n      return;\n    }\n    let best = 0;\n    points.forEach((_, i) => {\n      if (Math.abs(yFor(i) - projected) < Math.abs(yFor(best) - projected)) best = i;\n    });\n    goTo(best);\n  };\n\n  const pos = contained ? \"absolute\" : \"fixed\";\n\n  return (\n    <>\n      <div ref={anchorRef} className=\"contents\">\n        {triggerLabel && (\n          <button\n            type=\"button\"\n            onClick={() => {\n              setSnap(defaultSnap);\n              setOpen(true);\n            }}\n            aria-haspopup=\"dialog\"\n            aria-expanded={isOpen}\n            className=\"cursor-pointer rounded-full border-none px-5 py-2.5 text-[14px] font-semibold outline-none focus-visible:ring-2 focus-visible:ring-offset-2\"\n            style={{ background: p.trigger, color: p.triggerText, fontFamily: \"Inter, sans-serif\", [\"--tw-ring-color\" as string]: p.focus }}\n          >\n            {triggerLabel}\n          </button>\n        )}\n      </div>\n\n      <AnimatePresence>\n        {isOpen && (\n          <>\n            <motion.div\n              key=\"backdrop\"\n              aria-hidden=\"true\"\n              className={cn(pos, \"inset-0 z-40\")}\n              style={{ background: p.backdrop, opacity: backdrop }}\n              exit={{ opacity: 0 }}\n              onClick={() => dismissible && setOpen(false)}\n            />\n            <motion.div\n              key=\"sheet\"\n              ref={sheetRef}\n              role=\"dialog\"\n              aria-modal=\"true\"\n              aria-labelledby={title ? `${uid}-title` : undefined}\n              aria-describedby={description ? `${uid}-desc` : undefined}\n              tabIndex={-1}\n              drag=\"y\"\n              dragControls={dragControls}\n              dragListener={false}\n              dragConstraints={{ top: 0, bottom: sheetH }}\n              dragElastic={{ top: 0.06, bottom: 0.4 }}\n              dragMomentum={false}\n              onDragEnd={onDragEnd}\n              exit={{ y: sheetH, transition: reduce ? { duration: 0 } : { type: \"spring\", stiffness: 420, damping: 44 } }}\n              className={cn(pos, \"inset-x-0 bottom-0 z-50 flex flex-col outline-none\", className)}\n              style={{ y, height: sheetH, background: p.sheet, borderTop: `1px solid ${p.border}`, borderRadius: \"22px 22px 0 0\", boxShadow: \"0 -20px 60px rgba(0,0,0,0.35)\", fontFamily: \"Inter, sans-serif\", paddingBottom: \"env(safe-area-inset-bottom, 0px)\" }}\n            >\n              {/* Dragging starts from the handle and header only, so the content can scroll. */}\n              <div onPointerDown={(e) => dragControls.start(e)} className=\"shrink-0 cursor-grab touch-none active:cursor-grabbing\" style={{ padding: \"10px 20px 12px\" }}>\n                <button\n                  type=\"button\"\n                  aria-label={snap < points.length - 1 ? \"Expand sheet\" : \"Collapse sheet\"}\n                  onClick={() => goTo(snap < points.length - 1 ? snap + 1 : 0)}\n                  className=\"mx-auto mb-2 block cursor-pointer rounded-full border-none p-0 outline-none focus-visible:ring-2\"\n                  style={{ width: 40, height: 5, background: p.handle, [\"--tw-ring-color\" as string]: p.focus }}\n                />\n                {(title || description) && (\n                  <div className=\"flex items-start justify-between\" style={{ gap: 12 }}>\n                    <div className=\"flex min-w-0 flex-col\" style={{ gap: 2 }}>\n                      {title && (\n                        <h2 id={`${uid}-title`} className=\"m-0 font-semibold tracking-[-0.01em]\" style={{ color: p.text, fontSize: 17 }}>\n                          {title}\n                        </h2>\n                      )}\n                      {description && (\n                        <p id={`${uid}-desc`} className=\"m-0\" style={{ color: p.muted, fontSize: 13 }}>\n                          {description}\n                        </p>\n                      )}\n                    </div>\n                    {dismissible && (\n                      <button\n                        type=\"button\"\n                        aria-label=\"Close\"\n                        onClick={() => setOpen(false)}\n                        className=\"flex shrink-0 cursor-pointer items-center justify-center rounded-full border-none outline-none focus-visible:ring-2\"\n                        style={{ width: 30, height: 30, background: p.hover, color: p.muted, [\"--tw-ring-color\" as string]: p.focus }}\n                      >\n                        <svg width=\"12\" height=\"12\" viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                          <path d=\"M3 3l6 6M9 3L3 9\" />\n                        </svg>\n                      </button>\n                    )}\n                  </div>\n                )}\n              </div>\n              <div className=\"min-h-0 flex-1 overflow-y-auto overscroll-contain\" style={{ padding: \"0 20px 20px\", color: p.text, scrollbarWidth: \"none\" }}>\n                {children}\n              </div>\n            </motion.div>\n          </>\n        )}\n      </AnimatePresence>\n    </>\n  );\n}\n\nexport default BottomSheet;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}