diff --git a/.github/design-surfaces.json b/.github/design-surfaces.json index daed549b2f1b..0ec0b4fd1f7f 100644 --- a/.github/design-surfaces.json +++ b/.github/design-surfaces.json @@ -2,6 +2,15 @@ "about": "Which source paths make up each UI surface, and the design spec that surface follows (one spec per surface, in leo-workspace design/.md). scripts/ci/pr_design_spec_check.py warns, never fails, when a pull request changes a surface's paths and its description does not cite the spec. leo-workspace tools/prior_art.py reads this map to list a surface's open and recently merged PRs before work starts. A path is a file or a directory (everything under it). Tests and gallery files are left out: changing them changes no design. Keep paths current when files move; the check warns about a mapped path that no longer exists.", "version": 1, "surfaces": { + "tooltips": { + "spec": "leo-workspace design/overlay-surfaces.md", + "aliases": ["tooltip", "hover preview", "tooltip hierarchy"], + "paths": [ + "webviews/src/ui/Tooltip.tsx", + "webviews/src/ui/titleTooltips.ts", + "webviews/src/ui/tooltipTokens.ts" + ] + }, "onboarding": { "spec": "leo-workspace design/onboarding.md", "aliases": ["onboarding", "bring your history", "memory import"], diff --git a/webviews/src/pages/shared/desktop.css b/webviews/src/pages/shared/desktop.css index c14ab1139884..314a6cf9faba 100644 --- a/webviews/src/pages/shared/desktop.css +++ b/webviews/src/pages/shared/desktop.css @@ -157,15 +157,15 @@ 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). */ + quicker than it came. Truncated text wraps inside the same compact bubble. */ .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; @@ -206,6 +206,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(--grid-base) calc(var(--grid-base) * 2); border-width: 1px; background: var(--surface-popup); -webkit-backdrop-filter: none; @@ -240,9 +241,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; @@ -546,6 +553,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: calc(var(--grid-base) * 80); + /* Compact overlay scale: all tooltip dimensions stay on the 4px grid and follow interface zoom. */ + --tooltip-edge: var(--grid-base); + --tooltip-pad-block: calc(var(--grid-base) / 2); + --tooltip-pad-inline: calc(var(--grid-base) * 2); + --tooltip-detail-gap: calc(var(--grid-base) / 2); } /* Reduce Motion: the tooltip still fades, with no rise. */ diff --git a/webviews/src/ui/Tooltip.gallery.css b/webviews/src/ui/Tooltip.gallery.css new file mode 100644 index 000000000000..c4dab454183b --- /dev/null +++ b/webviews/src/ui/Tooltip.gallery.css @@ -0,0 +1,28 @@ +.tooltip-gallery-stage { + display: grid; + place-items: center; + align-content: center; + gap: var(--ds-space-4); + min-height: calc(var(--ds-space-56) * 4); + 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 { + font-size: var(--text-body); +} diff --git a/webviews/src/ui/Tooltip.gallery.tsx b/webviews/src/ui/Tooltip.gallery.tsx new file mode 100644 index 000000000000..627e234459ed --- /dev/null +++ b/webviews/src/ui/Tooltip.gallery.tsx @@ -0,0 +1,74 @@ +// 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. +// l10n-allow-file: gallery fixture labels, not shipped UI. +import { Button } from "./Button"; +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 ( + +
+
+ Compact title and detail + The selected hierarchy: an emphasized title with a dimmer second line. +
+ + + +
+
+ ); + return ( + +
+
+ {mode === "above" ? "Above, compact" : "Below, compact"} + Content-sized bubble with the same glass and shared spacing scale. +
+ + + +
+
+ ); +} + +const hover: Play = async (ctx) => { + await ctx.hover({ role: "button", name: /Copy|Fork/ }); + await ctx.waitFor(() => { + const popup = ctx.document.querySelector('[role="tooltip"]'); + return popup && ctx.document.defaultView?.getComputedStyle(popup).opacity === "1"; + }); +}; + +export default componentEntry({ + 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: () => Promise.all([import("./Tooltip.gallery.css"), import("./controls.css")]), + variants: { + "above-compact": { props: { mode: "above" }, play: hover }, + "below-compact": { props: { mode: "below" }, play: hover }, + "title-detail": { props: { mode: "detail" }, play: hover }, + }, +}); diff --git a/webviews/src/ui/Tooltip.tsx b/webviews/src/ui/Tooltip.tsx index 40641f5b8af8..62865f103a42 100644 --- a/webviews/src/ui/Tooltip.tsx +++ b/webviews/src/ui/Tooltip.tsx @@ -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, tooltipGap, tooltipScale } from "./tooltipTokens"; /** * A page's tooltips wait the hover delay before the first shows, then show at once while the group @@ -27,8 +28,11 @@ export function TooltipProvider({ children }: { children: ReactNode }) { export interface TooltipProps { label: ReactNode; + /** Optional supporting text on a dimmer second line. */ + detail?: 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; @@ -36,7 +40,7 @@ export interface TooltipProps { className?: string; } -export function Tooltip({ label, children, side = "bottom", shortcut, className }: TooltipProps) { +export function Tooltip({ label, detail, children, side = "top", shortcut, className }: TooltipProps) { const container = usePortalContainer(); const host = usePopupHost(); const [trigger, setTrigger] = useState(null); @@ -44,15 +48,26 @@ export function Tooltip({ label, children, side = "bottom", shortcut, className // 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 * (popup ? tooltipScale(popup.ownerDocument) : 1), + kind: "tooltip", + wraps, + }); return ( - - + + {shortcut && {shortcut}} - {label} + {typeof label === "string" || typeof label === "number" ? ( + {label} + ) : ( + label + )} + {detail != null && {detail}} @@ -123,7 +138,7 @@ export function AnchoredCard({ anchor={virtualAnchor(anchor)} side={side} align="start" - sideOffset={6} + sideOffset={tooltipGap} > { - // Untruncated: the standard tooltip width. - expect(tooltipWidth({ width: 120, truncated: false, view: 1000 })).toEqual({ min: 0, max: 320 }); - // A truncated 600 px line: at least the line, wrapping up to it. - expect(tooltipWidth({ width: 600, truncated: true, view: 1000 })).toEqual({ min: 600, max: 600 }); - // 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 }); +test("full labels stay content-sized and bounded even on wide truncated rows", () => { + for (const width of [140, 600, 900]) { + for (const truncated of [false, true]) { + expect(tooltipWidth({ width, truncated, view: 1000 })).toEqual({ min: 0, max: 320 }); + } + } + expect(tooltipWidth({ width: 900, truncated: true, view: 200 })).toEqual({ min: 0, max: 192 }); + expect(tooltipWidth({ width: 900, truncated: true, view: 1000, scale: 1.25 })).toEqual({ + min: 0, + max: 400, + }); }); let dom: JSDOM | undefined; @@ -42,7 +42,7 @@ function page(body: string, options: Parameters[1] = { d return dom.window.document; } -test("hovering a truncated row shows its full text as wide as the row", async () => { +test("hovering a truncated row shows its full text without adopting the row width", async () => { const doc = page( `
A long…
`, ); @@ -54,15 +54,21 @@ test("hovering a truncated row shows its full text as wide as the row", async () const tip = doc.querySelector(".ui-title-tooltip")!; expect(tip.hidden).toBe(false); expect(tip.textContent).toBe("A long chat title that the sidebar row cuts off with an ellipsis"); - expect(tip.style.minWidth).toBe("600px"); - expect(tip.style.maxWidth).toBe("600px"); + expect(tip.style.minWidth).toBe("0px"); + expect(tip.style.maxWidth).toBe("320px"); }); test("a short title's tooltip for truncated text is only as wide as its text", () => { - // The line is 600 px but the full text measures 250 px: no wide empty box. - expect(tooltipWidth({ width: 600, truncated: true, view: 1000, text: 250 })).toEqual({ min: 250, max: 600 }); - // Text longer than the line: at least the line, as before. - expect(tooltipWidth({ width: 600, truncated: true, view: 1000, text: 2000 })).toEqual({ min: 600, max: 600 }); + // The source and text never impose a minimum width. + expect(tooltipWidth({ width: 600, truncated: true, view: 1000, text: 250 })).toEqual({ + min: 0, + max: 320, + }); + // Long text wraps and stays fully available. + expect(tooltipWidth({ width: 600, truncated: true, view: 1000, text: 2000 })).toEqual({ + min: 0, + max: 320, + }); }); test("a row whose child clips its text gets the truncated tooltip, sized to the text", async () => { @@ -87,8 +93,8 @@ test("a row whose child clips its text gets the truncated tooltip, sized to the await hover(row); const tip = doc.querySelector(".ui-title-tooltip")!; expect(tip.hidden).toBe(false); - expect(tip.style.minWidth).toBe("330px"); - expect(tip.style.maxWidth).toBe("600px"); + expect(tip.style.minWidth).toBe("0px"); + expect(tip.style.maxWidth).toBe("320px"); }); test("an untruncated control's tooltip keeps the standard width and shows its shortcut hint", async () => { @@ -253,7 +259,12 @@ test("a key typed while a toolbar hint waits drops it: it does not pop up mid-ty const doc = page(``, { clock, group }); // A toolbar hint (ui/Toolbar.tsx) in the same group, waiting its delay. const hint: string[] = []; - const toolbarHint = new HoverIntent({ group, clock, show: (id) => hint.push(id), hide: () => {} }); + const toolbarHint = new HoverIntent({ + group, + clock, + show: (id) => hint.push(id), + hide: () => {}, + }); toolbarHint.hover("Share"); clock.advance(200); doc.dispatchEvent(new dom!.window.KeyboardEvent("keydown", { key: "a", bubbles: true })); @@ -277,17 +288,23 @@ test("a tooltip near the right edge is measured at its full width, wherever the proto.getBoundingClientRect = function (this: HTMLElement) { if (!this.classList.contains("ui-title-tooltip")) return original.call(this); const left = parseFloat(this.style.left) || 0; - return { left, top: 0, width: Math.min(7 * (this.textContent ?? "").length, 1000 - left), height: 16 } as DOMRect; + return { + left, + top: 0, + width: Math.min(7 * (this.textContent ?? "").length, 1000 - left), + height: 16, + } as DOMRect; }; try { const tip = doc.querySelector(".ui-title-tooltip")!; await hover(close); - expect(tip.style.left).toBe(`${1000 - 6 - 35}px`); + expect(tip.style.left).toBe(`${1000 - UI_TOOLTIP_EDGE - 35}px`); close.dispatchEvent(new dom!.window.MouseEvent("pointerout", { bubbles: true })); await hover(summary); expect(tip.textContent).toBe("Chat summary"); - // As wide as its text (84 px), not squeezed into the 41 px right of the last tooltip's place. - expect(tip.style.left).toBe(`${1000 - 6 - 84}px`); + // The full 84px label now fits centered on the trigger, before the 4px edge clamp. + expect(tip.style.left).toBe(`${940 + 26 / 2 - 84 / 2}px`); + expect(tip.getBoundingClientRect().width).toBe(84); } finally { proto.getBoundingClientRect = original; } @@ -297,9 +314,16 @@ 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 }); + const scaled = tooltipPosition(time, size, view, "top", 1.5); + expect(time.top - (scaled.top + size.height)).toBe(UI_TOOLTIP_GAP * 1.5); + 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); }); diff --git a/webviews/src/ui/titleTooltips.ts b/webviews/src/ui/titleTooltips.ts index 8d094ccd865f..fc1bae0f5cc5 100644 --- a/webviews/src/ui/titleTooltips.ts +++ b/webviews/src/ui/titleTooltips.ts @@ -6,47 +6,34 @@ // a control with no other name keeps it as its `aria-label`. Controls built on ./Tooltip keep theirs. // A `data-tooltip-shortcut` shows after the text in the secondary ink, like the native tooltip's; // a `data-tooltip-detail` on a line under it, also secondary (Fork from here, Claude's). -// A `data-tooltip-side="top"` puts it above the element rather than below (a message's time). +// Above by default; `data-tooltip-side="bottom"` explicitly prefers below. // A `data-tooltip-anchor` (a selector) places it at that part of the element instead of the whole // 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`). +// Text the element cuts off shows in full, wrapping in the same compact bubble. import { HOVER_INTENT, HoverGroup, HoverIntent, tooltipGroup, type HoverClock } from "./hoverIntent"; +import { UI_TOOLTIP_GAP, UI_TOOLTIP_EDGE, UI_TOOLTIP_MAX_WIDTH, tooltipScale } from "./tooltipTokens"; +export { UI_TOOLTIP_EDGE, UI_TOOLTIP_MAX_WIDTH } from "./tooltipTokens"; -/// Room kept between the tooltip and the window's edges, and its gap from the element. -const EDGE = 6; -/// 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). +/// A scrolling row must settle before its tooltip opens under a resting pointer. const SCROLL_QUIET = 150; -const GAP = 6; 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; -/// 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; - -/// The tooltip's min and max width for an element `width` px wide in a `view` px window. A tooltip -/// for text the element cuts off shows it in full, wrapping, up to the element's width (at least -/// 480 px) and never narrower than the element's line, unless the full text (`text`, its width on -/// one line) is shorter: then it is just the text's width. Any other tooltip wraps at 320 px. Both -/// stay inside the window's edges. +/// A full label wraps inside the compact bubble; its source row never forces an empty wide box. export function tooltipWidth({ - width, - truncated, view, - text, + scale = 1, }: { width: number; truncated: boolean; view: number; text?: number; + scale?: number; }) { - const room = Math.max(0, view - 2 * EDGE); - if (!truncated) return { min: 0, max: Math.min(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) }; + return { + min: 0, + max: Math.min(UI_TOOLTIP_MAX_WIDTH * scale, Math.max(0, view - 2 * UI_TOOLTIP_EDGE * scale)), + }; } /// Whether `element` or anything inside it cuts its text off: a row can carry the title while its @@ -58,28 +45,30 @@ 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", + scale = 1, ) { - const below = anchor.top + anchor.height + GAP; - const above = anchor.top - GAP - size.height; + const gap = UI_TOOLTIP_GAP * scale; + const edge = UI_TOOLTIP_EDGE * scale; + const below = anchor.top + anchor.height + gap; + const above = anchor.top - gap - size.height; const top = side === "top" - ? above >= EDGE || below + size.height + EDGE > view.height - ? Math.max(EDGE, above) + ? above >= edge || below + size.height + edge > view.height + ? Math.max(edge, above) : below - : below + size.height + EDGE <= view.height + : below + size.height + edge <= view.height ? below - : Math.max(EDGE, above); + : 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(edge, centered), Math.max(edge, view.width - edge - size.width)); return { left: Math.round(left), top: Math.round(top) }; } @@ -183,7 +172,7 @@ export function installTooltips( tip.replaceChildren(hint, label, ...(note ? [note] : [])); } else tip.replaceChildren(label, ...(note ? [note] : [])); const anchor = anchorOf(target).getBoundingClientRect(); - const truncated = clips(target); + const scale = tooltipScale(doc); const fadeIn = !instant && (tip.hidden === true || ending !== undefined); endFade(); tip.toggleAttribute("data-instant", !fadeIn); @@ -193,19 +182,11 @@ export function installTooltips( // room right of it, and its text would wrap inside a word ("Chat summar / y"). tip.style.left = "0px"; tip.style.top = "0px"; - let natural: number | undefined; - if (truncated) { - // The full text's width on one line, so a short title gets no wide empty box. - tip.style.minWidth = "0"; - tip.style.maxWidth = "none"; - // Zero means no layout to measure (a detached or unrendered page): keep the line's width. - natural = tip.getBoundingClientRect().width || undefined; - } const width = tooltipWidth({ width: anchor.width, - truncated, + truncated: false, view: doc.documentElement.clientWidth, - text: natural, + scale, }); tip.style.minWidth = `${width.min}px`; tip.style.maxWidth = `${width.max}px`; @@ -213,7 +194,8 @@ 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", + scale, ); tip.style.left = `${position.left}px`; tip.style.top = `${position.top}px`; diff --git a/webviews/src/ui/tooltipTokens.ts b/webviews/src/ui/tooltipTokens.ts new file mode 100644 index 000000000000..056eb586e788 --- /dev/null +++ b/webviews/src/ui/tooltipTokens.ts @@ -0,0 +1,18 @@ +// Tooltip geometry follows the shared grid and the host's chrome interface scale. +import designScale from "../../../schemas/design-scale/design-scale.json"; + +export const UI_TOOLTIP_GAP = designScale.spacing.steps[0]!.px; +export const UI_TOOLTIP_EDGE = UI_TOOLTIP_GAP; +export const UI_TOOLTIP_MAX_WIDTH = UI_TOOLTIP_GAP * 80; + +export function tooltipScale(doc: Document): number { + const value = Number( + doc.defaultView?.getComputedStyle(doc.documentElement).getPropertyValue("--cmux-interface-scale"), + ); + return Number.isFinite(value) && value > 0 ? value : 1; +} + +// Base UI calls this only while placing an open tooltip; no observer or idle work. +export function tooltipGap(): number { + return UI_TOOLTIP_GAP * (typeof document === "undefined" ? 1 : tooltipScale(document)); +} diff --git a/webviews/test/inbox-group-hover-anchor-browser.test.ts b/webviews/test/inbox-group-hover-anchor-browser.test.ts index 86bd7aa0f397..b7fa6be0837c 100644 --- a/webviews/test/inbox-group-hover-anchor-browser.test.ts +++ b/webviews/test/inbox-group-hover-anchor-browser.test.ts @@ -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); diff --git a/webviews/test/tooltip-surface.test.ts b/webviews/test/tooltip-surface.test.ts index e4a2d6781216..8f15a7a9d89d 100644 --- a/webviews/test/tooltip-surface.test.ts +++ b/webviews/test/tooltip-surface.test.ts @@ -59,7 +59,10 @@ await requireBrowserLane("tooltip-surface.test.ts", async () => { `; async function open(style: string, body = toolbar, options: { reducedMotion?: "reduce" } = {}) { - const page = await browser.newPage({ viewport: { width: 500, height: 300 }, deviceScaleFactor: 2 }); + const page = await browser.newPage({ + viewport: { width: 500, height: 300 }, + deviceScaleFactor: 2, + }); if (options.reducedMotion) await page.emulateMedia({ reducedMotion: options.reducedMotion }); await page.setContent( `${body}`, @@ -299,7 +302,9 @@ await requireBrowserLane("tooltip-surface.test.ts", async () => { const tip = (await page.locator(".ui-title-tooltip").boundingBox())!; // A pixel of the surface inside the rim, left of the text's first glyph. const shot = PNG.sync.read( - await page.screenshot({ clip: { x: tip.x + 2, y: tip.y + tip.height / 2, width: 1, height: 1 } }), + await page.screenshot({ + clip: { x: tip.x + 2, y: tip.y + tip.height / 2, width: 1, height: 1 }, + }), ); const fill = [shot.data[0], shot.data[1], shot.data[2]]; const ratio = contrast(rgb(themes[name].text), fill); @@ -331,4 +336,41 @@ await requireBrowserLane("tooltip-surface.test.ts", async () => { expect(swift).toContain("static var shadow: Elevation { PopupStyle.elevation1 }"); expect(desktop).toContain("--tooltip-shadow: var(--elevation-1);"); }); + test("wide rows keep compact scaled bubbles close to the control with title/detail hierarchy", async () => { + for (const scale of [1, 1.25]) { + const page = await open( + theme("dark", `--cmux-interface-scale:${scale};`), + '', + ); + try { + await hoverAndWait(page, "wide"); + const seen = await page.evaluate(() => { + const tip = document.querySelector(".ui-title-tooltip")!; + tip.getAnimations().forEach((animation) => animation.finish()); + const rect = tip.getBoundingClientRect(); + const anchor = document.getElementById("wide")!.getBoundingClientRect(); + const title = getComputedStyle(tip.querySelector(".ui-tooltip-text")!); + const detail = getComputedStyle(tip.querySelector(".ui-tooltip-detail")!); + return { + width: rect.width, + gap: anchor.top - rect.bottom, + titleWeight: Number(title.fontWeight), + detailWeight: Number(detail.fontWeight), + titleColor: title.color, + detailColor: detail.color, + text: tip.textContent, + }; + }); + expect(seen.width).toBeLessThanOrEqual(320 * scale); + expect(seen.width).toBeLessThan(450); + // Placement rounds its top to a CSS pixel, including fractional scaled line heights. + expect(Math.abs(seen.gap - 4 * scale)).toBeLessThanOrEqual(0.5); + expect(seen.titleWeight).toBeGreaterThan(seen.detailWeight); + expect(seen.titleColor).not.toBe(seen.detailColor); + expect(seen.text).toContain("This one stays as it is."); + } finally { + await page.close(); + } + } + }); }); diff --git a/webviews/test/transcript-row-hover-scope.test.ts b/webviews/test/transcript-row-hover-scope.test.ts index 002875715ee9..64fe0d59bbdf 100644 --- a/webviews/test/transcript-row-hover-scope.test.ts +++ b/webviews/test/transcript-row-hover-scope.test.ts @@ -79,7 +79,7 @@ test("a transcript line with no action behind it never lifts on hover", () => { // `.cv-worked` is both the "Worked for" button and the live line's div: a state rule that // lights the line itself names the button. Revealing a control inside it is fine. const lit = subject(selector); - if (/\.cv-worked(?![\w-])/.test(lit) && !/^button\.cv-worked/.test(lit)) found.push(`${file}: ${selector}`); + if (/\.cv-worked(?![\w-])/.test(lit) && !lit.startsWith("button.cv-worked")) found.push(`${file}: ${selector}`); } expect(found).toEqual([]); });