Skip to content

shadcn.io is an independent project built on shadcn/ui

Free

Event Preview Hover Card for React

Team Planning Session opens a card with an Upcoming badge, a short description, the date, a 90 minute slot, and 12 attendees.

The trigger is the name Team Planning Session. The card adds an Upcoming badge, a description of the quarterly planning meeting, Monday, January 15, 2024, 2:00 PM to 3:30 PM, and 12 attendees.

It belongs on a calendar or an agenda when the name is not enough. Touch screens have no hover, so a Popover is the stand-in. In React, Base UI keeps the card open while the pointer moves onto it.

Preview

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Hover Card anatomy: trigger, positioner, arrow, content

Usage

<HoverCard>
  <HoverCardTrigger
    closeDelay={100}
    delay={10}
    render={
      <button
        className="font-medium text-sm underline underline-offset-4"
        type="button"
      />
    }
  >
    Team Planning Session
  </HoverCardTrigger>
  <HoverCardContent className="w-80 max-w-full">
    <div className="flex flex-col gap-3">
      <div className="flex items-center justify-between">
        <h4 className="font-semibold text-sm">Team Planning Session</h4>
        <Badge variant="secondary">Upcoming</Badge>
      </div>
      <p className="text-muted-foreground text-sm">
        Quarterly planning meeting to discuss goals, priorities, and team
        alignment for Q1.
      </p>
      <div className="flex flex-col gap-2 text-muted-foreground text-sm">
        <div className="flex items-center gap-2">
          <CalendarIcon aria-hidden="true" className="size-4" />
          <span>Monday, January 15, 2024</span>
        </div>
        <div className="flex items-center gap-2">
          <ClockIcon aria-hidden="true" className="size-4" />
          <span>2:00 PM - 3:30 PM (90 min)</span>
{/* The rest of the file is under Installation. */}

FAQ

What is in the card?

The title with an Upcoming Badge, the description, then a calendar, a clock and a people icon, each beside its detail: Monday, January 15, 2024, 2:00 PM - 3:30 PM (90 min) and 12 attendees.

How is the event name made the trigger?

HoverCardTrigger takes the event name through render, a button with its classes.

How wide is the card?

w-80 on the card, for the extra content. The class is on HoverCardContent. max-w-full keeps it inside narrow screens.

How do I change how fast the card opens and closes?

The card opens a moment after the pointer rests on the trigger and stays up long enough for the pointer to move into it. Both delays are in milliseconds. The demo sets delay 10 and closeDelay 100 on HoverCardTrigger. side and align on HoverCardContent place it.

Does the card open from the keyboard and on touch screens?

Focusing the event name opens the card, moving focus away or pressing Escape closes it. Touch screens have no hover, so keep what matters reachable elsewhere, or use a Popover when the card has to open on a tap.

API Reference

Hover Card

No extra props in this demo. The rest is on the Hover Card page.

Badge

Sets variant="secondary". The rest is on the Badge page.