Tooltips open at once and take rich content; item icons say what they mean on hover

The app's Tooltip replaces the browser title: no delay, an optional bold title over any content, TipLines for a few lines of detail, and it stays on screen at the edges.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
David Mann committed 2026-11-17 00:00:58 +01:00
1 parent d656f897b3
commit ff4feeca4d
3 files changed
+60 -16

No files matched your search

+1 -1
View File
@@ -47,7 +47,7 @@ function App({ api }: { api: Api }) {
<QueryClientProvider client={queryClient}>
<LiveProvider source={source}>
<UserContext.Provider value={user}>
<Tooltip.Provider delayDuration={300}>
<Tooltip.Provider delayDuration={0} skipDelayDuration={0}>
<BrowserRouter>
<AppShell />
</BrowserRouter>
+20 -12
View File
@@ -1,24 +1,32 @@
import { CheckCircleIcon, CircleIcon, GitMergeIcon, GitPullRequestIcon, RadioButtonIcon, type Icon as PhosphorIcon } from "@phosphor-icons/react";
import type { ItemKind, ItemState } from "../../api/types";
import { cn } from "../cn";
import { Tooltip } from "./Tooltip";
/** Phosphor icon and colour for an item, as GitHub shows its state. */
function look(kind: ItemKind | null | undefined, state: ItemState | null | undefined, draft: boolean | undefined): [PhosphorIcon, string, string] {
function look(kind: ItemKind | null | undefined, state: ItemState | null | undefined, draft: boolean | undefined): [PhosphorIcon, string, string, string] {
if (kind === "pr") {
if (state === "merged") return [GitMergeIcon, "text-merged", "merged PR"];
if (state === "closed") return [GitPullRequestIcon, "text-bad", "closed PR"];
return draft ? [GitPullRequestIcon, "text-ink/60", "draft PR"] : [GitPullRequestIcon, "text-ok", "open PR"];
if (state === "merged") return [GitMergeIcon, "text-merged", "Merged pull request", "Its changes are in the base branch."];
if (state === "closed") return [GitPullRequestIcon, "text-bad", "Closed pull request", "Closed without merging."];
return draft
? [GitPullRequestIcon, "text-ink/60", "Draft pull request", "Open, but its author marked it as not ready for review."]
: [GitPullRequestIcon, "text-ok", "Open pull request", "Proposed changes, not merged yet."];
}
if (kind === "issue") return state === "closed" ? [CheckCircleIcon, "text-merged", "closed issue"] : [RadioButtonIcon, "text-ok", "open issue"];
return [CircleIcon, "text-ink/45", "item"];
if (kind === "issue")
return state === "closed"
? [CheckCircleIcon, "text-merged", "Closed issue", "Fixed, answered or closed as not planned."]
: [RadioButtonIcon, "text-ok", "Open issue", "A bug report or a request that is still open."];
return [CircleIcon, "text-ink/45", "Item", "An issue or a pull request."];
}
/** The item's kind and state as a plain icon, as tall as one text line (`1lh`) so it sits with the text, also on wrapped titles. */
export function ItemIcon({ kind, state, draft, className }: { kind?: ItemKind | null; state?: ItemState | null; draft?: boolean; className?: string }) {
const [Icon, tone, what] = look(kind, state, draft);
/** The item's kind and state as a plain icon, named and explained in its tip, as tall as one text line (`1lh`) so it sits with the text, also on wrapped titles. */
export function ItemIcon({ kind, state, draft, className, tip = true }: { kind?: ItemKind | null; state?: ItemState | null; draft?: boolean; className?: string; /** false leaves out the tip (inside another tip). */ tip?: boolean }) {
const [Icon, tone, what, explain] = look(kind, state, draft);
return (
<span role="img" aria-label={what} className={cn("inline-flex h-[1lh] shrink-0 items-center", tone, className)}>
<Icon aria-hidden size="1.2em" weight="bold" />
</span>
<Tooltip title={tip ? what : undefined} content={tip ? explain : undefined} align="start">
<span role="img" aria-label={what} className={cn("inline-flex h-[1lh] shrink-0 items-center", tone, className)}>
<Icon aria-hidden size="1.2em" weight="bold" />
</span>
</Tooltip>
);
}
+39 -3
View File
@@ -1,15 +1,51 @@
// The app's tooltip, in place of the browser's `title`: it opens at once (the provider in main.tsx has no delay), takes any content, so
// a tip can carry a heading, a state and a few lines of detail, and stays on screen at the edges. Keyboard focus opens it too.
// A tip is extra information: whatever it says must also be reachable without it (screen readers get the trigger's own text).
import type { ReactNode } from "react";
import { Tooltip as T } from "radix-ui";
import { cn } from "../cn";
export function Tooltip({ label, children, side = "top" }: { label: ReactNode; children: ReactNode; side?: "top" | "right" | "bottom" | "left" }) {
export function Tooltip({ content, title, children, side = "top", align = "center", className }: {
/** The body; plain text or any markup. Nothing to show leaves the trigger as it is. */
content?: ReactNode;
/** A bold first line. */
title?: ReactNode;
/** One element that takes a ref (a span, a button, a link). */
children: ReactNode;
side?: "top" | "right" | "bottom" | "left";
align?: "start" | "center" | "end";
className?: string;
}) {
if ((content == null || content === "" || content === false) && title == null) return <>{children}</>;
return (
<T.Root>
<T.Trigger asChild>{children}</T.Trigger>
<T.Portal>
<T.Content side={side} sideOffset={6} className="z-50 rounded-md border border-line-strong bg-raised px-2 py-1 text-xs text-ink shadow-[0_8px_24px_rgba(0,0,0,0.25)] animate-fadeIn">
{label}
<T.Content
side={side}
align={align}
sideOffset={6}
collisionPadding={8}
className={cn("z-50 max-w-[320px] rounded-md border border-line-strong bg-raised px-2.5 py-1.5 text-xs leading-snug text-ink shadow-[0_8px_24px_rgba(0,0,0,0.25)]", className)}
>
{title != null && <div className="font-medium text-ink">{title}</div>}
{content != null && content !== false && <div className={cn(title != null && "mt-0.5 text-ink/70")}>{content}</div>}
</T.Content>
</T.Portal>
</T.Root>
);
}
/** Lines of detail in a tip, one per non-empty entry. */
export function TipLines({ lines }: { lines: (ReactNode | null | undefined | false)[] }) {
const shown = lines.filter((l) => l != null && l !== false && l !== "");
return (
<>
{shown.map((l, i) => (
<div key={i} className="[overflow-wrap:anywhere]">
{l}
</div>
))}
</>
);
}