# Hover Card

A richer card than a tooltip, for previewing something without leaving the page: a contact, a summary. Built on ui-sdk's Hover Card: it opens at once on hover or keyboard focus, stays open while the pointer moves onto it, and Escape closes it. It sits against its trigger, and leaves as it arrived, in reverse.

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

```tsx
import { HoverCard, HoverCardTrigger, HoverCardContent } from "@leap-crm/design-system";
```

## Best practices

- Do: Use it to preview a record without leaving the page, like a contact's details on their name or the parties on an opportunity.
- Do: Pass a link or a name to `HoverCardTrigger`'s `render`, like a `TextLink`, so keyboard focus opens the card as well as hover.
- Do: Set `loading` while the content fetches. The small spinner card stays for at least one turn, then grows into the card.
- Do: Use `padding="card"` for text content, and leave it at `none` when the content sets its own, like a contact preview's status band.
- Don't: Put an action in it that the page doesn't also offer. It only opens on hover or focus, so a lawyer on touch may never see it.
- Don't: Use it for a one-line name or hint on a control. Use `SimpleTooltip`.

## Keyboard

| Keys | What they do |
| --- | --- |
| Tab | From the link, moves into the open card; out of the card, moves on past the link and closes it. |
| Shift + Tab | From the card, returns to the link. |
| Enter | Follows the link. |
| Escape | Closes the card and leaves focus on the link. |

## Related

- [Tooltip](./tooltip.md)
- [Popover](./popover.md)

## Examples

What the examples import:

```tsx
import { BriefcaseBusiness, Mail, Phone } from "lucide-react";
import { useState } from "react";
import { Avatar, Badge, HoverCard, HoverCardContent, HoverCardTrigger, TextLink } from "@leap-crm/design-system";
```

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

```tsx
const details = [
  { icon: <Mail />, label: "Email", value: "Not recorded" },
  { icon: <Phone />, label: "Phone", value: "0400 000 000" },
  { icon: <BriefcaseBusiness />, label: "Matter type", value: "Conveyancing" },
] as const;

function ContactPreview() {
  return (
    <div className="w-64">
      <div className="bg-neutral-surface-subtle flex h-10 items-center justify-end px-3">
        <Badge tone="info">Client</Badge>
      </div>
      <div className="flex flex-col gap-1 px-4 pb-4">
        <Avatar
          name="Ada Hartley"
          initials="AH"
          size="xl"
          className="ring-neutral-surface -mt-5 ring-2"
        />
        <span className="text-body font-book">Ada Hartley</span>
        <span className="text-caption text-neutral-text-muted">
          Client · Agency Purchase
        </span>
      </div>
      <ul className="border-neutral-divider m-0 flex list-none flex-col gap-2 border-t px-4 py-4">
        {details.map(detail => (
          <li key={detail.label} className="flex items-start gap-2">
            <span className="text-brand-navy mt-0.5 [&_svg]:size-3.5">
              {detail.icon}
            </span>
            <span className="flex flex-col">
              <span className="text-caption text-neutral-text-muted">
                {detail.label}
              </span>
              <span className="text-caption">{detail.value}</span>
            </span>
          </li>
        ))}
      </ul>
    </div>
  );
}

function Loading() {
  const [loading, setLoading] = useState(true);
  return (
    <HoverCard
      onOpenChange={open => {
        setLoading(true);
        if (open) setTimeout(() => setLoading(false), 400);
      }}
    >
      <HoverCardTrigger
        render={<TextLink href="/hover-card">Ada Hartley</TextLink>}
      />
      <HoverCardContent loading={loading}>
        <ContactPreview />
      </HoverCardContent>
    </HoverCard>
  );
}
```

### Contact preview

A 256 px card with a 36 px status band, a 40 px avatar over its edge, the name and a muted line, and detail rows with navy icons. No padding of its own: the content sets it.

```tsx
<HoverCard>
  <HoverCardTrigger
    render={<TextLink href="/hover-card">Ada Hartley</TextLink>}
  />
  <HoverCardContent>
    <ContactPreview />
  </HoverCardContent>
</HoverCard>
```

### Content card

padding="card" gives text content 16 / 12 padding.

```tsx
<HoverCard>
  <HoverCardTrigger
    render={<TextLink href="/hover-card">Phone call · 12 Nov</TextLink>}
  />
  <HoverCardContent padding="card" className="w-80">
    <span className="text-small font-book">Summary</span>
    <p className="text-small text-neutral-text-secondary m-0">
      Ada called about the settlement date and asked for the contract to
      be sent to her solicitor.
    </p>
  </HoverCardContent>
</HoverCard>
```

### Loading

While its data loads it's a 28 px card with a spinner; after at least one turn it grows into the card, easing its size without overshoot. Move away and it leaves as it arrived, in reverse. For feedback that follows the pointer while something fetches, use Fetch Cursor.

```tsx
<Loading />
```

## Props

HoverCard takes ui-sdk's options (open, defaultOpen, onOpenChange, delay, closeDelay, controller). HoverCardContent takes the position props (side, align, sideOffset, alignOffset, anchor, collisionPadding, keepMounted).

### HoverCard

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `delay` | `unknown` | `0` |  |

### HoverCardContent

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `children` | `ReactNode` |  | What it shows inside. |
| `padding` | `"none" \| "card"` | `"none"` | `card` for text content (16 / 12 padding); `none` when the content sets its own, like a contact preview's status band. |
| `loading` | `boolean` | `false` | Shows the 28 px loading card with a spinner while the content loads. It stays for at least one turn of the spinner, then grows into the card. |
| `className` | `string` |  | Classes added to the root element, merged with its own. Tokens only. |
| `side` | `unknown` | `"bottom"` | Which side it opens on. It flips to the other when there isn't room. |
| `align` | `unknown` | `"start"` | How it lines up along that side: start, center or end. |
