@bearmenu/ui 0.8.22 → 0.8.24

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 (57) hide show
  1. package/dist/{chunk-AHL45DD2.js → chunk-I4RUOAU7.js} +38 -11
  2. package/dist/{chunk-DJD3EMPK.js → chunk-YE4ZQUTI.js} +1 -1
  3. package/dist/components/badge.d.ts +1 -1
  4. package/dist/components/button.d.ts +1 -1
  5. package/dist/components/card.d.ts +2 -2
  6. package/dist/components/command.d.ts +15 -15
  7. package/dist/components/concept-compare.d.ts +1 -1
  8. package/dist/components/doorway-tiles.d.ts +1 -1
  9. package/dist/components/drift-rail.d.ts +29 -2
  10. package/dist/components/drift-rail.js +3 -1
  11. package/dist/components/grade-atom.d.ts +1 -1
  12. package/dist/components/grade-atom.js +1 -1
  13. package/dist/components/item.d.ts +2 -2
  14. package/dist/components/kitchen-dossier.d.ts +1 -1
  15. package/dist/components/menu-dead-end.d.ts +1 -1
  16. package/dist/components/menu-family-block.d.ts +1 -1
  17. package/dist/components/menu-family-card.d.ts +1 -1
  18. package/dist/components/menu-filter-chips.d.ts +1 -1
  19. package/dist/components/menu-group-rows.d.ts +1 -1
  20. package/dist/components/menu-index-header.d.ts +1 -1
  21. package/dist/components/menu-index-list.d.ts +1 -1
  22. package/dist/components/menu-intent-hero.d.ts +1 -1
  23. package/dist/components/menu-item.d.ts +1 -1
  24. package/dist/components/menu-kitchen-list.d.ts +1 -1
  25. package/dist/components/menu-mocks.d.ts +1 -1
  26. package/dist/components/menu-types.d.ts +1 -1
  27. package/dist/components/open-now-list.d.ts +1 -1
  28. package/dist/components/place-about-tab.d.ts +1 -1
  29. package/dist/components/place-card.d.ts +1 -1
  30. package/dist/components/place-card.js +1 -1
  31. package/dist/components/place-details-mobile.d.ts +1 -1
  32. package/dist/components/place-schedule-week.d.ts +1 -1
  33. package/dist/components/place-types.d.ts +1 -1
  34. package/dist/components/poster-tape.d.ts +15 -2
  35. package/dist/components/poster-tape.js +12 -3
  36. package/dist/components/qa-block.d.ts +1 -1
  37. package/dist/components/spinner.d.ts +2 -2
  38. package/dist/components/tag.d.ts +2 -2
  39. package/dist/components/text.d.ts +3 -3
  40. package/dist/components/top-comparison.d.ts +1 -1
  41. package/dist/components/top-cross-link.d.ts +1 -1
  42. package/dist/components/top-ranking-entry.d.ts +1 -1
  43. package/dist/components/top-ranking-hero.d.ts +1 -1
  44. package/dist/components/top-types.d.ts +1 -1
  45. package/dist/components/venue-grade-dimensions.d.ts +1 -1
  46. package/dist/components/venue-quotes.d.ts +1 -1
  47. package/dist/components/venue-wall.d.ts +1 -1
  48. package/dist/{place-types-BHdeMMiG.d.ts → place-types-C4rR3LTs.d.ts} +7 -0
  49. package/package.json +1 -1
  50. package/src/components/drift-rail.stories.tsx +29 -1
  51. package/src/components/drift-rail.test.tsx +125 -0
  52. package/src/components/drift-rail.tsx +71 -4
  53. package/src/components/grade-atom.test.tsx +32 -0
  54. package/src/components/grade-atom.tsx +8 -1
  55. package/src/components/poster-tape.stories.tsx +29 -0
  56. package/src/components/poster-tape.test.tsx +42 -0
  57. package/src/components/poster-tape.tsx +21 -5
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { QaItem } from './menu-types.js';
3
3
  import 'react';
4
- import '../place-types-BHdeMMiG.js';
4
+ import '../place-types-C4rR3LTs.js';
5
5
  import '../lib/grade.js';
6
6
 
7
7
  /**
@@ -4,11 +4,11 @@ import { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  declare const spinnerVariants: (props?: ({
6
6
  size?: "default" | "xs" | "sm" | "lg" | "xl" | null | undefined;
7
- tone?: "default" | "destructive" | "inherit" | "primary" | null | undefined;
7
+ tone?: "inherit" | "default" | "destructive" | "primary" | null | undefined;
8
8
  } & class_variance_authority_types.ClassProp) | undefined) => string;
9
9
  declare const Spinner: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLSpanElement> & VariantProps<(props?: ({
10
10
  size?: "default" | "xs" | "sm" | "lg" | "xl" | null | undefined;
11
- tone?: "default" | "destructive" | "inherit" | "primary" | null | undefined;
11
+ tone?: "inherit" | "default" | "destructive" | "primary" | null | undefined;
12
12
  } & class_variance_authority_types.ClassProp) | undefined) => string> & {
13
13
  /** Visually-hidden label for screen readers. Defaults to "Loading". */
14
14
  label?: string;
@@ -3,11 +3,11 @@ import * as React from 'react';
3
3
  import { VariantProps } from 'class-variance-authority';
4
4
 
5
5
  declare const tagVariants: (props?: ({
6
- variant?: "default" | "destructive" | "warning" | "success" | "primary" | "outline" | "quiet" | null | undefined;
6
+ variant?: "default" | "destructive" | "outline" | "warning" | "success" | "primary" | "quiet" | null | undefined;
7
7
  size?: "default" | "sm" | "lg" | null | undefined;
8
8
  } & class_variance_authority_types.ClassProp) | undefined) => string;
9
9
  declare const Tag: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLSpanElement> & VariantProps<(props?: ({
10
- variant?: "default" | "destructive" | "warning" | "success" | "primary" | "outline" | "quiet" | null | undefined;
10
+ variant?: "default" | "destructive" | "outline" | "warning" | "success" | "primary" | "quiet" | null | undefined;
11
11
  size?: "default" | "sm" | "lg" | null | undefined;
12
12
  } & class_variance_authority_types.ClassProp) | undefined) => string> & {
13
13
  onRemove?: () => void;
@@ -22,9 +22,9 @@ import { VariantProps } from 'class-variance-authority';
22
22
  * Weights are 400 / 600 / 700. 500 is not in the system.
23
23
  */
24
24
  declare const textVariants: (props?: ({
25
- variant?: "small" | "display" | "h1" | "h2" | "h3" | "h4" | "body-lg" | "body" | "body-sm" | "caption" | "label" | "overline" | null | undefined;
26
- color?: "default" | "destructive" | "inherit" | "muted" | "primary" | "primary-foreground" | null | undefined;
27
- weight?: "bold" | "normal" | "medium" | "semibold" | null | undefined;
25
+ variant?: "h2" | "h3" | "label" | "body" | "caption" | "h1" | "h4" | "small" | "display" | "body-lg" | "body-sm" | "overline" | null | undefined;
26
+ color?: "inherit" | "default" | "destructive" | "muted" | "primary" | "primary-foreground" | null | undefined;
27
+ weight?: "bold" | "medium" | "normal" | "semibold" | null | undefined;
28
28
  leading?: "none" | "normal" | "tight" | "snug" | "relaxed" | "loose" | null | undefined;
29
29
  tracking?: "normal" | "tight" | "wide" | "wider" | null | undefined;
30
30
  wrap?: "balance" | "pretty" | "nowrap" | null | undefined;
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { MenuLinkComponent } from './menu-types.js';
3
3
  import { TopComparisonRow } from './top-types.js';
4
4
  import 'react';
5
- import '../place-types-BHdeMMiG.js';
5
+ import '../place-types-C4rR3LTs.js';
6
6
  import '../lib/grade.js';
7
7
 
8
8
  type TopComparisonLabels = {
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { MenuLinkComponent } from './menu-types.js';
3
3
  import 'react';
4
- import '../place-types-BHdeMMiG.js';
4
+ import '../place-types-C4rR3LTs.js';
5
5
  import '../lib/grade.js';
6
6
 
7
7
  type TopCrossLinkProps = {
@@ -3,7 +3,7 @@ import { MenuItemLabels } from './menu-item.js';
3
3
  import { MenuItemPreview, MenuLinkComponent } from './menu-types.js';
4
4
  import { TopRankEntry } from './top-types.js';
5
5
  import 'react';
6
- import '../place-types-BHdeMMiG.js';
6
+ import '../place-types-C4rR3LTs.js';
7
7
  import '../lib/grade.js';
8
8
 
9
9
  type TopRankingEntryLabels = {
@@ -2,7 +2,7 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { MenuLinkComponent } from './menu-types.js';
3
3
  import { TopExit } from './top-types.js';
4
4
  import 'react';
5
- import '../place-types-BHdeMMiG.js';
5
+ import '../place-types-C4rR3LTs.js';
6
6
  import '../lib/grade.js';
7
7
 
8
8
  type TopRankingHeroProps = {
@@ -1,6 +1,6 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { MenuItemPreview } from './menu-types.js';
3
- import '../place-types-BHdeMMiG.js';
3
+ import '../place-types-C4rR3LTs.js';
4
4
  import 'react/jsx-runtime';
5
5
  import '../lib/grade.js';
6
6
 
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { a as PlaceGradeDimensions } from '../place-types-BHdeMMiG.js';
2
+ import { a as PlaceGradeDimensions } from '../place-types-C4rR3LTs.js';
3
3
  import '../lib/grade.js';
4
4
 
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { C as CitedText } from '../place-types-BHdeMMiG.js';
2
+ import { C as CitedText } from '../place-types-C4rR3LTs.js';
3
3
  import '../lib/grade.js';
4
4
 
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { MenuLinkComponent, MenuLinkProps } from './menu-types.js';
3
- import { P as PlacePreview } from '../place-types-BHdeMMiG.js';
3
+ import { P as PlacePreview } from '../place-types-C4rR3LTs.js';
4
4
  import 'react';
5
5
  import '../lib/grade.js';
6
6
 
@@ -12,6 +12,13 @@ type GradeAtomLabels = {
12
12
  aria: (value: string) => string;
13
13
  /** Title + aria suffix when `grade.capped`, e.g. "Capped for low confidence". */
14
14
  capped: string;
15
+ /**
16
+ * The number as the locale writes it, e.g. `8,7` in Romanian. Receives the
17
+ * grade already rounded to one decimal; return the glyphs to print. Defaults
18
+ * to `formatGrade` (`8.7`, a trailing `.0` dropped). It is a label because the
19
+ * decimal mark is translation, not styling — and `aria` gets the same string.
20
+ */
21
+ value?: (overall: number) => string;
15
22
  };
16
23
  type GradeAtomProps = {
17
24
  grade: PlaceGrade;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bearmenu/ui",
3
- "version": "0.8.22",
3
+ "version": "0.8.24",
4
4
  "description": "BearMenu design system — shared UI tokens, primitives, and components",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {
@@ -32,7 +32,7 @@ const meta: Meta<typeof DriftRail> = {
32
32
  docs: {
33
33
  description: {
34
34
  component:
35
- "An infinite horizontal marquee. Duplicates its children once so a `translateX(-50%)` loop is seamless — pass a fixed, ordered list. Pauses on hover, pauses when scrolled off-screen (`IntersectionObserver`), and stops outright under `prefers-reduced-motion`.",
35
+ "An infinite horizontal marquee the reader can take hold of. Duplicates its children once (the copy is `inert`) so the scroll loop is seamless — pass a fixed, ordered list. Pauses on hover, pauses when scrolled off-screen (`IntersectionObserver`), stops outright under `prefers-reduced-motion`, and with `labels` renders a pause/play latch (WCAG 2.2.2).",
36
36
  },
37
37
  },
38
38
  },
@@ -90,3 +90,31 @@ export const WithFeaturedItems: Story = {
90
90
  </div>
91
91
  ),
92
92
  };
93
+
94
+ /**
95
+ * With `labels`, a pause/play toggle renders under the rail's right edge —
96
+ * the same latch, glyph and 44px target as `WeekendPanel`'s (WCAG 2.2.2).
97
+ * Pressing it holds the rail still until play is pressed; hover and touch
98
+ * still pause it on their own. The control is not rendered under
99
+ * `prefers-reduced-motion`, where nothing drifts. The duplicate pass is
100
+ * `inert`, so Tab visits each item once.
101
+ */
102
+ export const WithPauseControl: Story = {
103
+ render: () => (
104
+ <div className="max-w-[420px]">
105
+ <DriftRail durationSeconds={30} labels={{ pause: "Pause the rail", play: "Play the rail" }}>
106
+ {["Warehouse Rave", "Jazz on the Rooftop", "Open Mic Night", "Street Food Market"].map(
107
+ (title) => (
108
+ <FeaturedRailItem
109
+ key={title}
110
+ title={title}
111
+ venue="Atelier Café"
112
+ note="Sat 5 · 20:00"
113
+ href={`/events/${title.toLowerCase().replace(/\s+/g, "-")}`}
114
+ />
115
+ )
116
+ )}
117
+ </DriftRail>
118
+ </div>
119
+ ),
120
+ };
@@ -0,0 +1,125 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
2
+ import { act, fireEvent, render, screen } from "@testing-library/react";
3
+ import { DriftRail } from "./drift-rail";
4
+
5
+ const labels = { pause: "Pause the rail", play: "Play the rail" };
6
+
7
+ /**
8
+ * jsdom lays nothing out, so the track's `scrollWidth` is 0 and the loop's
9
+ * `half > 0` guard skips every frame. The tests give the track a width and
10
+ * the scroller a writable `scrollLeft`, capture the rAF callbacks, and drive
11
+ * the frames by hand with a clock that moves in whole seconds.
12
+ */
13
+ const TRACK_WIDTH = 2000;
14
+
15
+ let frames = new Map<number, FrameRequestCallback>();
16
+ let nextFrameId = 1;
17
+ let now = 0;
18
+
19
+ function runFrame(elapsedMs: number) {
20
+ now += elapsedMs;
21
+ const pending = [...frames.values()];
22
+ frames = new Map();
23
+ act(() => {
24
+ for (const frame of pending) frame(now);
25
+ });
26
+ }
27
+
28
+ function renderRail(props: Partial<React.ComponentProps<typeof DriftRail>> = {}) {
29
+ const view = render(
30
+ <DriftRail durationSeconds={10} {...props}>
31
+ <a href="/a">A</a>
32
+ <a href="/b">B</a>
33
+ </DriftRail>
34
+ );
35
+ const track = screen.getAllByText("A")[0].parentElement as HTMLElement;
36
+ const scroller = track.parentElement as HTMLElement;
37
+ Object.defineProperty(track, "scrollWidth", { value: TRACK_WIDTH, configurable: true });
38
+ let scrollLeft = 0;
39
+ Object.defineProperty(scroller, "scrollLeft", {
40
+ get: () => scrollLeft,
41
+ set: (value: number) => {
42
+ scrollLeft = value;
43
+ },
44
+ configurable: true,
45
+ });
46
+ return { ...view, scroller, track };
47
+ }
48
+
49
+ beforeEach(() => {
50
+ frames = new Map();
51
+ nextFrameId = 1;
52
+ now = 0;
53
+ vi.spyOn(window, "requestAnimationFrame").mockImplementation((callback) => {
54
+ const id = nextFrameId++;
55
+ frames.set(id, callback);
56
+ return id;
57
+ });
58
+ vi.spyOn(window, "cancelAnimationFrame").mockImplementation((id) => {
59
+ frames.delete(id);
60
+ });
61
+ vi.spyOn(performance, "now").mockImplementation(() => now);
62
+ });
63
+
64
+ afterEach(() => {
65
+ vi.restoreAllMocks();
66
+ });
67
+
68
+ describe("DriftRail", () => {
69
+ it("advances the scroller by width / duration per second", () => {
70
+ const { scroller } = renderRail();
71
+ runFrame(0);
72
+ runFrame(1000);
73
+ // One copy is half the track; 1000px over 10s is 100px per second.
74
+ expect(scroller.scrollLeft).toBeCloseTo(100, 5);
75
+ });
76
+
77
+ it("renders no control without labels", () => {
78
+ renderRail();
79
+ expect(screen.queryByRole("button")).not.toBeInTheDocument();
80
+ });
81
+
82
+ it("stops advancing when the reader presses pause, and stays stopped until play", () => {
83
+ const { scroller } = renderRail({ labels });
84
+ runFrame(0);
85
+ runFrame(1000);
86
+ const advanced = scroller.scrollLeft;
87
+ expect(advanced).toBeGreaterThan(0);
88
+
89
+ const toggle = screen.getByRole("button", { name: labels.pause });
90
+ expect(toggle).toHaveAttribute("aria-pressed", "false");
91
+ fireEvent.click(toggle);
92
+
93
+ expect(toggle).toHaveAttribute("aria-pressed", "true");
94
+ expect(toggle).toHaveAccessibleName(labels.play);
95
+
96
+ runFrame(0);
97
+ runFrame(1000);
98
+ runFrame(1000);
99
+ expect(scroller.scrollLeft).toBe(advanced);
100
+
101
+ // The latch survives the hover hold lifting: nothing but play resumes it.
102
+ fireEvent.mouseEnter(scroller);
103
+ fireEvent.mouseLeave(scroller);
104
+ runFrame(0);
105
+ runFrame(1000);
106
+ expect(scroller.scrollLeft).toBe(advanced);
107
+
108
+ fireEvent.click(toggle);
109
+ expect(toggle).toHaveAttribute("aria-pressed", "false");
110
+ runFrame(0);
111
+ runFrame(1000);
112
+ expect(scroller.scrollLeft).toBeGreaterThan(advanced);
113
+ });
114
+
115
+ it("makes the duplicate pass inert as well as aria-hidden", () => {
116
+ const { track } = renderRail();
117
+ const copies = screen.getAllByText("A");
118
+ expect(copies).toHaveLength(2);
119
+ const clone = copies[1].parentElement as HTMLElement;
120
+ expect(clone.parentElement).toBe(track);
121
+ expect(clone).toHaveAttribute("aria-hidden", "true");
122
+ expect(clone).toHaveAttribute("inert");
123
+ expect(copies[0].parentElement).toBe(track);
124
+ });
125
+ });
@@ -3,6 +3,7 @@
3
3
  import { useEffect, useRef, useState } from "react";
4
4
  import type { PointerEvent as ReactPointerEvent } from "react";
5
5
  import { cn } from "../lib/utils";
6
+ import { MotionPlayPause } from "./motion-icon-controls";
6
7
 
7
8
  /**
8
9
  * DriftRail — an infinite horizontal marquee for logos, tag chips or small
@@ -30,7 +31,29 @@ import { cn } from "../lib/utils";
30
31
  * work nobody can see. `prefers-reduced-motion` removes the drift entirely;
31
32
  * the rail stays scrollable by hand, which is more than the static strip it
32
33
  * used to collapse to.
34
+ *
35
+ * THE READER CAN STOP IT FOR GOOD. Hover and touch are holds; a rail that
36
+ * drifts for longer than five seconds also needs a control the reader can
37
+ * press (WCAG 2.2.2), and a low-vision reader who cannot follow the motion
38
+ * needs it to stay stopped. Pass `labels` and the rail renders a pause/play
39
+ * toggle under its right edge — the same latch, glyph and 44px target as
40
+ * `WeekendPanel`'s, so the hub's rails all answer to one control. It is not
41
+ * rendered under `prefers-reduced-motion`, where there is nothing to stop.
42
+ *
43
+ * THE DUPLICATE IS INERT. The second copy is what makes the loop seamless,
44
+ * but its links are the same links again: `aria-hidden` kept them out of the
45
+ * accessibility tree and left them in the tab order, so a keyboard reader
46
+ * tabbed through every item twice. `inert` removes them from focus and
47
+ * hit-testing as well.
33
48
  */
49
+ /** Accessible names for the pause/play toggle, injected so the DS owns no copy. */
50
+ export type DriftRailLabels = {
51
+ /** Name announced while the rail drifts (the button pauses it). */
52
+ pause: string;
53
+ /** Name announced while the rail is paused (the button resumes it). */
54
+ play: string;
55
+ };
56
+
34
57
  export type DriftRailProps = {
35
58
  children: React.ReactNode;
36
59
  /** Runs the loop right-to-left instead of left-to-right. */
@@ -39,6 +62,12 @@ export type DriftRailProps = {
39
62
  durationSeconds?: number;
40
63
  /** Pauses the loop while the pointer hovers the rail. */
41
64
  pauseOnHover?: boolean;
65
+ /**
66
+ * Accessible names for the pause/play toggle. When given, the toggle
67
+ * renders whenever the rail drifts (never under `prefers-reduced-motion`);
68
+ * without it there is no control, as before.
69
+ */
70
+ labels?: DriftRailLabels;
42
71
  className?: string;
43
72
  };
44
73
 
@@ -51,6 +80,7 @@ export function DriftRail({
51
80
  reverse = false,
52
81
  durationSeconds = DRIFT_RAIL_DEFAULT_DURATION_SECONDS,
53
82
  pauseOnHover = true,
83
+ labels,
54
84
  className,
55
85
  }: DriftRailProps) {
56
86
  const scrollerRef = useRef<HTMLDivElement>(null);
@@ -58,6 +88,9 @@ export function DriftRail({
58
88
  const [isHovered, setIsHovered] = useState(false);
59
89
  const [inView, setInView] = useState(true);
60
90
  const [reducedMotion, setReducedMotion] = useState(false);
91
+ // A latch, not a hold: it only clears when the reader presses play.
92
+ const [isManuallyPaused, setIsManuallyPaused] = useState(false);
93
+ const [playPauseReplayToken, setPlayPauseReplayToken] = useState(0);
61
94
  // `heldUntil` is a timestamp rather than a boolean so a native touch scroll
62
95
  // that keeps going after the finger lifts is not fought by the drift.
63
96
  const heldUntil = useRef(0);
@@ -98,7 +131,8 @@ export function DriftRail({
98
131
 
99
132
  let frame = 0;
100
133
  let last = performance.now();
101
- const drifting = !reducedMotion && inView && !(pauseOnHover && isHovered);
134
+ const drifting =
135
+ !reducedMotion && !isManuallyPaused && inView && !(pauseOnHover && isHovered);
102
136
 
103
137
  // Start the reverse loop inside the second copy so it has room to travel.
104
138
  if (reverse && scroller.scrollLeft === 0) scroller.scrollLeft = track.scrollWidth / 2;
@@ -132,7 +166,7 @@ export function DriftRail({
132
166
  };
133
167
  frame = requestAnimationFrame(tick);
134
168
  return () => cancelAnimationFrame(frame);
135
- }, [durationSeconds, inView, isHovered, pauseOnHover, reducedMotion, reverse]);
169
+ }, [durationSeconds, inView, isHovered, isManuallyPaused, pauseOnHover, reducedMotion, reverse]);
136
170
 
137
171
  const hold = () => {
138
172
  heldUntil.current = Number.POSITIVE_INFINITY;
@@ -178,7 +212,7 @@ export function DriftRail({
178
212
  }
179
213
  };
180
214
 
181
- return (
215
+ const scroller = (
182
216
  <div
183
217
  ref={scrollerRef}
184
218
  onMouseEnter={() => setIsHovered(true)}
@@ -202,10 +236,43 @@ export function DriftRail({
202
236
  >
203
237
  <div ref={trackRef} className="flex w-max items-stretch gap-3.5">
204
238
  {children}
205
- <div className="contents" aria-hidden="true">
239
+ {/* `inert` as well as `aria-hidden`: the copy's links must leave the
240
+ tab order too, or a keyboard reader tabs every item twice. */}
241
+ <div className="contents" aria-hidden="true" inert>
206
242
  {children}
207
243
  </div>
208
244
  </div>
209
245
  </div>
210
246
  );
247
+
248
+ // The toggle exists to stop a drift; under reduced motion there is none.
249
+ // A sibling row, not an overlay: a button floated over the rail's corner
250
+ // would sit on an item and intercept the grab that starts there.
251
+ if (!labels || reducedMotion) return scroller;
252
+
253
+ return (
254
+ <>
255
+ {scroller}
256
+ <div className="flex justify-end">
257
+ {/* `MotionPlayPause`, as in `WeekendPanel`: the triangle folding into
258
+ two bars IS the state change. `active` is the bars, so it is
259
+ `!isManuallyPaused`; `replayToken` bumps on pointer down so the
260
+ gesture answers the touch. */}
261
+ <button
262
+ type="button"
263
+ onClick={() => setIsManuallyPaused((current) => !current)}
264
+ onPointerDown={() => setPlayPauseReplayToken((n) => n + 1)}
265
+ aria-label={isManuallyPaused ? labels.play : labels.pause}
266
+ aria-pressed={isManuallyPaused}
267
+ className="flex h-11 w-11 shrink-0 cursor-pointer items-center justify-center rounded-full text-muted-foreground transition-colors duration-150 hover:bg-muted hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 motion-reduce:transition-none"
268
+ >
269
+ <MotionPlayPause
270
+ active={!isManuallyPaused}
271
+ replayToken={playPauseReplayToken}
272
+ className="size-4"
273
+ />
274
+ </button>
275
+ </div>
276
+ </>
277
+ );
211
278
  }
@@ -0,0 +1,32 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { GradeAtom, type GradeAtomLabels } from "./grade-atom";
4
+
5
+ const labels: GradeAtomLabels = {
6
+ soft: "Worth exploring",
7
+ bands: { exceptional: "Exceptional", great: "Great", good: "Good", decent: "Decent", weak: "Weak" },
8
+ aria: (value) => `Grade ${value} out of 10`,
9
+ capped: "Capped for low confidence",
10
+ };
11
+
12
+ describe("GradeAtom", () => {
13
+ it("prints the grade with a dot and no trailing .0 by default", () => {
14
+ render(<GradeAtom grade={{ overall: 8.74 }} labels={labels} size="md" />);
15
+ expect(screen.getByLabelText("Grade 8.7 out of 10")).toHaveTextContent("8.7");
16
+ render(<GradeAtom grade={{ overall: 9 }} labels={labels} size="md" />);
17
+ expect(screen.getByLabelText("Grade 9 out of 10")).toHaveTextContent("9");
18
+ });
19
+
20
+ it("lets the labels write the number their locale's way, in the pill and in the aria name", () => {
21
+ const ro: GradeAtomLabels = { ...labels, value: (n) => n.toFixed(1).replace(".", ","), aria: (v) => `Nota ${v} din 10` };
22
+ render(<GradeAtom grade={{ overall: 8.74 }} labels={ro} size="md" />);
23
+ expect(screen.getByLabelText("Nota 8,7 din 10")).toHaveTextContent("8,7");
24
+ });
25
+
26
+ it("hands the formatter the rounded, clamped grade", () => {
27
+ const seen: number[] = [];
28
+ const spy: GradeAtomLabels = { ...labels, value: (n) => (seen.push(n), String(n)) };
29
+ render(<GradeAtom grade={{ overall: 12.26 }} labels={spy} size="md" />);
30
+ expect(seen).toEqual([10]);
31
+ });
32
+ });
@@ -41,6 +41,13 @@ export type GradeAtomLabels = {
41
41
  aria: (value: string) => string;
42
42
  /** Title + aria suffix when `grade.capped`, e.g. "Capped for low confidence". */
43
43
  capped: string;
44
+ /**
45
+ * The number as the locale writes it, e.g. `8,7` in Romanian. Receives the
46
+ * grade already rounded to one decimal; return the glyphs to print. Defaults
47
+ * to `formatGrade` (`8.7`, a trailing `.0` dropped). It is a label because the
48
+ * decimal mark is translation, not styling — and `aria` gets the same string.
49
+ */
50
+ value?: (overall: number) => string;
44
51
  };
45
52
 
46
53
  export type GradeAtomProps = {
@@ -221,7 +228,7 @@ export function GradeAtom({
221
228
  }
222
229
 
223
230
  const band = resolveGradeBand(overall);
224
- const value = formatGrade(overall);
231
+ const value = labels.value ? labels.value(Math.round(Math.min(10, Math.max(1, overall)) * 10) / 10) : formatGrade(overall);
225
232
  const descriptor = labels.bands[band];
226
233
  const showDesc = sz.showDesc && !hideDescriptor;
227
234
  const photo = onPhoto ? BAND_CLASSES_PHOTO[band] : null;
@@ -68,3 +68,32 @@ export const LongTitles: Story = {
68
68
  ],
69
69
  },
70
70
  };
71
+
72
+ /**
73
+ * A long localised date with the time split out into `time`. The date
74
+ * truncates ("sâm., 5 sept." becomes "sâm., 5 se…" if it must); the time is
75
+ * `shrink-0` outside the truncating span and is always whole. Before this the
76
+ * whole line was one truncating string and clipped to "17:…".
77
+ */
78
+ export const LocalisedDateAndTime: Story = {
79
+ args: {
80
+ items: [
81
+ { id: "1", title: "Warehouse Rave", meta: "sâmbătă, 5 septembrie", time: "17:00" },
82
+ { id: "2", title: "Jazz on the Rooftop", meta: "vineri, 4 septembrie", time: "19:30" },
83
+ { id: "3", title: "Open Mic Night", meta: "joi, 3 sept.", time: "21:00" },
84
+ { id: "4", title: "Street Food Market", meta: "duminică, 6 septembrie", time: "12:00" },
85
+ ],
86
+ },
87
+ };
88
+
89
+ /**
90
+ * With `labels`, a pause/play toggle renders under the tape's right edge —
91
+ * `<DriftRail>`'s control, forwarded. Pressing it latches the tape still
92
+ * until play is pressed again. It does not render under
93
+ * `prefers-reduced-motion`, where nothing drifts.
94
+ */
95
+ export const WithPauseControl: Story = {
96
+ args: {
97
+ labels: { pause: "Pause the tape", play: "Play the tape" },
98
+ },
99
+ };
@@ -0,0 +1,42 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { render, screen } from "@testing-library/react";
3
+ import { PosterTape } from "./poster-tape";
4
+
5
+ describe("PosterTape", () => {
6
+ it("renders meta alone when no time is given", () => {
7
+ render(<PosterTape items={[{ id: "1", title: "Warehouse Rave", meta: "SAT 20:00" }]} />);
8
+ const [meta] = screen.getAllByText("SAT 20:00");
9
+ expect(meta).toHaveClass("truncate");
10
+ expect(meta.parentElement?.childElementCount).toBe(1);
11
+ });
12
+
13
+ it("renders the time outside the truncating span so it never clips", () => {
14
+ render(
15
+ <PosterTape
16
+ items={[{ id: "1", title: "Warehouse Rave", meta: "sâm., 5 sept.", time: "17:00" }]}
17
+ />
18
+ );
19
+ const [meta] = screen.getAllByText("sâm., 5 sept.");
20
+ const [time] = screen.getAllByText("· 17:00");
21
+
22
+ expect(meta).toHaveClass("truncate");
23
+ expect(meta.contains(time)).toBe(false);
24
+ expect(time).toHaveClass("shrink-0");
25
+ expect(time).not.toHaveClass("truncate");
26
+ expect(time.parentElement).toBe(meta.parentElement);
27
+ expect(meta.parentElement).not.toHaveClass("truncate");
28
+ });
29
+
30
+ it("forwards labels to the rail's pause control", () => {
31
+ render(
32
+ <PosterTape
33
+ items={[{ id: "1", title: "Warehouse Rave", meta: "SAT 20:00" }]}
34
+ labels={{ pause: "Pause the tape", play: "Play the tape" }}
35
+ />
36
+ );
37
+ expect(screen.getByRole("button", { name: "Pause the tape" })).toHaveAttribute(
38
+ "aria-pressed",
39
+ "false"
40
+ );
41
+ });
42
+ });
@@ -3,7 +3,7 @@
3
3
  import { useState } from "react";
4
4
  import type { ReactNode } from "react";
5
5
  import { cn } from "../lib/utils";
6
- import { DriftRail } from "./drift-rail";
6
+ import { DriftRail, type DriftRailLabels } from "./drift-rail";
7
7
  import { EventPosterFallback } from "./event-poster-fallback";
8
8
 
9
9
  /**
@@ -17,8 +17,18 @@ import { EventPosterFallback } from "./event-poster-fallback";
17
17
  export type PosterTapeItem = {
18
18
  id: string;
19
19
  title: string;
20
- /** Caller-composed, e.g. "Sat 5 · 20:00". Rendered as mono, small. */
20
+ /**
21
+ * Caller-composed, e.g. "Sat 5" — or "Sat 5 · 20:00" when `time` is not
22
+ * given. Rendered as mono, small, and truncated at the tape's width.
23
+ */
21
24
  meta: string;
25
+ /**
26
+ * The time, e.g. "20:00", rendered after `meta` and never truncated. The
27
+ * tape is 132px wide and a long localised date ("sâm., 5 sept. · 17:00")
28
+ * used to clip to "17:…" — the one figure the reader came for. Split it out
29
+ * and the date is what gives way.
30
+ */
31
+ time?: string;
22
32
  posterUrl?: string;
23
33
  href?: string;
24
34
  /** Rendered instead of the poster when it's absent or failed to load. Defaults to `<EventPosterFallback />`. */
@@ -40,6 +50,8 @@ export type PosterTapeProps = {
40
50
  /** Defaults to a plain `<a>`. Pass `next/link` in a Next app. */
41
51
  linkComponent?: React.ComponentType<PosterTapeLinkProps>;
42
52
  durationSeconds?: number;
53
+ /** Forwarded to `<DriftRail>`: names for its pause/play toggle, which renders only when given. */
54
+ labels?: DriftRailLabels;
43
55
  className?: string;
44
56
  };
45
57
 
@@ -81,8 +93,11 @@ function PosterTapeItemCard({
81
93
  <div className="mt-1.5 text-[11px] font-semibold leading-[1.3] sm:mt-[7px] sm:text-[11.5px]">
82
94
  {item.title}
83
95
  </div>
84
- <div className="mt-0.5 truncate font-mono text-[10px] text-muted-foreground sm:text-[10.5px]">
85
- {item.meta}
96
+ {/* The date truncates; the time is `shrink-0` outside the truncating
97
+ span, so it is always whole. */}
98
+ <div className="mt-0.5 flex gap-1 font-mono text-[10px] text-muted-foreground sm:text-[10.5px]">
99
+ <span className="min-w-0 truncate">{item.meta}</span>
100
+ {item.time && <span className="shrink-0">· {item.time}</span>}
86
101
  </div>
87
102
  </>
88
103
  );
@@ -110,10 +125,11 @@ export function PosterTape({
110
125
  items,
111
126
  linkComponent: LinkComponent = DefaultLink,
112
127
  durationSeconds = POSTER_TAPE_DEFAULT_DURATION_SECONDS,
128
+ labels,
113
129
  className,
114
130
  }: PosterTapeProps) {
115
131
  return (
116
- <DriftRail durationSeconds={durationSeconds} className={className}>
132
+ <DriftRail durationSeconds={durationSeconds} labels={labels} className={className}>
117
133
  {items.map((item) => (
118
134
  <PosterTapeItemCard key={item.id} item={item} LinkComponent={LinkComponent} />
119
135
  ))}