# Animated Tooltip

> React row of overlapping avatars where hovering or focusing one pops up a name and role card that tilts and slides with the pointer on springs.

- Kind: Motion component (Overlays)
- Docs: https://ui.minidev.pro/docs/animated-tooltip
- Source (registry JSON with the full file): https://ui.minidev.pro/r/animated-tooltip.json
- License: MIT. One file, yours to edit after install.

## When to use

The card rises on a spring, tilts a few degrees toward the pointer as it crosses the face, and settles back when it leaves. Keyboard focus opens the same card centred; Escape closes it; a tap toggles it on touch. Reduced motion shows and hides the card instantly with no tilt. Use it for team, contributor or "who's online" rows; for a tooltip on any trigger use Tooltip, and for a plain stacked row use AvatarGroup.

## Installation

### shadcn CLI (copies the source into your project)

```bash
npx shadcn@latest add @minidev/animated-tooltip
```

Writes `components/ui/animated-tooltip.tsx` and installs its npm dependencies. Older CLI versions: `npx shadcn@latest add https://ui.minidev.pro/r/animated-tooltip.json`.

### npm package

```bash
npm i minidev-ui-kit motion
```

Add the tokens to your global stylesheet once:

```css
@import "tailwindcss";
@import "minidev-ui-kit/styles.css";
@source "../node_modules/minidev-ui-kit";
```

Next.js also needs `transpilePackages: ["minidev-ui-kit"]` in next.config.

## Import

After the shadcn install:

```tsx
import { AnimatedTooltip } from "@/components/ui/animated-tooltip"
```

From the npm package:

```tsx
import { AnimatedTooltip } from "minidev-ui-kit/premium/animated-tooltip"
```

## Usage

```tsx
import { AnimatedTooltip } from "@/components/ui/animated-tooltip"

export function Example() {
  return (
    <AnimatedTooltip />
  )
}
```

## Props

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `people` | `AnimatedTooltipPerson[]` | - | no | People to show, left to right. Defaults to a five-person sample team. |
| `size` | `number` | `44` | no | Avatar diameter in pixels. |
| `defaultActive` | `number` | - | no | Index of a card to show before any hover. Defaults to the second person for the built-in sample only. |
| `onSelect` | `(person: AnimatedTooltipPerson, index: number) => void` | - | no | Called when an avatar is clicked or activated with the keyboard. |
| `className` | `string` | - | no |  |

## Examples

### Custom team

Pass people with a name and a role; initials come from the name when there is no image.

```tsx
<AnimatedTooltip
  people={[
    { name: "Maya Chen", role: "CFO, Northwind" },
    { name: "Theo Okafor", role: "Controller" },
    { name: "Priya Raman", role: "Accounts payable" },
    { name: "Sam Lowe", role: "Treasury" },
  ]}
/>
```

### Large avatars

size sets the diameter in pixels; initials overrides the letters taken from the name.

```tsx
<AnimatedTooltip
  size={56}
  defaultActive={0}
  people={[
    { name: "Northwind Traders", role: "Customer since 2021", initials: "NW" },
    { name: "Lumen Labs", role: "Customer since 2023", initials: "LL" },
    { name: "Okafor and Sons", role: "Customer since 2024", initials: "OS" },
  ]}
/>
```

### Select handler

onSelect fires on click or Enter with the person and their index, so the row can double as a picker.

```tsx
function AssignOwner() {
  const [owner, setOwner] = React.useState("Theo Okafor")
  return (
    <div className="flex flex-col items-center gap-4">
      <AnimatedTooltip
        people={[
          { name: "Maya Chen", role: "Founder" },
          { name: "Theo Okafor", role: "Engineering" },
          { name: "Priya Raman", role: "Design" },
          { name: "Sam Lowe", role: "Finance" },
        ]}
        defaultActive={1}
        onSelect={(p) => setOwner(p.name)}
      />
      <p className="text-sm text-fg-muted">
        INV-2041 is assigned to <span className="font-medium text-fg">{owner}</span>
      </p>
    </div>
  )
}
```

## Keyboard interactions

| Key | Action |
| --- | --- |
| `Tab` or `Shift+Tab` | Moves between avatars. Focusing one opens its card, centred with no tilt. |
| `Escape` | Closes the open card; focus stays on the avatar. |
| `Enter` or `Space` | Activates the focused avatar and calls `onSelect`. |

## Accessibility

- Each avatar is a `<button>` with `aria-label` "{name}, {role}", such as "Theo Okafor, Head of Engineering".
- The card has `role="tooltip"` but is `aria-hidden`, because the button's label already carries the same text.
- Under reduced motion the card shows and hides with no rise or tilt, and avatars do not grow on hover.

## FAQ

### How do I show photos instead of initials?

Pass `src` for each person. The image has `alt=""` because the button's `aria-label` already names the person. Without `src`, initials come from the first two words of `name`, or from `initials`.

### Why is the second person's card open on load?

Only with the built-in sample team: `defaultActive` falls back to 1 so the preview shows a card. When you pass `people`, no card opens until hover or focus, unless you set `defaultActive`.

### How does it behave on touch screens?

A tap opens the card and a second tap on the same avatar closes it. The lean and slide follow a mouse pointer only. `onSelect` fires on every tap or click.

## Rules for generating code

- Use semantic tokens only (bg, surface, sunken, border, fg, fg-muted, fg-subtle, ink, accent, success, warning, danger). Never raw hex or palette steps like blue-500.
- Shadows only from the set: shadow-xs, shadow-sm, shadow-raised, shadow-md, shadow-lg, shadow-overlay.
- Numbers use tabular-nums. Dark mode is the `dark` class on <html>; components never branch on theme.

## Dependencies

- npm: `motion`

## Related

- [Tooltip](https://ui.minidev.pro/docs/tooltip/md): React tooltip on Base UI with a provider for delay, a trigger, and content that positions on any side with an arrow and portal. Drop-in shadcn Tooltip API.
- [Avatar Group](https://ui.minidev.pro/docs/avatar-group/md): React avatar group that stacks overlapping avatars with tooltips, collapses extras into a +N chip with a popover list and falls back to tinted initials.
- [Alert Dialog](https://ui.minidev.pro/docs/alert-dialog/md): Shadcn style alert dialog on Base UI for confirmations that need an explicit answer. Modal backdrop, focus trap, title, description and an actions row.
- [Command Dialog](https://ui.minidev.pro/docs/command-dialog/md): Command dialog that opens the command palette in a modal from a list of commands with labels and handlers. Wire it to a Cmd K shortcut in your React app.
- [Confirm Destructive](https://ui.minidev.pro/docs/confirm-destructive/md): Destructive action confirm: a red trigger button opens a dialog with a title, warning text, Cancel and Confirm. Labels are configurable for deletes and resets.
- [Context Menu](https://ui.minidev.pro/docs/context-menu/md): Right click context menu that opens at the cursor with menu items, including destructive items in red. Closes on selection or click outside, in React.

---

All 557 components: https://ui.minidev.pro/llms.txt (full text: https://ui.minidev.pro/llms-full.txt).
