# Tooltip

A short dark label for a control, shown when the pointer rests on it or keyboard focus reaches it. Built on ui-sdk's Tooltip: it names an icon button and describes anything else, closes on Escape, and opens in the top layer. Opens at once by default.

- Beta: ready to use; its API can still change in a minor release.
- Category: Overlays

```tsx
import { SimpleTooltip, Tooltip, TooltipTrigger, TooltipContent } from "@leap-crm/design-system";
```

## Best practices

- Do: Wrap an `IconButton` in `SimpleTooltip` for the common case: one label on one trigger, matching the button's `aria-label`.
- Do: Pick the delay from `tooltipDelay`: `quick` names a control, `deliberate` suits form help and editor buttons, `explanatory` explains a label already on screen.
- Do: Use `size="rich"` with `TooltipTitle`, `TooltipText` and `TooltipHint` for more than one line, like the time an opportunity has spent in a stage.
- Don't: Put a link, a button or the only copy of an error in a tooltip. It closes when the pointer moves away; use `Popover` for actions or `HoverCard` for a preview.
- Don't: Add a tooltip by hand to show a cut-off value. Use `Truncate`, which shows the whole value only while it is clipped.
- Don't: Colour custom tooltip text with `text-neutral-surface`. The tooltip stays dark in dark mode, so use `text-on-tooltip`, as its parts do.

## Keyboard

| Keys | What they do |
| --- | --- |
| Tab | Focus on the trigger shows the tooltip. |
| Escape | Closes the tooltip and leaves focus on the trigger. |

## Related

- [Hover Card](./hover-card.md)
- [Popover](./popover.md)
- [Truncate](./truncate.md)
- [Kbd](./kbd.md)

## Examples

What the examples import:

```tsx
import { Bold, Italic, Link, List, Save, Settings, Strikethrough, Underline } from "lucide-react";
import { Button, IconButton, SimpleTooltip, Tooltip, TooltipContent, TooltipHint, TooltipText, TooltipTitle, TooltipTrigger, tooltipDelay } from "@leap-crm/design-system";
```

Scaffolding the examples call. It lives in the docs page, not in the library:

```tsx
const formatting = [
  { label: "Bold", icon: <Bold />, shortcut: "mod+b" },
  { label: "Italic", icon: <Italic />, shortcut: "mod+i" },
  { label: "Underline", icon: <Underline />, shortcut: "mod+u" },
  { label: "Strikethrough", icon: <Strikethrough />, shortcut: undefined },
  { label: "Bulleted list", icon: <List />, shortcut: undefined },
  { label: "Link", icon: <Link />, shortcut: "mod+k" },
] as const;
```

### Icon buttons

The common case: SimpleTooltip around an IconButton. Move along the toolbar: once one tooltip is open, the next opens at once without animating, so nothing flickers. Shortcuts show in the platform's form.

```tsx
<div className="border-neutral-border flex gap-1 rounded-lg border p-1">
  {formatting.map(item => (
    <SimpleTooltip
      key={item.label}
      label={item.label}
      shortcut={item.shortcut}
    >
      <IconButton icon={item.icon} aria-label={item.label} size="sm" />
    </SimpleTooltip>
  ))}
</div>
```

### Rich

More than one line: a title with a quieter value, secondary lines and a hint. Used on pipeline stages and avatar groups, below the trigger with 8 px between.

```tsx
<Tooltip>
  <TooltipTrigger
    render={
      <Button intent="outline" size="sm">
        Enquired
      </Button>
    }
  />
  <TooltipContent size="rich" side="bottom" sideOffset={8}>
    <TooltipTitle meta="21d 6h">Enquired (Current)</TooltipTitle>
    <TooltipText>New enquiry, awaiting first contact.</TooltipText>
    <TooltipHint>Click to change</TooltipHint>
  </TooltipContent>
</Tooltip>
```

### Delays

Quick (0 ms) names controls. Deliberate (400 ms) is for form help and editor buttons the pointer crosses on its way past. Explanatory (650 ms) explains a label already on screen.

```tsx
<div className="flex flex-wrap gap-3">
  <SimpleTooltip label="Opens at once">
    <Button intent="outline">Quick</Button>
  </SimpleTooltip>
  <SimpleTooltip
    label="Opens after 400 ms"
    delay={tooltipDelay.deliberate}
  >
    <Button intent="outline">Deliberate</Button>
  </SimpleTooltip>
  <SimpleTooltip
    label="Opens after 650 ms"
    delay={tooltipDelay.explanatory}
  >
    <Button intent="outline">Explanatory</Button>
  </SimpleTooltip>
</div>
```

### Placement

Above the trigger and lined up with its start edge by default. It flips when there isn't room, and grows out of the side it opens from.

```tsx
<div className="flex flex-wrap gap-3 py-8">
  {(["top", "right", "bottom", "left"] as const).map(side => (
    <SimpleTooltip
      key={side}
      label={`Opens ${side}`}
      side={side}
      align="center"
    >
      <Button intent="outline" className="capitalize">
        {side}
      </Button>
    </SimpleTooltip>
  ))}
</div>
```

### Wrapping

A long label wraps at 320 px rather than running off the page.

```tsx
<SimpleTooltip label="Saves the agreement as a draft. Nothing is sent to the client until you press Send, and you can keep editing the draft from the opportunity workspace.">
  <IconButton
    intent="outline"
    icon={<Save />}
    aria-label="Save draft"
  />
</SimpleTooltip>
```

### Disabled

disabled keeps the trigger working but never opens the tooltip. A label of null, undefined or false renders the trigger alone.

```tsx
<div className="flex gap-3">
  <SimpleTooltip label="Settings" disabled>
    <IconButton icon={<Settings />} aria-label="Settings" />
  </SimpleTooltip>
  <SimpleTooltip label={null}>
    <Button intent="outline">No label</Button>
  </SimpleTooltip>
</div>
```

## Props

Tooltip also takes ui-sdk's Tooltip options (open, defaultOpen, onOpenChange, closeDelay, toggleable, closeOnPress, type, controller). TooltipContent takes its position props (collisionPadding, anchor, container), and TooltipTrigger takes render and payload.

### SimpleTooltip

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` (required) | `ReactNode` |  | What the tooltip says. Nothing (null, undefined or false) renders the trigger alone. |
| `children` (required) | `ReactElement` |  | The one element it labels, like an IconButton. |
| `disabled` | `boolean` |  | Keeps the trigger but never opens. |
| `delay` | `number` |  | How long the pointer rests before it opens. |
| `shortcut` | `string` |  | A keyboard shortcut to show after the label, like `"mod+s"`. |
| `side` | `TooltipContentProps["side"]` |  | Which side it opens on. It flips to the other when there isn't room. |
| `align` | `TooltipContentProps["align"]` |  | How it lines up along that side: start, center or end. |

### Tooltip

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `delay` | `number` | `0` | How long the pointer rests before it opens. |

### TooltipContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `size` | `"plain" \| "rich"` | `"plain"` | Plain for a short label. Rich for a title with lines under it, built from TooltipTitle, TooltipText and TooltipHint. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `side` | `TooltipContentProps["side"]` | `"top"` | Which side it opens on. It flips to the other when there isn't room. |
| `align` | `TooltipContentProps["align"]` | `"start"` | How it lines up along that side: start, center or end. |
| `sideOffset` | `unknown` | `4` | The gap between it and what it opens from, in pixels. |

### TooltipTitle

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` (required) | `ReactNode` |  | What it shows inside. |
| `meta` | `ReactNode` |  | A quieter value after the title. |

### TooltipText

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` (required) | `ReactNode` |  | What it shows inside. |

### TooltipHint

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` (required) | `ReactNode` |  | What it shows inside. |
