HoverCard
@codeui/styles v0.3.0
A card of extra detail next to a link, in plain HTML.
Load @codeui/styles/hovercard.css, or all.css. The Solid component is documented in HoverCard.
Demo
<div class="cui-stack" data-gap="1" data-align="start"> <a href="#thread" class="cui-link" data-cui="hovercard-trigger" data-expanded>Fix flaky hydration test</a> <div class="cui-hovercard-content" data-cui="hovercard-content" data-expanded> <strong>Fix flaky hydration test</strong> <span>Opened 2 hours ago · 3 subagents</span> </div></div>The demo renders the open card in normal flow, under its trigger. On a page, the card floats and your positioning code places it.
Markup
| Part | Element | Class | data-cui |
|---|---|---|---|
| Trigger | a with an href. It gets a dotted underline in the hint tone | none | hovercard-trigger |
| Content | div | cui-hovercard-content | hovercard-content |
| List | ul with an aria-label | cui-hovercard-list | hovercard-list |
| Entry | li | cui-hovercard-item | hovercard-item |
| State icon | span, 16px, always present | cui-hovercard-item-icon | hovercard-item-icon |
| Identifier | span | cui-hovercard-item-id | hovercard-item-id |
| Title | span, truncated | cui-hovercard-item-title | hovercard-item-title |
| Attribute | Values | Default |
|---|---|---|
data-expanded on the trigger | Presence, while the card is open. The dotted underline takes the text colour | Off |
data-expanded on the content | Presence | Off |
data-motion on the content | none | None |
List of entries
<div class="cui-hovercard-content" data-cui="hovercard-content" data-expanded data-motion="none"> <span class="cui-text" data-cui="text" data-weight="semibold">Migrate the kit to Solid 2</span> <ul class="cui-hovercard-list" data-cui="hovercard-list" aria-label="Tasks" tabindex="0"> <li class="cui-hovercard-item" data-cui="hovercard-item"> <span class="cui-hovercard-item-icon" data-cui="hovercard-item-icon" role="img" aria-label="Running"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="5.5" /><path d="M8 2.5a5.5 5.5 0 0 1 0 11z" fill="currentColor" /></svg></span> <span class="cui-hovercard-item-id" data-cui="hovercard-item-id">T-12</span> <span class="cui-hovercard-item-title" data-cui="hovercard-item-title">Migrate the kit to Solid 2</span> </li> <li class="cui-hovercard-item" data-cui="hovercard-item" style="--cui-hovercard-item-depth: 1"> <span class="cui-hovercard-item-icon" data-cui="hovercard-item-icon" role="img" aria-label="Done"></span> <span class="cui-hovercard-item-id" data-cui="hovercard-item-id">T-13</span> <span class="cui-hovercard-item-title" data-cui="hovercard-item-title">Port Popover and Tooltip to the new reactivity model</span> </li> <li class="cui-hovercard-item" data-cui="hovercard-item" style="--cui-hovercard-item-depth: 2"> <span class="cui-hovercard-item-icon" data-cui="hovercard-item-icon" role="img" aria-label="To do"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5"><circle cx="8" cy="8" r="5.5" /></svg></span> <span class="cui-hovercard-item-id" data-cui="hovercard-item-id">T-15</span> <span class="cui-hovercard-item-title" data-cui="hovercard-item-title">Keep keyboard opens free of motion</span> </li> </ul></div>One line per entry: state icon, identifier, then the title truncated. Set --cui-hovercard-item-depth on an entry to indent it 16px per level. The list caps at 24rem and scrolls on its own. Keep the icon span on a finished entry, empty, so the identifiers line up.
States
Open
data-expanded plays the pop-in: a fade from scale(0.96). The animation grows from --cui-popper-content-transform-origin, so set it to the side that faces the trigger.
Without data-expanded, the content plays its exit animation and stays transparent. Set it on an open card even without a script.
Closing
Remove data-expanded while the card is still in the page, and remove the card when the animation ends. data-motion="none" turns off both animations. Use it when the card opens from keyboard focus. With reduced motion, the card only fades.
What you supply
- Showing the card at once on a click or tap, and 500ms after the pointer rests on the trigger or the trigger gets focus, and hiding it 150ms after the pointer leaves the trigger and the card, on blur, and on Escape.
- Placement beside the trigger, on the right unless there is no room, then on the left, and
--cui-popper-content-transform-origin. - A focusable trigger. Nothing in the card may be the only way to reach an action: the card never takes focus.
Helper
import "@codeui/styles/hovercard.css";
import { hoverCardParts, hoverCardStyles } from "@codeui/styles/hovercard";
const card = document.querySelector<HTMLElement>("#thread-card")!;
card.className = hoverCardStyles.content();
card.dataset.cui = hoverCardParts.content;
// class="cui-hovercard-content" data-cui="hovercard-content"