A link that shows a screenshot of the page it leads to when hovered, in a card that links there too. Built on reka-ui's Hover Card.
Installation
It's built on reka-ui's Hover Card, a peer dependency of this primitive:
Usage
<script setup lang="ts">
import {
PreviewLinkCard,
PreviewLinkCardContent,
PreviewLinkCardImage,
PreviewLinkCardPortal,
PreviewLinkCardTrigger,
} from '@animate-ui/vue/primitives/reka-ui';
</script>
<template>
<PreviewLinkCard href="https://animate-ui.com/docs">
<PreviewLinkCardTrigger>Animate UI Docs</PreviewLinkCardTrigger>
<PreviewLinkCardPortal>
<PreviewLinkCardContent>
<PreviewLinkCardImage alt="Animate UI Docs" />
</PreviewLinkCardContent>
</PreviewLinkCardPortal>
</PreviewLinkCard>
</template>The screenshot comes from Microlink's API: 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 (
--reka-hover-card-content-transform-origin), on a spring (stiffness 400, damping 29) that overshoots a little before it settles. - It opens after reka-ui's
open-delay(700ms by default) and, once itsclose-delayis 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.
- reka-ui only opens it for mouse-like pointers: a tap on a touch screen follows the link, nothing sticks.
- With
follow-cursoron the Root, the card leans towards the pointer while it moves over the trigger, on a spring (stiffness 200, damping 17). - Under reduced motion, it only fades (no scale).
API Reference
The parts take the props of Animate UI's Hover Card, so those of reka-ui's Hover Card, plus the ones below.
PreviewLinkCard
Hover Card's Root (open-delay, close-delay, open, follow-cursor…), plus:
| Prop | Type | Default |
|---|---|---|
href | string | - |
src? | string | - |
width? | number | 240 |
height? | number | 135 |
device-scale-factor? | number | 1 |
color-scheme? | '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, exit-transition, side, align…), rendered as a link to the Root's href: it is the card, and its class styles it. With as-child, your element is rendered instead.
| Prop | Type | Default |
|---|---|---|
side? | 'top' | 'right' | 'bottom' | 'left' | 'top' |
side-offset? | number | 10 |
align? | 'start' | 'center' | 'end' | 'center' |
href? | string | - |
target, rel, download, hreflang, ping, referrerpolicy? | string | - |
PreviewLinkCardImage
| Prop | Type | Default |
|---|---|---|
alt? | string | 'preview image' |
...props? | ImgHTMLAttributes | - |
usePreviewLinkCard
Returns getters for the card's href, its image's src, width and height: for an image of your own.
Credits
- reka-ui's Hover Card.
- Inspired by Aceternity UI's Link Preview.