Hover Card

A preview card shown on hover — richer than a tooltip, and pointer-only. There is a close delay as well as an open delay, so the pointer can travel into the card without it vanishing.

src/components/ui/hover-card.tsx

About

From the component's own source, where it was written.

A preview card shown on hover — richer than a tooltip, and pointer-only.

There is a close delay as well as an open delay, so the pointer can travel from the trigger into the card without it vanishing on the way.

Deliberately not keyboard-triggered: the content is supplementary, and a keyboard user reaches the same information by following the link. A Popover is the right component when the content must be reachable.

Install

npx astralyx-ui add hover-card

Usage

import { HoverCard } from '@/components/ui/hover-card'

<HoverCard content={<Profile user={user} />}>
  <a href={user.url}>@{user.handle}</a>
</HoverCard>

Composer

Change the props and the source below follows.

Props
tsx
<HoverCard side="bottom" openDelay={300} content={<Profile />}>
  <Button variant="link">@ada</Button>
</HoverCard>

Examples

On a link

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

HoverCard

A preview card shown on hover — richer than a tooltip, and pointer-only.

Extends Omit<ComponentProps<'div'>, 'content'>.

PropTypeDefaultDescription
childrenReactNoderequiredThe trigger, cloned rather than wrapped.
contentReactNoderequiredWhat the card shows.
sideSide'bottom'—
alignAlign'center'—
openDelaynumber300The close delay is what lets the pointer travel into the card.
closeDelaynumber200The close delay is what lets the pointer travel into the card.

Behaviour

TopicDetailDescription
keyboardnot triggeredDeliberately pointer-only — the content is supplementary. Use Popover when it must be reachable by keyboard.