{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "nav-01",
  "title": "Nav 01",
  "description": "A top bar that shrinks a little as you scroll. On a small screen the links fold into a menu.",
  "dependencies": [
    "motion"
  ],
  "files": [
    {
      "path": "registry/nav-01/nav.tsx",
      "content": "\"use client\"\n\nimport { mergeProps } from \"@base-ui/react/merge-props\"\nimport { useRender } from \"@base-ui/react/use-render\"\nimport { motion } from \"motion/react\"\nimport { IconPlaceholder } from \"@/components/icon-placeholder\"\nimport {\n  createContext,\n  useCallback,\n  useContext,\n  useEffect,\n  useId,\n  useRef,\n  useState,\n  type ComponentProps,\n  type CSSProperties,\n  type ReactNode,\n  type RefObject,\n} from \"react\"\nimport { cn } from \"@/lib/utils\"\nimport { useScrollShrink } from \"@/hooks/use-scroll-shrink\"\n\ntype NavContextValue = {\n  open: boolean\n  setOpen: (open: boolean) => void\n  menuId: string\n  menuButtonRef: RefObject<HTMLButtonElement | null>\n  scrolled: boolean\n}\n\nconst NavContext = createContext<NavContextValue | null>(null)\n\nfunction useNav() {\n  const context = useContext(NavContext)\n  if (!context) {\n    throw new Error(\"useNav must be used within Nav.\")\n  }\n  return context\n}\n\nfunction Nav({\n  defaultOpen = false,\n  open: openProp,\n  onOpenChange,\n  className,\n  style,\n  children,\n  ...props\n}: ComponentProps<\"header\"> & {\n  defaultOpen?: boolean\n  open?: boolean\n  onOpenChange?: (open: boolean) => void\n  children?: ReactNode\n}) {\n  const [uncontrolledOpen, setUncontrolledOpen] = useState(defaultOpen)\n  const open = openProp ?? uncontrolledOpen\n  const rootRef = useRef<HTMLElement>(null)\n  const menuButtonRef = useRef<HTMLButtonElement>(null)\n  const menuId = useId()\n  const scrolled = useScrollShrink(rootRef)\n\n  const setOpen = useCallback(\n    (next: boolean) => {\n      if (openProp === undefined) setUncontrolledOpen(next)\n      onOpenChange?.(next)\n    },\n    [openProp, onOpenChange],\n  )\n\n  useEffect(() => {\n    if (!open) return\n\n    const onKeyDown = (event: KeyboardEvent) => {\n      if (event.key !== \"Escape\") return\n      setOpen(false)\n      menuButtonRef.current?.focus()\n    }\n\n    document.addEventListener(\"keydown\", onKeyDown)\n    return () => document.removeEventListener(\"keydown\", onKeyDown)\n  }, [open, setOpen])\n\n  return (\n    <NavContext.Provider\n      value={{ open, setOpen, menuId, menuButtonRef, scrolled }}\n    >\n      <header\n        {...props}\n        ref={rootRef}\n        data-slot=\"nav\"\n        data-state={open ? \"open\" : \"closed\"}\n        data-scrolled={scrolled ? \"true\" : \"false\"}\n        style={\n          {\n            ...style,\n            \"--nav-pad\": scrolled ? \"0.75rem\" : \"1.5rem\",\n          } as CSSProperties\n        }\n        className={cn(\"fixed inset-x-0 top-0 z-30 w-full\", className)}\n      >\n        <nav\n          data-slot=\"nav-bar\"\n          aria-label=\"Primary\"\n          className=\"@container px-3 pt-2\"\n        >\n          <div\n            data-slot=\"nav-surface\"\n            className={cn(\n              \"mx-auto max-w-7xl rounded-3xl bg-background/80 px-4 backdrop-blur-2xl transition-shadow duration-300 ease-[cubic-bezier(0.19,1,0.22,1)] motion-reduce:transition-none @sm:px-8\",\n              scrolled && \"shadow-lg shadow-foreground/5\",\n            )}\n          >\n            <motion.div className=\"relative grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-4 py-3 transition-[padding] duration-300 ease-[cubic-bezier(0.19,1,0.22,1)] motion-reduce:transition-none @sm:grid-cols-[auto_minmax(0,1fr)_auto] @sm:gap-x-8 @sm:py-(--nav-pad)\">\n              {children}\n            </motion.div>\n          </div>\n        </nav>\n      </header>\n    </NavContext.Provider>\n  )\n}\n\nfunction NavBrand({\n  className,\n  render,\n  ...props\n}: useRender.ComponentProps<\"a\"> & ComponentProps<\"a\">) {\n  return useRender({\n    defaultTagName: \"a\",\n    render,\n    props: mergeProps<\"a\">(\n      {\n        \"data-slot\": \"nav-brand\",\n        className: cn(\n          \"col-start-1 row-start-1 flex min-w-0 items-center gap-3 rounded-md outline-none focus-visible:ring-3 focus-visible:ring-ring/50\",\n          className,\n        ),\n      } as ComponentProps<\"a\">,\n      props,\n    ),\n  })\n}\n\nfunction NavTitle({ className, ...props }: ComponentProps<\"span\">) {\n  return (\n    <span\n      data-slot=\"nav-title\"\n      className={cn(\n        \"text-base font-semibold leading-none tracking-tight text-foreground @sm:text-lg\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction NavSubtitle({ className, ...props }: ComponentProps<\"span\">) {\n  return (\n    <span\n      data-slot=\"nav-subtitle\"\n      className={cn(\n        \"hidden text-[0.7rem] font-medium leading-none tracking-[0.16em] text-primary uppercase @sm:inline\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nfunction NavMenu({ className, onClick, ...props }: ComponentProps<\"button\">) {\n  const { open, setOpen, menuId, menuButtonRef } = useNav()\n\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"nav-menu\"\n      aria-expanded={open}\n      aria-controls={menuId}\n      aria-label={open ? \"Close menu\" : \"Open menu\"}\n      {...props}\n      ref={menuButtonRef}\n      className={cn(\n        \"relative col-start-2 row-start-1 size-11 cursor-pointer justify-self-end rounded-lg text-foreground outline-none focus-visible:ring-3 focus-visible:ring-ring/50 @sm:hidden\",\n        className,\n      )}\n      onClick={(event) => {\n        onClick?.(event)\n        setOpen(!open)\n      }}\n    >\n      <span\n        className={cn(\n          \"m-auto grid size-6 place-items-center transition-[opacity,transform] duration-200 ease-[cubic-bezier(0.19,1,0.22,1)] motion-reduce:transition-none [&_svg]:size-6\",\n          open\n            ? \"scale-0 rotate-180 opacity-0 motion-reduce:scale-100 motion-reduce:rotate-0\"\n            : \"scale-100 rotate-0 opacity-100\",\n        )}\n      >\n        <IconPlaceholder\n          lucide=\"MenuIcon\"\n          tabler=\"IconMenu2\"\n          hugeicons=\"Menu01Icon\"\n          phosphor=\"ListIcon\"\n          remixicon=\"RiMenuLine\"\n          aria-hidden=\"true\"\n        />\n      </span>\n      <span\n        className={cn(\n          \"absolute inset-0 m-auto grid size-6 place-items-center transition-[opacity,transform] duration-200 ease-[cubic-bezier(0.19,1,0.22,1)] motion-reduce:transition-none [&_svg]:size-6\",\n          open\n            ? \"rotate-0 scale-100 opacity-100\"\n            : \"-rotate-180 scale-0 opacity-0 motion-reduce:rotate-0 motion-reduce:scale-100\",\n        )}\n      >\n        <IconPlaceholder\n          lucide=\"XIcon\"\n          tabler=\"IconX\"\n          hugeicons=\"Cancel01Icon\"\n          phosphor=\"XIcon\"\n          remixicon=\"RiCloseLine\"\n          aria-hidden=\"true\"\n        />\n      </span>\n    </button>\n  )\n}\n\nfunction NavLinks({ className, children, ...props }: ComponentProps<\"ul\">) {\n  const { open, menuId } = useNav()\n\n  return (\n    <>\n      <ul\n        data-slot=\"nav-links\"\n        data-placement=\"desktop\"\n        className={cn(\n          \"group/links col-span-full row-start-2 hidden min-w-0 items-center gap-6 @sm:col-span-1 @sm:col-start-2 @sm:row-start-1 @sm:flex\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </ul>\n      <div\n        id={menuId}\n        data-slot=\"nav-panel\"\n        className={cn(\n          \"col-span-full row-start-2 mt-4 flex-col gap-4 rounded-t-2xl border border-b-0 bg-background px-4 pt-4 shadow-lg @sm:hidden\",\n          open ? \"flex\" : \"hidden\",\n        )}\n      >\n        <ul\n          data-slot=\"nav-links\"\n          data-placement=\"mobile\"\n          className={cn(\"group/links flex flex-col gap-4\", className)}\n        >\n          {children}\n        </ul>\n      </div>\n    </>\n  )\n}\n\nfunction NavLink({\n  className,\n  render,\n  ...props\n}: useRender.ComponentProps<\"a\"> & ComponentProps<\"a\">) {\n  const { setOpen } = useNav()\n\n  return (\n    <li data-slot=\"nav-item\">\n      {useRender({\n        defaultTagName: \"a\",\n        render,\n        props: mergeProps<\"a\">(\n          {\n            \"data-slot\": \"nav-link\",\n            className: cn(\n              \"rounded-md text-sm text-muted-foreground transition-colors duration-150 ease-out hover:text-foreground focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/50 motion-reduce:transition-none group-data-[placement=mobile]/links:py-1 group-data-[placement=mobile]/links:text-base\",\n              className,\n            ),\n            onClick: () => {\n              setOpen(false)\n            },\n          } as ComponentProps<\"a\">,\n          props,\n        ),\n      })}\n    </li>\n  )\n}\n\nfunction NavActions({ className, ...props }: ComponentProps<\"div\">) {\n  const { open } = useNav()\n\n  return (\n    <div\n      data-slot=\"nav-actions\"\n      className={cn(\n        \"col-span-full row-start-3 flex-col gap-3 rounded-b-2xl border border-t-0 bg-background px-4 pt-6 pb-4 @sm:col-span-1 @sm:col-start-3 @sm:row-start-1 @sm:flex @sm:flex-row @sm:items-center @sm:justify-self-end @sm:rounded-none @sm:border-0 @sm:bg-transparent @sm:p-0 @sm:shadow-none\",\n        open ? \"flex\" : \"hidden\",\n        className,\n      )}\n      {...props}\n    />\n  )\n}\n\nexport {\n  Nav,\n  NavActions,\n  NavBrand,\n  NavLink,\n  NavLinks,\n  NavMenu,\n  NavSubtitle,\n  NavTitle,\n  useNav,\n}\n",
      "type": "registry:ui",
      "target": "@ui/nav-01/nav.tsx"
    },
    {
      "path": "registry/nav-01/use-scroll-shrink.ts",
      "content": "\"use client\"\n\nimport { useEffect, useState, type RefObject } from \"react\"\n\nconst scrollShrinkDistance = 8\n\nfunction isScrollable(node: Element) {\n  const overflowY = getComputedStyle(node).overflowY\n  return (\n    overflowY === \"auto\" || overflowY === \"scroll\" || overflowY === \"overlay\"\n  )\n}\n\nexport function findScrollParent(node: HTMLElement | null) {\n  let current = node?.parentElement ?? null\n  while (current) {\n    if (isScrollable(current)) return current\n    current = current.parentElement\n  }\n  return null\n}\n\nfunction findScrollTarget(node: HTMLElement | null) {\n  const ancestor = findScrollParent(node)\n  if (ancestor) return ancestor\n  const parent = node?.parentElement\n  if (!parent) return null\n  for (const child of parent.children) {\n    if (child !== node && child instanceof HTMLElement && isScrollable(child)) {\n      return child\n    }\n  }\n  return null\n}\n\nexport function useScrollShrink(rootRef: RefObject<HTMLElement | null>) {\n  const [scrolled, setScrolled] = useState(false)\n\n  useEffect(() => {\n    const target = findScrollTarget(rootRef.current) ?? window\n    const read = () => {\n      const top = target instanceof Window ? target.scrollY : target.scrollTop\n      const next = top > scrollShrinkDistance\n      setScrolled((current) => (current === next ? current : next))\n    }\n\n    read()\n    target.addEventListener(\"scroll\", read, { passive: true })\n    return () => target.removeEventListener(\"scroll\", read)\n  }, [rootRef])\n\n  return scrolled\n}\n",
      "type": "registry:hook",
      "target": "@hooks/use-scroll-shrink.ts"
    }
  ],
  "type": "registry:ui"
}