Hover Card
WebFor sighted users to preview content available behind a link.
Installation
pnpm dlx cubix-ui@latest add hover-cardUsage
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"
<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.
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | - | Controlled open state. Omit to use uncontrolled mode. |
| defaultOpen | boolean | false | Initial open state when uncontrolled. |
| onOpenChange | (open: boolean) => void | - | Called when the open state changes. |
| openDelay | number | 600 | Milliseconds to wait after hover or focus before opening. |
| closeDelay | number | 300 | Milliseconds 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. |
| children | React.ReactNode | - | The trigger and content elements. |
HoverCardTrigger
The element that opens the card on hover or focus. Renders a link by default.
| Prop | Type | Default | Description |
|---|---|---|---|
| render | React.ReactElement | - | Render the trigger as another element, such as a Cubix Button or a link. Works on all three bases. |
| href | string | - | Link target when the trigger renders its default anchor. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |
HoverCardContent
The card rendered in a portal, positioned relative to the trigger.
| Prop | Type | Default | Description |
|---|---|---|---|
| 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). |
| sideOffset | number | 4 | Distance in pixels between the trigger and the card. |
| alignOffset | number | 0 | Offset in pixels away from the aligned edge. |
| className | string | - | Additional Tailwind classes merged with the component styles (last one wins). |