Copies›Toolbar Tooltip

Toolbar Tooltip

Vercel-style floating toolbar where one shared tooltip glides between buttons, resizing to fit labels and keyboard shortcuts; works with focus and keyboard.

Copy a ready prompt for Claude Code, Codex or Cursor

Seen on

Vercel

Dependencies

reacttailwindcssmotionlucide-react

Interaction type

navigation

Install via CLI

pnpm dlx shadcn@latest add @copia/toolbar-tooltip

Without the namespace: npx shadcn@latest add https://copia-ui.vercel.app/r/toolbar-tooltip.json

How to use

demo.tsx
import { Eye, Inbox, Menu, MessageCircle, Share, ToggleRight } from "lucide-react"
import { ToolbarTooltip, type ToolbarTooltipProps } from "./toolbar-tooltip"

const items = [
  { label: "Comment", icon: <MessageCircle />, shortcut: ["C"] },
  { label: "Inbox", icon: <Inbox />, shortcut: ["I"] },
  { label: "Draft mode", icon: <ToggleRight /> },
  { label: "Preview", icon: <Eye />, shortcut: ["P"] },
  { label: "Share", icon: <Share /> },
  { label: "Menu", icon: <Menu />, shortcut: ["⌘", "K"] },
]

export default function Demo(props: Pick<ToolbarTooltipProps, "delay" | "side">) {
  return (
    <div className="grid flex-1 place-items-center p-6">
      <ToolbarTooltip delay={150} {...props} items={items} className="scale-[1.6]" />
    </div>
  )
}

Customization

Use the sliders button at the top right of the preview to tweak delay, side live and copy the generated JSX.

Props

PropTypeDefaultDescription
items{ label, icon, shortcut?, onClick? }[]-Buttons in the toolbar.
delaynumber350Delay before the first tooltip (ms); later ones are instant.
side"top" | "bottom""top"Where the tooltip appears.

Attribution

Inspired by Vercel. Recreated by Copia.

Read how it was reverse engineered

Source code

toolbar-tooltip.tsx
"use client"

import { useEffect, useRef, useState } from "react"
import { AnimatePresence, motion, useReducedMotion } from "motion/react"
import { cn } from "@/lib/utils"

export type ToolbarItem = {
  /** Accessible name and tooltip text. */
  label: string
  icon: React.ReactNode
  /** Keys shown in the tooltip, e.g. ["⌘", "K"]. */
  shortcut?: string[]
  onClick?: () => void
}

export type ToolbarTooltipProps = {
  items: ToolbarItem[]
  /** Delay before the first tooltip appears (ms). Once one is open, others appear instantly. */
  delay?: number
  /** Show the tooltip above or below the toolbar. */
  side?: "top" | "bottom"
  className?: string
}

const SLIDE = { type: "spring", bounce: 0.15, duration: 0.35 } as const

/** A floating toolbar with one shared tooltip that glides between buttons. */
export function ToolbarTooltip({ items, delay = 350, side = "top", className }: ToolbarTooltipProps) {
  const [active, setActive] = useState<number | null>(null)
  const [center, setCenter] = useState(0)
  const timer = useRef<ReturnType<typeof setTimeout>>(undefined)
  const warm = useRef(false)
  const buttons = useRef<(HTMLButtonElement | null)[]>([])
  // Roving tabindex: the toolbar is one tab stop; arrow keys move between buttons.
  const [focusIndex, setFocusIndex] = useState(0)
  const reduceMotion = useReducedMotion()

  useEffect(() => () => clearTimeout(timer.current), [])

  const onKeyDown = (event: React.KeyboardEvent) => {
    if (event.key === "Escape") return hide()
    const moves: Record<string, number> = { ArrowRight: focusIndex + 1, ArrowLeft: focusIndex - 1, Home: 0, End: items.length - 1 }
    if (!(event.key in moves)) return
    event.preventDefault()
    const next = (moves[event.key] + items.length) % items.length
    setFocusIndex(next)
    buttons.current[next]?.focus()
  }

  const show = (index: number, el: HTMLElement) => {
    clearTimeout(timer.current)
    const open = () => {
      setCenter(el.offsetLeft + el.offsetWidth / 2)
      setActive(index)
      warm.current = true
    }
    if (warm.current) open()
    else timer.current = setTimeout(open, delay)
  }
  const hide = () => {
    clearTimeout(timer.current)
    setActive(null)
    // Stay "warm" briefly so moving back in does not wait for the delay again.
    timer.current = setTimeout(() => (warm.current = false), 300)
  }

  const item = active === null ? null : items[active]

  return (
    <div role="toolbar" aria-orientation="horizontal" onPointerLeave={hide} onBlur={hide} onKeyDown={onKeyDown} className={cn("relative inline-flex items-center gap-0.5 rounded-full bg-neutral-950 p-1 text-neutral-400 shadow-lg ring-1 ring-white/10", className)}>
      {items.map((it, i) => (
        <button
          key={it.label}
          ref={(el) => {
            buttons.current[i] = el
          }}
          type="button"
          tabIndex={i === focusIndex ? 0 : -1}
          aria-label={it.label}
          aria-keyshortcuts={it.shortcut?.join("+")}
          onClick={it.onClick}
          onPointerEnter={(e) => show(i, e.currentTarget)}
          onFocus={(e) => {
            setFocusIndex(i)
            show(i, e.currentTarget)
          }}
          className={cn(
            "grid size-8 place-items-center rounded-full transition-colors outline-none hover:text-white focus-visible:ring-2 focus-visible:ring-white/40 [&_svg]:size-4",
            active === i && "bg-white/10 text-white",
          )}
        >
          {it.icon}
        </button>
      ))}

      <AnimatePresence>
        {item && (
          <motion.div
            role="tooltip"
            initial={{ opacity: 0, x: center, y: side === "top" ? 4 : -4, scale: 0.96 }}
            animate={{ opacity: 1, x: center, y: 0, scale: 1 }}
            exit={{ opacity: 0, scale: 0.96, transition: { duration: 0.12 } }}
            transition={reduceMotion ? { duration: 0 } : SLIDE}
            className={cn("pointer-events-none absolute left-0", side === "top" ? "bottom-full mb-2" : "top-full mt-2")}
          >
            <motion.div
              layout={!reduceMotion}
              transition={SLIDE}
              className="flex -translate-x-1/2 items-center gap-1.5 rounded-lg bg-neutral-950 py-1 pr-1 pl-2.5 text-xs whitespace-nowrap text-white ring-1 ring-white/10"
            >
              <AnimatePresence mode="popLayout" initial={false}>
                <motion.span key={item.label} initial={{ opacity: 0, filter: "blur(2px)" }} animate={{ opacity: 1, filter: "blur(0px)" }} exit={{ opacity: 0, filter: "blur(2px)" }} transition={{ duration: 0.15 }} className="flex items-center gap-1.5">
                  {item.label}
                  {item.shortcut?.map((key) => (
                    <kbd key={key} className="grid h-5 min-w-5 place-items-center rounded bg-white/10 px-1 font-sans text-[10px] text-neutral-300">
                      {key}
                    </kbd>
                  ))}
                  {!item.shortcut && <span className="w-1" />}
                </motion.span>
              </AnimatePresence>
            </motion.div>
          </motion.div>
        )}
      </AnimatePresence>
    </div>
  )
}

Keep in mind

Most components here are recreations of the best interfaces out there. We don't claim to be the original creators: this is our attempt to reverse engineer, replicate and often add a few features. We credit everyone we can; if we missed someone, let us know.

Contact

Found a bug or a missing credit? Open an issue

License & usage

  • — Free to use and modify in personal and commercial projects (MIT).
  • — No attribution required, but a link back to Copia is appreciated.
  • — Demo images are not part of the license; replace them with your own.
PreviousToken SwapNext Agent Status