@remit/ui 0.0.220 → 0.0.222

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/ui",
3
- "version": "0.0.220",
3
+ "version": "0.0.222",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -32,6 +32,8 @@
32
32
  "@lexical/table": "0.49.0",
33
33
  "@lexical/utils": "0.49.0",
34
34
  "@react-types/shared": "^3.36.0",
35
+ "@use-gesture/react": "^10.3.1",
36
+ "@use-gesture/vanilla": "^10.3.1",
35
37
  "clsx": "^2",
36
38
  "dompurify": "^3.4.7",
37
39
  "franc-min": "^6.2.0",
@@ -88,6 +88,8 @@ const base: CalendarGridProps = {
88
88
  onSelectEvent: () => undefined,
89
89
  onPickSlot: () => undefined,
90
90
  onRangeChange: () => undefined,
91
+ dayHref: (day) => `/day/${day}`,
92
+ onZoomDay: () => undefined,
91
93
  };
92
94
 
93
95
  interface Chip {
@@ -182,6 +184,129 @@ describe("CalendarGrid placement", () => {
182
184
  });
183
185
  });
184
186
 
187
+ const monthDays = (root: HTMLElement): string[] =>
188
+ Array.from(
189
+ new Set(
190
+ Array.from(root.querySelectorAll<HTMLElement>("[data-date]")).map(
191
+ (cell) => cell.dataset.date ?? "",
192
+ ),
193
+ ),
194
+ ).sort();
195
+
196
+ const nextWeek = "2026-06-17";
197
+ const lastOfMonth = anEvent({
198
+ id: "close",
199
+ title: "Month close",
200
+ start: "2026-06-30T15:00:00+02:00",
201
+ end: "2026-06-30T16:00:00+02:00",
202
+ });
203
+ const spill = anEvent({
204
+ id: "spill",
205
+ title: "Kickoff",
206
+ start: "2026-07-02T09:00:00+02:00",
207
+ end: "2026-07-02T10:00:00+02:00",
208
+ });
209
+ const later = anEvent({
210
+ id: "later",
211
+ title: "Planning",
212
+ start: `${nextWeek}T13:00:00+02:00`,
213
+ end: `${nextWeek}T14:00:00+02:00`,
214
+ });
215
+
216
+ describe("CalendarGrid month", () => {
217
+ it("draws whole weeks from the Monday on or before the 1st to the Sunday on or after the last", () => {
218
+ const days = monthDays(grid({ view: "month", date: "2026-07-10" }));
219
+ assert.equal(days.length, 35);
220
+ assert.equal(days[0], "2026-06-29");
221
+ assert.equal(days[34], "2026-08-02");
222
+ });
223
+
224
+ it("draws exactly the month's days when it fills its weeks", () => {
225
+ const days = monthDays(grid({ view: "month", date: "2027-02-14" }));
226
+ assert.equal(days.length, 28);
227
+ assert.equal(days[0], "2027-02-01");
228
+ assert.equal(days[27], "2027-02-28");
229
+ });
230
+
231
+ it("puts each event on its own day, including the neighbouring month's edge days", () => {
232
+ const root = grid({
233
+ view: "month",
234
+ date: TODAY,
235
+ events: [roadmap, handover, later, lastOfMonth, spill],
236
+ });
237
+ assert.equal(chip(root, "Roadmap review").date, TODAY);
238
+ assert.equal(chip(root, "Handover").date, TOMORROW);
239
+ assert.equal(chip(root, "Planning").date, nextWeek);
240
+ assert.equal(chip(root, "Month close").date, "2026-06-30");
241
+ assert.equal(chip(root, "Kickoff").date, "2026-07-02");
242
+ });
243
+
244
+ it("draws every event as a row, never a column block", () => {
245
+ const drawn = chips(
246
+ grid({ view: "month", date: TODAY, events: [roadmap, handover] }),
247
+ );
248
+ assert.equal(drawn.length, 2);
249
+ assert.ok(drawn.every((one) => one.timed === false));
250
+ });
251
+
252
+ it("marks today in the month", () => {
253
+ assert.ok(
254
+ grid({ view: "month", date: TODAY }).querySelector(
255
+ `[data-date="${TODAY}"][aria-current="date"]`,
256
+ ),
257
+ );
258
+ });
259
+
260
+ it("makes each day's number a real link to that day", () => {
261
+ const root = grid({ view: "month", date: TODAY });
262
+ const link = root.querySelector<HTMLAnchorElement>(
263
+ "a[aria-label='Open Wednesday, 10 June 2026']",
264
+ );
265
+ assert.ok(link);
266
+ assert.equal(link.getAttribute("href"), "/day/2026-06-10");
267
+ assert.equal(link.textContent, "10");
268
+ assert.equal(root.querySelectorAll("a[href^='/day/']").length, 35);
269
+ });
270
+
271
+ it("draws an event that crosses Sunday into Monday on both days", () => {
272
+ const drawn = chips(
273
+ grid({
274
+ view: "month",
275
+ date: TODAY,
276
+ events: [
277
+ anEvent({
278
+ id: "overnight",
279
+ title: "Overnight deploy",
280
+ start: "2026-06-28T22:00:00+02:00",
281
+ end: "2026-06-29T02:00:00+02:00",
282
+ }),
283
+ ],
284
+ }),
285
+ ).filter((one) => one.title === "Overnight deploy");
286
+ assert.deepEqual(
287
+ drawn.map((one) => one.date),
288
+ ["2026-06-28", "2026-06-29"],
289
+ );
290
+ });
291
+
292
+ it("places an event on the day it falls on in the grid's zone, not its own", () => {
293
+ const root = grid({
294
+ view: "month",
295
+ date: TODAY,
296
+ events: [
297
+ anEvent({
298
+ id: "newyork",
299
+ title: "Late call",
300
+ timeZone: "America/New_York",
301
+ start: "2026-06-30T23:30:00-04:00",
302
+ end: "2026-07-01T00:30:00-04:00",
303
+ }),
304
+ ],
305
+ });
306
+ assert.equal(chip(root, "Late call").date, "2026-07-01");
307
+ });
308
+ });
309
+
185
310
  describe("CalendarGrid all-day band", () => {
186
311
  it("gives the week a band of its own, named", () => {
187
312
  assert.match(grid().innerHTML, /All day/);
@@ -126,6 +126,8 @@ const meta: Meta<typeof CalendarGrid> = {
126
126
  onSelectEvent: () => undefined,
127
127
  onPickSlot: () => undefined,
128
128
  onRangeChange: () => undefined,
129
+ dayHref: (day) => `#${day}`,
130
+ onZoomDay: () => undefined,
129
131
  },
130
132
  };
131
133
  export default meta;
@@ -10,7 +10,7 @@ import interactionPlugin from "@fullcalendar/react/interaction";
10
10
  import listPlugin from "@fullcalendar/react/list";
11
11
  import multiMonthPlugin from "@fullcalendar/react/multimonth";
12
12
  import timeGridPlugin from "@fullcalendar/react/timegrid";
13
- import { useEffect, useMemo, useRef } from "react";
13
+ import { type MouseEvent, useEffect, useMemo, useRef } from "react";
14
14
  import { calendarEventBodyClasses } from "../lib/calendar-event-shell.js";
15
15
  import {
16
16
  isDraggedSelection,
@@ -104,6 +104,8 @@ export interface CalendarGridProps {
104
104
  onPickSlot: (pick: CalendarSlotPick) => void;
105
105
  /** The range title the grid computed, e.g. "8 – 14 Jun 2026". */
106
106
  onRangeChange: (title: string) => void;
107
+ dayHref: (date: string) => string;
108
+ onZoomDay: (date: string) => void;
107
109
  className?: string;
108
110
  }
109
111
 
@@ -141,6 +143,21 @@ function toInput(event: CalendarEventData): EventInput {
141
143
  };
142
144
  }
143
145
 
146
+ const isoDayInZone = (instant: Date, timeZone: string): string =>
147
+ new Intl.DateTimeFormat("en-CA", {
148
+ timeZone,
149
+ year: "numeric",
150
+ month: "2-digit",
151
+ day: "2-digit",
152
+ }).format(instant);
153
+
154
+ const isModifiedClick = (click: MouseEvent<HTMLElement>): boolean =>
155
+ click.button !== 0 ||
156
+ click.metaKey ||
157
+ click.ctrlKey ||
158
+ click.shiftKey ||
159
+ click.altKey;
160
+
144
161
  export function CalendarGrid({
145
162
  view,
146
163
  date,
@@ -153,6 +170,8 @@ export function CalendarGrid({
153
170
  onSelectEvent,
154
171
  onPickSlot,
155
172
  onRangeChange,
173
+ dayHref,
174
+ onZoomDay,
156
175
  className,
157
176
  }: CalendarGridProps) {
158
177
  const calendarRef = useRef<CalendarRef>(null);
@@ -241,6 +260,7 @@ export function CalendarGrid({
241
260
  height="100%"
242
261
  headerToolbar={false}
243
262
  firstDay={1}
263
+ fixedWeekCount={false}
244
264
  nowIndicator
245
265
  selectable
246
266
  selectMirror
@@ -252,6 +272,39 @@ export function CalendarGrid({
252
272
  allDayText="All day"
253
273
  dayMaxEvents={isTight ? 2 : 3}
254
274
  eventMaxStack={3}
275
+ dayCellTopContent={(info) => {
276
+ if (view !== "month") return;
277
+ const day = isoDayInZone(info.date, timeZone);
278
+ return (
279
+ <a
280
+ href={dayHref(day)}
281
+ aria-label={`Open ${info.date.toLocaleDateString("en-GB", { dateStyle: "full", timeZone })}`}
282
+ className="hover:underline"
283
+ onClick={(click) => {
284
+ if (isModifiedClick(click)) return;
285
+ click.preventDefault();
286
+ onZoomDay(day);
287
+ }}
288
+ >
289
+ {Number(day.slice(8))}
290
+ </a>
291
+ );
292
+ }}
293
+ dayCellDidMount={(info) => {
294
+ if (view !== "month") return;
295
+ /* The engine hides a day number from assistive tech unless it is its
296
+ own nav link, and a link inside a hidden wrapper is unreachable. */
297
+ info.el
298
+ .querySelector(":scope [aria-hidden='true']:has(> a)")
299
+ ?.removeAttribute("aria-hidden");
300
+ /* A press on the link must not start the engine's cell click: it
301
+ finishes a task after the pointer is up, by which time the link
302
+ has already moved the view and the cell it wants is gone. */
303
+ const link = info.el.querySelector("a");
304
+ for (const type of ["mousedown", "touchstart", "pointerdown"]) {
305
+ link?.addEventListener(type, (press) => press.stopPropagation());
306
+ }
307
+ }}
255
308
  moreLinkClick="popover"
256
309
  moreLinkText={(num) => `+${num}`}
257
310
  scrollTime="08:30:00"
@@ -1,4 +1,13 @@
1
- import { useEffect, useMemo, useRef, useState } from "react";
1
+ import { DragGesture } from "@use-gesture/vanilla";
2
+ import { useContext, useEffect, useMemo, useRef, useState } from "react";
3
+ import { SWIPE_DRAG_CONFIG } from "../lib/swipe-config.js";
4
+ import {
5
+ isZoomed,
6
+ releasedSwipe,
7
+ SWIPE_EVENT,
8
+ SwipeSurface,
9
+ subscribeToZoom,
10
+ } from "../lib/use-swipe-navigation.js";
2
11
  import {
3
12
  type AuthorDeclarations,
4
13
  buildEmailSrcDoc,
@@ -207,6 +216,7 @@ export const IsolatedEmailFrame = ({
207
216
  }: IsolatedEmailFrameProps) => {
208
217
  const ref = useRef<HTMLIFrameElement>(null);
209
218
  const [height, setHeight] = useState(0);
219
+ const swipeSurface = useContext(SwipeSurface);
210
220
 
211
221
  const srcDoc = useMemo(
212
222
  () => buildEmailSrcDoc(html, variant, isDark, declares),
@@ -220,6 +230,7 @@ export const IsolatedEmailFrame = ({
220
230
  const measure = () => {
221
231
  const doc = iframe.contentDocument;
222
232
  if (!doc?.body) return;
233
+ syncTouchAction();
223
234
  const root = doc.documentElement;
224
235
  const scale = fitToFrame(doc.body);
225
236
  const next =
@@ -243,8 +254,25 @@ export const IsolatedEmailFrame = ({
243
254
  pendingFrame = requestAnimationFrame(measure);
244
255
  };
245
256
 
257
+ const claimsSideways = (doc: Document): boolean => {
258
+ const root = doc.documentElement;
259
+ return isZoomed() || root.scrollWidth > root.clientWidth + 1;
260
+ };
261
+
262
+ const syncTouchAction = () => {
263
+ const doc = iframe.contentDocument;
264
+ if (!swipeSurface || !doc?.body) return;
265
+ const touchAction = claimsSideways(doc) ? "auto" : "pan-y pinch-zoom";
266
+ doc.documentElement.style.touchAction = touchAction;
267
+ doc.body.style.touchAction = touchAction;
268
+ };
269
+
246
270
  let observer: ResizeObserver | undefined;
247
271
  let keyDoc: Document | undefined;
272
+ let gesture: DragGesture | undefined;
273
+ const unsubscribeZoom = swipeSurface
274
+ ? subscribeToZoom(syncTouchAction)
275
+ : undefined;
248
276
  const handleLoad = () => {
249
277
  measure();
250
278
  // The srcDoc is rebuilt whenever the mail, theme or treatment changes,
@@ -255,8 +283,30 @@ export const IsolatedEmailFrame = ({
255
283
  keyDoc?.removeEventListener("keydown", forwardKeyDown);
256
284
  keyDoc?.removeEventListener("load", measure, true);
257
285
  keyDoc = undefined;
286
+ gesture?.destroy();
287
+ gesture = undefined;
258
288
  const doc = iframe.contentDocument;
259
289
  if (!doc?.body) return;
290
+ syncTouchAction();
291
+ if (swipeSurface)
292
+ gesture = new DragGesture(
293
+ doc.documentElement,
294
+ (state) => {
295
+ const direction = releasedSwipe(state);
296
+ if (!direction) return;
297
+ iframe.dispatchEvent(
298
+ new CustomEvent(SWIPE_EVENT, {
299
+ bubbles: true,
300
+ detail: direction,
301
+ }),
302
+ );
303
+ },
304
+ {
305
+ ...SWIPE_DRAG_CONFIG,
306
+ axis: "x",
307
+ window: doc.defaultView ?? undefined,
308
+ },
309
+ );
260
310
  observer = new ResizeObserver(measureNextFrame);
261
311
  observer.observe(doc.body);
262
312
  if (doc.documentElement) observer.observe(doc.documentElement);
@@ -278,9 +328,11 @@ export const IsolatedEmailFrame = ({
278
328
  keyDoc?.removeEventListener("keydown", forwardKeyDown);
279
329
  keyDoc?.removeEventListener("load", measure, true);
280
330
  observer?.disconnect();
331
+ gesture?.destroy();
332
+ unsubscribeZoom?.();
281
333
  cancelAnimationFrame(pendingFrame);
282
334
  };
283
- }, []);
335
+ }, [swipeSurface]);
284
336
 
285
337
  return (
286
338
  <iframe
@@ -114,12 +114,12 @@ describe("MobileReadingPane", () => {
114
114
  assert.doesNotMatch(html, /title="Reply \(r\)"/);
115
115
  });
116
116
 
117
- it("keeps pinch-zoom enabled on the scroll area when swipe handlers are set", () => {
117
+ it("keeps pinch-zoom enabled on the scroll area when swipe is wired", () => {
118
118
  const html = renderToString(
119
119
  createElement(MobileReadingPane, {
120
120
  thread,
121
121
  onBack: () => undefined,
122
- touchHandlers: { onTouchStart: () => undefined },
122
+ onSwipeNext: () => undefined,
123
123
  }),
124
124
  );
125
125
  assert.match(html, /touch-action:\s*pan-y pinch-zoom/);
@@ -0,0 +1,78 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { useState } from "react";
3
+ import { expect, waitFor, within } from "storybook/test";
4
+ import { MobileReadingPane } from "./mobile-reading-pane.js";
5
+
6
+ const subjects = ["First message", "Second message", "Third message"];
7
+
8
+ const meta: Meta<typeof MobileReadingPane> = {
9
+ title: "Design System/Primitives/MobileReadingPane",
10
+ component: MobileReadingPane,
11
+ parameters: { layout: "fullscreen" },
12
+ };
13
+ export default meta;
14
+
15
+ type Story = StoryObj<typeof MobileReadingPane>;
16
+
17
+ const SwipeBetweenMessages = () => {
18
+ const [index, setIndex] = useState(1);
19
+ return (
20
+ <div className="h-96 max-w-md">
21
+ <MobileReadingPane
22
+ thread={{ subject: subjects[index] ?? "", messages: [] }}
23
+ onBack={() => undefined}
24
+ onSwipeNext={
25
+ index < subjects.length - 1 ? () => setIndex(index + 1) : undefined
26
+ }
27
+ onSwipePrevious={index > 0 ? () => setIndex(index - 1) : undefined}
28
+ >
29
+ <p className="p-4">Swipe the body left or right.</p>
30
+ </MobileReadingPane>
31
+ </div>
32
+ );
33
+ };
34
+
35
+ const swipe = (area: Element, fromX: number, toX: number) => {
36
+ const touch = (type: string, x: number) =>
37
+ area.dispatchEvent(
38
+ new PointerEvent(type, {
39
+ bubbles: true,
40
+ buttons: type === "pointerup" ? 0 : 1,
41
+ pointerType: "touch",
42
+ pointerId: 1,
43
+ clientX: x,
44
+ clientY: 200,
45
+ }),
46
+ );
47
+ touch("pointerdown", fromX);
48
+ touch("pointermove", (fromX + toX) / 2);
49
+ touch("pointermove", toX);
50
+ touch("pointerup", toX);
51
+ };
52
+
53
+ export const SwipeToOpenNextAndPrevious: Story = {
54
+ name: "Swipe to open next and previous (interactive)",
55
+ render: () => <SwipeBetweenMessages />,
56
+ play: async ({ canvasElement }) => {
57
+ const canvas = within(canvasElement);
58
+ const area = canvasElement.querySelector("article > div.overflow-y-auto");
59
+ if (!area) throw new Error("reading area did not render");
60
+ await expect(canvas.getByRole("heading")).toHaveTextContent(
61
+ "Second message",
62
+ );
63
+
64
+ swipe(area, 300, 100);
65
+ await waitFor(() =>
66
+ expect(canvas.getByRole("heading")).toHaveTextContent("Third message"),
67
+ );
68
+
69
+ swipe(area, 100, 300);
70
+ await waitFor(() =>
71
+ expect(canvas.getByRole("heading")).toHaveTextContent("Second message"),
72
+ );
73
+ swipe(area, 100, 300);
74
+ await waitFor(() =>
75
+ expect(canvas.getByRole("heading")).toHaveTextContent("First message"),
76
+ );
77
+ },
78
+ };
@@ -1,6 +1,10 @@
1
1
  import { ArrowLeft, Info } from "lucide-react";
2
- import { type HTMLAttributes, type ReactNode, useState } from "react";
2
+ import { type ReactNode, useState } from "react";
3
3
  import { cn } from "../lib/cn.js";
4
+ import {
5
+ SwipeSurface,
6
+ useSwipeNavigation,
7
+ } from "../lib/use-swipe-navigation.js";
4
8
  import type { ThreadData } from "./app-shell-types.js";
5
9
  import { Button } from "./button.js";
6
10
  import { Dialog } from "./dialog.js";
@@ -49,8 +53,10 @@ export interface MobileReadingPaneProps {
49
53
  * still drives the top bar.
50
54
  */
51
55
  children?: ReactNode;
52
- /** Touch handlers attached to the scroll area (swipe-between-messages). */
53
- touchHandlers?: HTMLAttributes<HTMLDivElement>;
56
+ /** Swipe left on the reading area: open the next message. */
57
+ onSwipeNext?: () => void;
58
+ /** Swipe right on the reading area: open the previous message. */
59
+ onSwipePrevious?: () => void;
54
60
  }
55
61
 
56
62
  /**
@@ -71,8 +77,13 @@ export function MobileReadingPane({
71
77
  onToggleIntelligence,
72
78
  actions,
73
79
  children,
74
- touchHandlers,
80
+ onSwipeNext,
81
+ onSwipePrevious,
75
82
  }: MobileReadingPaneProps) {
83
+ const swipe = useSwipeNavigation({
84
+ onSwipeLeft: onSwipeNext,
85
+ onSwipeRight: onSwipePrevious,
86
+ });
76
87
  const [localIntelligenceOpen, setLocalIntelligenceOpen] = useState(false);
77
88
  const controlled = onToggleIntelligence !== undefined;
78
89
  const isOpen = controlled
@@ -129,49 +140,52 @@ export function MobileReadingPane({
129
140
  )}
130
141
  </header>
131
142
 
132
- <div
133
- className="flex-1 overflow-y-auto"
134
- style={touchHandlers ? { touchAction: "pan-y pinch-zoom" } : undefined}
135
- {...touchHandlers}
136
- >
137
- {/* Newest first, as on the wide pane. */}
138
- {children ??
139
- [...thread.messages].reverse().map((message) => {
140
- const bind = (handler?: (id: string) => void) =>
141
- handler ? () => handler(message.id) : undefined;
143
+ <SwipeSurface.Provider value={swipe.enabled}>
144
+ <div
145
+ ref={swipe.ref}
146
+ className="flex-1 overflow-y-auto"
147
+ style={{ touchAction: swipe.touchAction }}
148
+ {...swipe.bind()}
149
+ >
150
+ {/* Newest first, as on the wide pane. */}
151
+ {children ??
152
+ [...thread.messages].reverse().map((message) => {
153
+ const bind = (handler?: (id: string) => void) =>
154
+ handler ? () => handler(message.id) : undefined;
155
+
156
+ if (!message.expanded) {
157
+ return (
158
+ <CollapsedMessage
159
+ key={message.id}
160
+ message={message}
161
+ onClick={bind(actions?.onToggleExpand)}
162
+ />
163
+ );
164
+ }
142
165
 
143
- if (!message.expanded) {
144
166
  return (
145
- <CollapsedMessage
167
+ <ExpandedMessage
146
168
  key={message.id}
147
169
  message={message}
148
- onClick={bind(actions?.onToggleExpand)}
170
+ warning={thread.warning}
171
+ onHeaderClick={bind(actions?.onToggleExpand)}
172
+ actionBar={
173
+ <MobileMessageActionBar
174
+ hasThread
175
+ onReply={bind(actions?.onReply)}
176
+ onReplyAll={bind(actions?.onReplyAll)}
177
+ onForward={bind(actions?.onForward)}
178
+ onToggleStar={bind(actions?.onToggleStar)}
179
+ onDelete={bind(actions?.onDelete)}
180
+ onToggleRead={bind(actions?.onToggleRead)}
181
+ moveSlot={actions?.moveSlot?.(message.id)}
182
+ />
183
+ }
149
184
  />
150
185
  );
151
- }
152
-
153
- return (
154
- <ExpandedMessage
155
- key={message.id}
156
- message={message}
157
- warning={thread.warning}
158
- onHeaderClick={bind(actions?.onToggleExpand)}
159
- actionBar={
160
- <MobileMessageActionBar
161
- hasThread
162
- onReply={bind(actions?.onReply)}
163
- onReplyAll={bind(actions?.onReplyAll)}
164
- onForward={bind(actions?.onForward)}
165
- onToggleStar={bind(actions?.onToggleStar)}
166
- onDelete={bind(actions?.onDelete)}
167
- onToggleRead={bind(actions?.onToggleRead)}
168
- moveSlot={actions?.moveSlot?.(message.id)}
169
- />
170
- }
171
- />
172
- );
173
- })}
174
- </div>
186
+ })}
187
+ </div>
188
+ </SwipeSurface.Provider>
175
189
 
176
190
  {intelligence && !controlled && (
177
191
  <Dialog