Yuchen Yuan commited on
Commit
0f6846e
·
1 Parent(s): f6e6b69

Extract shared TipIcon; add hover-tooltip on family badge + live-IBM chip

Browse files

Pull the inline ⓘ tooltip from NodeParamEditor.FieldLabel into a
shared `TipIcon` component so other places that need the same
'short label, long explanation behind a hover' affordance can reuse
it without copying the named-group / no-aria-label / pointer-events
gotchas. (Three iterations earlier in this session were spent
re-discovering each one.)

Two concrete spots where the shared component now adds context:

* QNode family badge (SOURCE / BACKEND / ALGORITHM / METRIC / SINK).
Useful tag for someone fluent in workflow-editor lingo, opaque to
a non-quantum first-time visitor. New per-family hint explains
what each role does in plain language.

* TopBar 'live ibm: ...' status chip. Already had a long native
`title` tooltip, but native titles race our CSS tooltips and have
the 1-2 s display delay. Replaced with TipIcon next to the chip
text — instant, theme-styled, and the chip stays clickable to
toggle live mode.

NodeParamEditor.FieldLabel collapses to a thin call-site of TipIcon;
behaviour identical.

frontend/src/components/NodeParamEditor.tsx CHANGED
@@ -1,5 +1,5 @@
1
- import { HelpCircle } from "lucide-react";
2
  import type { NodeParamSpec } from "../lib/nodeCatalog";
 
3
 
4
  /**
5
  * Inline parameter editor for a canvas node.
@@ -153,31 +153,7 @@ function NumberField({
153
  }
154
 
155
  /** Field label with a small ⓘ icon when the param spec carries a hint.
156
- *
157
- * Uses a CSS `group-hover` / `group-focus` tooltip — instant, no
158
- * delay, works for keyboard tabs as well as mouse hovers.
159
- *
160
- * Why no `aria-label` or `title` on the icon wrapper:
161
- * - `title` has a 1-2 s display delay on macOS Chrome and races our
162
- * own tooltip.
163
- * - `aria-label` on a `cursor:help` element causes some browsers to
164
- * fall back to the same delayed native tooltip, which is what
165
- * gave users the "wait 2 seconds before anything shows up" bug.
166
- *
167
- * Instead, the tooltip's own text is what screen readers read (it's
168
- * a visible `<span role="tooltip">` containing the same words a
169
- * sighted user sees). The icon itself is decorative
170
- * (`aria-hidden="true"`).
171
- *
172
- * Geometry: tooltip pops above the icon (`bottom-full mb-1`),
173
- * anchored to the icon's center, capped at 14rem so it doesn't
174
- * overflow narrow nodes, z-50 to clear React Flow's edge layer.
175
- * `pointer-events-none` so the tooltip doesn't trap hovers.
176
- *
177
- * `tabIndex={0}` makes the icon keyboard-focusable so users tabbing
178
- * through the form can read each hint without using the mouse;
179
- * `group-focus:block` reuses the same tooltip for the focus state.
180
- */
181
  function FieldLabel({
182
  label,
183
  hint,
@@ -188,36 +164,7 @@ function FieldLabel({
188
  return (
189
  <span className="inline-flex items-center gap-1 min-w-0">
190
  <span className="truncate">{label}</span>
191
- {hint && (
192
- <span
193
- tabIndex={0}
194
- // Use a NAMED Tailwind group (`group/tip`) instead of plain
195
- // `group`. The QNode card already carries `group` to drive the
196
- // hover-reveal × delete button, and unnamed `group-hover:`
197
- // matches ANY ancestor `.group` — so a plain `group` here was
198
- // showing every tooltip whenever the user hovered the node
199
- // card at all. Named groups scope the hover/focus check to
200
- // exactly this wrapper.
201
- className="group/tip relative shrink-0 inline-flex items-center text-mute/70 hover:text-ink focus:text-ink focus:outline-none focus-visible:ring-1 focus-visible:ring-accent/60 rounded-full cursor-help"
202
- onClick={(e) => {
203
- // Keep clicking the icon from focusing the wrapped input.
204
- e.preventDefault();
205
- e.stopPropagation();
206
- }}
207
- >
208
- <HelpCircle
209
- className="w-3 h-3"
210
- strokeWidth={2}
211
- aria-hidden="true"
212
- />
213
- <span
214
- role="tooltip"
215
- className="hidden group-hover/tip:block group-focus/tip:block pointer-events-none absolute left-1/2 -translate-x-1/2 bottom-full mb-1 z-50 w-max max-w-[14rem] rounded-md border border-edge bg-surface text-ink shadow-lg px-2 py-1 text-[11px] leading-snug normal-case tracking-normal font-normal whitespace-normal text-left"
216
- >
217
- {hint}
218
- </span>
219
- </span>
220
- )}
221
  </span>
222
  );
223
  }
 
 
1
  import type { NodeParamSpec } from "../lib/nodeCatalog";
2
+ import { TipIcon } from "./TipIcon";
3
 
4
  /**
5
  * Inline parameter editor for a canvas node.
 
153
  }
154
 
155
  /** Field label with a small ⓘ icon when the param spec carries a hint.
156
+ * Tooltip behaviour lives in the shared `TipIcon` component. */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
  function FieldLabel({
158
  label,
159
  hint,
 
164
  return (
165
  <span className="inline-flex items-center gap-1 min-w-0">
166
  <span className="truncate">{label}</span>
167
+ {hint && <TipIcon hint={hint} />}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  </span>
169
  );
170
  }
frontend/src/components/QNode.tsx CHANGED
@@ -11,10 +11,30 @@ import {
11
  NODE_BY_KIND,
12
  type NodeKind,
13
  type NodeParamSpec,
 
14
  } from "../lib/nodeCatalog";
15
  import { NodeParamEditor } from "./NodeParamEditor";
 
16
  import { useApp } from "../lib/store";
17
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  export interface QNodeData extends Record<string, unknown> {
19
  kind: NodeKind;
20
  params?: Record<string, unknown>;
@@ -102,8 +122,9 @@ export function QNode({ id, data, selected }: NodeProps) {
102
  </span>
103
  <div className="min-w-0 flex-1">
104
  <div className="font-medium text-ink text-sm">{spec.label}</div>
105
- <div className="text-[10px] text-mute uppercase tracking-wider">
106
- {spec.family}
 
107
  </div>
108
  </div>
109
  </div>
 
11
  NODE_BY_KIND,
12
  type NodeKind,
13
  type NodeParamSpec,
14
+ type NodeSpec,
15
  } from "../lib/nodeCatalog";
16
  import { NodeParamEditor } from "./NodeParamEditor";
17
+ import { TipIcon } from "./TipIcon";
18
  import { useApp } from "../lib/store";
19
 
20
+ /** Plain-language description of each node-family role, surfaced as a
21
+ * tooltip on the small family badge under the node label. The 5 words
22
+ * (SOURCE / BACKEND / ALGORITHM / METRIC / SINK) make sense to anyone
23
+ * who's seen a workflow editor before, but not to the quantum-only or
24
+ * newcomer audience this demo gets. */
25
+ const FAMILY_HINTS: Record<NodeSpec["family"], string> = {
26
+ source:
27
+ "Where the pipeline starts — feeds your quantum circuit to the rest of the graph.",
28
+ backend:
29
+ "Provides a noise model. Algorithm blocks downstream use it to simulate hardware behaviour.",
30
+ algorithm:
31
+ "A research algorithm. Reads the circuit (and noise) from upstream, may transform the circuit or attach a metric.",
32
+ metric:
33
+ "Computes a quantitative score on the current circuit (e.g. fidelity).",
34
+ sink:
35
+ "Where the pipeline ends — aggregates final metrics and the resulting circuit.",
36
+ };
37
+
38
  export interface QNodeData extends Record<string, unknown> {
39
  kind: NodeKind;
40
  params?: Record<string, unknown>;
 
122
  </span>
123
  <div className="min-w-0 flex-1">
124
  <div className="font-medium text-ink text-sm">{spec.label}</div>
125
+ <div className="text-[10px] text-mute uppercase tracking-wider flex items-center gap-1">
126
+ <span>{spec.family}</span>
127
+ <TipIcon hint={FAMILY_HINTS[spec.family]} size={10} />
128
  </div>
129
  </div>
130
  </div>
frontend/src/components/TipIcon.tsx ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { HelpCircle } from "lucide-react";
2
+
3
+ /**
4
+ * Small ⓘ help icon with a CSS-only tooltip.
5
+ *
6
+ * Reused wherever a UI element has a short label that some users
7
+ * (especially non-quantum readers) might not recognise — block family
8
+ * badges, status chips, terse stat labels in the pipeline pane.
9
+ *
10
+ * Why this looks the way it does (in detail because the previous
11
+ * iterations had a few subtle gotchas):
12
+ *
13
+ * - **Named Tailwind group (`group/tip`).** The wrapping span carries
14
+ * `group/tip` and the tooltip carries `group-hover/tip:block` /
15
+ * `group-focus/tip:block`. An unnamed `group` would be matched by
16
+ * every ancestor that also uses unnamed `group` — including
17
+ * QNode's `node-card` — so hovering anywhere on a node card would
18
+ * pop every tooltip simultaneously.
19
+ *
20
+ * - **No `aria-label` or `title`.** When a `cursor:help` element
21
+ * carries `aria-label`, browsers (notably macOS Chrome) fall back
22
+ * to a delayed native tooltip that races our own. The visible
23
+ * `<span role="tooltip">` *is* the accessible name — screen readers
24
+ * read its text.
25
+ *
26
+ * - **`tabIndex={0}` + `group-focus/tip`.** Keyboard users can tab
27
+ * onto the icon and read the hint without a mouse.
28
+ *
29
+ * - **`pointer-events-none` on the bubble.** Moving the cursor onto
30
+ * the tooltip itself doesn't extend its visibility — once the
31
+ * cursor leaves the icon, the tooltip closes immediately. Keeps it
32
+ * a pure read-only affordance.
33
+ *
34
+ * - The `onClick` blocks both default and propagation, so clicking
35
+ * the icon inside a `<label>` doesn't redirect focus to the
36
+ * label's wrapped `<input>`.
37
+ */
38
+ export function TipIcon({
39
+ hint,
40
+ className = "",
41
+ size = 12,
42
+ }: {
43
+ hint: string;
44
+ /** Extra classes on the wrapper (e.g. for inline alignment). */
45
+ className?: string;
46
+ /** Pixel size of the icon. Defaults to 12 to match small inline labels. */
47
+ size?: number;
48
+ }) {
49
+ return (
50
+ <span
51
+ tabIndex={0}
52
+ className={`group/tip relative shrink-0 inline-flex items-center text-mute/70 hover:text-ink focus:text-ink focus:outline-none focus-visible:ring-1 focus-visible:ring-accent/60 rounded-full cursor-help ${className}`}
53
+ onClick={(e) => {
54
+ e.preventDefault();
55
+ e.stopPropagation();
56
+ }}
57
+ >
58
+ <HelpCircle
59
+ style={{ width: size, height: size }}
60
+ strokeWidth={2}
61
+ aria-hidden="true"
62
+ />
63
+ <span
64
+ role="tooltip"
65
+ className="hidden group-hover/tip:block group-focus/tip:block pointer-events-none absolute left-1/2 -translate-x-1/2 bottom-full mb-1 z-50 w-max max-w-[16rem] rounded-md border border-edge bg-surface text-ink shadow-lg px-2 py-1 text-[11px] leading-snug normal-case tracking-normal font-normal whitespace-normal text-left"
66
+ >
67
+ {hint}
68
+ </span>
69
+ </span>
70
+ );
71
+ }
frontend/src/components/TopBar.tsx CHANGED
@@ -10,6 +10,7 @@ import {
10
  import { ThemeSwitcher } from "./ThemeSwitcher";
11
  import { PapersPopover } from "./PapersPopover";
12
  import { DevelopersPopover } from "./DevelopersPopover";
 
13
 
14
  /**
15
  * Top application bar.
@@ -118,10 +119,10 @@ export function TopBar({
118
  }}
119
  disabled={!serverCanGoLive}
120
  aria-pressed={effectiveLive}
121
- className={`chip transition-colors ${chipClass}`}
122
- title={chipTitle}
123
  >
124
- {mobile ? chipLabelShort : chipLabel}
 
125
  </button>
126
  </div>
127
  </div>
 
10
  import { ThemeSwitcher } from "./ThemeSwitcher";
11
  import { PapersPopover } from "./PapersPopover";
12
  import { DevelopersPopover } from "./DevelopersPopover";
13
+ import { TipIcon } from "./TipIcon";
14
 
15
  /**
16
  * Top application bar.
 
119
  }}
120
  disabled={!serverCanGoLive}
121
  aria-pressed={effectiveLive}
122
+ className={`chip transition-colors gap-1 ${chipClass}`}
 
123
  >
124
+ <span>{mobile ? chipLabelShort : chipLabel}</span>
125
+ <TipIcon hint={chipTitle} size={10} />
126
  </button>
127
  </div>
128
  </div>