Skip to content

Commit 87b4599

Browse files
committed
fix(webapp): address review feedback on agent storybook
Clamp animation speed so a non-positive value cannot spin the step loop. Cancel a pending return-to-rest when thinking is re-enabled mid-settle. Mark in-button logos decorative so they do not pollute the button accessible name. Size the scratch canvas used for logo hit-testing.
1 parent 684b0d9 commit 87b4599

4 files changed

Lines changed: 42 additions & 12 deletions

File tree

apps/webapp/app/routes/storybook.ai-agent/AgentDotMatrix.tsx

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,11 @@ export type AgentDotMatrixProps = {
245245
gridAtRest?: boolean;
246246
/** Animation speed multiplier. */
247247
speed?: number;
248+
/**
249+
* Render as a decorative glyph (aria-hidden, no role) — use when the logo
250+
* sits beside a text label that already names the control.
251+
*/
252+
decorative?: boolean;
248253
className?: string;
249254
style?: CSSProperties;
250255
"aria-label"?: string;
@@ -267,6 +272,7 @@ export function AgentDotMatrix({
267272
gridOpacity = 0.18,
268273
gridAtRest = false,
269274
speed = 1,
275+
decorative = false,
270276
className,
271277
style,
272278
"aria-label": ariaLabel,
@@ -311,8 +317,11 @@ export function AgentDotMatrix({
311317

312318
const pitch = size / MATRIX;
313319
const dotR = Math.max(0.75, pitch * 0.3);
314-
const stepMs = STEP_MS / speed;
315-
const blendMs = BLEND_MS / speed;
320+
// Clamp: a zero or negative speed would make stepMs non-positive and spin
321+
// the step loop forever.
322+
const safeSpeed = Math.max(0.01, speed);
323+
const stepMs = STEP_MS / safeSpeed;
324+
const blendMs = BLEND_MS / safeSpeed;
316325
// White ink at low opacity reads as subtle grey on any dark background;
317326
// light mode flips to black ink.
318327
const gridRgb: Rgb = mode === "light" ? [0, 0, 0] : [255, 255, 255];
@@ -496,8 +505,16 @@ export function AgentDotMatrix({
496505

497506
if (!activeRef.current) {
498507
seeking = "rest";
499-
} else if (seeking !== "next" && stepsInShape >= cyclesPerShape * route.length) {
500-
seeking = "next";
508+
} else {
509+
if (seeking === "rest") {
510+
// Re-activated mid-settle: cancel the pending return to rest so a
511+
// quick off/on toggle carries on instead of restarting.
512+
seeking = null;
513+
seekSteps = 0;
514+
}
515+
if (seeking !== "next" && stepsInShape >= cyclesPerShape * route.length) {
516+
seeking = "next";
517+
}
501518
}
502519
if (!seeking) return;
503520

@@ -600,8 +617,9 @@ export function AgentDotMatrix({
600617
return (
601618
<canvas
602619
ref={canvasRef}
603-
role="img"
604-
aria-label={ariaLabel ?? (active ? "Agent thinking" : "Agent")}
620+
{...(decorative
621+
? { "aria-hidden": true }
622+
: { role: "img", "aria-label": ariaLabel ?? (active ? "Agent thinking" : "Agent") })}
605623
className={className}
606624
style={{ width: size, height: size, display: "block", ...style }}
607625
/>

apps/webapp/app/routes/storybook.ai-agent/AgentOrb.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,12 @@ function logoCloud(count: number): Pt[] {
153153
const cached = logoCloudCache.get(count);
154154
if (cached) return cached;
155155

156-
const ctx = document.createElement("canvas").getContext("2d");
156+
// Size the scratch canvas to the logo box: isPointInPath is specified against
157+
// the path region, not the bitmap, but this removes any engine-specific doubt.
158+
const scratch = document.createElement("canvas");
159+
scratch.width = LOGO_W;
160+
scratch.height = LOGO_H;
161+
const ctx = scratch.getContext("2d");
157162
if (!ctx) return [];
158163
const path = new Path2D(LOGO_PATH);
159164
const scale = 0.9 / Math.max(LOGO_W, LOGO_H); // fit to ~0.9 box, preserve aspect

apps/webapp/app/routes/storybook.ai-agent/route.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,13 @@ function AskOttoButton({ variant, matrixSize }: { variant: ButtonVariant; matrix
212212
variant === "ask-ai/small" ? "gap-x-1.5" : "gap-x-2"
213213
)}
214214
>
215-
<AgentDotMatrix size={matrixSize} active={active} palette="mono" restColor="#ffffff" />
215+
<AgentDotMatrix
216+
size={matrixSize}
217+
active={active}
218+
palette="mono"
219+
restColor="#ffffff"
220+
decorative
221+
/>
216222
Ask Otto
217223
</span>
218224
</Button>
@@ -240,6 +246,7 @@ function FaceButton({ name }: { name: DotShapeName }) {
240246
restShape={name}
241247
palette="mono"
242248
restColor="#ffffff"
249+
decorative
243250
/>
244251
{name}
245252
</span>

apps/webapp/app/routes/storybook.buttons/route.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -406,19 +406,19 @@ export default function Story() {
406406
<Header3 className="mb-1 uppercase">Sizes</Header3>
407407
<Button variant="ask-ai/small">
408408
<span className="flex items-center gap-x-1.5 text-text-bright">
409-
<AgentDotMatrix size={16} palette="mono" restColor="#ffffff" />
409+
<AgentDotMatrix size={16} palette="mono" restColor="#ffffff" decorative />
410410
Ask AI
411411
</span>
412412
</Button>
413413
<Button variant="ask-ai/medium">
414414
<span className="flex items-center gap-x-2 text-text-bright">
415-
<AgentDotMatrix size={16} palette="mono" restColor="#ffffff" />
415+
<AgentDotMatrix size={16} palette="mono" restColor="#ffffff" decorative />
416416
Ask AI
417417
</span>
418418
</Button>
419419
<Button variant="ask-ai/large">
420420
<span className="flex items-center gap-x-2 text-text-bright">
421-
<AgentDotMatrix size={20} palette="mono" restColor="#ffffff" />
421+
<AgentDotMatrix size={20} palette="mono" restColor="#ffffff" decorative />
422422
Ask AI
423423
</span>
424424
</Button>
@@ -427,7 +427,7 @@ export default function Story() {
427427
<Header3 className="mb-1 uppercase">Disabled</Header3>
428428
<Button variant="ask-ai/small" disabled>
429429
<span className="flex items-center gap-x-1.5 text-text-bright">
430-
<AgentDotMatrix size={16} palette="mono" restColor="#ffffff" />
430+
<AgentDotMatrix size={16} palette="mono" restColor="#ffffff" decorative />
431431
Ask AI
432432
</span>
433433
</Button>

0 commit comments

Comments
 (0)