@multiplatform.one/components 10.2.0 → 10.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/dist/cjs/views/Gantt.cjs +54 -37
  2. package/dist/cjs/views/Gantt.native.cjs +45 -30
  3. package/dist/cjs/views/Gantt.native.js +45 -30
  4. package/dist/cjs/views/Gantt.native.js.map +1 -1
  5. package/dist/cjs/views/GanttDateGrip.cjs +3 -3
  6. package/dist/cjs/views/GanttDateGrip.native.cjs +3 -3
  7. package/dist/cjs/views/GanttDateGrip.native.js +3 -3
  8. package/dist/cjs/views/GanttDateGrip.native.js.map +1 -1
  9. package/dist/cjs/views/eventTint.cjs +16 -4
  10. package/dist/cjs/views/eventTint.native.cjs +17 -4
  11. package/dist/cjs/views/eventTint.native.js +17 -4
  12. package/dist/cjs/views/eventTint.native.js.map +1 -1
  13. package/dist/cjs/views/ganttMath.cjs +10 -0
  14. package/dist/cjs/views/ganttMath.native.cjs +10 -0
  15. package/dist/cjs/views/ganttMath.native.js +10 -0
  16. package/dist/cjs/views/ganttMath.native.js.map +1 -1
  17. package/dist/cjs/views/index.cjs +3 -0
  18. package/dist/cjs/views/index.native.cjs +3 -0
  19. package/dist/cjs/views/index.native.js +3 -0
  20. package/dist/cjs/views/index.native.js.map +1 -1
  21. package/dist/esm/views/Gantt.mjs +58 -41
  22. package/dist/esm/views/Gantt.mjs.map +1 -1
  23. package/dist/esm/views/Gantt.native.js +49 -34
  24. package/dist/esm/views/Gantt.native.js.map +1 -1
  25. package/dist/esm/views/GanttDateGrip.mjs +3 -3
  26. package/dist/esm/views/GanttDateGrip.mjs.map +1 -1
  27. package/dist/esm/views/GanttDateGrip.native.js +3 -3
  28. package/dist/esm/views/GanttDateGrip.native.js.map +1 -1
  29. package/dist/esm/views/eventTint.mjs +15 -5
  30. package/dist/esm/views/eventTint.mjs.map +1 -1
  31. package/dist/esm/views/eventTint.native.js +16 -5
  32. package/dist/esm/views/eventTint.native.js.map +1 -1
  33. package/dist/esm/views/ganttMath.mjs +8 -1
  34. package/dist/esm/views/ganttMath.mjs.map +1 -1
  35. package/dist/esm/views/ganttMath.native.js +8 -1
  36. package/dist/esm/views/ganttMath.native.js.map +1 -1
  37. package/dist/esm/views/index.mjs +2 -2
  38. package/dist/esm/views/index.native.js +2 -2
  39. package/dist/jsx/views/Gantt.mjs +58 -41
  40. package/dist/jsx/views/Gantt.mjs.map +1 -1
  41. package/dist/jsx/views/Gantt.native.cjs +45 -30
  42. package/dist/jsx/views/Gantt.native.js +45 -30
  43. package/dist/jsx/views/Gantt.native.js.map +1 -1
  44. package/dist/jsx/views/GanttDateGrip.mjs +3 -3
  45. package/dist/jsx/views/GanttDateGrip.mjs.map +1 -1
  46. package/dist/jsx/views/GanttDateGrip.native.cjs +3 -3
  47. package/dist/jsx/views/GanttDateGrip.native.js +3 -3
  48. package/dist/jsx/views/GanttDateGrip.native.js.map +1 -1
  49. package/dist/jsx/views/eventTint.mjs +15 -5
  50. package/dist/jsx/views/eventTint.mjs.map +1 -1
  51. package/dist/jsx/views/eventTint.native.cjs +17 -4
  52. package/dist/jsx/views/eventTint.native.js +17 -4
  53. package/dist/jsx/views/eventTint.native.js.map +1 -1
  54. package/dist/jsx/views/ganttMath.mjs +8 -1
  55. package/dist/jsx/views/ganttMath.mjs.map +1 -1
  56. package/dist/jsx/views/ganttMath.native.cjs +10 -0
  57. package/dist/jsx/views/ganttMath.native.js +10 -0
  58. package/dist/jsx/views/ganttMath.native.js.map +1 -1
  59. package/dist/jsx/views/index.mjs +2 -2
  60. package/dist/jsx/views/index.native.cjs +3 -0
  61. package/dist/jsx/views/index.native.js +3 -0
  62. package/dist/jsx/views/index.native.js.map +1 -1
  63. package/package.json +7 -7
  64. package/src/views/Gantt.barInk.spec.tsx +149 -21
  65. package/src/views/Gantt.grips.spec.tsx +21 -4
  66. package/src/views/Gantt.phone.spec.tsx +205 -0
  67. package/src/views/Gantt.spec.tsx +15 -2
  68. package/src/views/Gantt.tint.palette.spec.ts +14 -7
  69. package/src/views/Gantt.tsx +144 -101
  70. package/src/views/GanttDateGrip.tsx +4 -4
  71. package/src/views/eventTint.ts +23 -4
  72. package/src/views/ganttMath.ts +26 -0
  73. package/src/views/index.ts +3 -0
  74. package/types/views/Gantt.d.ts.map +1 -1
  75. package/types/views/eventTint.d.ts +5 -2
  76. package/types/views/eventTint.d.ts.map +1 -1
  77. package/types/views/ganttMath.d.ts +14 -0
  78. package/types/views/ganttMath.d.ts.map +1 -1
  79. package/types/views/index.d.ts +1 -1
  80. package/types/views/index.d.ts.map +1 -1
@@ -14,8 +14,11 @@ import type { ReactNode } from "react";
14
14
  import { Theme, useTheme } from "tamagui";
15
15
  import { afterEach, describe, expect, it, vi } from "vitest";
16
16
  import { GanttView, type GanttTask } from "./Gantt";
17
+ import { labelFitsBar } from "./ganttMath";
17
18
  import {
18
19
  EVENT_BAR_PX,
20
+ EVENT_STRIP_BAND_PX,
21
+ EVENT_STRIP_BOTTOM_PX,
19
22
  EVENT_STRIP_FLOOR,
20
23
  EVENT_STRIP_STEP,
21
24
  eventPaint,
@@ -44,6 +47,10 @@ const tasks: GanttTask[] = [
44
47
  })),
45
48
  ];
46
49
 
50
+ const ghostTasks: GanttTask[] = tasks
51
+ .filter((task) => task.end !== undefined)
52
+ .map((task) => ({ ...task, id: `ghost-${task.id}`, ghost: true }));
53
+
47
54
  type Values = Record<string, { val?: unknown } | undefined>;
48
55
 
49
56
  function Capture({ into, name }: { into: Record<string, Values>; name: string }) {
@@ -69,7 +76,7 @@ function hex(theme: Values, color: string): string {
69
76
 
70
77
  const lum = (h: string) => relativeLuminance(h);
71
78
 
72
- function render(scheme: string, hue?: string) {
79
+ function render(scheme: string, hue?: string, list: GanttTask[] = tasks) {
73
80
  const themes: Record<string, Values> = {};
74
81
  const view = renderWithProviders(
75
82
  <Scheme scheme={scheme} hue={hue}>
@@ -81,7 +88,7 @@ function render(scheme: string, hue?: string) {
81
88
  <Capture into={themes} name={intent} />
82
89
  </Intent>
83
90
  ))}
84
- <GanttView tasks={tasks} initialDate={day(1)} onItemPress={vi.fn()} />
91
+ <GanttView tasks={list} initialDate={day(1)} onItemPress={vi.fn()} />
85
92
  </Scheme>,
86
93
  );
87
94
  return { view, themes };
@@ -124,7 +131,19 @@ function assertBar(
124
131
  expect(progress, `${task.id} progress strip`).not.toBeNull();
125
132
  expect(atomicStyle(progress!).opacity ?? "1", `${task.id} progress opaque`).toBe("1");
126
133
  expect(progress!.parentElement, `${task.id} progress clipped by the bar`).toBe(tint);
127
- const { left, borderRadius } = fiberProps(progress!, "height");
134
+ const track = tint!.querySelector("[data-gantt-progress-track]");
135
+ expect(track, `${task.id} progress track in ${scheme}`).not.toBeNull();
136
+ const { left, borderRadius, height: stripHeight, bottom } = fiberProps(progress!, "height");
137
+ const barBox = fiberProps(bar, "height");
138
+ expect(
139
+ Number(barBox.height) - Number(fiberProps(label!, "marginBottom").marginBottom),
140
+ `${task.id} label box stops above the strip band`,
141
+ ).toBeLessThanOrEqual(Number(barBox.height) - Number(bottom) - Number(stripHeight));
142
+ expect(
143
+ Number(fiberProps(label!, "marginBottom").marginBottom),
144
+ `${task.id} label gives up the strip's band`,
145
+ ).toBe(EVENT_STRIP_BAND_PX);
146
+ expect(Number(bottom), `${task.id} strip sits on its clearance`).toBe(EVENT_STRIP_BOTTOM_PX);
128
147
  expect(Number(left), `${task.id} strip clears the leading edge`).toBeGreaterThan(
129
148
  dark ? EVENT_BAR_PX : 0,
130
149
  );
@@ -143,10 +162,6 @@ function assertBar(
143
162
  }
144
163
  if (onSolid) {
145
164
  expect(ink, `light ${task.id} takes the on-solid ink`).toBe(onSolid.ink);
146
- expect(
147
- Math.abs(apcaContrast(ink, paint)),
148
- `light ${task.id}: ${ink} on ${paint} APCA`,
149
- ).toBeGreaterThanOrEqual(fillLabelLc);
150
165
  if (task.intent !== "warning")
151
166
  expect(lum(ink), `light ${task.id}: near-white on the solid`).toBeGreaterThan(lum(paint));
152
167
  } else {
@@ -155,10 +170,49 @@ function assertBar(
155
170
  if (contrastRatio(lum(primary), lum(paint)) >= aaTextContrastRatio)
156
171
  expect(ink, `dark ${task.id} keeps ${hue12 ? "its hue's 12" : "$color-12"}`).toBe(primary);
157
172
  }
173
+ assertInkReads(ink, paint, `${scheme} ${task.id}`);
174
+ }
175
+
176
+ /**
177
+ * Every bar's label, in both schemes and at every state, clears WCAG AA and
178
+ * APCA Lc 60 on the paint it actually sits on. Asserting this only on the
179
+ * light solid left the dark ghost bar out of the gate (FZ-11773).
180
+ */
181
+ function assertInkReads(ink: string, paint: string, label: string) {
158
182
  expect(
159
183
  contrastRatio(lum(ink), lum(paint)),
160
- `${scheme} ${task.id}: ${ink} on ${paint}`,
184
+ `${label}: ${ink} on ${paint}`,
161
185
  ).toBeGreaterThanOrEqual(aaTextContrastRatio);
186
+ expect(
187
+ Math.abs(apcaContrast(ink, paint)),
188
+ `${label}: ${ink} on ${paint} APCA`,
189
+ ).toBeGreaterThanOrEqual(fillLabelLc);
190
+ }
191
+
192
+ function assertGhostBar(
193
+ view: ReturnType<typeof render>["view"],
194
+ themes: Record<string, Values>,
195
+ task: GanttTask,
196
+ scheme: string,
197
+ ) {
198
+ const bar = view.container.querySelector(`[data-gantt-bar="${task.id}"]`)!;
199
+ expect(bar, task.id).not.toBeNull();
200
+ const tint = bar.querySelector("[data-gantt-bar-state]") as HTMLElement | null;
201
+ expect(tint!.getAttribute("data-gantt-bar-state"), `${task.id} state`).toBe("ghost");
202
+ const theme = task.intent && task.intent !== "accent" ? themes[task.intent] : themes.base;
203
+ const fill = tint!.querySelector("[data-gantt-bar-fill]")!.getAttribute("data-gantt-bar-fill")!;
204
+ const paint = eventPaint(theme, fill, "ghost", {
205
+ dark: scheme === "dark",
206
+ surface: hex(themes.base, "$background"),
207
+ })!;
208
+ expect(tint!.getAttribute("data-gantt-bar-paint"), `${task.id} paint`).toBe(paint);
209
+ const label = bar.querySelector("[data-gantt-ghost-label]");
210
+ expect(label?.textContent, `${task.id} label`).toContain(task.title);
211
+ assertInkReads(
212
+ hex(theme, label!.getAttribute("data-gantt-bar-ink")!),
213
+ paint,
214
+ `${scheme} ghost ${task.id}`,
215
+ );
162
216
  }
163
217
 
164
218
  describe("Gantt bar labels read on their fill (FZ-9366)", () => {
@@ -174,6 +228,13 @@ describe("Gantt bar labels read on their fill (FZ-9366)", () => {
174
228
  }
175
229
  });
176
230
 
231
+ for (const scheme of ["light", "dark"])
232
+ for (const hue of [undefined, "blue", "pink", "purple"])
233
+ it(`${scheme}${hue ? `_${hue}` : ""}: every proposed bar's label reads on its tint`, () => {
234
+ const { view, themes } = render(scheme, hue, ghostTasks);
235
+ for (const task of ghostTasks) assertGhostBar(view, themes, task, scheme);
236
+ });
237
+
177
238
  it("a milestone too narrow for its title carries it outside, on the canvas", () => {
178
239
  const view = renderWithProviders(
179
240
  <GanttView
@@ -189,6 +250,55 @@ describe("Gantt bar labels read on their fill (FZ-9366)", () => {
189
250
  expect(Number(fiberProps(outside!, "width").width)).toBeGreaterThan(44);
190
251
  });
191
252
 
253
+ it("a bar too narrow for its title carries the whole title outside, never an ellipsis", () => {
254
+ const title = "Discovery & scoping of the data migration";
255
+ const view = renderWithProviders(
256
+ <GanttView tasks={[{ id: "cut", title, start: day(2), end: day(6) }]} initialDate={day(1)} />,
257
+ );
258
+ const bar = view.container.querySelector('[data-gantt-bar="cut"]')!;
259
+ const width = Number(fiberProps(bar, "width").width);
260
+ expect(labelFitsBar(title, width, 16, 15)).toBe(false);
261
+ expect(bar.querySelector("[data-gantt-bar-ink]")).toBeNull();
262
+ expect(bar.querySelector("[data-gantt-bar-outside-label]")?.textContent).toBe(title);
263
+ });
264
+
265
+ it("a bar wide enough for its title keeps it inside", () => {
266
+ const view = renderWithProviders(
267
+ <GanttView
268
+ tasks={[{ id: "fits", title: "Build", start: day(2), end: day(12) }]}
269
+ initialDate={day(1)}
270
+ />,
271
+ );
272
+ const bar = view.container.querySelector('[data-gantt-bar="fits"]')!;
273
+ expect(bar.querySelector("[data-gantt-bar-ink]")?.textContent).toContain("Build");
274
+ expect(bar.querySelector("[data-gantt-bar-outside-label]")).toBeNull();
275
+ });
276
+
277
+ it("a span row and a proposed bar keep a title they cannot fit, since neither can carry it outside", () => {
278
+ const title = "Discovery & scoping of the data migration";
279
+ const view = renderWithProviders(
280
+ <GanttView
281
+ tasks={[
282
+ { id: "ghost", title, start: day(2), end: day(6), ghost: true },
283
+ {
284
+ id: "multi",
285
+ title,
286
+ spans: [
287
+ { id: "a", start: day(2), end: day(6) },
288
+ { id: "b", start: day(8), end: day(10) },
289
+ ],
290
+ },
291
+ ]}
292
+ initialDate={day(1)}
293
+ />,
294
+ );
295
+ for (const id of ["ghost", "a"]) {
296
+ const bar = view.container.querySelector(`[data-gantt-bar="${id}"]`)!;
297
+ expect(bar.querySelector("[data-gantt-bar-ink]")?.textContent, id).toContain(title);
298
+ expect(bar.querySelector("[data-gantt-bar-outside-label]"), id).toBeNull();
299
+ }
300
+ });
301
+
192
302
  it("a proposed bar's label sits above its opaque tint in its hue's secondary ink", () => {
193
303
  const view = renderWithProviders(
194
304
  <GanttView
@@ -225,20 +335,38 @@ describe("Gantt bar labels read on their fill (FZ-9366)", () => {
225
335
  expect(openStart.querySelector('[data-gantt-open-fade="start"]')).not.toBeNull();
226
336
  });
227
337
 
228
- it("progress on a light solid runs over a faint track in the same ink; a dark tint has none", () => {
229
- const light = render("light").view;
230
- const bars = [...light.container.querySelectorAll("[data-gantt-progress]")];
231
- expect(bars.length).toBeGreaterThan(0);
232
- for (const strip of bars) {
233
- const track = strip.parentElement!.querySelector("[data-gantt-progress-track]");
234
- expect(track?.getAttribute("data-gantt-progress-track")).toBe(
235
- strip.getAttribute("data-gantt-progress-paint"),
236
- );
237
- expect(track!.compareDocumentPosition(strip) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy();
338
+ it("progress runs over a faint track in the strip's own paint, in dark as in light", () => {
339
+ for (const scheme of ["light", "dark"]) {
340
+ const view = render(scheme).view;
341
+ const bars = [...view.container.querySelectorAll("[data-gantt-progress]")];
342
+ expect(bars.length, scheme).toBeGreaterThan(0);
343
+ for (const strip of bars) {
344
+ const track = strip.parentElement!.querySelector("[data-gantt-progress-track]");
345
+ expect(track?.getAttribute("data-gantt-progress-track"), scheme).toBe(
346
+ strip.getAttribute("data-gantt-progress-paint"),
347
+ );
348
+ expect(
349
+ track!.compareDocumentPosition(strip) & Node.DOCUMENT_POSITION_FOLLOWING,
350
+ scheme,
351
+ ).toBeTruthy();
352
+ expect(atomicStyle(track as HTMLElement).opacity, scheme).toBe("0.3");
353
+ }
354
+ cleanup();
238
355
  }
239
- cleanup();
240
- const dark = render("dark").view;
241
- expect(dark.container.querySelector("[data-gantt-progress-track]")).toBeNull();
356
+ });
357
+
358
+ it("a rail nobody has touched paints at rest, and takes the selected paint on focus", () => {
359
+ const view = renderWithProviders(
360
+ <GanttView tasks={[{ id: "always", title: "Base policy" }]} initialDate={day(1)} />,
361
+ );
362
+ const rail = view.container.querySelector('[data-gantt-bar="always"]') as HTMLElement;
363
+ expect(rail.getAttribute("data-gantt-rail")).toBe("true");
364
+ const tint = () => rail.querySelector("[data-gantt-bar-state]")!;
365
+ expect(tint().getAttribute("data-gantt-bar-state")).toBe("rest");
366
+ const atRest = tint().getAttribute("data-gantt-bar-paint");
367
+ act(() => rail.focus());
368
+ expect(tint().getAttribute("data-gantt-bar-state")).toBe("selected");
369
+ expect(tint().getAttribute("data-gantt-bar-paint")).not.toBe(atRest);
242
370
  });
243
371
 
244
372
  it("the today line sits under the bars, so it never cuts a label", () => {
@@ -2,6 +2,7 @@ import { act, cleanup } from "@testing-library/react";
2
2
  import { atomicStyle, renderWithProviders } from "@multiplatform.one/test-utils";
3
3
  import { afterEach, describe, expect, it, vi } from "vitest";
4
4
  import { GanttView } from "./Gantt";
5
+ import { EVENT_GRIP_DOT_PX } from "./eventTint";
5
6
 
6
7
  afterEach(cleanup);
7
8
  const day = (n: number) => new Date(2026, 2, n);
@@ -80,7 +81,7 @@ describe("Gantt endpoint grips (FZ-9366)", () => {
80
81
  expect(opacities("policy")).toEqual([0, 1]);
81
82
  });
82
83
 
83
- it("both grips are dots on opposite corners, ringed in the bar colour, clear of the label", () => {
84
+ it("both grips are dots inside opposite corners, ringed in the bar colour, clear of the label", () => {
84
85
  const { view, glyphs, bar } = setup();
85
86
  act(() => bar("contract").focus());
86
87
  expect(dotBoxes(bar("contract"), glyphs("contract"))).toSatisfy(cornersClearOfLabel);
@@ -204,6 +205,11 @@ function dotBoxes(bar: HTMLElement, dots: Element[]) {
204
205
  };
205
206
  }
206
207
 
208
+ /**
209
+ * FZ-11773 defect 7: the dots were centred ON the corner, so half of each one
210
+ * (5 px of 10) hung outside the bar and ran into the label's box. They now sit
211
+ * inside the corner, and the gap to the label's box is measured, not claimed.
212
+ */
207
213
  function cornersClearOfLabel({
208
214
  boxes,
209
215
  bar,
@@ -216,11 +222,22 @@ function cornersClearOfLabel({
216
222
  const overlaps = (a: Box, b: Box) =>
217
223
  a.left < b.right && b.left < a.right && a.top < b.bottom && b.top < a.bottom;
218
224
  const centre = (b: Box) => ({ x: (b.left + b.right) / 2, y: (b.top + b.bottom) / 2 });
225
+ const half = EVENT_GRIP_DOT_PX / 2;
219
226
  const start = boxes.find((b) => b.edge === "start")!;
220
227
  const end = boxes.find((b) => b.edge === "end")!;
221
228
  expect(boxes.every((b) => b.shown)).toBe(true);
222
- expect(centre(start.box)).toEqual({ x: bar.left, y: bar.bottom });
223
- expect(centre(end.box)).toEqual({ x: bar.right, y: bar.top });
224
- for (const { box } of boxes) expect(overlaps(box, label)).toBe(false);
229
+ expect(centre(start.box)).toEqual({ x: bar.left + half, y: bar.bottom - half });
230
+ expect(centre(end.box)).toEqual({ x: bar.right - half, y: bar.top + half });
231
+ const gap = (box: Box) =>
232
+ box.right <= label.left ? label.left - box.right : box.left - label.right;
233
+ for (const { edge, box } of boxes) {
234
+ expect(
235
+ [box.left >= bar.left, box.right <= bar.right, box.top >= bar.top, box.bottom <= bar.bottom],
236
+ `${edge} dot inside the bar`,
237
+ ).toEqual([true, true, true, true]);
238
+ expect(overlaps(box, label), `${edge} dot clear of the label`).toBe(false);
239
+ expect(gap(box), `${edge} dot gap to the label`).toBe(label.left - EVENT_GRIP_DOT_PX);
240
+ }
241
+ expect(label.left - EVENT_GRIP_DOT_PX, "measured gap at the default preset").toBe(6);
225
242
  return true;
226
243
  }
@@ -0,0 +1,205 @@
1
+ /**
2
+ * FZ-11773 defect 3: at 390 the chart named no month and no year anywhere on
3
+ * screen, and the task column ate 180 of the 390. The axis month band now
4
+ * follows the canvas scroll instead of leaving with its own left edge, the
5
+ * header's range title is dropped in its favour, and the column is dropped so
6
+ * each row's name rides its own bar.
7
+ */
8
+ import {
9
+ atViewport,
10
+ renderWithProviders,
11
+ usePhoneViewport,
12
+ wideViewport,
13
+ } from "@multiplatform.one/test-utils";
14
+ import { act, cleanup } from "@testing-library/react";
15
+ import { afterEach, describe, expect, it } from "vitest";
16
+ import { GanttView } from "./Gantt";
17
+ import {
18
+ aaTextContrastRatio,
19
+ apcaContrast,
20
+ contrastRatio,
21
+ fillLabelLc,
22
+ formatMonthYear,
23
+ normalizeToHex,
24
+ relativeLuminance,
25
+ } from "@multiplatform.one/theme";
26
+ import { useTheme } from "tamagui";
27
+
28
+ usePhoneViewport();
29
+ afterEach(cleanup);
30
+
31
+ const day = (n: number) => new Date(2026, 2, n);
32
+ const rangeTitle = /\w+ \d{4} – \w+ \d{4}/;
33
+ const tasks = [
34
+ { id: "discovery", title: "Discovery & scoping", start: day(2), end: day(12) },
35
+ { id: "build", title: "Implementation", start: day(14), end: day(40) },
36
+ { id: "launch", title: "Launch", start: day(44), end: day(44) },
37
+ ];
38
+
39
+ /** The Components/Gantt Default story's six tasks, on fixed dates. */
40
+ const storyTasks = [
41
+ { id: "1", title: "Discovery & scoping", start: day(2), end: day(6), progress: 100 },
42
+ { id: "2", title: "Design review", start: day(5), end: day(9) },
43
+ { id: "3", title: "Implementation", start: day(9), end: day(17), progress: 55 },
44
+ { id: "4", title: "QA pass", start: day(15), end: day(20), progress: 20 },
45
+ { id: "5", title: "Docs & handoff", start: day(18), end: day(22), intent: "success" as const },
46
+ { id: "6", title: "Launch", start: day(23), end: day(23), intent: "error" as const },
47
+ ];
48
+
49
+ function fiberProps(node: Element, has: string): Record<string, any> {
50
+ const key = Object.keys(node).find((k) => k.startsWith("__reactFiber$"));
51
+ let fiber = key ? (node as any)[key] : null;
52
+ while (fiber && fiber.memoizedProps?.[has] === undefined) fiber = fiber.return;
53
+ return fiber?.memoizedProps ?? {};
54
+ }
55
+
56
+ function scrollerProps(node: Element): Record<string, any> {
57
+ const key = Object.keys(node).find((k) => k.startsWith("__reactFiber$"));
58
+ let fiber = key ? (node as any)[key] : null;
59
+ while (
60
+ fiber &&
61
+ !(
62
+ typeof fiber.memoizedProps?.onScroll === "function" &&
63
+ typeof fiber.memoizedProps?.onLayout === "function" &&
64
+ fiber.memoizedProps?.horizontal === true &&
65
+ "flex" in fiber.memoizedProps
66
+ )
67
+ )
68
+ fiber = fiber.return;
69
+ return fiber?.memoizedProps ?? {};
70
+ }
71
+
72
+ const event = (nativeEvent: unknown) => ({ nativeEvent, stopPropagation() {}, persist() {} });
73
+
74
+ describe("a Gantt on a phone (FZ-11773)", () => {
75
+ it("names the month and year of whatever the canvas is showing, however far it is scrolled", () => {
76
+ const view = renderWithProviders(<GanttView tasks={tasks} initialDate={day(1)} />);
77
+ const chart = view.container.querySelector("[data-gantt-chart]")!;
78
+ const width = 210;
79
+ const chartWidth = Number(
80
+ fiberProps(view.container.querySelector("[data-gantt-axis]")!, "width").width,
81
+ );
82
+ expect(chartWidth).toBeGreaterThan(width);
83
+ for (const offset of [0, chartWidth / 3, chartWidth]) {
84
+ act(() => {
85
+ scrollerProps(chart).onLayout(event({ layout: { width } }));
86
+ scrollerProps(chart).onScroll(event({ contentOffset: { x: offset } }));
87
+ });
88
+ const start = Math.max(0, Math.min(offset, chartWidth - width));
89
+ const months = Array.from(view.container.querySelectorAll("[data-gantt-month]"));
90
+ const onScreen = months.filter((month) => {
91
+ const left = Number(fiberProps(month, "width").left);
92
+ return left >= start && left <= start + width;
93
+ });
94
+ expect(onScreen.length, `offset ${offset}`).toBeGreaterThan(0);
95
+ expect(onScreen[0]!.textContent, `offset ${offset}`).toMatch(/\d{4}$/);
96
+ }
97
+ });
98
+
99
+ it("drops the header's range title on a phone, since the axis band carries it", () => {
100
+ const phone = renderWithProviders(<GanttView tasks={tasks} initialDate={day(1)} />);
101
+ const months = Array.from(phone.container.querySelectorAll("[data-gantt-month]")).map(
102
+ (month) => month.textContent,
103
+ );
104
+ expect(months).toContain(formatMonthYear(day(1)));
105
+ expect(phone.container.textContent).not.toMatch(rangeTitle);
106
+ cleanup();
107
+ atViewport(wideViewport, () => {
108
+ const wide = renderWithProviders(<GanttView tasks={tasks} initialDate={day(1)} />);
109
+ expect(wide.container.textContent).toMatch(rangeTitle);
110
+ });
111
+ });
112
+
113
+ it("drops the task column, and every row's name rides its own bar instead", () => {
114
+ const phone = renderWithProviders(<GanttView tasks={storyTasks} initialDate={day(1)} />);
115
+ expect(phone.container.querySelectorAll("[data-gantt-row-label]")).toHaveLength(0);
116
+ for (const task of storyTasks) {
117
+ const bar = phone.container.querySelector(`[data-gantt-bar="${task.id}"]`)!;
118
+ const inside = bar.querySelector("[data-gantt-bar-ink]")?.textContent;
119
+ const outside = bar.querySelector("[data-gantt-bar-outside-label]")?.textContent;
120
+ expect(`${inside ?? ""}${outside ?? ""}`, task.id).toContain(task.title);
121
+ }
122
+ cleanup();
123
+ atViewport(wideViewport, () => {
124
+ const wide = renderWithProviders(<GanttView tasks={storyTasks} initialDate={day(1)} />);
125
+ expect(wide.container.querySelectorAll("[data-gantt-row-label]")).toHaveLength(6);
126
+ });
127
+ });
128
+
129
+ it("names an eternal rail too, which the column used to name for it", () => {
130
+ const phone = renderWithProviders(
131
+ <GanttView tasks={[{ id: "base", title: "Base policy" }]} initialDate={day(1)} />,
132
+ );
133
+ const rail = phone.container.querySelector('[data-gantt-bar="base"]')!;
134
+ expect(rail.getAttribute("data-gantt-rail")).toBe("true");
135
+ expect(rail.querySelector("[data-gantt-bar-ink]")?.textContent).toContain("Base policy");
136
+ cleanup();
137
+ atViewport(wideViewport, () => {
138
+ const wide = renderWithProviders(
139
+ <GanttView tasks={[{ id: "base", title: "Base policy" }]} initialDate={day(1)} />,
140
+ );
141
+ expect(wide.container.querySelector('[data-gantt-bar="base"]')).not.toBeNull();
142
+ expect(
143
+ wide.container.querySelector('[data-gantt-bar="base"] [data-gantt-bar-ink]'),
144
+ ).toBeNull();
145
+ });
146
+ });
147
+
148
+ it("holds a name carried on the canvas to the floors the on-bar ink holds", () => {
149
+ const captured: Record<string, { val?: unknown } | undefined>[] = [];
150
+ function Capture() {
151
+ captured.push(useTheme() as never);
152
+ return null;
153
+ }
154
+ const title = "Discovery & scoping of the data migration";
155
+ const phone = renderWithProviders(
156
+ <>
157
+ <Capture />
158
+ <GanttView
159
+ tasks={[{ id: "long", title, start: day(2), end: day(4) }]}
160
+ initialDate={day(1)}
161
+ />
162
+ </>,
163
+ );
164
+ expect(phone.container.querySelector("[data-gantt-bar-outside-label]")?.textContent).toBe(
165
+ title,
166
+ );
167
+ const theme = captured[0]!;
168
+ const read = (token: string) => normalizeToHex(String(theme[token]?.val))!;
169
+ const ink = read("color");
170
+ const canvas = read("background");
171
+ expect(contrastRatio(relativeLuminance(ink), relativeLuminance(canvas))).toBeGreaterThanOrEqual(
172
+ aaTextContrastRatio,
173
+ );
174
+ expect(Math.abs(apcaContrast(ink, canvas))).toBeGreaterThanOrEqual(fillLabelLc);
175
+ });
176
+
177
+ it("shows more of the schedule with the column gone, and still not all of it", () => {
178
+ const widestWindow = (width: number) => {
179
+ const view = renderWithProviders(<GanttView tasks={storyTasks} initialDate={day(1)} />);
180
+ const chart = view.container.querySelector("[data-gantt-chart]")!;
181
+ act(() => {
182
+ scrollerProps(chart).onLayout(event({ layout: { width } }));
183
+ });
184
+ const boxes = storyTasks.map((task) => {
185
+ const box = fiberProps(
186
+ view.container.querySelector(`[data-gantt-bar="${task.id}"]`)!,
187
+ "width",
188
+ );
189
+ return { left: Number(box.left), right: Number(box.left) + Number(box.width) };
190
+ });
191
+ const best = Math.max(
192
+ ...boxes.map(
193
+ ({ left }) => boxes.filter((box) => box.left < left + width && box.right > left).length,
194
+ ),
195
+ );
196
+ cleanup();
197
+ return best;
198
+ };
199
+ const withColumn = widestWindow(390 - 180);
200
+ const withoutColumn = widestWindow(390);
201
+ expect(withoutColumn).toBeGreaterThan(withColumn);
202
+ expect([withColumn, withoutColumn]).toEqual([4, 5]);
203
+ expect(withoutColumn).toBeLessThan(storyTasks.length);
204
+ });
205
+ });
@@ -11,11 +11,14 @@ import {
11
11
  dateToX,
12
12
  dayDiff,
13
13
  dxToDayDelta,
14
+ estimateLabelWidth,
14
15
  formatSpanLabel,
15
16
  ganttTaskAccessibleLabel,
16
17
  generateTicks,
17
18
  isBoundedSpan,
18
19
  isEternalSpan,
20
+ LABEL_CHAR_EM,
21
+ labelFitsBar,
19
22
  normalizeSpanEdges,
20
23
  openBarGeometry,
21
24
  openSpanExtent,
@@ -111,6 +114,14 @@ describe("ganttMath", () => {
111
114
  const geom = barGeometry({ start: mar(10), end: mar(10) }, rangeStart, 4, 6);
112
115
  expect(geom.width).toBe(6);
113
116
  });
117
+
118
+ it("answers whether a one-line label fits a bar, since the bar's width is its dates", () => {
119
+ expect(estimateLabelWidth("Discovery & scoping", 15)).toBeCloseTo(19 * LABEL_CHAR_EM * 15, 5);
120
+ expect(labelFitsBar("Build", 120, 16, 15)).toBe(true);
121
+ expect(labelFitsBar("Discovery & scoping", 120, 16, 15)).toBe(false);
122
+ expect(labelFitsBar("Discovery & scoping", 240, 16, 15)).toBe(true);
123
+ expect(labelFitsBar("Build", 40, 16, 15)).toBe(false);
124
+ });
114
125
  });
115
126
 
116
127
  describe("zoom-level scale changes", () => {
@@ -344,8 +355,10 @@ const tasks: GanttTask[] = [
344
355
  describe("GanttView", () => {
345
356
  it("renders one labeled row and one bar per task", () => {
346
357
  const { container } = renderWithProviders(<GanttView tasks={tasks} />);
347
- expect(screen.getByText("Design review")).toBeInTheDocument();
348
- expect(screen.getByText("Implementation")).toBeInTheDocument();
358
+ const rowLabel = (id: string) =>
359
+ container.querySelector(`[data-gantt-row-label="${id}"]`)?.textContent;
360
+ expect(rowLabel("t1")).toContain("Design review");
361
+ expect(rowLabel("t2")).toContain("Implementation");
349
362
  expect(container.querySelectorAll("[data-gantt-bar]")).toHaveLength(3);
350
363
  expect(container.querySelector('[data-gantt-bar="t1"]')).toBeTruthy();
351
364
  });
@@ -228,22 +228,23 @@ describe("a light Gantt bar is a solid with on-solid ink (FZ-9366)", () => {
228
228
  });
229
229
  });
230
230
 
231
- describe("secondary tones sit on the AA floor, pinned (FZ-9366)", () => {
231
+ describe("secondary tones sit on the label floor, pinned (FZ-9366, FZ-11773)", () => {
232
232
  it.each([
233
- ["light Calendar green time", "light_blue", "#2b9a66", "selected", "#1e6446", 4.54],
234
- ["dark Calendar green time", "dark_blue", "#2b9a66", "selected", "#8ae8b6", 4.51],
235
- ["light proposed label", "light_blue", Colors.blue.blue9, "ghost", "#0e6abe", 4.52],
236
- ] as const)("%s", (_, name, fill, state, tone, floor) => {
233
+ ["light Calendar green time", "light_blue", "#2b9a66", "selected", "#1c593f", 5.28, 60.3],
234
+ ["dark Calendar green time", "dark_blue", "#2b9a66", "selected", "#8ae8b6", 4.51, 60.9],
235
+ ["light proposed label", "light_blue", Colors.blue.blue9, "ghost", "#0e6abe", 4.52, 63.7],
236
+ ] as const)("%s", (_, name, fill, state, tone, floor, lc) => {
237
237
  const theme = themes[name]!;
238
238
  const dark = name.startsWith("dark");
239
239
  const paint = eventPaint(theme, fill, state, { dark, surface: hex(theme, "$background") })!;
240
240
  const ink = eventLabelInk(theme, fill, [paint], dark, "secondary");
241
241
  expect(ink).toBe(tone);
242
242
  expect(ratio(ink, paint)).toBeCloseTo(floor, 2);
243
+ expect(Math.abs(apcaContrast(ink, paint))).toBeCloseTo(lc, 1);
243
244
  });
244
245
  });
245
246
 
246
- describe("bar labels hold AA and keep their preferred ink where it reads (FZ-9366)", () => {
247
+ describe("bar labels hold AA and Lc 60 and keep their preferred ink where it reads (FZ-9366, FZ-11773)", () => {
247
248
  for (const scheme of ["light", "dark"] as const)
248
249
  for (const hue of hues)
249
250
  it(`${scheme}${hue}`, () => {
@@ -261,7 +262,9 @@ describe("bar labels hold AA and keep their preferred ink where it reads (FZ-936
261
262
  const label = `${name} ${state}`;
262
263
  const ramp = eventRamp(theme, fill, scheme === "dark")!;
263
264
  const [dim, full] = [11, 12].map((step) => normalizeToHex(ramp(step)!)!);
264
- const reads = (tone: string) => ratio(tone, paint) >= aaTextContrastRatio;
265
+ const reads = (tone: string) =>
266
+ ratio(tone, paint) >= aaTextContrastRatio &&
267
+ Math.abs(apcaContrast(tone, paint)) >= fillLabelLc;
265
268
  if (tone === "primary") {
266
269
  if (reads(full!)) expect(ink, `${label} keeps step 12`).toBe(full);
267
270
  } else if (reads(full!)) {
@@ -283,6 +286,10 @@ describe("bar labels hold AA and keep their preferred ink where it reads (FZ-936
283
286
  expect(ratio(inkHex, paint), `${label}: ${inkHex} on ${paint}`).toBeGreaterThanOrEqual(
284
287
  aaTextContrastRatio,
285
288
  );
289
+ expect(
290
+ Math.abs(apcaContrast(inkHex, paint)),
291
+ `${label}: ${inkHex} on ${paint} APCA`,
292
+ ).toBeGreaterThanOrEqual(fillLabelLc);
286
293
  }
287
294
  });
288
295
  });