Hover Card
A preview card that opens when you rest the pointer on a link, or focus it with the keyboard. Same markup and props in every style: switch the style in the header to see it change.
Profile preview
Rest the pointer on the name, or Tab to it. In HTML, add data-vin-hover-card and include vinui.js once.
Typography by @ada, who also wrote the first program.
Ada Lovelace
Mathematician. Wrote notes on the Analytical Engine, including the first published program.
<p class="vin-p">Typography by <a class="vin-link" href="#" data-vin-hover-card="hc-ada">@ada</a>, who also wrote the first program.</p>
<div class="vin-popover vin-hover-card" id="hc-ada" popover="manual">
<div class="vin-hover-card__header">
<span class="vin-avatar" role="img" aria-label="Ada Lovelace">
<img class="vin-avatar__img" src="/ui/avatars/ada.svg" alt="">
<span class="vin-avatar__fallback">AL</span>
</span>
<div>
<p class="vin-popover__title">Ada Lovelace</p>
<p class="vin-hover-card__meta">@ada</p>
</div>
</div>
<p class="vin-popover__description">Mathematician. Wrote notes on the Analytical Engine, including the first published program.</p>
<p class="vin-hover-card__meta"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4.5" width="18" height="16.5" rx="2.5"/><path d="M3 9.5h18M8 2.5v4M16 2.5v4"/></svg>Joined December 1815</p>
</div>Typography by @ada
Ada Lovelace
Mathematician. Wrote notes on the Analytical Engine, including the first published program.
import { HoverCard } from "@/components/vin/hover-card";
import { Avatar } from "@/components/vin/avatar";
import { Text } from "@/components/vin/typography";
export function HoverCardBasic() {
return (
<Text>
Typography by{" "}
<HoverCard trigger={<a className="vin-link" href="#">@ada</a>}>
<div className="vin-hover-card__header">
<Avatar name="Ada Lovelace" src="/ui/avatars/ada.svg" />
<div>
<p className="vin-popover__title">Ada Lovelace</p>
<p className="vin-hover-card__meta">@ada</p>
</div>
</div>
<p className="vin-popover__description">Mathematician. Wrote notes on the Analytical Engine, including the first published program.</p>
<p className="vin-hover-card__meta">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><rect x="3" y="4.5" width="18" height="16.5" rx="2.5" /><path d="M3 9.5h18M8 2.5v4M16 2.5v4" /></svg>
Joined December 1815
</p>
</HoverCard>
, who also wrote the first program.
</Text>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import HoverCard from "@/components/vin/hover-card.vue";
import Avatar from "@/components/vin/avatar.vue";
import { Text } from "@/components/vin/typography.vue";
</script>
<template>
<Text>
Typography by
<HoverCard>
<template #trigger><a class="vin-link" href="#">@ada</a></template>
<div class="vin-hover-card__header">
<Avatar name="Ada Lovelace" src="/ui/avatars/ada.svg" />
<div>
<p class="vin-popover__title">Ada Lovelace</p>
<p class="vin-hover-card__meta">@ada</p>
</div>
</div>
<p class="vin-popover__description">Mathematician. Wrote notes on the Analytical Engine, including the first published program.</p>
<p class="vin-hover-card__meta">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4.5" width="18" height="16.5" rx="2.5" /><path d="M3 9.5h18M8 2.5v4M16 2.5v4" /></svg>
Joined December 1815
</p>
</HoverCard>, who also wrote the first program.
</Text>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import HoverCard from "$lib/components/vin/hover-card.svelte";
import Avatar from "$lib/components/vin/avatar.svelte";
import Text from "$lib/components/vin/typography.svelte";
import Link from "$lib/components/vin/typography-link.svelte";
</script>
<Text>
Typography by
<HoverCard>
{#snippet trigger(props)}<Link href="#ada" {...props}>@ada</Link>{/snippet}
<div class="vin-hover-card__header">
<Avatar name="Ada Lovelace" src="/ui/avatars/ada.svg" />
<div>
<p class="vin-popover__title">Ada Lovelace</p>
<p class="vin-hover-card__meta">@ada</p>
</div>
</div>
<p class="vin-popover__description">Mathematician. Wrote notes on the Analytical Engine, including the first published program.</p>
<p class="vin-hover-card__meta">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="3" y="4.5" width="18" height="16.5" rx="2.5" /><path d="M3 9.5h18M8 2.5v4M16 2.5v4" /></svg>
Joined December 1815
</p>
</HoverCard>, who also wrote the first program.
</Text>Link preview
Preview a page before opening it.
Read the theming guide before you pick an accent colour.
Theming
Pick a style and any accent colour. Text on the accent stays readable in light and dark.
<p class="vin-p">Read the <a class="vin-link" href="#" data-vin-hover-card="hc-guide">theming guide</a> before you pick an accent colour.</p>
<div class="vin-popover vin-hover-card" id="hc-guide" popover="manual" data-side="top">
<p class="vin-popover__title">Theming</p>
<p class="vin-popover__description">Pick a style and any accent colour. Text on the accent stays readable in light and dark.</p>
<p class="vin-hover-card__meta"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="M12 7v5l3 2"/></svg>4 minute read</p>
</div>Read the theming guide
Theming
Pick a style and any accent colour. Text on the accent stays readable in light and dark.
import { HoverCard } from "@/components/vin/hover-card";
import { Text } from "@/components/vin/typography";
export function HoverCardLink() {
return (
<Text>
Read the{" "}
<HoverCard side="top" trigger={<a className="vin-link" href="#">theming guide</a>}>
<p className="vin-popover__title">Theming</p>
<p className="vin-popover__description">Pick a style and any accent colour. Text on the accent stays readable in light and dark.</p>
<p className="vin-hover-card__meta">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" /></svg>
4 minute read
</p>
</HoverCard>{" "}
before you pick an accent colour.
</Text>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import HoverCard from "@/components/vin/hover-card.vue";
import { Text } from "@/components/vin/typography.vue";
</script>
<template>
<Text>
Read the
<HoverCard side="top">
<template #trigger><a class="vin-link" href="#">theming guide</a></template>
<p class="vin-popover__title">Theming</p>
<p class="vin-popover__description">Pick a style and any accent colour. Text on the accent stays readable in light and dark.</p>
<p class="vin-hover-card__meta">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" /></svg>
4 minute read
</p>
</HoverCard>
before you pick an accent colour.
</Text>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import HoverCard from "$lib/components/vin/hover-card.svelte";
import Text from "$lib/components/vin/typography.svelte";
import Link from "$lib/components/vin/typography-link.svelte";
</script>
<Text>
Read the
<HoverCard side="top">
{#snippet trigger(props)}<Link href="#theming" {...props}>theming guide</Link>{/snippet}
<p class="vin-popover__title">Theming</p>
<p class="vin-popover__description">Pick a style and any accent colour. Text on the accent stays readable in light and dark.</p>
<p class="vin-hover-card__meta">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9" /><path d="M12 7v5l3 2" /></svg>
4 minute read
</p>
</HoverCard>
before you pick an accent colour.
</Text>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add hover-cardimport { HoverCard } from "@/components/vin/hover-card";import HoverCard from "@/components/vin/hover-card.vue";import HoverCard from "$lib/components/vin/hover-card.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.
API
From spec/hover-card.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
triggerThe link (or button) it previews. | ReactElement | — | a[data-vin-hover-card="card-id"] |
childrenThe card's content. Use the Popover title and description classes, an Avatar, and .vin-hover-card__meta for small details. | ReactNode | — | .vin-popover.vin-hover-card#card-id[popover=manual] |
side | bottomtopleftright | bottom | data-side on the card |
openDelay / closeDelayMilliseconds before it opens on hover and before it closes after the pointer leaves. | number | 500 / 300 | — |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<HoverCard> | .vin-hover-card.vin-hover-card__header.vin-hover-card__meta |
Accessibility
- Opens on hover after a short pause, and straight away on keyboard focus; Esc closes it.
- The pointer can move onto the card (to select text or follow a link in it) without it closing.
- It shows extra detail only: anything people need must also be on the page, because touch screens can't hover.
- Placed in the top layer, flipping to the other side when there's no room.
Customize
Saved in this browser. Style and accent are in the header.