A link that shows a screenshot of the page it leads to when hovered, in a card that links there too. Built on Radix UI's Hover Card.
Read the Animate UI Docs — hover to preview, click to dive in.
Installation
It's built on Radix UI's Hover Card, a peer dependency of this primitive:
Usage
import {
PreviewLinkCard,
PreviewLinkCardContent,
PreviewLinkCardImage,
PreviewLinkCardPortal,
PreviewLinkCardTrigger,
} from '@animate-ui/react/primitives/radix-ui/preview-link-card';
export function DocsLink() {
return (
<PreviewLinkCard href="https://animate-ui.com/docs">
<PreviewLinkCardTrigger>Animate UI Docs</PreviewLinkCardTrigger>
<PreviewLinkCardPortal>
<PreviewLinkCardContent>
<PreviewLinkCardImage alt="Animate UI Docs" />
</PreviewLinkCardContent>
</PreviewLinkCardPortal>
</PreviewLinkCard>
);
}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
It is Animate UI's Hover Card, so the card moves exactly like it:
- Content grows from 0.8 and fades in, from the trigger (
--radix-hover-card-content-transform-origin), on a spring (stiffness 400, damping 29) that overshoots a little before it settles. - It opens after Radix's
openDelay(700ms by default) and, once itscloseDelayis over (300ms), closes the same way: it shrinks back to 0.8 on the same spring while it fades out, then unmounts. - Reopening while it closes picks up from where it is, on the same spring.
- Radix only opens it for mouse-like pointers: a tap on a touch screen follows the link, nothing sticks.
- With
followCursoron the Root, the card leans towards the pointer while it moves over the trigger, on a spring (stiffness 200, damping 17), as in v1. - Under reduced motion, it only fades (no scale).
API Reference
The parts take the props of Animate UI's Hover Card, so those of Radix UI's Hover Card, plus the ones below.
PreviewLinkCard
Hover Card's Root (openDelay, closeDelay, open, followCursor…), plus:
| Prop | Type | Default |
|---|---|---|
href | string | - |
src? | string | - |
width? | number | 240 |
height? | number | 135 |
deviceScaleFactor? | number | 1 |
colorScheme? | 'light' | 'dark' | 'light' |
PreviewLinkCardTrigger
Hover Card's Trigger: a link, to the Root's href unless it has its own.
PreviewLinkCardPortal, PreviewLinkCardArrow
Hover Card's Portal and Arrow.
PreviewLinkCardContent
Hover Card's Content (transition, exitTransition, side, align…), rendered as a link to the Root's href: it is the card, and its className styles it. With asChild, your element is rendered instead.
| Prop | Type | Default |
|---|---|---|
side? | 'top' | 'right' | 'bottom' | 'left' | 'top' |
sideOffset? | number | 10 |
align? | 'start' | 'center' | 'end' | 'center' |
href? | string | - |
target, rel, download, hrefLang, ping, referrerPolicy? | React.ComponentProps<'a'> | - |
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
- Radix UI's Hover Card.
- Inspired by Aceternity UI's Link Preview.