Playground

Hover card

Preview extra content when a link or element is hovered or focused.

  • Built on native ARIA (shared positioning)
  • 3 parts, named exports
  • Opens on pointer hover and on keyboard focus of the trigger.
  • Supplementary only: never put the sole path to information or actions in it.
  • Not shown on touch devices; the trigger must work on its own.
  • Styles in one file: popover.css

Import

import '@monoline/css';
import {HoverCard} from '@monoline/react';

Not installed yet? Pick a route.

Copies the source and its styles into your project.

npx monoline add hover-card

Usage

import {HoverCard, HoverCardContent, HoverCardTrigger} from '@monoline/react';

<HoverCard>
  <HoverCardTrigger asChild>
    <a href="#ada">@ada</a>
  </HoverCardTrigger>
  <HoverCardContent>
    <strong>Ada Lovelace</strong>
    <p className="muted small">Wrote the first published program.</p>
  </HoverCardContent>
</HoverCard>

Anatomy

Import the parts you need and nest them like this.

import {HoverCard, HoverCardTrigger, HoverCardContent} from '@monoline/react';

<HoverCard>
  <HoverCardTrigger />
  <HoverCardContent />
</HoverCard>

Examples

Profile preview

Props

HoverCardProps

PropTypeDefaultDescription
openboolean–Controlled open state.
defaultOpenbooleanfalseInitial open state when uncontrolled. Default false.
onOpenChange((open: boolean) => void)–Called with the next open state.
openDelaynumber700Milliseconds the pointer must rest on the trigger before the card opens. Default 700.
closeDelaynumber300Milliseconds before the card closes after the pointer leaves the trigger and the card. Default 300.
childrenReactNode–The parts of the component: a trigger and its content.

Data Attributes

State is exposed through attributes. Style it with these selectors, not with class toggles.

AttributeStylesheet
[data-disabled]popover.css
[data-highlighted]popover.css
[data-variant="danger"]popover.css

CSS classes

ClassStylesheet
.menu-contentpopover.css
.menu-indicatorpopover.css
.menu-itempopover.css
.menu-item-checkpopover.css
.menu-labelpopover.css
.popoverpopover.css

Customization

Style it with the kit's tokens in your own CSS, loaded after @monoline/css. Prefer the attributes above over extra classes. See Theming for every token.

app.css
.menu-content {
  border-color: var(--accent);
}
.menu-content[data-disabled] {
  background: var(--wash);
}

Accessibility

  • Opens on pointer hover and on keyboard focus of the trigger.
  • Supplementary only: never put the sole path to information or actions in it.
  • Not shown on touch devices; the trigger must work on its own.