A link that shows a screenshot of the page it leads to when hovered, in a card that links there too. Built on React Aria's PreviewTrigger and Popover.
Read the Animate UI Docs — hover to preview, click to dive in.
Installation
It's built on React Aria Components, a peer dependency of this primitive:
Usage
import {
PreviewLinkCard,
PreviewLinkCardImage,
PreviewLinkCardPopover,
PreviewLinkCardTrigger,
} from '@animate-ui/react/primitives/react-aria/preview-link-card';
export function DocsLink() {
return (
<PreviewLinkCard href="https://animate-ui.com/docs">
<PreviewLinkCardTrigger>Animate UI Docs</PreviewLinkCardTrigger>
<PreviewLinkCardPopover>
<PreviewLinkCardImage alt="Animate UI Docs" />
</PreviewLinkCardPopover>
</PreviewLinkCard>
);
}Animate UI v1 had no React Aria version: this one has the parts of the Radix UI and Base UI ones, the React Aria way. The Root is a PreviewTrigger (delay, closeDelay, isOpen…), the trigger a Link, and the card a Popover (placement, offset…), which portals itself: there is no Portal part.
The screenshot comes from Microlink's API, as in Animate UI v1: it captures href on a mobile viewport three times the image's size. Pass src to show an image of your own instead. Either way, it's preloaded (a <link rel="preload"> in the head) as soon as the card mounts, so it's there when the card opens.
Animation
The card is Animate UI's Popover under a PreviewTrigger, so it moves exactly like the Hover Card:
- Popover grows from 0.8 and fades in, from the link (
--trigger-anchor-point), on a spring (stiffness 400, damping 29) that overshoots a little before it settles. - It opens after the
delay(600ms by default) and, once thecloseDelayis over (200ms), closes the same way: it shrinks back to 0.8 on the same spring while it fades out, then unmounts. - Moving straight from one preview to the next during
PreviewTrigger's warmup swaps them without animation, as React Aria intends. - React Aria opens it on hover for pointer input, after a delay on keyboard focus, and on a long press: nothing sticks on touch screens.
- Under reduced motion, it only fades (no scale).
API Reference
PreviewLinkCard
React Aria's PreviewTrigger props (delay, closeDelay, isOpen, onOpenChange…), plus:
| Prop | Type | Default |
|---|---|---|
href | string | - |
src? | string | - |
width? | number | 240 |
height? | number | 135 |
deviceScaleFactor? | number | 1 |
colorScheme? | 'light' | 'dark' | 'light' |
PreviewLinkCardTrigger
React Aria's Link props: a link, to the Root's href unless it has its own.
PreviewLinkCardPopover
Animate UI's Popover (transition, exitTransition, placement…), filled with a Link to the Root's href: the Popover is the card, and its className styles it.
| Prop | Type | Default |
|---|---|---|
placement? | Placement | 'top' |
offset? | number | 10 |
href? | string | - |
target, rel, download, hrefLang, ping, referrerPolicy? | LinkProps | - |
PreviewLinkCardImage
| Prop | Type | Default |
|---|---|---|
alt? | string | 'preview image' |
...props? | Omit<React.ComponentProps<'img'>, 'src' | 'width' | 'height'> | - |
usePreviewLinkCard
Returns the card's href, its image's src, width and height: for an image of your own.
Credits
- React Aria's
PreviewTrigger. - Inspired by Aceternity UI's Link Preview.