Overlays
Hover card
Previews what a link leads to, on hover or keyboard focus.
Installation
npx sinaui add hover-cardCopy src/lib/ui/HoverCard.svelte, floating.ts and tokens.css. No other dependencies.
Put the link in a <div> of text rather than a <p>: the
card sits right after its link, and a paragraph can't contain it.
Examples
Basic
Opens after a moment, so passing over the link doesn't flash it, and waits long enough to move onto the card. Tab moves into it; Escape closes it.
The theory of vision was rewritten by Ibn al-Haytham in the early 11th century.
Ibn al-Haytham c. 965 – c. 1040 · Basra and Cairo
Showed that we see because light enters the eye, and tested it by experiment in his Book of Optics.
Holdings: 4 manuscripts, Bayt al-Ḥikma reading room · Read more
<script lang="ts">
import Avatar from '#lib/ui/Avatar.svelte';
import HoverCard from '#lib/ui/HoverCard.svelte';
</script>
<!-- A div, not a p: a paragraph can't contain the card (the browser would split it). -->
<div class="text">
The theory of vision was rewritten by
<HoverCard>
{#snippet trigger(props)}
<a href="#basic" {...props}>Ibn al-Haytham</a>
{/snippet}
<div class="person">
<Avatar name="Ibn al-Haytham" decorative />
<div>
<strong>Ibn al-Haytham</strong>
<span class="dates">c. 965 – c. 1040 · Basra and Cairo</span>
</div>
</div>
<p class="about">
Showed that we see because light enters the eye, and tested it by experiment in his Book of
Optics.
</p>
<p class="more">
Holdings: 4 manuscripts, Bayt al-Ḥikma reading room · <a href="#basic">Read more</a>
</p>
</HoverCard>
in the early 11th century.
</div>
<style>
.text {
text-align: center;
}
.person {
display: flex;
align-items: center;
gap: 0.75rem;
}
.person div {
display: grid;
}
.dates,
.more {
color: var(--ui-muted);
font-size: 0.8125rem;
}
.about {
margin: 0.75rem 0 0.5rem;
}
.more {
margin: 0;
}
</style>Props
| Prop | Type | Default |
|---|---|---|
trigger | Snippet: your link, with the props spread on it | |
side | 'top' | 'bottom' | 'left' | 'right' | 'bottom' |
openDelay | number (ms) | 500 |
closeDelay | number (ms) | 250 |
Accessibility
- Extra detail only: touch has no hover, so everything in the card must be reachable another way (the link's own page).
- It opens on keyboard focus too, stays while the pointer or focus is on it, and Escape closes it (WCAG 1.4.13).
- It comes right after its link, so Tab moves into it and on through its links.