HoverCard

A rich preview shown while hovering or focusing a link, such as a user or repository card.

Status: beta. Category: Overlays.

import { HoverCard, HoverCardTrigger, HoverCardContent } from '@glyphui/ui'

Exports: HoverCard, HoverCardTrigger, HoverCardContent, hoverCardStyles.

Notes

  • Touch and screen-reader users may never see a hover card. Keep it a preview of information that is also available on the linked page.
  • Use Tooltip for a short text label and Popover for interactive content opened by click.

HoverCardContent props

PropTypeDefaultDescription
asChildboolean

Example: User preview

import { Avatar, Badge, HoverCard, HoverCardContent, HoverCardTrigger, Text } from '@glyphui/ui'
import { CalendarDays } from 'lucide-react'

export default function Example() {
  return (
    <Text>
      Reviewed by{' '}
      <HoverCard>
        <HoverCardTrigger
          href="#ada"
          className="font-medium text-primary-text underline decoration-primary-text/40 underline-offset-4 hover:decoration-primary-text"
        >
          @ada
        </HoverCardTrigger>
        <HoverCardContent>
          <div className="flex gap-3">
            <Avatar name="Ada Lovelace" size="lg" />
            <div className="grid gap-1">
              <div className="flex items-center gap-2">
                <span className="font-medium">Ada Lovelace</span>
                <Badge tone="primary">Admin</Badge>
              </div>
              <Text size="small" tone="muted">
                Engineering lead. Owns the analytics engine and the design system.
              </Text>
              <span className="flex items-center gap-1.5 text-caption text-faint-foreground">
                <CalendarDays className="size-3.5" aria-hidden="true" />
                Joined March 2021
              </span>
            </div>
          </div>
        </HoverCardContent>
      </HoverCard>{' '}
      2 hours ago.
    </Text>
  )
}

Example: Delays

openDelay and closeDelay tune how eager it is.

import { HoverCard, HoverCardContent, HoverCardTrigger, Text } from '@glyphui/ui'
import { GitPullRequest } from 'lucide-react'

export default function Example() {
  return (
    <Text>
      Fixed in{' '}
      <HoverCard openDelay={150} closeDelay={100}>
        <HoverCardTrigger
          href="#pr-482"
          className="font-mono text-primary-text underline decoration-primary-text/40 underline-offset-4 hover:decoration-primary-text"
        >
          #482
        </HoverCardTrigger>
        <HoverCardContent side="top" className="w-80">
          <div className="flex gap-3">
            <GitPullRequest className="mt-0.5 size-4 shrink-0 text-success" aria-hidden="true" />
            <div className="grid gap-1">
              <span className="text-small font-medium">
                Keep badges at content width in flex columns
              </span>
              <span className="text-caption text-muted-foreground">
                khalmohak merged 3 commits into main
              </span>
            </div>
          </div>
        </HoverCardContent>
      </HoverCard>
      .
    </Text>
  )
}

Live page: https://glyphui.xyz/components/hover-card