Hover Card

For sighted users to preview content available behind a link.

Installation

CLI

bash
npx fivui add hover-card

Manual

Install the required dependencies:

bash
npm install @radix-ui/react-hover-card

The component uses Avatar and Button components.

Usage

tsx
import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
} from "@/components/ui/hover-card"
tsx
<HoverCard>
<HoverCardTrigger>Hover</HoverCardTrigger>
<HoverCardContent>
The React Framework – created and maintained by @vercel.
</HoverCardContent>
</HoverCard>

Examples

Profile Card

FL

Hover over the avatar

This demonstrates a hover card triggered by an avatar

tsx
import { CalendarDays } from "lucide-react"
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
import { Button } from "@/components/ui/button"
import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
} from "@/components/ui/hover-card"
export function HoverCardDemo() {
return (
<HoverCard>
<HoverCardTrigger asChild>
<Button variant="link">@nextjs</Button>
</HoverCardTrigger>
<HoverCardContent className="w-80">
<div className="flex justify-between space-x-4">
<Avatar>
<AvatarImage src="https://github.com/vercel.png" />
<AvatarFallback>VC</AvatarFallback>
</Avatar>
<div className="space-y-1">
<h4 className="text-sm font-semibold">@nextjs</h4>
<p className="text-sm">
The React Framework – created and maintained by @vercel.
</p>
<div className="flex items-center pt-2">
<CalendarDays className="mr-2 h-4 w-4 opacity-70" />{" "}
<span className="text-xs text-muted-foreground">
Joined December 2021
</span>
</div>
</div>
</div>
</HoverCardContent>
</HoverCard>
)
}

Link Preview

For help with your account, please contact or visit our help center.

tsx
import { CalendarDays } from "lucide-react"
import { Button } from "@/components/ui/button"
import {
HoverCard,
HoverCardContent,
HoverCardTrigger,
} from "@/components/ui/hover-card"
export function HoverCardLinkDemo() {
return (
<div className="space-y-2">
<p className="text-sm">
For help with your account, please contact{" "}
<HoverCard>
<HoverCardTrigger asChild>
<Button variant="link" className="p-0 h-auto text-sm">
support@example.com
</Button>
</HoverCardTrigger>
<HoverCardContent className="w-80">
<div className="space-y-2">
<h4 className="text-sm font-semibold">Support Team</h4>
<p className="text-sm">
Our support team is available 24/7 to help you with any questions or issues.
</p>
<div className="flex items-center pt-2">
<CalendarDays className="mr-2 h-4 w-4 opacity-70" />{" "}
<span className="text-xs text-muted-foreground">
Average response time: 2 hours
</span>
</div>
</div>
</HoverCardContent>
</HoverCard>
{" "}or visit our help center.
</p>
</div>
)
}

API Reference

HoverCard

PropTypeDefaultDescription
defaultOpenbooleanfalseThe open state of the hover card when it is initially rendered
openboolean-The controlled open state of the hover card
onOpenChangefunction-Event handler called when the open state changes
openDelaynumber700The duration from when the mouse enters the trigger until the hover card opens
closeDelaynumber300The duration from when the mouse leaves the trigger until the hover card closes

HoverCardContent

PropTypeDefaultDescription
align"start" | "center" | "end""center"The preferred alignment against the trigger
sideOffsetnumber4The distance in pixels from the trigger

External Documentation