Hover Card
Installation
npx @mielui/svelte add hover-cardyarn dlx @mielui/svelte add hover-cardbunx @mielui/svelte add hover-cardUsage
Put the link or label in Trigger and the preview in Content. The card opens on hover or keyboard focus and stays open while the pointer moves into it. Give Trigger an href to render a link; without one it renders a button that toggles the card. Bind open on Root to control it from outside.
Title and Description give the card a heading and supporting text. Trigger, Content, Title, and Description accept class; Root renders no element of its own.
<script lang="ts">
import * as HoverCard from '@mielui/svelte/components/hover-card';
</script>
<HoverCard.Root>
<HoverCard.Trigger href="https://github.com/mielsense">@mielsense</HoverCard.Trigger>
<HoverCard.Content>
<HoverCard.Title>mielsense</HoverCard.Title>
<HoverCard.Description>Maintains the shared components.</HoverCard.Description>
</HoverCard.Content>
</HoverCard.Root>Examples
User mention
A mention inside a sentence previews the profile, with a follow button in the card.
Link preview
Definition
Placement and timing
placement on Root picks the side of the trigger the card opens on, bottom by default, and an optional -start or -end aligns it to that edge, as in bottom-start. It flips to the opposite side when there is no room. sideOffset on Content sets the gap to the trigger in pixels, 8 by default.
delay and closeDelay on Root set how long the pointer rests before the card opens and how long it stays after the pointer leaves. They default to 200 and 150 milliseconds.
Glass surface
surface="glass" on Content gives the card a translucent, blurred background. Omit surface to inherit --mielui-surface from the theme, or set surface="solid" to override it. Glass falls back to an opaque fill when backdrop filtering is unavailable or reduced transparency is requested.
API reference
HoverCard.Root
Controls hover card state.
openBindablebooleanWhether it is open. Bind it to control the state from outside.
Default
falsedelaynumberMilliseconds the pointer rests on the trigger before the card opens.
Default
200closeDelaynumberMilliseconds after the pointer leaves before the card closes.
Default
150placementHoverCardPlacementPreferred side and alignment relative to the trigger, such as
bottom-start. It flips when there is no room.Default
'bottom'childrenSnippet<[]>Content rendered inside.
HoverCard.Content
Renders hover card content.
surface"solid" | "glass"Surface treatment. Omit it to inherit
--mielui-surfacefrom the theme.sideOffsetnumberGap between the trigger and the card, in pixels.
Default
8childrenSnippet<[]>Content rendered inside.
classstringClasses added to the element.
HoverCard.Description
Renders the hover card description.
classstringClasses added to the element.
childrenSnippet<[]>Content rendered inside.
HoverCard.Title
Renders the hover card title.
classstringClasses added to the element.
childrenSnippet<[]>Content rendered inside.
HoverCard.Trigger
Opens the hover card.
hrefstringDestination of the trigger link. The card previews it.
childrenSnippet<[]>Content rendered inside.
classstringClasses added to the element.
pnpm dlx @mielui/svelte add hover-card