{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toolbar",
  "title": "Toolbar",
  "description": "An accessible toolbar of icon buttons, toggles, radio-style toggle groups and separators with roving-focus arrow-key navigation, a sliding hover highlight and animated tooltips.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/toolbar/toolbar.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion } 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\nexport type ToolbarIconName =\n  | \"bold\"\n  | \"italic\"\n  | \"underline\"\n  | \"strike\"\n  | \"alignLeft\"\n  | \"alignCenter\"\n  | \"alignRight\"\n  | \"link\"\n  | \"code\"\n  | \"list\"\n  | \"undo\"\n  | \"redo\"\n  | \"image\"\n  | \"share\"\n  | \"comment\"\n  | \"more\";\n\nexport type ToolbarOrientation = \"horizontal\" | \"vertical\";\nexport type ToolbarVariant = \"solid\" | \"floating\" | \"ghost\";\nexport type ToolbarSize = \"sm\" | \"md\" | \"lg\";\n\ninterface ToolbarItemBase {\n  id: string;\n  label: string;\n  icon?: ToolbarIconName | React.ReactNode;\n  /** Visible text next to the icon. The label is still used for the tooltip and aria-label. */\n  text?: string;\n  /** Shown inside the tooltip, e.g. \"⌘B\". */\n  shortcut?: string;\n  disabled?: boolean;\n}\n\nexport interface ToolbarButton extends ToolbarItemBase {\n  type: \"button\";\n  onClick?: () => void;\n}\n\nexport interface ToolbarToggle extends ToolbarItemBase {\n  type: \"toggle\";\n  /** Toggles sharing a group behave like a radio set: exactly one stays pressed. */\n  group?: string;\n}\n\nexport interface ToolbarSeparator {\n  type: \"separator\";\n}\n\nexport type ToolbarEntry = ToolbarButton | ToolbarToggle | ToolbarSeparator;\n\nexport interface ToolbarProps {\n  items: ToolbarEntry[];\n  /** Ids of the pressed toggles (controlled). */\n  value?: string[];\n  defaultValue?: string[];\n  onValueChange?: (value: string[]) => void;\n  orientation?: ToolbarOrientation;\n  variant?: ToolbarVariant;\n  size?: ToolbarSize;\n  radius?: number;\n  showTooltips?: boolean;\n  theme?: \"dark\" | \"light\";\n  accentColor?: string;\n  ariaLabel?: string;\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0E0E0E\", border: \"rgba(255,255,255,0.1)\", text: \"rgba(245,244,241,0.62)\", strong: \"#F5F4F1\", hover: \"rgba(255,255,255,0.08)\", sep: \"rgba(255,255,255,0.12)\", tipBg: \"#F5F4F1\", tipText: \"#0A0A0A\", tipMuted: \"rgba(10,10,10,0.5)\", shadow: \"0 18px 44px rgba(0,0,0,0.5)\" },\n  light: { bg: \"#FFFFFF\", border: \"rgba(10,10,10,0.1)\", text: \"rgba(10,10,10,0.6)\", strong: \"#0A0A0A\", hover: \"rgba(10,10,10,0.06)\", sep: \"rgba(10,10,10,0.12)\", tipBg: \"#0A0A0A\", tipText: \"#F5F4F1\", tipMuted: \"rgba(245,244,241,0.55)\", shadow: \"0 18px 44px rgba(10,10,10,0.14)\" },\n};\n\nconst SIZES: Record<ToolbarSize, { item: number; icon: number; font: number; pad: number; gap: number }> = {\n  sm: { item: 30, icon: 15, font: 12, pad: 3, gap: 2 },\n  md: { item: 36, icon: 17, font: 13, pad: 4, gap: 2 },\n  lg: { item: 44, icon: 20, font: 14, pad: 5, gap: 3 },\n};\n\nconst ICON_PATHS: Record<ToolbarIconName, string> = {\n  bold: \"M4.5 2.5h3.9a2.5 2.5 0 0 1 0 5H4.5z M4.5 7.5h4.5a2.75 2.75 0 0 1 0 5.5H4.5z\",\n  italic: \"M10.5 2.5H6.5 M9.5 13.5h-4 M9.4 2.5 6.6 13.5\",\n  underline: \"M4.5 2.5v5a3.5 3.5 0 0 0 7 0v-5 M3.5 13.5h9\",\n  strike: \"M3 8h10 M10.6 4.8C10.3 3.5 9.3 2.8 8 2.8c-1.6 0-2.6.9-2.6 2.1 0 .9.5 1.4 1.6 2 M5.4 11.3c.3 1.3 1.3 1.9 2.6 1.9 1.6 0 2.6-.9 2.6-2.1 0-.5-.2-.9-.6-1.2\",\n  alignLeft: \"M2.5 3.5h11 M2.5 6.5h7 M2.5 9.5h11 M2.5 12.5h7\",\n  alignCenter: \"M2.5 3.5h11 M4.5 6.5h7 M2.5 9.5h11 M4.5 12.5h7\",\n  alignRight: \"M2.5 3.5h11 M6.5 6.5h7 M2.5 9.5h11 M6.5 12.5h7\",\n  link: \"M6.8 9.2a2.6 2.6 0 0 0 3.7 0l2-2a2.6 2.6 0 0 0-3.7-3.7l-.6.6 M9.2 6.8a2.6 2.6 0 0 0-3.7 0l-2 2a2.6 2.6 0 0 0 3.7 3.7l.6-.6\",\n  code: \"M5.5 4.5 2 8l3.5 3.5 M10.5 4.5 14 8l-3.5 3.5\",\n  list: \"M6 4h7.5 M6 8h7.5 M6 12h7.5 M2.5 4h.01 M2.5 8h.01 M2.5 12h.01\",\n  undo: \"M3.5 6.5h6a3.5 3.5 0 0 1 0 7H6 M6 3.5 3 6.5l3 3\",\n  redo: \"M12.5 6.5h-6a3.5 3.5 0 0 0 0 7H10 M10 3.5l3 3-3 3\",\n  image: \"M4.5 3h7A2 2 0 0 1 13.5 5v6a2 2 0 0 1-2 2h-7A2 2 0 0 1 2.5 11V5A2 2 0 0 1 4.5 3z M2.7 11.2l3.3-3 2.8 2.4 1.9-1.5 2.8 2.2 M6 6.2h.01\",\n  share: \"M8 10V2.5 M5 5.2 8 2.5l3 2.7 M3.5 8.5v3.5a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1V8.5\",\n  comment: \"M3.5 3.5h9a1 1 0 0 1 1 1v5.5a1 1 0 0 1-1 1H8.5L5.5 13.5V11h-2a1 1 0 0 1-1-1V4.5a1 1 0 0 1 1-1z\",\n  more: \"M3.5 8h.01 M8 8h.01 M12.5 8h.01\",\n};\n\nexport function ToolbarIcon({ name, size = 16 }: { name: ToolbarIconName; 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      <path d={ICON_PATHS[name]} />\n    </svg>\n  );\n}\n\ntype PalettePart = (typeof PALETTES)[\"dark\"];\n\nfunction isActionable(entry: ToolbarEntry): entry is ToolbarButton | ToolbarToggle {\n  return entry.type !== \"separator\";\n}\n\nexport function Toolbar({\n  items,\n  value,\n  defaultValue,\n  onValueChange,\n  orientation = \"horizontal\",\n  variant = \"solid\",\n  size = \"md\",\n  radius = 12,\n  showTooltips = true,\n  theme = \"dark\",\n  accentColor = \"#F2A841\",\n  ariaLabel = \"Toolbar\",\n  className,\n}: ToolbarProps) {\n  const p: PalettePart = PALETTES[theme];\n  const s = SIZES[size];\n  const vertical = orientation === \"vertical\";\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const tipTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n\n  const [inner, setInner] = React.useState<string[]>(defaultValue ?? []);\n  const pressedIds = value ?? inner;\n  const [activeId, setActiveId] = React.useState<string | null>(null);\n  const [hoverId, setHoverId] = React.useState<string | null>(null);\n  const [tipId, setTipId] = React.useState<string | null>(null);\n\n  const actionable = items.filter(isActionable);\n  const enabled = actionable.filter((i) => !i.disabled);\n  const rovingId = activeId && enabled.some((i) => i.id === activeId) ? activeId : (enabled[0]?.id ?? null);\n\n  React.useEffect(\n    () => () => {\n      if (tipTimer.current) clearTimeout(tipTimer.current);\n    },\n    [],\n  );\n\n  const commit = (next: string[]) => {\n    if (value === undefined) setInner(next);\n    onValueChange?.(next);\n  };\n\n  const press = (item: ToolbarButton | ToolbarToggle) => {\n    if (item.type === \"button\") {\n      item.onClick?.();\n      return;\n    }\n    const isOn = pressedIds.includes(item.id);\n    if (item.group) {\n      if (isOn) return;\n      const siblings = actionable.filter((i): i is ToolbarToggle => i.type === \"toggle\" && i.group === item.group).map((i) => i.id);\n      commit([...pressedIds.filter((id) => !siblings.includes(id)), item.id]);\n    } else {\n      commit(isOn ? pressedIds.filter((id) => id !== item.id) : [...pressedIds, item.id]);\n    }\n  };\n\n  const showTip = (id: string, delay: number) => {\n    if (!showTooltips) return;\n    if (tipTimer.current) clearTimeout(tipTimer.current);\n    if (delay === 0) setTipId(id);\n    else tipTimer.current = setTimeout(() => setTipId(id), delay);\n  };\n\n  const hideTip = () => {\n    if (tipTimer.current) clearTimeout(tipTimer.current);\n    setTipId(null);\n  };\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    const next = vertical ? \"ArrowDown\" : \"ArrowRight\";\n    const prev = vertical ? \"ArrowUp\" : \"ArrowLeft\";\n    if (e.key !== next && e.key !== prev && e.key !== \"Home\" && e.key !== \"End\") return;\n    const nodes = Array.from(rootRef.current?.querySelectorAll<HTMLButtonElement>(\"[data-toolbar-item]:not([disabled])\") ?? []);\n    if (nodes.length === 0) return;\n    const idx = nodes.findIndex((n) => n === document.activeElement);\n    let target = idx;\n    if (e.key === \"Home\") target = 0;\n    else if (e.key === \"End\") target = nodes.length - 1;\n    else if (e.key === next) target = (idx + 1) % nodes.length;\n    else target = (idx - 1 + nodes.length) % nodes.length;\n    e.preventDefault();\n    nodes[target]?.focus();\n  };\n\n  const surface: React.CSSProperties =\n    variant === \"ghost\"\n      ? { background: \"transparent\" }\n      : variant === \"floating\"\n        ? { background: p.bg, border: `1px solid ${p.border}`, boxShadow: p.shadow }\n        : { background: p.bg, border: `1px solid ${p.border}` };\n\n  const itemRadius = Math.max(4, radius - s.pad - 1);\n\n  return (\n    <div\n      ref={rootRef}\n      role=\"toolbar\"\n      aria-label={ariaLabel}\n      aria-orientation={orientation}\n      onKeyDown={onKeyDown}\n      onPointerLeave={() => {\n        setHoverId(null);\n        hideTip();\n      }}\n      className={cn(\"inline-flex max-w-full flex-wrap items-center\", vertical ? \"flex-col\" : \"flex-row\", className)}\n      style={{ ...surface, gap: s.gap, padding: s.pad, borderRadius: radius, fontFamily: \"Inter, sans-serif\" }}\n    >\n      {items.map((entry, index) => {\n        if (entry.type === \"separator\") {\n          return (\n            <div\n              key={`sep-${index}`}\n              role=\"separator\"\n              aria-orientation={vertical ? \"horizontal\" : \"vertical\"}\n              style={vertical ? { height: 1, width: s.item * 0.6, margin: `${s.gap + 2}px 0`, background: p.sep } : { width: 1, height: s.item * 0.55, margin: `0 ${s.gap + 2}px`, background: p.sep }}\n            />\n          );\n        }\n        const pressed = entry.type === \"toggle\" && pressedIds.includes(entry.id);\n        const icon = typeof entry.icon === \"string\" && entry.icon in ICON_PATHS ? <ToolbarIcon name={entry.icon as ToolbarIconName} size={s.icon} /> : entry.icon;\n        const hovered = hoverId === entry.id && !entry.disabled;\n        return (\n          <div key={entry.id} className=\"relative\" onPointerEnter={() => { if (!entry.disabled) { setHoverId(entry.id); showTip(entry.id, 380); } }}>\n            <motion.button\n              type=\"button\"\n              data-toolbar-item=\"\"\n              disabled={entry.disabled}\n              aria-label={entry.label}\n              aria-pressed={entry.type === \"toggle\" ? pressed : undefined}\n              tabIndex={rovingId === entry.id ? 0 : -1}\n              onFocus={(e) => {\n                setActiveId(entry.id);\n                if (e.currentTarget.matches(\":focus-visible\")) showTip(entry.id, 0);\n              }}\n              onBlur={hideTip}\n              onClick={() => press(entry)}\n              whileTap={entry.disabled ? undefined : { scale: 0.92 }}\n              transition={{ type: \"spring\", stiffness: 500, damping: 30 }}\n              className=\"relative flex cursor-pointer items-center justify-center border-none bg-transparent outline-none focus-visible:ring-2 disabled:cursor-not-allowed\"\n              style={{\n                minWidth: s.item,\n                height: s.item,\n                padding: entry.text ? `0 ${Math.round(s.item * 0.3)}px` : 0,\n                gap: 6,\n                borderRadius: itemRadius,\n                fontSize: s.font,\n                fontWeight: 500,\n                fontFamily: \"inherit\",\n                opacity: entry.disabled ? 0.35 : 1,\n                color: pressed ? accentColor : hovered ? p.strong : p.text,\n                background: pressed ? `color-mix(in srgb, ${accentColor} 16%, transparent)` : \"transparent\",\n                transition: \"color 0.15s, background 0.15s\",\n                [\"--tw-ring-color\" as string]: accentColor,\n              }}\n            >\n              {hovered && !pressed && (\n                <motion.span\n                  layoutId={`${uid}-hl`}\n                  aria-hidden=\"true\"\n                  className=\"absolute inset-0\"\n                  style={{ borderRadius: itemRadius, background: p.hover }}\n                  transition={{ type: \"spring\", stiffness: 520, damping: 38 }}\n                />\n              )}\n              <span className=\"relative flex items-center\" style={{ gap: 6 }}>\n                {icon}\n                {entry.text && <span>{entry.text}</span>}\n              </span>\n            </motion.button>\n\n            <AnimatePresence>\n              {tipId === entry.id && (\n                <div\n                  aria-hidden=\"true\"\n                  className={cn(\"pointer-events-none absolute z-50 flex\", vertical ? \"inset-y-0 left-full items-center\" : \"inset-x-0 top-full justify-center\")}\n                  style={vertical ? { paddingLeft: 10 } : { paddingTop: 10 }}\n                >\n                  <motion.div\n                    initial={vertical ? { opacity: 0, x: -4 } : { opacity: 0, y: -4 }}\n                    animate={vertical ? { opacity: 1, x: 0 } : { opacity: 1, y: 0 }}\n                    exit={{ opacity: 0, transition: { duration: 0.1 } }}\n                    transition={{ duration: 0.14, ease: \"easeOut\" }}\n                    className=\"flex items-center whitespace-nowrap\"\n                    style={{ gap: 8, padding: \"5px 9px\", borderRadius: 8, background: p.tipBg, color: p.tipText, fontSize: 12, fontWeight: 500, boxShadow: \"0 8px 24px rgba(0,0,0,0.25)\" }}\n                  >\n                    {entry.label}\n                    {entry.shortcut && <span style={{ color: p.tipMuted, fontSize: 11 }}>{entry.shortcut}</span>}\n                  </motion.div>\n                </div>\n              )}\n            </AnimatePresence>\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}