Documentation / Feedback & overlays
Tooltip
A lightweight tooltip: four positions, six colour variants, three sizes and an optional arrow. The content can be plain text or JSX. The bubble is rendered under the <body> of its trigger's document and placed against it: no parent in overflow: hidden cuts it, it goes to the other side when that has more room and stays inside the window, its arrow still pointing at the trigger.
Three opening modes through trigger:
"hover"(default): on hover and on keyboard focus, with an optionaldelay;"click": a click toggles it;"manual": display follows theopenprop, which you control.
The bubble carries role="tooltip". Keep it for supplementary information: essential or interactive content belongs in a Popover, a HelpButton or a modal. "use client" component.
Examples
Basic usage
The trigger is the child; content is the bubble’s text, shown above by default.
import { Button, Tooltip } from "@synertech/ui";
export function Basic() {
return (
<Tooltip content="Enregistre le brouillon sans le publier">
<Button>Enregistrer</Button>
</Tooltip>
);
}Positions
position places the bubble above, below, left or right of the trigger.
import { Button, Tooltip } from "@synertech/ui";
export function Positions() {
return (
<div className="flex flex-wrap items-center gap-6 p-12">
<Tooltip content="En haut" position="top">
<Button size="sm">Haut</Button>
</Tooltip>
<Tooltip content="En bas" position="bottom">
<Button size="sm">Bas</Button>
</Tooltip>
<Tooltip content="À gauche" position="left">
<Button size="sm">Gauche</Button>
</Tooltip>
<Tooltip content="À droite" position="right">
<Button size="sm">Droite</Button>
</Tooltip>
</div>
);
}Variants and sizes
variant colours the bubble by message; size sets the padding and type size, showArrow the arrow.
import { Tooltip } from "@synertech/ui";
export function Variants() {
return (
<div className="flex flex-wrap items-center gap-4 pt-12">
<Tooltip content="Clair" variant="light" size="sm">
<span className="text-sm underline decoration-dotted">light</span>
</Tooltip>
<Tooltip content="Quota presque atteint" variant="warning">
<span className="text-sm underline decoration-dotted">warning</span>
</Tooltip>
<Tooltip content="Synchronisation réussie" variant="success" showArrow={false}>
<span className="text-sm underline decoration-dotted">success</span>
</Tooltip>
<Tooltip content="Clé d’API invalide" variant="error" size="lg">
<span className="text-sm underline decoration-dotted">error</span>
</Tooltip>
</div>
);
}Delay, click and rich content
delay (in ms) avoids bubbles flickering as the mouse passes over; trigger="click" opens on click.
import { Button, Tooltip } from "@synertech/ui";
export function TriggersAndRichContent() {
return (
<div className="flex items-center gap-4 pt-24">
<Tooltip content="Apparaît après 500 ms" delay={500}>
<Button size="sm">Survol avec délai</Button>
</Tooltip>
<Tooltip
trigger="click"
variant="light"
maxWidth="max-w-sm"
content={
<div className="space-y-1">
<p className="font-semibold">Raccourcis</p>
<p>
<kbd>Ctrl</kbd> + <kbd>S</kbd> : enregistrer
</p>
</div>
}
>
<Button size="sm">Cliquez-moi</Button>
</Tooltip>
</div>
);
}Controlled display
With trigger="manual", the bubble follows open: useful to flag an input error.
import { useState } from "react";
import { Tooltip } from "@synertech/ui";
export function Controlled() {
const [code, setCode] = useState("");
const invalid = code.length > 0 && !/^\d{5}$/.test(code);
return (
<div className="pt-12">
<Tooltip
trigger="manual"
open={invalid}
variant="error"
position="right"
content="5 chiffres attendus"
>
<input
value={code}
onChange={(event) => setCode(event.target.value)}
placeholder="Code postal"
aria-invalid={invalid}
className="rounded-md border border-gray-300 px-3 py-2 text-sm"
/>
</Tooltip>
</div>
);
}API reference
Components
import { Tooltip } from "@synertech/ui";Props — TooltipProps
| Prop | Type | Default | Description |
|---|---|---|---|
children• |
ReactNode |
— | |
content• |
ReactNode |
— | |
contentClassName |
string |
— | |
delay |
number |
0 |
|
disabled |
boolean |
false |
|
maxWidth |
string |
"max-w-xs" |
|
offset |
number |
— | Distance between the trigger and the bubble, in pixels. Defaults to 8. |
open |
boolean |
— | |
position |
TooltipPosition |
"top" |
|
showArrow |
boolean |
true |
|
size |
TooltipSize |
"md" |
|
trigger |
TooltipTrigger |
"hover" |
|
variant |
TooltipVariant |
"default" |
+ 276 inherited native attributes from HTMLAttributes, AriaAttributes, DOMAttributes (className, id, aria-*, event handlers…).
Types
TooltipPosition
Typetype TooltipPosition = "top" | "bottom" | "left" | "right"TooltipSize
Typetype TooltipSize = "sm" | "md" | "lg"TooltipTrigger
Typetype TooltipTrigger = "hover" | "click" | "manual"TooltipVariant
Typetype TooltipVariant = "default" | "light" | "error" | "success" | "warning" | "info"