{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tooltip-on-icon-buttons-in-an-editor-toolbar","type":"registry:component","title":"Tooltip On Icon Buttons In An Editor Toolbar","description":"","dependencies":[],"files":[{"path":"components/we-inc/tooltip-on-icon-buttons-in-an-editor-toolbar.tsx","type":"registry:component","content":"import { useState } from \"react\";\n\n// Icon-only toolbar buttons whose tooltip is also their accessible name (aria-labelledby), with the keyboard shortcut.\nconst tools = [\n  { id: \"bold\", name: \"Bold\", keys: \"Ctrl B\", d: \"M6 4h5a3.5 3.5 0 0 1 2.5 6A3.8 3.8 0 0 1 12 17H6zm2.5 2.2v3.3H11a1.6 1.6 0 0 0 0-3.3zm0 5.4v3.2H12a1.6 1.6 0 0 0 0-3.2z\" },\n  { id: \"italic\", name: \"Italic\", keys: \"Ctrl I\", d: \"M8 4h7v2h-2.4l-2.2 9H13v2H6v-2h2.4l2.2-9H8z\" },\n  { id: \"link\", name: \"Insert link\", keys: \"Ctrl K\", d: \"M8.5 11.5l3-3 1 1-3 3zM6 14a2.5 2.5 0 0 1 0-3.5l2-2 1 1-2 2a1 1 0 0 0 1.5 1.5l2-2 1 1-2 2A2.5 2.5 0 0 1 6 14zm8-8a2.5 2.5 0 0 1 0 3.5l-2 2-1-1 2-2A1 1 0 0 0 11.5 7l-2 2-1-1 2-2A2.5 2.5 0 0 1 14 6z\" },\n  { id: \"list\", name: \"Bulleted list\", keys: \"Ctrl Shift 8\", d: \"M4 5.5a1.2 1.2 0 1 1 0 2.4 1.2 1.2 0 0 1 0-2.4zM8 6h9v1.5H8zm-4 3.8a1.2 1.2 0 1 1 0 2.4 1.2 1.2 0 0 1 0-2.4zM8 10.2h9v1.5H8zm-4 3.8a1.2 1.2 0 1 1 0 2.4 1.2 1.2 0 0 1 0-2.4zM8 14.5h9V16H8z\" },\n  { id: \"undo\", name: \"Undo\", keys: \"Ctrl Z\", d: \"M8 5L3 9.5 8 14v-3h4a3 3 0 0 1 0 6h-2v2h2a5 5 0 0 0 0-10H8z\" },\n];\n\nexport default function TooltipOnIconButtonsInAnEditorToolbar() {\n  // \"link\" starts open for the preview; any pointer move or key press hands control to hover and focus.\n  const [demo, setDemo] = useState(true);\n  const [hidden, setHidden] = useState<string | null>(null);\n  const stop = () => demo && setDemo(false);\n  return (\n    <section className=\"bg-zinc-100 px-5 pb-16 pt-12\" onPointerMove={stop} onKeyDown={stop}>\n      <div className=\"mx-auto max-w-xl overflow-visible rounded-2xl border border-zinc-200 bg-white\">\n        <div role=\"toolbar\" aria-label=\"Formatting\" className=\"flex flex-wrap gap-1 border-b border-zinc-200 p-2\">\n          {tools.map((t) => (\n            <span key={t.id} className=\"group relative\" onMouseLeave={() => setHidden(null)}>\n              <button\n                type=\"button\"\n                aria-labelledby={`tt4-${t.id}`}\n                onBlur={() => setHidden(null)}\n                onKeyDown={(e) => e.key === \"Escape\" && setHidden(t.id)}\n                className=\"grid h-10 w-10 place-items-center rounded-lg text-zinc-700 hover:bg-zinc-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-violet-600\"\n              >\n                <svg viewBox=\"0 0 20 20\" width=\"20\" height=\"20\" aria-hidden=\"true\" className=\"fill-current\"><path d={t.d} /></svg>\n              </button>\n              <span\n                id={`tt4-${t.id}`}\n                role=\"tooltip\"\n                className={`pointer-events-none absolute left-1/2 top-full z-10 mt-2 flex -translate-x-1/2 items-center gap-2 whitespace-nowrap rounded-md bg-zinc-900 px-2 py-1.5 text-xs font-medium text-white opacity-0 transition-opacity duration-100 group-hover:opacity-100 group-focus-within:opacity-100 motion-reduce:transition-none ${demo && t.id === \"link\" ? \"!opacity-100\" : \"\"} ${hidden === t.id ? \"!opacity-0\" : \"\"}`}\n              >\n                {t.name}\n                <kbd className=\"rounded bg-zinc-700 px-1 py-0.5 font-sans text-[11px] text-zinc-200\">{t.keys}</kbd>\n              </span>\n            </span>\n          ))}\n        </div>\n        <p className=\"p-5 text-sm leading-relaxed text-zinc-700\">The Saturday market moves to Mill Square from 3 November while the bridge is repaired.</p>\n      </div>\n    </section>\n  );\n}\n"}]}
