Hover Card

Web

For sighted users to preview content available behind a link.

Installation

pnpm dlx cubix-ui@latest add hover-card --base aria

Usage

Import
import { CalendarIcon } from "lucide-react"

import { Avatar, AvatarFallback, AvatarImage } from "@/components/cubix/avatar"
import { Button } from "@/components/cubix/button"
import { HoverCard, HoverCardContent, HoverCardTrigger } from "@/components/cubix/hover-card"
Example
<HoverCard>
  <HoverCardTrigger render={<Button variant="link" />}>@maryam</HoverCardTrigger>
  <HoverCardContent className="w-72">
    <div className="flex gap-3">
      <Avatar size="lg" ring>
        <AvatarImage src="/docs/avatar/girl.jpg" alt="مریم رضایی" />
        <AvatarFallback>م</AvatarFallback>
      </Avatar>
      <div className="flex flex-col gap-3">
        <div className="flex flex-col gap-0.5">
          <p className="text-label font-semibold">مریم رضایی</p>
          <p className="text-label text-muted-foreground">@maryam</p>
        </div>
        <p className="text-label text-muted-foreground">طراح رابط کاربری و علاقه‌مند به سیستم‌های طراحی فارسی.</p>
        <div className="flex items-center gap-1.5 text-caption text-muted-foreground">
          <CalendarIcon className="size-3.5" />
          <span>عضو از مهر ۱۴۰۲</span>
        </div>
      </div>
    </div>
  </HoverCardContent>
</HoverCard>

Examples

Sides

Use side on HoverCardContent to place the card on the top, right, bottom, or left of the trigger.

Delay

Use openDelay and closeDelay on HoverCard to control how long the pointer must rest on, or leave, the trigger.

API Reference

Note: Hover cards open on hover and keyboard focus only, not on touch. Do not put content there that users cannot reach another way. Use Popover for click-triggered panels.

HoverCard

The container that wraps the trigger and content and manages open state and delays.

PropTypeDefaultDescription
openboolean-Controlled open state. Omit to use uncontrolled mode.
defaultOpenbooleanfalseInitial open state when uncontrolled.
onOpenChange(open: boolean) => void-Called when the open state changes.
openDelaynumber600Milliseconds to wait after hover or focus before opening.
closeDelaynumber300Milliseconds to wait after the pointer leaves before closing.
dir"ltr" | "rtl""rtl"Text direction for the card. Defaults to RTL. When omitted, follows the closest dir on the page.
childrenReact.ReactNode-The trigger and content elements.

HoverCardTrigger

The element that opens the card on hover or focus. Renders a link by default.

PropTypeDefaultDescription
renderReact.ReactElement-Render the trigger as another element, such as a Cubix Button or a link. Works on all three bases.
hrefstring-Link target when the trigger renders its default anchor.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).

HoverCardContent

The card rendered in a portal, positioned relative to the trigger.

PropTypeDefaultDescription
side"top" | "right" | "bottom" | "left""bottom"Preferred side of the trigger to render the card on.
align"start" | "center" | "end""center"Logical alignment along the other axis (start is the right edge in RTL).
sideOffsetnumber4Distance in pixels between the trigger and the card.
alignOffsetnumber0Offset in pixels away from the aligned edge.
classNamestring-Additional Tailwind classes merged with the component styles (last one wins).