{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bottom-nav",
  "title": "Bottom Nav",
  "description": "Fixed bottom tab bar for phones: icon and label per item, a gradient that fades the page into the background behind it, and an active item you hand it from your router, so it works under Next, Remix or a plain anchor.",
  "registryDependencies": [
    "https://www.deltacomponents.dev/r/utils.json",
    "https://www.deltacomponents.dev/r/motion.json",
    "https://www.deltacomponents.dev/r/tokens.json"
  ],
  "files": [
    {
      "path": "registry/ui/bottom-nav.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\n\ninterface BottomNavContextValue {\n  value: string;\n  onValueChange?: (value: string) => void;\n  labels: boolean;\n  LinkComponent: React.ElementType;\n}\n\nconst BottomNavContext = React.createContext<BottomNavContextValue | null>(null);\n\nfunction useBottomNav() {\n  const context = React.useContext(BottomNavContext);\n  if (!context) throw new Error(\"BottomNavItem must be used within a BottomNav\");\n  return context;\n}\n\ninterface BottomNavProps\n  extends Omit<React.ComponentProps<\"nav\">, \"onChange\" | \"defaultValue\"> {\n  /** The active item's `value`. The nav never guesses this from the URL —\n   *  hand it the router's current path (or any state) so it works the same\n   *  under Next, Remix, Vite or a plain `<a>`. */\n  value: string;\n  onValueChange?: (value: string) => void;\n  /** Caption under each icon. Off gives the icon-only bar. */\n  labels?: boolean;\n  /** Fade the page into the background colour through the bar's top\n   *  rather than ending it at a hard edge. */\n  gradient?: boolean;\n  /** How far the bar gives way to the page, 0 to 1. 0 is a solid bar; 0.5\n   *  turns solid at the icons' bottom edge, so the page shows through behind\n   *  them; past that the bar itself thins out, until at 1 nothing is drawn\n   *  but the items. It never reaches above the bar, and the bar's own box\n   *  never changes with it. */\n  fade?: number;\n  /** What an item with an `href` renders as. `\"a\"` by default; a Next app\n   *  passes `Link` here once to keep client-side routing and prefetching. */\n  linkComponent?: React.ElementType;\n}\n\nfunction BottomNav({\n  value,\n  onValueChange,\n  labels = true,\n  gradient = true,\n  fade = 0.5,\n  linkComponent = \"a\",\n  className,\n  style,\n  children,\n  ...props\n}: BottomNavProps) {\n  const contextValue = React.useMemo<BottomNavContextValue>(\n    () => ({ value, onValueChange, labels, LinkComponent: linkComponent }),\n    [value, onValueChange, labels, linkComponent]\n  );\n\n  // Two halves of one dial. Up to 0.5 the fade reaches further down the bar,\n  // to the icons' bottom edge; past it the reach stays there and the colour\n  // itself thins out, so at 1 the bar draws nothing but its items.\n  const dial = Math.min(Math.max(fade, 0), 1);\n  const reach = Math.min(dial, 0.5) * 2;\n  const strength = Math.min(1, (1 - dial) * 2);\n\n  return (\n    <BottomNavContext.Provider value={contextValue}>\n      <nav\n        data-slot=\"bottom-nav\"\n        {...props}\n        // The icons' bottom edge: the bar's 4px padding, the item's (8px\n        // with labels, 12px without) and the 24px glyph.\n        style={\n          {\n            \"--bottom-nav-fade\": `${reach * (labels ? 36 : 40)}px`,\n            \"--bottom-nav-bg\": `color-mix(in srgb, var(--background) ${strength * 100}%, transparent)`,\n            ...style,\n          } as React.CSSProperties\n        }\n        className={cn(\n          // No breakpoint of its own: the layout that mounts it decides where\n          // it hides (`md:hidden`), which is also what lets a demo show it on\n          // a desktop inside a phone-sized frame.\n          // Bottom padding is the home-indicator inset when there is one and\n          // the same 4px as the top otherwise. The fade is painted inside\n          // this box, so lengthening it never changes it.\n          \"fixed inset-x-0 bottom-0 z-50 pt-1 pb-[max(env(safe-area-inset-bottom,0px),0.25rem)]\",\n          // The fade runs from the bar's top edge, never above it: clear\n          // there, solid at --bottom-nav-fade, eased through the stops between\n          // (15%, 40%, 60%, 80% at 1/9, 2/9, 3/9, 5/9 of the way) so it\n          // builds quickly and settles gently rather than ramping evenly.\n          gradient\n            ? \"bg-[linear-gradient(transparent,color-mix(in_srgb,var(--bottom-nav-bg)_15%,transparent)_calc(var(--bottom-nav-fade)/9),color-mix(in_srgb,var(--bottom-nav-bg)_40%,transparent)_calc(var(--bottom-nav-fade)*2/9),color-mix(in_srgb,var(--bottom-nav-bg)_60%,transparent)_calc(var(--bottom-nav-fade)/3),color-mix(in_srgb,var(--bottom-nav-bg)_80%,transparent)_calc(var(--bottom-nav-fade)*5/9),var(--bottom-nav-bg)_var(--bottom-nav-fade))]\"\n            : \"bg-background\",\n          className\n        )}\n      >\n        {/* Four or more items fill the bar, as iPhone's own tab bar does at\n            any count. Fewer leave a thumb's width of nothing between them, so\n            two or three are drawn in toward the middle. Material's\n            navigation bar puts three destinations on 60% of the bar; that\n            read as crowded at phone widths, so three take 72% here and two\n            56%. Counted in CSS, so a conditionally rendered item needs no\n            prop to say so. */}\n        <ul\n          data-slot=\"bottom-nav-list\"\n          className={cn(\n            \"flex items-stretch justify-around\",\n            \"has-[li:nth-child(2):last-child]:px-[22%] has-[li:nth-child(3):last-child]:px-[14%]\"\n          )}\n        >\n          {children}\n        </ul>\n      </nav>\n    </BottomNavContext.Provider>\n  );\n}\n\ninterface BottomNavItemProps\n  extends Omit<React.HTMLAttributes<HTMLElement>, \"onClick\"> {\n  value: string;\n  /** With an `href` the item is a link (see `linkComponent`); without one it\n   *  is a button, for an item that opens something rather than going\n   *  somewhere, or a demo that must not change the page's route. */\n  href?: string;\n  icon?: React.ReactNode;\n  onClick?: (event: React.MouseEvent<HTMLElement>) => void;\n  /** The label. */\n  children?: React.ReactNode;\n}\n\n/** The nearest ancestor that scrolls, or the document. A bar pinned inside\n *  a scrolling panel sends that panel back to the top, not the page. */\nfunction scrollParentOf(el: HTMLElement | null): Element | Window {\n  for (let node = el?.parentElement; node; node = node.parentElement) {\n    const { overflowY } = getComputedStyle(node);\n    if (overflowY === \"auto\" || overflowY === \"scroll\") return node;\n  }\n  return window;\n}\n\ntype BottomNavLabelProps = React.ComponentProps<\"span\">;\n\n/** The caption under an icon. An item wraps plain children in one of these\n *  itself; pass one explicitly to restyle it (its spacing, its size) for\n *  that item. */\nfunction BottomNavLabel({ className, ...props }: BottomNavLabelProps) {\n  return (\n    <span\n      data-slot=\"bottom-nav-label\"\n      className={cn(\"mt-1.5 truncate text-center text-[10px] leading-tight font-medium\", className)}\n      {...props}\n    />\n  );\n}\n\nfunction BottomNavItem({\n  value,\n  href,\n  icon,\n  onClick,\n  className,\n  children,\n  ...props\n}: BottomNavItemProps) {\n  const { value: activeValue, onValueChange, labels, LinkComponent } = useBottomNav();\n  const isActive = activeValue === value;\n  const itemRef = React.useRef<HTMLElement>(null);\n  const Element: React.ElementType = href ? LinkComponent : \"button\";\n\n  // Children are the label: either a ready-made BottomNavLabel, kept as is,\n  // or text to wrap in one. The bare text is also what an icon-only bar\n  // gives a screen reader.\n  const isLabelElement =\n    React.isValidElement<BottomNavLabelProps>(children) && children.type === BottomNavLabel;\n  const labelText = isLabelElement ? children.props.children : children;\n  const label = isLabelElement ? children : children ? <BottomNavLabel>{children}</BottomNavLabel> : null;\n\n  const handleClick = (event: React.MouseEvent<HTMLElement>) => {\n    onClick?.(event);\n    if (event.defaultPrevented) return;\n    // Re-tapping the tab you are on scrolls back to the top, as it does in\n    // every iOS tab bar — and does not navigate: a link to the page you are\n    // already on would reload it, or have the router scroll its first\n    // element into view and cut the glide short.\n    if (isActive) {\n      event.preventDefault();\n      scrollParentOf(itemRef.current).scrollTo({ top: 0, behavior: \"smooth\" });\n      return;\n    }\n    onValueChange?.(value);\n  };\n\n  return (\n    <li className=\"min-w-0 flex-1\">\n      <Element\n        ref={itemRef}\n        {...props}\n        href={href}\n        type={href ? undefined : \"button\"}\n        aria-current={isActive ? \"page\" : undefined}\n        data-slot=\"bottom-nav-item\"\n        data-state={isActive ? \"active\" : \"inactive\"}\n        onClick={handleClick}\n        className={cn(\n          // h-full: the row stretches every item to the tallest, and this is\n          // what centres each one's glyph in that height rather than at the\n          // top of its own.\n          \"group/item flex h-full w-full cursor-pointer flex-col items-center justify-center px-1\",\n          labels ? \"py-2\" : \"py-3\",\n          // `touch-manipulation` drops the 300ms double-tap wait, so a tap is\n          // answered the instant it lands rather than feeling ignored.\n          \"touch-manipulation select-none [-webkit-touch-callout:none]\",\n          \"transition-colors duration-(--motion-fast) ease-spring\",\n          // Inactive sits a step under muted-foreground so the active item\n          // reads at a glance, but no lower: 4.0:1 on light and 4.5:1 on\n          // dark keeps the 10px labels legible (WCAG wants 4.5 for text,\n          // 3 for the icons; iOS's own inactive gray is 3.1 on white).\n          isActive\n            ? \"text-foreground\"\n            : \"text-muted-foreground/85 dark:text-muted-foreground/75\",\n          \"rounded-[var(--radius-bg,var(--radius,0.5rem))] outline-none\",\n          \"focus-visible:ring-1 focus-visible:ring-[color:var(--focus-ring,#6B97FF)]\",\n          className\n        )}\n      >\n        {/* The dip is on the glyph, not the whole target: a tap on a phone\n            has no hover to confirm it landed, and the icon shrinking under\n            the thumb is the acknowledgement before the route changes.\n            Button's press, exactly: the `scale` property (what `scale-*`\n            sets — transitioning `transform` leaves it snapping), in on the\n            moderate tier and out a tier quicker, to 0.9 and no deeper, on\n            its own compositor layer so the glyph is scaled as a cached\n            raster rather than re-rasterised and pixel-snapped every frame. */}\n        <span\n          className={cn(\n            \"pointer-events-none flex flex-col items-center will-change-transform\",\n            \"transition-[scale] [transition-duration:var(--motion-moderate-exit)] ease-spring\",\n            \"group-active/item:scale-90 group-active/item:[transition-duration:var(--motion-moderate)]\"\n          )}\n        >\n          {icon && (\n            <span\n              data-slot=\"bottom-nav-icon\"\n              // inline-flex, not inline: the slot hugs the glyph rather than\n              // sitting it on a text baseline with line-height slack under\n              // it, which shows the moment the slot is given a background.\n              className=\"inline-flex [&_svg]:size-6 [&_svg]:stroke-[1.5] [&_svg]:pointer-events-none\"\n            >\n              {icon}\n            </span>\n          )}\n          {labels && label}\n        </span>\n        {/* Icon-only bars still name every item for a screen reader. */}\n        {!labels && labelText && <span className=\"sr-only\">{labelText}</span>}\n      </Element>\n    </li>\n  );\n}\n\nexport {\n  BottomNav,\n  BottomNavItem,\n  BottomNavLabel,\n  type BottomNavProps,\n  type BottomNavItemProps,\n  type BottomNavLabelProps,\n};\n",
      "type": "registry:ui",
      "target": "components/ui/bottom-nav.tsx"
    }
  ],
  "docs": "Docs: https://www.deltacomponents.dev/docs/bottom-nav.",
  "categories": [
    "components"
  ],
  "type": "registry:ui"
}
