{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "bottom-nav",
  "title": "Bottom navigation",
  "description": "Mobile bottom bar where a pill glides to the selected tab and its icon bounces, in a labelled or expanding variant, with popping badges and an optional raised center action.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json"
  ],
  "files": [
    {
      "path": "registry/components/navigation/bottom-nav.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, LayoutGroup, motion, useReducedMotion, type Transition } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { GooduiTokens, spring as springs } from \"@/lib/goodui-motion\"\n\nexport type BottomNavItem = {\n  /** Unique key of the tab; this is what value and onValueChange use. */\n  value: string\n  /** Text under the icon (or beside it when expanded) and the button's accessible name. */\n  label: string\n  /** Icon component (e.g. a lucide icon), rendered at 20px. */\n  icon: React.ComponentType<{ className?: string }>\n  /** A number shows a count bubble, `true` shows a dot. */\n  badge?: number | boolean\n}\n\nexport type BottomNavProps = Omit<React.ComponentProps<\"nav\">, \"defaultValue\" | \"onChange\"> & {\n  /** The tabs, left to right. With centerAction, the first half goes before it. */\n  items: BottomNavItem[]\n  /** Selected tab value (controlled), e.g. derived from the current route. */\n  value?: string\n  /** Initially selected tab when uncontrolled; defaults to the first item. */\n  defaultValue?: string\n  /** Called with the tab's value when it is tapped. */\n  onValueChange?: (value: string) => void\n  /** `pill`: pill behind the icon with labels always shown. `expand`: the active tab grows to show its label. */\n  variant?: \"pill\" | \"expand\"\n  /** Raised round button in the middle of the bar, e.g. \"New booking\". */\n  centerAction?: { label: string; icon: React.ComponentType<{ className?: string }>; onClick?: () => void }\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<BottomNavLabels>\n}\n\n/** Screen-reader text read after a tab's label when it has a badge. */\nexport type BottomNavLabels = {\n  /** Number badge, e.g. \", 3 new\". */\n  badgeCount: (count: number) => string\n  /** Dot badge (badge: true). */\n  badgeDot: string\n}\nconst DEFAULT_LABELS: BottomNavLabels = { badgeCount: (count) => `, ${count} new`, badgeDot: \", new\" }\n\nfunction useControllable<T>(value: T | undefined, defaultValue: T, onChange?: (v: T) => void) {\n  const [inner, setInner] = React.useState(defaultValue)\n  const controlled = value !== undefined\n  const current = controlled ? value : inner\n  const set = React.useCallback(\n    (next: T) => {\n      if (!controlled) setInner(next)\n      onChange?.(next)\n    },\n    [controlled, onChange],\n  )\n  return [current, set] as const\n}\n\nfunction Badge({ badge, reduce }: { badge: BottomNavItem[\"badge\"]; reduce: boolean }) {\n  const show = badge === true || (typeof badge === \"number\" && badge > 0)\n  return (\n    <AnimatePresence initial={false}>\n      {show && (\n        <motion.span\n          key={typeof badge === \"number\" ? badge : \"dot\"}\n          aria-hidden=\"true\"\n          initial={{ scale: reduce ? 1 : 0.3, opacity: 0 }}\n          animate={{ scale: 1, opacity: 1 }}\n          exit={{ scale: reduce ? 1 : 0.3, opacity: 0 }}\n          transition={reduce ? { duration: 0 } : springs.play}\n          className={cn(\n            \"absolute z-10 rounded-full bg-rose-600 text-white ring-2 ring-background\",\n            badge === true\n              ? \"-end-0.5 -top-0.5 size-2.5\"\n              : \"-end-2.5 -top-1.5 flex h-4 min-w-4 items-center justify-center px-1 text-[10px] leading-none font-semibold tabular-nums\",\n          )}\n        >\n          {typeof badge === \"number\" ? (badge > 99 ? \"99+\" : badge) : null}\n        </motion.span>\n      )}\n    </AnimatePresence>\n  )\n}\n\n/**\n * Mobile bottom navigation: a pill glides to the selected tab (shared layout), the icon bounces when chosen,\n * badges pop in, and an optional raised center action. Left and Right arrows move focus between tabs (mirrored in RTL).\n */\nexport function BottomNav({\n  items,\n  value,\n  defaultValue,\n  onValueChange,\n  variant = \"pill\",\n  centerAction,\n  labels,\n  className,\n  \"aria-label\": ariaLabel = \"Main\",\n  ...props\n}: BottomNavProps) {\n  const l = useLabels(\"bottom-nav\", DEFAULT_LABELS, labels)\n  const uid = React.useId()\n  const reduce = useReducedMotion() ?? false\n  const rowRef = React.useRef<HTMLDivElement>(null)\n  // Right-to-left: the expanding label slides in from the other side. Read after mount so SSR output is unchanged.\n  const [rtl, setRtl] = React.useState(false)\n  React.useEffect(() => {\n    if (rowRef.current) setRtl(getComputedStyle(rowRef.current).direction === \"rtl\")\n  }, [])\n  const [current, setCurrent] = useControllable(value, defaultValue ?? items[0]?.value ?? \"\", onValueChange)\n  const refs = React.useRef<(HTMLButtonElement | null)[]>([])\n  const spring: Transition = reduce ? { duration: 0 } : springs.snap\n  const expand = variant === \"expand\"\n\n  const onKeyDown = (e: React.KeyboardEvent, i: number) => {\n    const n = items.length\n    let next = -1\n    const isRtl = getComputedStyle(e.currentTarget).direction === \"rtl\"\n    if (e.key === (isRtl ? \"ArrowLeft\" : \"ArrowRight\")) next = (i + 1) % n\n    else if (e.key === (isRtl ? \"ArrowRight\" : \"ArrowLeft\")) next = (i - 1 + n) % n\n    else if (e.key === \"Home\") next = 0\n    else if (e.key === \"End\") next = n - 1\n    if (next < 0) return\n    e.preventDefault()\n    refs.current[next]?.focus()\n  }\n\n  const half = Math.ceil(items.length / 2)\n  const CenterIcon = centerAction?.icon\n\n  const renderItem = (item: BottomNavItem, i: number) => {\n    const active = item.value === current\n    const Icon = item.icon\n    const count = typeof item.badge === \"number\" && item.badge > 0 ? l.badgeCount(item.badge) : item.badge === true ? l.badgeDot : \"\"\n    // The visible label starts the accessible name; the badge text follows as sr-only.\n    const srCount = count ? <span className=\"sr-only\">{count}</span> : null\n    const bounce = active && !reduce ? { y: [0, -5, 0], scale: [1, 1.18, 1] } : { y: 0, scale: 1 }\n\n    if (expand) {\n      return (\n        <motion.button\n          key={item.value}\n          ref={(el) => {\n            refs.current[i] = el\n          }}\n          layout\n          type=\"button\"\n          aria-current={active ? \"page\" : undefined}\n          onClick={() => setCurrent(item.value)}\n          onKeyDown={(e) => onKeyDown(e, i)}\n          transition={spring}\n          style={{ borderRadius: 9999 }}\n          className={cn(\n            \"pc-press relative flex h-11 min-w-11 cursor-pointer items-center justify-center px-3 outline-none focus-visible:ring-3 focus-visible:ring-ring/50\",\n            active ? \"text-primary\" : \"text-muted-foreground hover:text-foreground\",\n          )}\n        >\n          {active && (\n            <motion.span\n              layoutId={`${uid}-pill`}\n              aria-hidden=\"true\"\n              className=\"absolute inset-0 bg-primary/10 dark:bg-primary/20\"\n              style={{ borderRadius: 9999 }}\n              transition={spring}\n            />\n          )}\n          <motion.span layout=\"position\" transition={spring} className=\"relative\">\n            <motion.span className=\"block\" animate={bounce} transition={{ duration: 0.45, ease: \"easeOut\" }}>\n              <Icon aria-hidden=\"true\" className=\"size-5\" />\n            </motion.span>\n            <Badge badge={item.badge} reduce={reduce} />\n          </motion.span>\n          {!active && <span className=\"sr-only\">{item.label}</span>}\n          {active && (\n            <motion.span\n              layout=\"position\"\n              initial={{ opacity: 0, x: reduce ? 0 : rtl ? 4 : -4 }}\n              animate={{ opacity: 1, x: 0 }}\n              transition={reduce ? { duration: 0 } : { duration: 0.2, delay: 0.06 }}\n              className=\"relative ms-2 text-sm font-semibold whitespace-nowrap\"\n            >\n              {item.label}\n            </motion.span>\n          )}\n          {srCount}\n        </motion.button>\n      )\n    }\n\n    return (\n      <button\n        key={item.value}\n        ref={(el) => {\n          refs.current[i] = el\n        }}\n        type=\"button\"\n        aria-current={active ? \"page\" : undefined}\n        onClick={() => setCurrent(item.value)}\n        onKeyDown={(e) => onKeyDown(e, i)}\n        className={cn(\n          \"pc-press pc-press-soft group flex min-w-0 flex-1 cursor-pointer flex-col items-center justify-center gap-1 rounded-xl py-1.5 outline-none focus-visible:ring-3 focus-visible:ring-ring/50\",\n          active ? \"text-foreground\" : \"text-muted-foreground hover:text-foreground\",\n        )}\n      >\n        <span className=\"relative flex h-8 w-14 items-center justify-center\">\n          {active && (\n            <motion.span\n              layoutId={`${uid}-pill`}\n              aria-hidden=\"true\"\n              className=\"absolute inset-0 bg-primary/10 dark:bg-primary/20\"\n              style={{ borderRadius: 9999 }}\n              transition={spring}\n            />\n          )}\n          <span className=\"relative\">\n            <motion.span className={cn(\"block\", active && \"text-primary\")} animate={bounce} transition={{ duration: 0.45, ease: \"easeOut\" }}>\n              <Icon aria-hidden=\"true\" className=\"size-5\" />\n            </motion.span>\n            <Badge badge={item.badge} reduce={reduce} />\n          </span>\n        </span>\n        <span className={cn(\"max-w-full truncate text-[11px] leading-none transition-[font-weight]\", active ? \"font-semibold\" : \"font-medium\")}>\n          {item.label}\n          {srCount}\n        </span>\n      </button>\n    )\n  }\n\n  const center = centerAction && CenterIcon && (\n    <div key=\"center\" className=\"flex shrink-0 items-start justify-center px-1\">\n      <motion.button\n        type=\"button\"\n        aria-label={centerAction.label}\n        onClick={centerAction.onClick}\n        whileHover={reduce ? undefined : { y: -2 }}\n        whileTap={reduce ? undefined : { scale: 0.9 }}\n        transition={springs.play}\n        className=\"group -mt-7 flex size-14 cursor-pointer items-center justify-center rounded-full bg-primary text-primary-foreground shadow-[var(--pc-e2)] ring-4 ring-background outline-none focus-visible:ring-ring/50\"\n      >\n        <CenterIcon className=\"size-6 transition-transform duration-300 group-hover:rotate-90 motion-reduce:transition-none\" />\n      </motion.button>\n    </div>\n  )\n\n  return (\n    <nav\n      data-slot=\"bottom-nav\"\n      aria-label={ariaLabel}\n      className={cn(\"border-t bg-background/90 pb-[env(safe-area-inset-bottom)] backdrop-blur-md\", className)}\n      {...props}\n    >\n      <GooduiTokens />\n      <LayoutGroup id={uid}>\n        <div ref={rowRef} className={cn(\"flex h-16 items-center px-2\", expand ? \"justify-around gap-1\" : \"gap-0.5\")}>\n          {items.slice(0, centerAction ? half : items.length).map((item, i) => renderItem(item, i))}\n          {center}\n          {centerAction && items.slice(half).map((item, i) => renderItem(item, i + half))}\n        </div>\n      </LayoutGroup>\n    </nav>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/bottom-nav.tsx"
    }
  ],
  "categories": [
    "components",
    "navigation"
  ],
  "type": "registry:component"
}