Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/hover-card-shared-surface.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@codeui/kit": minor
"@codeui/styles": minor
---

Hover cards share one card and move it between triggers.

- All the hover cards of a page share one card. Moving the pointer or keyboard focus to another trigger while a card is open moves that card at once: it slides to the new trigger, resizes to the new content, and fades the new content in. For 400ms after a card closes, the next one opens at once and without the pop. The move lasts 200ms (`--cui-motion-duration-panel`) with the kit's ease-out. While the pointer is on its way to the open card, another trigger it crosses takes the card only after 150ms of rest. A move from the keyboard swaps the content in place with no motion; with reduced motion only the new content fades in.
- `HoverCardGroup` gives the cards inside it a card of their own, with `skipDelayDuration` for the skip window. `shared={false}` gives one `HoverCard` its own surface; `forceMount` implies it.
- `HoverCardContent` is no longer polymorphic. Its `class`, `classes`, `style`, `ref`, `mount` and dismiss handlers go on the card; other attributes and event handlers go on a `display: contents` element around the children.
- `HoverCard` drops the Kobalte root options it never used (`id`). The trigger renders without a Kobalte popover anchor and still sets `data-expanded` and `data-closed`.
- Overlays opened by hover tell pointer from keyboard more reliably: the input tracker also records `pointerover`, which the browser fires before the `pointermove` that crosses into an element.
- A hover card opened from inside another card's content gets a surface of its own. The outer card stays open while the pointer is on the inner card and until it closes, and a press on the inner card does not close it.
- An `a` trigger (alone or `as={Link}`) has a dotted underline in the hint tone (`--cui-hovercard-trigger-decoration-color`) that takes the text colour on hover and while the card is open.
53 changes: 47 additions & 6 deletions apps/docs/content/docs/(kit)/components/hover-card.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ Put `HoverCardTrigger` and `HoverCardContent` in `HoverCard`. Hover the link, or

| Export | Renders | `classes` key | `data-cui` | Role |
| --- | --- | --- | --- | --- |
| `HoverCardGroup` | Nothing. Gives the cards inside it a surface of their own, optional | none | none | none |
| `HoverCard` | Nothing. Holds the open state and the timers | none | none | none |
| `HoverCardTrigger` | `a`, or the element passed to `as` | none | `hovercard-trigger` | Link |
| `HoverCardContent` | `div` in a portal on `mount`, or `document.body` | `content` | `hovercard-content` | none |
| `HoverCardContent` | The shared card, a `div` in a portal on `mount` or `document.body`, and a `display: contents` `div` around the children | `content` | `hovercard-content` | none |
| `HoverCardList` | `ul`, optional | none | `hovercard-list` | List |
| `HoverCardItem` | `li`, with an icon slot, an identifier and a title | `item`, `itemIcon`, `itemId`, `itemTitle` | `hovercard-item`, `hovercard-item-icon`, `hovercard-item-id`, `hovercard-item-title` | List item |

Expand All @@ -49,6 +50,36 @@ Put `HoverCardTrigger` and `HoverCardContent` in `HoverCard`. Hover the link, or
The card opens 500ms after the pointer enters or the trigger gets focus, and closes 150ms after the pointer leaves the trigger and the card. Change this with `openDelay` and `closeDelay`.
On its way from the trigger to the card, the pointer may cross the gap between them without closing the card. `ignoreSafeArea` turns that off.

Once one card is open, the next one opens at once. See [Moving between cards](#moving-between-cards).

### Moving between cards

<SolidDemo name="hover-card/shared" />

All the hover cards of a page share one card. When the pointer or keyboard focus moves to another trigger while a card is open, that card moves to the new trigger instead of closing while a second one opens: it slides to its new place, grows or shrinks to the new content, and the new content fades in. Each `HoverCard` keeps its own props, so the card takes the `placement`, `gutter`, class and handlers of the trigger it moves to.

- The move happens at once, without `openDelay`.
- For 400ms after a card closes, the next one still opens at once and without the pop.
- On its way to the open card, the pointer may cross another trigger. The card only moves when the pointer rests on that trigger for 150ms, so you can still reach the card you opened.
- When focus moves from the keyboard, the card swaps its content in place, with no motion.
- With reduced motion, the card stays in place and only the new content fades in.

Because the card is shared, only one hover card of the page is open at a time. A card that must stay open next to another needs its own surface: put it in a `HoverCardGroup` or pass `shared={false}`.

### Nested cards

A hover card inside the content of another one gets a surface of its own, without a group. Both cards stay open: the outer card waits while the pointer is on the inner card and until the inner card closes. A press on the inner card does not close the outer one. Escape closes the inner card first.

### Groups

<SolidDemo name="hover-card/group" />

`HoverCardGroup` gives the cards inside it a card of their own. Moving between triggers of the same group moves the group's card. The cards of a group never take over the page card or another group's card, so a card from each can be open at the same time. A card uses the nearest group above it; outside any group it uses the page card.

`skipDelayDuration` sets how long after a card of the group closes the next one still opens at once. The page card uses 400ms.

`shared={false}` gives one `HoverCard` a surface of its own, like a group with a single card. A card with `forceMount` always has its own.

### List of entries

<SolidDemo name="hover-card/list" />
Expand All @@ -67,12 +98,18 @@ A click opens the card at once, without `openDelay`. On a touch screen, the firs

### Controlled

Without `open`, the card manages its own state. To control it, pass `open` and `onOpenChange`.
Without `open`, the card manages its own state. To control it, pass `open` and `onOpenChange`. When another card takes over the shared surface, the card calls `onOpenChange(false)`.

## Ready API

Import from `@codeui/kit/hover-card` or from `@codeui/kit`.

### `HoverCardGroup`

Optional. Gives the cards inside it a surface of their own.

<PropsTable name="HoverCardGroup" />

### `HoverCard`

Holds the open state, the hover and focus timers, and the position.
Expand All @@ -87,9 +124,11 @@ Inherited from Kobalte's [popover](https://kobalte.dev/docs/core/components/popo

Renders an `a`. Give it an `href`, or render another focusable element with `as`, so keyboard users can reach it. An `a` without `href` cannot take focus.

A trigger that renders an `a`, alone or through `as={Link}`, has a dotted underline in the hint tone, so it reads as something to hover inside running text. The underline takes the text colour on hover and while the card is open. A trigger rendered as a button or a row keeps its own look.

### `HoverCardContent`

Portals the card to `document.body` and places it next to the trigger.
Renders its children into the shared card, which is portaled to `document.body` and placed next to the trigger. While this card is the one shown, its `class`, `classes`, `style`, `ref`, `mount` and dismiss handlers go on the card. Any other attribute or event handler, such as `id`, `aria-hidden` or `onPointerEnter`, goes on a `display: contents` element around the children.

<PropsTable name="HoverCardContent" />

Expand All @@ -115,7 +154,7 @@ One line in a `HoverCardList`.

| Key | Action |
| --- | --- |
| <kbd>Tab</kbd> | Moving focus to the trigger opens the card after `openDelay`. Moving focus away closes it. |
| <kbd>Tab</kbd> | Moving focus to the trigger opens the card after `openDelay`. Moving focus away closes it. Moving focus to another trigger while the card is open moves the card there at once. |
| <kbd>Enter</kbd> | Follows the link. A trigger rendered as a button opens the card. |
| <kbd>Escape</kbd> | Closes the card. Focus stays on the trigger. |

Expand All @@ -131,14 +170,15 @@ The card never takes focus. Focus stays on the trigger while it is open.

## SSR notes

The trigger renders on the server. The card renders on the client, and only while it is open.
The trigger renders on the server. The card renders on the client, and only while it is open. The page card is created the first time a card opens, in a `div` it appends to `document.body`.

## Theming hooks

`HoverCardContent` reads these variables. Set the `--cui-hovercard-content-*` ones on the card to change a single card. See [Tokens](/docs/foundations/tokens) for the defaults.

| Variable | Default | Used for |
| --- | --- | --- |
| `--cui-hovercard-trigger-decoration-color` | `--cui-text-hint` | Dotted underline of an `a` trigger, before hover |
| `--cui-hovercard-content-background` | `--cui-surface-dialog` | Fill |
| `--cui-hovercard-content-box-shadow` | `--cui-shadow-dialog` | Shadow, and the 1px ring in dark mode |
| `--cui-hovercard-content-radius` | `--cui-radius-card` | Radius (16px) |
Expand All @@ -150,8 +190,9 @@ The trigger renders on the server. The card renders on the client, and only whil
| `--cui-hovercard-item-indent` | `16px` | Indent per `depth` level |
| `--cui-hovercard-item-depth` | Set from `depth` | Nesting level of one entry |
| `--cui-motion-duration-normal`, `--cui-motion-duration-fast`, `--cui-motion-ease-out` | | Pop: in from `scale(0.96)` over 160ms, out to `scale(0.98)` over 120ms |
| `--cui-motion-duration-panel`, `--cui-motion-ease-out` | | Moving between cards: slide, resize and content fade over 200ms, ease-out |

A card opened by hover or click pops from the trigger side, with `transform-origin` from `--cui-popper-content-transform-origin`. A card opened by keyboard focus appears with no animation (`data-motion="none"`). With reduced motion, the card only fades.
A card opened by hover or click pops from the trigger side, with `transform-origin` from `--cui-popper-content-transform-origin`. A card opened by keyboard focus, or within 400ms of another card closing, appears with no animation (`data-motion="none"`). With reduced motion, the card only fades, and moving between cards only fades the new content in. Moving between cards from the keyboard has no motion.

## Related

Expand Down
3 changes: 2 additions & 1 deletion apps/docs/content/docs/css/components/hover-card.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The demo renders the open card in normal flow, under its trigger. On a page, the

| Part | Element | Class | `data-cui` |
| --- | --- | --- | --- |
| Trigger | `a` with an `href` | none | `hovercard-trigger` |
| 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` |
Expand All @@ -25,6 +25,7 @@ The demo renders the open card in normal flow, under its trigger. On a page, the

| 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 |

Expand Down
2 changes: 1 addition & 1 deletion apps/docs/content/docs/design/patterns.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ A picker opens over the panel that holds it, anchored to its row. It does not pu

A dialog is for settings and for decisions the user must make before continuing, such as reviewing detected secrets before an export. It is not for asking "are you sure?" about something that can be undone.

A tooltip is one line that names one thing. A description, or several facts about a row, goes in a hover card beside its trigger, on the right unless there is no room, wrapped at about 20rem. It opens on click too, so touch works, and everything in it is reachable another way. The `title` attribute is never used: it is slow, unstyled, and invisible to touch and keyboard. Use the kit [`HoverCard`](/docs/components/hover-card): it opens on hover, focus and click, sits on the right by default, and follows Pop.
A tooltip is one line that names one thing. A description, or several facts about a row, goes in a hover card beside its trigger, on the right unless there is no room, wrapped at about 20rem. It opens on click too, so touch works, and everything in it is reachable another way. The `title` attribute is never used: it is slow, unstyled, and invisible to touch and keyboard. Use the kit [`HoverCard`](/docs/components/hover-card): it opens on hover, focus and click, sits on the right by default, and follows Pop. Moving to the next trigger while a card is open moves that card instead of opening a second one: it slides to the new trigger and resizes to the new content. A trigger in running text has a dotted underline in the hint tone, so it reads as something to hover.

A list inside a menu or a hover card has one line per entry: state icon, identifier, title truncated. Nesting shows by indent, and a prefix that every entry shares is dropped. Two or more entries for the same action go in a submenu labelled with the count, so the menu does not fill up with "Open …" rows. A long list caps at about 24rem and scrolls on its own. In a hover card, build it with `HoverCardList` and `HoverCardItem`.

Expand Down
8 changes: 6 additions & 2 deletions apps/docs/export-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,9 @@
"HoverCardList": "components/hover-card#hovercardlist",
"HoverCardListProps": "components/hover-card#hovercardlist",
"TooltipDefaults": "components/tooltip#defaults-for-a-whole-app",
"TooltipProvider": "components/tooltip#defaults-for-a-whole-app"
"TooltipProvider": "components/tooltip#defaults-for-a-whole-app",
"HoverCardGroup": "components/hover-card#hovercardgroup",
"HoverCardGroupProps": "components/hover-card#hovercardgroup"
},
"@codeui/kit/accordion/parts": {
"AccordionClasses": "components/accordion#anatomy",
Expand Down Expand Up @@ -1260,7 +1262,9 @@
"HoverCardItem": "components/hover-card#hovercarditem",
"HoverCardItemProps": "components/hover-card#hovercarditem",
"HoverCardList": "components/hover-card#hovercardlist",
"HoverCardListProps": "components/hover-card#hovercardlist"
"HoverCardListProps": "components/hover-card#hovercardlist",
"HoverCardGroup": "components/hover-card#hovercardgroup",
"HoverCardGroupProps": "components/hover-card#hovercardgroup"
},
"@codeui/kit/resizable": {
"Resizable": "components/resizable#resizable",
Expand Down
51 changes: 51 additions & 0 deletions packages/docs-demos/src/demos/hover-card/group.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { For } from "solid-js";
import {
HoverCard,
HoverCardContent,
HoverCardGroup,
HoverCardTrigger,
Link,
Text,
} from "@codeui/kit";

const columns = [
{ name: "Files", items: ["fetch-retry.ts", "hover-card.tsx", "tokens.css"] },
{ name: "People", items: ["Ada Lovelace", "Grace Hopper", "Alan Turing"] },
];

export default function HoverCardGroups() {
return (
<div style={{ display: "flex", gap: "var(--cui-space-8)" }}>
<For each={columns}>
{column => (
<HoverCardGroup>
<div
style={{
display: "flex",
"flex-direction": "column",
"align-items": "flex-start",
gap: "var(--cui-space-2)",
}}
>
<Text weight="semibold">{column.name}</Text>
<For each={column.items}>
{item => (
<HoverCard>
<HoverCardTrigger as={Link} href={`#${item}`}>
{item}
</HoverCardTrigger>
<HoverCardContent>
<Text>
{item}, from the {column.name.toLowerCase()} group.
</Text>
</HoverCardContent>
</HoverCard>
)}
</For>
</div>
</HoverCardGroup>
)}
</For>
</div>
);
}
44 changes: 44 additions & 0 deletions packages/docs-demos/src/demos/hover-card/shared.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { For } from "solid-js";
import { HoverCard, HoverCardContent, HoverCardTrigger, Link, Text } from "@codeui/kit";

const threads = [
{
id: "fix-flaky",
title: "Fix flaky hydration test",
detail: "Codex · 2 hours ago · 3 subagents",
},
{ id: "port-popover", title: "Port Popover to Solid 2", detail: "Claude · yesterday" },
{
id: "docs-demos",
title: "Update the docs demos",
detail:
"Codex · 3 days ago · waiting for review. Checks every story in dark and light.",
},
];

export default function HoverCardShared() {
return (
<div
style={{
display: "flex",
"flex-direction": "column",
"align-items": "flex-start",
gap: "var(--cui-space-2)",
}}
>
<For each={threads}>
{thread => (
<HoverCard>
<HoverCardTrigger as={Link} href={`#${thread.id}`}>
{thread.title}
</HoverCardTrigger>
<HoverCardContent>
<Text weight="semibold">{thread.title}</Text>
<Text tone="muted">{thread.detail}</Text>
</HoverCardContent>
</HoverCard>
)}
</For>
</div>
);
}
22 changes: 20 additions & 2 deletions packages/docs-demos/src/props/hover-card.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
HoverCardContentProps,
HoverCardGroupProps,
HoverCardItemProps,
HoverCardProps,
} from "@codeui/kit";
Expand All @@ -8,9 +9,12 @@ import type { PropNotes } from "./notes";
/** Props that HoverCard adds or changes on Kobalte's popover root. */
export type HoverCard = Pick<
HoverCardProps,
"openDelay" | "closeDelay" | "ignoreSafeArea"
"openDelay" | "closeDelay" | "ignoreSafeArea" | "shared"
>;

/** Props of the group that gives its hover cards a surface of their own. */
export type HoverCardGroup = Pick<HoverCardGroupProps, "skipDelayDuration">;

/** Kobalte popover root options that change behavior. The kit sets the gutter default. */
export type HoverCardInherited = Pick<
HoverCardProps,
Expand Down Expand Up @@ -53,6 +57,18 @@ export const notes = {
default: "false",
description: "Closes as soon as the pointer leaves, even on its way to the card.",
},
shared: {
default: "true",
description:
"Shares one card with the page or the nearest HoverCardGroup. With false, the card has its own.",
},
},
HoverCardGroup: {
skipDelayDuration: {
default: "400",
description:
"Milliseconds after a card of the group closes during which the next one opens at once.",
},
},
HoverCardInherited: {
open: { description: "Controlled open state." },
Expand All @@ -68,7 +84,9 @@ export const notes = {
description: "Distance between the trigger and the card, in pixels.",
},
shift: { default: "0", description: "Offset along the trigger edge, in pixels." },
forceMount: { description: "Keeps the card in the DOM while it is closed." },
forceMount: {
description: "Keeps the card in the DOM while it is closed. The card gets a surface of its own.",
},
},
HoverCardContent: {
mount: { default: "document.body", description: "Node the card is portaled into." },
Expand Down
Loading
Loading