Hover card
Preview extra content when a link or element is hovered or focused.
SourceStyles source@monoline/react 0.5.0Markdown for AI toolsstable
- 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
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | – | Controlled open state. |
defaultOpen | boolean | false | Initial open state when uncontrolled. Default false. |
onOpenChange | ((open: boolean) => void) | – | Called with the next open state. |
openDelay | number | 700 | Milliseconds the pointer must rest on the trigger before the card opens. Default 700. |
closeDelay | number | 300 | Milliseconds before the card closes after the pointer leaves the trigger and the card. Default 300. |
children | ReactNode | – | 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.
| Attribute | Stylesheet |
|---|---|
[data-disabled] | popover.css |
[data-highlighted] | popover.css |
[data-variant="danger"] | popover.css |
CSS classes
| Class | Stylesheet |
|---|---|
.menu-content | popover.css |
.menu-indicator | popover.css |
.menu-item | popover.css |
.menu-item-check | popover.css |
.menu-label | popover.css |
.popover | popover.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.