{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sidebar",
  "title": "Sidebar",
  "description": "A collapsible app sidebar with grouped nav sections, a sliding active-item indicator, badges, an icon-only rail mode with hover tooltips, a user footer and full keyboard navigation.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/sidebar/sidebar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport { motion, AnimatePresence } 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\n// A minimal self-contained tooltip just for a collapsed row's icon —\n// registry components ship as a single file, so this doesn't reach for\n// the separate Tooltip element even though the two would otherwise share\n// a lot of code.\nfunction RailTooltip({ label, theme, children }: { label: string; theme: \"dark\" | \"light\"; children: React.ReactElement }) {\n  const wrapRef = React.useRef<HTMLSpanElement>(null);\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n  const [open, setOpen] = React.useState(false);\n  const [pos, setPos] = React.useState<{ top: number; left: number } | null>(null);\n  const dark = theme === \"dark\";\n\n  const show = () => {\n    timer.current = setTimeout(() => {\n      const r = wrapRef.current?.getBoundingClientRect();\n      if (r) setPos({ top: r.top + r.height / 2, left: r.right + 10 });\n      setOpen(true);\n    }, 150);\n  };\n  const hide = () => {\n    if (timer.current) clearTimeout(timer.current);\n    setOpen(false);\n  };\n  React.useEffect(() => () => {\n    if (timer.current) clearTimeout(timer.current);\n  }, []);\n\n  return (\n    <span ref={wrapRef} onMouseEnter={show} onMouseLeave={hide} onFocus={show} onBlur={hide} className=\"block w-full\">\n      {children}\n      {typeof document !== \"undefined\" &&\n        createPortal(\n          <AnimatePresence>\n            {open && pos && (\n              <motion.span\n                role=\"tooltip\"\n                initial={{ opacity: 0, x: -4 }}\n                animate={{ opacity: 1, x: 0 }}\n                exit={{ opacity: 0 }}\n                transition={{ duration: 0.12 }}\n                className=\"fixed z-[9999] font-medium whitespace-nowrap\"\n                style={{ top: pos.top, left: pos.left, transform: \"translateY(-50%)\", padding: \"5px 9px\", borderRadius: 8, background: dark ? \"#161616\" : \"#FFFFFF\", border: `1px solid ${dark ? \"rgba(255,255,255,0.12)\" : \"rgba(10,10,10,0.1)\"}`, color: dark ? \"#F5F4F1\" : \"#0A0A0A\", fontSize: 12.5, boxShadow: dark ? \"0 12px 32px rgba(0,0,0,0.5)\" : \"0 12px 32px rgba(0,0,0,0.16)\" }}\n              >\n                {label}\n              </motion.span>\n            )}\n          </AnimatePresence>,\n          document.body,\n        )}\n    </span>\n  );\n}\n\nexport type SidebarSize = \"sm\" | \"md\" | \"lg\";\n\nexport interface SidebarItem {\n  id: string;\n  label: string;\n  icon?: React.ReactNode;\n  badge?: string | number;\n  disabled?: boolean;\n  onClick?: () => void;\n}\n\nexport interface SidebarSection {\n  id: string;\n  label?: string;\n  items: SidebarItem[];\n}\n\nexport interface SidebarUser {\n  name: string;\n  subtitle?: string;\n  initials?: string;\n  onClick?: () => void;\n}\n\nexport interface SidebarProps {\n  sections: SidebarSection[];\n  activeId?: string;\n  defaultActiveId?: string;\n  onActiveChange?: (id: string) => void;\n  collapsed?: boolean;\n  defaultCollapsed?: boolean;\n  onCollapsedChange?: (collapsed: boolean) => void;\n  collapsible?: boolean;\n  header?: React.ReactNode;\n  user?: SidebarUser;\n  width?: number;\n  collapsedWidth?: number;\n  height?: number | string;\n  size?: SidebarSize;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.5)\", faint: \"rgba(245,244,241,0.32)\", bg: \"#0E0E0E\", border: \"rgba(255,255,255,0.1)\", hover: \"rgba(255,255,255,0.06)\", active: \"#F5F4F1\", activeText: \"#0A0A0A\", divider: \"rgba(255,255,255,0.08)\", badge: \"rgba(255,255,255,0.1)\", avatarBg: \"rgba(255,255,255,0.1)\" },\n  light: { text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.5)\", faint: \"rgba(10,10,10,0.32)\", bg: \"#FFFFFF\", border: \"rgba(10,10,10,0.12)\", hover: \"rgba(10,10,10,0.05)\", active: \"#0A0A0A\", activeText: \"#FFFFFF\", divider: \"rgba(10,10,10,0.08)\", badge: \"rgba(10,10,10,0.06)\", avatarBg: \"rgba(10,10,10,0.08)\" },\n};\n\nconst SIZES: Record<SidebarSize, { font: number; icon: number; rowH: number; padX: number; radius: number }> = {\n  sm: { font: 12.5, icon: 16, rowH: 32, padX: 10, radius: 9 },\n  md: { font: 13.5, icon: 18, rowH: 36, padX: 12, radius: 10 },\n  lg: { font: 15, icon: 20, rowH: 40, padX: 14, radius: 11 },\n};\n\nfunction CollapseIcon({ collapsed, size }: { collapsed: boolean; size: number }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n      <rect x=\"2\" y=\"3\" width=\"12\" height=\"10\" rx=\"2\" />\n      <path d=\"M6.5 3v10\" />\n      <path d={collapsed ? \"M9.5 6.5L11.5 8L9.5 9.5\" : \"M11 6.5L9 8L11 9.5\"} />\n    </svg>\n  );\n}\n\nfunction initialsOf(name: string) {\n  const parts = name.trim().split(/\\s+/);\n  return ((parts[0]?.[0] ?? \"\") + (parts[1]?.[0] ?? \"\")).toUpperCase() || \"?\";\n}\n\nexport function Sidebar({\n  sections,\n  activeId,\n  defaultActiveId,\n  onActiveChange,\n  collapsed,\n  defaultCollapsed = false,\n  onCollapsedChange,\n  collapsible = true,\n  header,\n  user,\n  width = 240,\n  collapsedWidth = 72,\n  height = 560,\n  size = \"md\",\n  theme = \"dark\",\n  className,\n}: SidebarProps) {\n  const p = PALETTES[theme];\n  const s = SIZES[size];\n  const uid = React.useId();\n  const navRef = React.useRef<HTMLDivElement>(null);\n  const itemRefs = React.useRef<Record<string, HTMLButtonElement | null>>({});\n\n  const allItems = React.useMemo(() => sections.flatMap((sec) => sec.items), [sections]);\n  const isActiveControlled = activeId !== undefined;\n  const [internalActive, setInternalActive] = React.useState(defaultActiveId ?? allItems.find((i) => !i.disabled)?.id ?? \"\");\n  const currentActive = isActiveControlled ? activeId : internalActive;\n\n  const isCollapsedControlled = collapsed !== undefined;\n  const [internalCollapsed, setInternalCollapsed] = React.useState(defaultCollapsed);\n  const isCollapsed = isCollapsedControlled ? collapsed! : internalCollapsed;\n\n  const [focusedId, setFocusedId] = React.useState(currentActive || allItems.find((i) => !i.disabled)?.id || \"\");\n\n  const setCollapsed = (next: boolean) => {\n    if (!isCollapsedControlled) setInternalCollapsed(next);\n    onCollapsedChange?.(next);\n  };\n\n  const activate = (item: SidebarItem) => {\n    if (item.disabled) return;\n    if (!isActiveControlled) setInternalActive(item.id);\n    setFocusedId(item.id);\n    onActiveChange?.(item.id);\n    item.onClick?.();\n  };\n\n  const focusableIds = allItems.filter((i) => !i.disabled).map((i) => i.id);\n  const move = (dir: 1 | -1) => {\n    if (focusableIds.length === 0) return;\n    const i = focusableIds.indexOf(focusedId);\n    const next = focusableIds[(i + dir + focusableIds.length) % focusableIds.length];\n    setFocusedId(next);\n    itemRefs.current[next]?.focus({ preventScroll: true });\n  };\n\n  const onNavKeyDown = (e: React.KeyboardEvent) => {\n    if (e.key === \"ArrowDown\") {\n      e.preventDefault();\n      move(1);\n    } else if (e.key === \"ArrowUp\") {\n      e.preventDefault();\n      move(-1);\n    } else if (e.key === \"Home\") {\n      e.preventDefault();\n      if (focusableIds.length) {\n        setFocusedId(focusableIds[0]);\n        itemRefs.current[focusableIds[0]]?.focus({ preventScroll: true });\n      }\n    } else if (e.key === \"End\") {\n      e.preventDefault();\n      if (focusableIds.length) {\n        const last = focusableIds[focusableIds.length - 1];\n        setFocusedId(last);\n        itemRefs.current[last]?.focus({ preventScroll: true });\n      }\n    }\n  };\n\n  const row = (item: SidebarItem) => {\n    const active = item.id === currentActive;\n    const btn = (\n      <button\n        key={item.id}\n        ref={(el) => {\n          itemRefs.current[item.id] = el;\n        }}\n        type=\"button\"\n        role=\"button\"\n        aria-current={active ? \"page\" : undefined}\n        aria-label={isCollapsed ? item.label : undefined}\n        aria-disabled={item.disabled || undefined}\n        disabled={item.disabled}\n        tabIndex={item.id === focusedId ? 0 : -1}\n        onClick={() => activate(item)}\n        onFocus={() => setFocusedId(item.id)}\n        className=\"relative flex w-full cursor-pointer items-center border-none bg-transparent outline-none focus-visible:ring-2 disabled:cursor-not-allowed disabled:opacity-40\"\n        style={{ height: s.rowH, padding: isCollapsed ? 0 : `0 ${s.padX}px`, justifyContent: isCollapsed ? \"center\" : \"flex-start\", gap: 10, borderRadius: s.radius, color: active ? p.activeText : p.text, fontSize: s.font, fontWeight: 500, [\"--tw-ring-color\" as string]: p.text }}\n        onMouseEnter={(e) => {\n          if (!active) e.currentTarget.style.background = p.hover;\n        }}\n        onMouseLeave={(e) => {\n          if (!active) e.currentTarget.style.background = \"transparent\";\n        }}\n      >\n        {active && (\n          <motion.span\n            layoutId={`${uid}-active-pill`}\n            aria-hidden=\"true\"\n            className=\"absolute inset-0\"\n            style={{ borderRadius: s.radius, background: p.active }}\n            transition={{ type: \"spring\", stiffness: 500, damping: 40 }}\n          />\n        )}\n        <span className=\"relative flex shrink-0 items-center justify-center\" style={{ width: s.icon, height: s.icon, color: active ? p.activeText : p.muted }}>\n          {item.icon}\n          {isCollapsed && item.badge !== undefined && <span aria-hidden=\"true\" className=\"absolute rounded-full\" style={{ top: -3, right: -3, width: 7, height: 7, background: active ? p.activeText : p.text, border: `1.5px solid ${p.bg}` }} />}\n        </span>\n        {!isCollapsed && (\n          <>\n            <span className=\"relative min-w-0 flex-1 truncate text-left\">{item.label}</span>\n            {item.badge !== undefined && (\n              <span className=\"relative shrink-0 rounded-full px-1.5 py-px font-semibold tabular-nums\" style={{ background: active ? \"rgba(0,0,0,0.12)\" : p.badge, color: active ? p.activeText : p.muted, fontSize: s.font - 3 }}>\n                {item.badge}\n              </span>\n            )}\n          </>\n        )}\n      </button>\n    );\n    return isCollapsed ? (\n      <RailTooltip key={item.id} label={item.label} theme={theme}>\n        {btn}\n      </RailTooltip>\n    ) : (\n      btn\n    );\n  };\n\n  return (\n    <motion.div\n      role=\"navigation\"\n      aria-label=\"Sidebar\"\n      className={cn(\"flex flex-col overflow-hidden\", className)}\n      style={{ height, borderRadius: 18, background: p.bg, border: `1px solid ${p.border}`, fontFamily: \"Inter, sans-serif\" }}\n      animate={{ width: isCollapsed ? collapsedWidth : width }}\n      transition={{ type: \"spring\", stiffness: 360, damping: 36 }}\n    >\n      <div className=\"flex shrink-0 items-center\" style={{ height: 52, padding: `0 ${isCollapsed ? 0 : 14}px`, justifyContent: isCollapsed ? \"center\" : \"space-between\", borderBottom: `1px solid ${p.divider}` }}>\n        {!isCollapsed && header && <div className=\"min-w-0 flex-1 truncate\" style={{ color: p.text, fontSize: s.font + 1.5, fontWeight: 700 }}>{header}</div>}\n        {collapsible && (\n          <button\n            type=\"button\"\n            aria-label={isCollapsed ? \"Expand sidebar\" : \"Collapse sidebar\"}\n            onClick={() => setCollapsed(!isCollapsed)}\n            className=\"flex shrink-0 cursor-pointer items-center justify-center rounded-lg border-none bg-transparent outline-none focus-visible:ring-2\"\n            style={{ width: 28, height: 28, color: p.muted, [\"--tw-ring-color\" as string]: p.text }}\n            onMouseEnter={(e) => (e.currentTarget.style.background = p.hover)}\n            onMouseLeave={(e) => (e.currentTarget.style.background = \"transparent\")}\n          >\n            <CollapseIcon collapsed={isCollapsed} size={s.icon - 2} />\n          </button>\n        )}\n      </div>\n\n      <div ref={navRef} onKeyDown={onNavKeyDown} className=\"flex min-h-0 flex-1 flex-col overflow-y-auto\" style={{ padding: 10, gap: 16 }}>\n        {sections.map((section) => (\n          <div key={section.id} className=\"flex flex-col\" style={{ gap: 2 }}>\n            <AnimatePresence initial={false}>\n              {!isCollapsed && section.label && (\n                <motion.div\n                  initial={{ opacity: 0, height: 0 }}\n                  animate={{ opacity: 1, height: \"auto\" }}\n                  exit={{ opacity: 0, height: 0 }}\n                  transition={{ duration: 0.16 }}\n                  className=\"overflow-hidden font-semibold uppercase\"\n                  style={{ padding: \"4px 10px 6px\", color: p.faint, fontSize: s.font - 3, letterSpacing: \"0.07em\" }}\n                >\n                  {section.label}\n                </motion.div>\n              )}\n            </AnimatePresence>\n            {section.items.map(row)}\n          </div>\n        ))}\n      </div>\n\n      {user && (\n        <div className=\"shrink-0\" style={{ borderTop: `1px solid ${p.divider}`, padding: isCollapsed ? \"10px 0\" : 10 }}>\n          <button\n            type=\"button\"\n            onClick={user.onClick}\n            className=\"flex w-full cursor-pointer items-center border-none bg-transparent outline-none focus-visible:ring-2\"\n            style={{ gap: 10, padding: isCollapsed ? 0 : \"6px 8px\", justifyContent: isCollapsed ? \"center\" : \"flex-start\", borderRadius: s.radius, [\"--tw-ring-color\" as string]: p.text }}\n            onMouseEnter={(e) => (e.currentTarget.style.background = p.hover)}\n            onMouseLeave={(e) => (e.currentTarget.style.background = \"transparent\")}\n          >\n            <span className=\"flex shrink-0 items-center justify-center rounded-full font-semibold\" style={{ width: 30, height: 30, background: p.avatarBg, color: p.text, fontSize: s.font - 2 }}>\n              {user.initials ?? initialsOf(user.name)}\n            </span>\n            {!isCollapsed && (\n              <span className=\"flex min-w-0 flex-1 flex-col items-start\" style={{ gap: 1 }}>\n                <span className=\"w-full truncate text-left font-semibold\" style={{ color: p.text, fontSize: s.font - 0.5 }}>\n                  {user.name}\n                </span>\n                {user.subtitle && (\n                  <span className=\"w-full truncate text-left\" style={{ color: p.muted, fontSize: s.font - 3 }}>\n                    {user.subtitle}\n                  </span>\n                )}\n              </span>\n            )}\n          </button>\n        </div>\n      )}\n    </motion.div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}