Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
20 changes: 17 additions & 3 deletions webviews/src/pages/shared/desktop.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,16 @@ body {
(ui/Tooltip.tsx), a toolbar hint (ui/Toolbar.tsx) and the title tooltip that replaces WebKit's
bubble on every first-party page (ui/titleTooltips.ts) all sit on the one tooltip surface
(--tooltip-*, below; Leo, 2026-10-14): frosted glass under a tint the primary ink reads on, a
one-device-pixel separator rim and a small tight shadow, in the caption font. The first of a warm
one-device-pixel separator rim and a small tight shadow, in the caption font. The title is an
emphasized first line and an optional detail sits below in dimmer ink. The first of a warm
group fades in and rises 2px; a warm neighbor's is there at once (data-instant); each fades out
quicker than it came. A truncated row's title tooltip is as wide as the row (tooltipWidth sets
its min and max width). */
.ui-tooltip,
.ui-title-tooltip {
box-sizing: border-box;
max-width: min(320px, calc(100vw - 12px));
padding: 4px 8px;
max-width: min(var(--tooltip-max-width), calc(100vw - var(--tooltip-edge) - var(--tooltip-edge)));
padding: var(--tooltip-pad-block) var(--tooltip-pad-inline);
border: var(--tooltip-rim-width) solid
var(--cmux-separator, color-mix(in srgb, var(--cmux-text, CanvasText) 12%, transparent));
border-radius: 5px;
Expand Down Expand Up @@ -206,6 +207,7 @@ body {
/* A hover card (ui/Tooltip.tsx AnchoredCard, .ui-tooltip.ui-card) with no glass (a link card) keeps
the solid popup surface and its own look; a toolbar hint (.ui-hint) is a tooltip. */
.ui-card {
padding: var(--ds-space-2);
border-width: 1px;
background: var(--surface-popup);
-webkit-backdrop-filter: none;
Expand Down Expand Up @@ -240,9 +242,15 @@ body {
/* A shortcut hint after the text, in the secondary ink, at the tooltip's top right. */
.ui-tooltip-detail {
display: block;
margin-block-start: var(--tooltip-detail-gap);
font-weight: var(--weight-regular);
color: var(--cmux-text-secondary, color-mix(in srgb, var(--cmux-text, CanvasText) 64%, transparent));
}

.ui-tooltip-text {
font-weight: var(--weight-emphasis);
}

.ui-tooltip-hint {
float: inline-end;
margin-inline-start: 8px;
Expand Down Expand Up @@ -546,6 +554,12 @@ label:not([for]):has(:is(input, select, textarea):disabled):not(
--tooltip-fade-in: var(--ui-popup-open, 120ms);
--tooltip-fade-out: var(--ui-popup-close, 80ms);
--tooltip-rise: 2px;
--tooltip-max-width: 320px;
/* Compact overlay scale: all tooltip dimensions stay on the 4px grid and follow interface zoom. */
--tooltip-edge: var(--ds-space-1);
--tooltip-pad-block: var(--grid-half-step);
--tooltip-pad-inline: var(--ds-space-2);
--tooltip-detail-gap: var(--grid-half-step);
}

/* Reduce Motion: the tooltip still fades, with no rise. */
Expand Down
39 changes: 39 additions & 0 deletions webviews/src/ui/Tooltip.gallery.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.tooltip-gallery-stage {
display: grid;
place-items: center;
align-content: center;
gap: var(--ds-space-4);
min-height: 220px;
padding: var(--ds-space-4);
color: var(--cmux-text, CanvasText);
font-family: var(--font-ui);
}

.tooltip-gallery-copy {
display: grid;
gap: var(--grid-half-step);
text-align: center;
color: var(--cmux-text-secondary, color-mix(in srgb, CanvasText 68%, transparent));
font-size: var(--text-detail);
}

.tooltip-gallery-copy strong {
color: var(--cmux-text, CanvasText);
font-size: var(--text-body);
font-weight: var(--weight-emphasis);
}

.tooltip-gallery-control {
min-width: var(--ds-control-row);
height: var(--ds-control-row);
padding-inline: var(--ds-space-3);
border: 0;
border-radius: var(--ds-radius-md);
background: var(--ds-color-hover);
color: inherit;
font: inherit;
}

.tooltip-gallery-control:hover {
background: var(--ds-color-pressed);
}
64 changes: 64 additions & 0 deletions webviews/src/ui/Tooltip.gallery.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Reference variants for the shared compact tooltip surface. The matrix captures the three
// placement/content choices beside the ChatGPT and Claude references; the shipped choice is the
// compact title/detail hierarchy with an above-first anchor.
import { Tooltip, TooltipProvider } from "./Tooltip";
import { componentEntry } from "../gallery/format";
import type { Play } from "../gallery/play";

type Props = { mode?: "above" | "below" | "detail" };

function TooltipGallery({ mode = "detail" }: Props) {
if (mode === "detail")
return (
<TooltipProvider>
<div className="tooltip-gallery-stage">
<div className="tooltip-gallery-copy">
<strong>Compact title and detail</strong>
<span>The selected hierarchy: an emphasized title with a dimmer second line.</span>
</div>
<button className="tooltip-gallery-control" title="Fork from here" data-tooltip-detail="Start a new thread">
Fork
</button>
</div>
</TooltipProvider>
);
return (
<TooltipProvider>
<div className="tooltip-gallery-stage">
<div className="tooltip-gallery-copy">
<strong>{mode === "above" ? "Above, compact" : "Below, compact"}</strong>
<span>Content-sized bubble with the same glass and shared spacing scale.</span>
</div>
<Tooltip label={mode === "above" ? "Copy response" : "Copy response"} side={mode === "above" ? "top" : "bottom"}>
<button className="tooltip-gallery-control">Copy</button>
</Tooltip>
</div>
</TooltipProvider>
);
}

const hover: Play = async (ctx) => {
await ctx.hover({ role: "button", name: /Copy|Fork/ });
};

export default componentEntry<Props>({
id: "ui.tooltip",
title: "Tooltip",
area: "UI primitives",
height: 260,
widths: { narrow: 360, normal: 560, wide: 820 },
anchors: [{ selector: ".tooltip-gallery-control" }],
checks: {
anchorMovePx: { value: 0, reason: "Showing a tooltip must not move its trigger." },
layoutShiftMax: { value: 0, reason: "The portaled tooltip must not shift the gallery stage." },
settleMaxMs: { value: 500, reason: "Tooltip hover uses the shared warm-group delay." },
},
covers: ["ui/Tooltip.tsx#Tooltip", "ui/titleTooltips.ts#installTooltips"],
load: async () => TooltipGallery,
styles: () => import("./Tooltip.gallery.css"),
variants: {
"above-compact": { props: { mode: "above" }, play: hover },
"below-compact": { props: { mode: "below" }, play: hover },
"title-detail": { props: { mode: "detail" }, play: hover },
},
});
22 changes: 17 additions & 5 deletions webviews/src/ui/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useEscapingPopup } from "./popupHost";
import { virtualAnchor, type UiAnchor } from "./Popover";
import { cx } from "./cx";
import { HOVER_INTENT } from "./hoverIntent";
import { UI_TOOLTIP_GAP } from "./anchor";

/**
* A page's tooltips wait the hover delay before the first shows, then show at once while the group
Expand All @@ -29,30 +30,41 @@ export interface TooltipProps {
label: ReactNode;
/** The control it describes (its `render` target). */
children: ReactElement;
/** Tooltips sit above their control when there is room, like the reference surfaces. */
side?: "top" | "bottom";
/** A keyboard shortcut shown after the label in the secondary ink (`⌘T`), as on native tooltips. */
shortcut?: string;
/** Extra classes on the popup (a hover card's own look, as `ui-card`). */
className?: string;
}

export function Tooltip({ label, children, side = "bottom", shortcut, className }: TooltipProps) {
export function Tooltip({ label, children, side = "top", shortcut, className }: TooltipProps) {
const container = usePortalContainer();
const host = usePopupHost();
const [trigger, setTrigger] = useState<HTMLElement | null>(null);
const [popup, setPopup] = useState<HTMLElement | null>(null);
// No room in the page (a tiny pane): past the window's edge, as a Mac tooltip (popupHost.ts). A
// hover card (`ui-card`) wraps its lines, so its width never sends it there.
const wraps = /(^|\s)ui-card(\s|$)/.test(className ?? "");
useEscapingPopup(host, popup, () => trigger, { side, align: "start", gap: 6, kind: "tooltip", wraps });
useEscapingPopup(host, popup, () => trigger, {
side,
align: "start",
gap: UI_TOOLTIP_GAP,
kind: "tooltip",
wraps,
});
return (
<BaseTooltip.Root>
<BaseTooltip.Trigger ref={host ? setTrigger : undefined} render={children} />
<BaseTooltip.Portal container={container}>
<BaseTooltip.Positioner className="ui-positioner" side={side} sideOffset={6}>
<BaseTooltip.Positioner className="ui-positioner" side={side} sideOffset={UI_TOOLTIP_GAP}>
<BaseTooltip.Popup ref={host ? setPopup : undefined} className={cx("ui-tooltip ui-glass", className)}>
{shortcut && <span className="ui-tooltip-hint">{shortcut}</span>}
{label}
{typeof label === "string" || typeof label === "number" ? (
<span className="ui-tooltip-text">{label}</span>
) : (
label
)}
</BaseTooltip.Popup>
</BaseTooltip.Positioner>
</BaseTooltip.Portal>
Expand Down Expand Up @@ -123,7 +135,7 @@ export function AnchoredCard({
anchor={virtualAnchor(anchor)}
side={side}
align="start"
sideOffset={6}
sideOffset={UI_TOOLTIP_GAP}
>
<BaseTooltip.Popup
ref={popupRef}
Expand Down
2 changes: 2 additions & 0 deletions webviews/src/ui/anchor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useLayoutEffect, useRef, useState, type CSSProperties, type RefObject }

/** The gap used by every anchored menu and popover. Keep this in one place. */
export const UI_ANCHOR_GAP = 6;
/** The compact tooltip sits on the 4px grid, closer than menus and popovers. */
export const UI_TOOLTIP_GAP = 4;

export type UiAnchorSide = "above" | "below";
export type UiAnchorAlign = "start" | "end";
Expand Down
18 changes: 12 additions & 6 deletions webviews/src/ui/titleTooltips.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import { afterEach, expect, jest, test } from "bun:test";
import { JSDOM } from "jsdom";
import { HoverGroup, HoverIntent } from "./hoverIntent";
import { installTooltips, tooltipPosition, tooltipWidth } from "./titleTooltips";
import { installTooltips, tooltipPosition, tooltipWidth, UI_TOOLTIP_EDGE, UI_TOOLTIP_MAX_WIDTH } from "./titleTooltips";
import { UI_TOOLTIP_GAP } from "./anchor";

test("a tooltip for truncated text wraps up to its source's width, never narrower than the line", () => {
// Untruncated: the standard tooltip width.
Expand All @@ -15,7 +16,7 @@ test("a tooltip for truncated text wraps up to its source's width, never narrowe
// A narrow truncated chip: up to 480 px.
expect(tooltipWidth({ width: 140, truncated: true, view: 1000 })).toEqual({ min: 140, max: 480 });
// Never wider than the window's room.
expect(tooltipWidth({ width: 900, truncated: true, view: 700 })).toEqual({ min: 688, max: 688 });
expect(tooltipWidth({ width: 900, truncated: true, view: 700 })).toEqual({ min: 692, max: 692 });
});

let dom: JSDOM | undefined;
Expand Down Expand Up @@ -297,9 +298,14 @@ test("a top-side tooltip (a message's time) sits above its element, below only w
const view = { width: 800, height: 600 };
const size = { width: 140, height: 22 };
const time = { left: 100, top: 300, width: 80, height: 24 };
// Centered on the time, 6px above it (as Claude's), and below by default.
expect(tooltipPosition(time, size, view, "top")).toEqual({ left: 70, top: 272 });
expect(tooltipPosition(time, size, view)).toEqual({ left: 70, top: 330 });
// Centered on the time, on the compact 4px grid gap above it (as Claude's), and above by default.
expect(tooltipPosition(time, size, view, "top")).toEqual({ left: 70, top: 274 });
expect(tooltipPosition(time, size, view)).toEqual({ left: 70, top: 274 });
// At the pane's top edge: below.
expect(tooltipPosition({ ...time, top: 10 }, size, view, "top")).toEqual({ left: 70, top: 40 });
expect(tooltipPosition({ ...time, top: 10 }, size, view, "top")).toEqual({ left: 70, top: 38 });
expect(UI_TOOLTIP_GAP).toBe(4);
expect(UI_TOOLTIP_EDGE).toBe(UI_TOOLTIP_GAP);
expect(UI_TOOLTIP_MAX_WIDTH).toBe(320);
const positioned = tooltipPosition(time, size, view);
expect(time.top - (positioned.top + size.height)).toBe(UI_TOOLTIP_GAP);
});
27 changes: 15 additions & 12 deletions webviews/src/ui/titleTooltips.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
// element: a row as wide as the pane shows its tooltip at its words, not under its middle.
// Text the element cuts off shows in full, as wide as the element (`tooltipWidth`).
import { HOVER_INTENT, HoverGroup, HoverIntent, tooltipGroup, type HoverClock } from "./hoverIntent";
import { UI_TOOLTIP_GAP } from "./anchor";

/// Room kept between the tooltip and the window's edges, and its gap from the element.
const EDGE = 6;
export const UI_TOOLTIP_EDGE = 4;
/// After a scroll, how long the page stays still before the element under the pointer shows its
/// tooltip: rows passing under a resting pointer show none (at once, each would flash by).
const SCROLL_QUIET = 150;
const GAP = 6;
const GAP = UI_TOOLTIP_GAP;

type Box = { left: number; top: number; width: number; height: number };

/// The standard tooltip's widest, the native one's (TooltipPanel.maxWidth).
const MAX_WIDTH = 320;
export const UI_TOOLTIP_MAX_WIDTH = 320;
/// The narrowest a truncated element's tooltip may wrap at, so a cut-off chip's text is not a column.
const TRUNCATED_MIN_MAX = 480;

Expand All @@ -42,8 +43,8 @@ export function tooltipWidth({
view: number;
text?: number;
}) {
const room = Math.max(0, view - 2 * EDGE);
if (!truncated) return { min: 0, max: Math.min(MAX_WIDTH, room) };
const room = Math.max(0, view - 2 * UI_TOOLTIP_EDGE);
if (!truncated) return { min: 0, max: Math.min(UI_TOOLTIP_MAX_WIDTH, room) };
const line = Math.ceil(width);
const min = text === undefined ? line : Math.min(line, Math.ceil(text));
return { min: Math.min(min, room), max: Math.min(Math.max(line, TRUNCATED_MIN_MAX), room) };
Expand All @@ -58,15 +59,14 @@ function clips(element: Element): boolean {
return false;
}

/// Where a `size` tooltip for `anchor` goes in a `view` window: below and centered, above when
/// there is no room below, and shifted to stay inside the edges. `side` "top" (an element's
/// `data-tooltip-side="top"`: a message's time, as Claude's) puts it above, below only when there
/// is no room above.
/// Where a `size` tooltip for `anchor` goes in a `view` window: above and centered by default, below
/// when there is no room above, and shifted to stay inside the edges. `side` "top" (the default,
/// and an element's `data-tooltip-side="top"`) puts it above, below only when there is no room above.
export function tooltipPosition(
anchor: Box,
size: { width: number; height: number },
view: { width: number; height: number },
side: "top" | "bottom" = "bottom",
side: "top" | "bottom" = "top",
) {
const below = anchor.top + anchor.height + GAP;
const above = anchor.top - GAP - size.height;
Expand All @@ -79,7 +79,10 @@ export function tooltipPosition(
? below
: Math.max(EDGE, above);
const centered = anchor.left + anchor.width / 2 - size.width / 2;
const left = Math.min(Math.max(EDGE, centered), Math.max(EDGE, view.width - EDGE - size.width));
const left = Math.min(
Math.max(UI_TOOLTIP_EDGE, centered),
Math.max(UI_TOOLTIP_EDGE, view.width - UI_TOOLTIP_EDGE - size.width),
);
return { left: Math.round(left), top: Math.round(top) };
}

Expand Down Expand Up @@ -213,7 +216,7 @@ export function installTooltips(
anchor,
tip.getBoundingClientRect(),
{ width: doc.documentElement.clientWidth, height: doc.documentElement.clientHeight },
target.getAttribute("data-tooltip-side") === "top" ? "top" : "bottom",
target.getAttribute("data-tooltip-side") === "bottom" ? "bottom" : "top",
);
tip.style.left = `${position.left}px`;
tip.style.top = `${position.top}px`;
Expand Down
2 changes: 1 addition & 1 deletion webviews/test/inbox-group-hover-anchor-browser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ await requireBrowserLane("inbox-group-hover-anchor-browser.test.ts", async () =>
return { rect: await box(tip), text: await tip.textContent() };
}

/** The tooltip sits just above or just below `anchor` (6px gap) and overlaps it horizontally. */
/** The tooltip sits just above or just below `anchor` (the compact 4px gap) and overlaps it horizontally. */
function expectAt(tip: Box, anchor: Box, what: string) {
const gap = Math.min(Math.abs(tip.top - anchor.bottom), Math.abs(anchor.top - tip.bottom));
const overlap = Math.min(tip.right, anchor.right) - Math.max(tip.left, anchor.left);
Expand Down