{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"tailwind-tooltip-css-with-arrow-on-four-sides","type":"registry:component","title":"Tailwind Tooltip CSS With Arrow On Four Sides","description":"Free Tailwind and CSS tooltip with an arrow on top, right, bottom or left, shown on hover and keyboard focus, linked with aria-describedby and closed by Escape.","dependencies":[],"files":[{"path":"components/we-inc/tailwind-tooltip-css-with-arrow-on-four-sides.tsx","type":"registry:component","content":"import { useState } from \"react\";\n\n// Pure Tailwind tooltips on four sides: shown by group-hover and group-focus-within, linked by aria-describedby, closed by Escape.\nconst tips = [\n  { id: \"tt1-a\", label: \"Copy link\", tip: \"Anyone with the link can view\", side: \"top\" },\n  { id: \"tt1-c\", label: \"Archive\", tip: \"Hidden from the board, not deleted\", side: \"right\" },\n  { id: \"tt1-b\", label: \"Export\", tip: \"Saves a PDF of this page\", side: \"left\" },\n  { id: \"tt1-d\", label: \"Pin\", tip: \"Keeps it first in the list\", side: \"bottom\" },\n] as const;\n\nconst place = {\n  top: { box: \"bottom-full left-1/2 mb-2.5 -translate-x-1/2 translate-y-1 group-hover:translate-y-0 group-focus-within:translate-y-0\", arrow: \"left-1/2 top-full -mt-1 -translate-x-1/2\" },\n  bottom: { box: \"top-full left-1/2 mt-2.5 -translate-x-1/2 -translate-y-1 group-hover:translate-y-0 group-focus-within:translate-y-0\", arrow: \"left-1/2 bottom-full -mb-1 -translate-x-1/2\" },\n  left: { box: \"right-full top-1/2 mr-2.5 -translate-y-1/2 translate-x-1 group-hover:translate-x-0 group-focus-within:translate-x-0\", arrow: \"left-full top-1/2 -ml-1 -translate-y-1/2\" },\n  right: { box: \"left-full top-1/2 ml-2.5 -translate-y-1/2 -translate-x-1 group-hover:translate-x-0 group-focus-within:translate-x-0\", arrow: \"right-full top-1/2 -mr-1 -translate-y-1/2\" },\n};\n\n// Each placement gets its own cell, with the button pushed away from the side its tooltip opens on.\nconst cell = {\n  top: \"items-end justify-center pb-5\",\n  bottom: \"items-start justify-center pt-5\",\n  left: \"items-center justify-end pr-5\",\n  right: \"items-center justify-start pl-5\",\n};\n\nexport default function TailwindTooltipCssWithArrowOnFourSides() {\n  const [closed, setClosed] = useState<string | null>(null);\n  // All four start visible so the preview shows them; the first pointer move or key press hands over to hover and focus.\n  const [demo, setDemo] = useState(true);\n  const stopDemo = () => demo && setDemo(false);\n  return (\n    <section className=\"bg-indigo-50 px-5 py-16\" onPointerMove={stopDemo} onKeyDown={stopDemo}>\n      <div className=\"mx-auto max-w-2xl rounded-2xl bg-white p-5 sm:p-8 shadow-sm ring-1 ring-indigo-100\">\n        <h2 className=\"text-center text-lg font-semibold text-slate-900\">Q3 roadmap board</h2>\n        <p className=\"mt-1 text-center text-sm text-slate-600\">Hover or tab to a button. Press Escape to hide its tooltip.</p>\n        <div className=\"mt-8 grid gap-3 sm:grid-cols-2\">\n          {tips.map((t) => (\n            <div key={t.id} className={`relative flex h-32 rounded-xl bg-slate-50 ring-1 ring-slate-200 ${cell[t.side]}`}>\n              <span className=\"absolute left-3 top-2 text-[11px] font-semibold uppercase tracking-wider text-slate-500\">{t.side}</span>\n              <span className=\"group relative inline-flex\" onMouseLeave={() => setClosed(null)}>\n                <button\n                  type=\"button\"\n                  aria-describedby={t.id}\n                  onBlur={() => setClosed(null)}\n                  onKeyDown={(e) => e.key === \"Escape\" && setClosed(t.id)}\n                  className=\"min-h-[44px] rounded-lg border border-slate-300 bg-white px-4 text-sm font-medium text-slate-800 hover:bg-slate-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-indigo-600\"\n                >\n                  {t.label}\n                </button>\n                <span\n                  role=\"tooltip\"\n                  id={t.id}\n                  className={`pointer-events-none absolute z-10 w-max max-w-[10rem] rounded-md bg-slate-900 px-2.5 py-1.5 text-xs font-medium leading-snug text-white opacity-0 shadow-lg transition duration-150 group-hover:opacity-100 group-focus-within:opacity-100 motion-reduce:transition-none ${place[t.side].box} ${demo && closed !== t.id ? \"!opacity-100\" : \"\"} ${closed === t.id ? \"!opacity-0\" : \"\"}`}\n                >\n                  {t.tip}\n                  <span aria-hidden=\"true\" className={`absolute h-2 w-2 rotate-45 bg-slate-900 ${place[t.side].arrow}`} />\n                </span>\n              </span>\n            </div>\n          ))}\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
