{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "use-scroll-lock",
  "title": "UseScrollLock",
  "description": "Lock and unlock scrolling on an element or the page",
  "files": [
    {
      "path": "registry/hooks/use-scroll-lock.tsx",
      "content": "'use client';\n\nimport {\n  MutableRefObject,\n  RefObject,\n  useCallback,\n  useEffect,\n  useRef,\n  useState,\n} from 'react';\n\nexport interface UseScrollLockReturn {\n  isLocked: boolean;\n  lock: () => void;\n  unlock: () => void;\n  toggle: () => void;\n}\n\nexport function useScrollLock<T extends HTMLElement = HTMLElement>(\n  ref?: RefObject<T> | MutableRefObject<T | null>,\n): UseScrollLockReturn {\n  const refCached = useRef<\n    RefObject<T> | MutableRefObject<T | null> | undefined\n  >(ref);\n\n  useEffect(() => {\n    refCached.current = ref;\n  }, [ref]);\n\n  const [isLocked, setIsLocked] = useState<boolean>(false);\n  const originalOverflow = useRef<string>('');\n\n  const getTarget = useCallback((): HTMLElement => {\n    const currentRef = refCached.current;\n    const el = currentRef?.current ?? null;\n    return (el as HTMLElement) || document.body;\n  }, []);\n\n  const lock = useCallback(() => {\n    if (!isLocked) {\n      const target = getTarget();\n      originalOverflow.current = target.style.overflow;\n      target.style.overflow = 'hidden';\n      setIsLocked(true);\n    }\n  }, [getTarget, isLocked]);\n\n  const unlock = useCallback(() => {\n    if (isLocked) {\n      const target = getTarget();\n      target.style.overflow = originalOverflow.current;\n      setIsLocked(false);\n    }\n  }, [getTarget, isLocked]);\n\n  const toggle = useCallback(() => {\n    isLocked ? unlock() : lock();\n  }, [isLocked, lock, unlock]);\n\n  // Restore on unmount\n  useEffect(() => {\n    return () => {\n      const target = getTarget();\n      target.style.overflow = originalOverflow.current;\n    };\n  }, [getTarget]);\n\n  return { isLocked, lock, unlock, toggle };\n}\n",
      "type": "registry:hook",
      "target": "hooks/guarahooks/use-scroll-lock.tsx"
    }
  ],
  "categories": [
    "ui-and-dom"
  ],
  "type": "registry:hook"
}