@remit/ui 0.0.198 → 0.0.200

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.198",
3
+ "version": "0.0.200",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -0,0 +1,91 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import { expect, fn, userEvent, waitFor, within } from "storybook/test";
3
+ import { AccountMenu } from "./account-menu.js";
4
+
5
+ const EMAIL = "info@example.com";
6
+
7
+ const meta: Meta<typeof AccountMenu> = {
8
+ title: "Design System/Auth/AccountMenu",
9
+ component: AccountMenu,
10
+ parameters: { layout: "padded" },
11
+ args: { email: EMAIL, onSignOut: () => undefined },
12
+ render: (args) => (
13
+ <div className="flex h-48 justify-end p-4">
14
+ <AccountMenu {...args} />
15
+ </div>
16
+ ),
17
+ };
18
+ export default meta;
19
+
20
+ type Story = StoryObj<typeof AccountMenu>;
21
+
22
+ export const Closed: Story = {};
23
+
24
+ export const Open: Story = {
25
+ play: async ({ canvasElement }) => {
26
+ const canvas = within(canvasElement);
27
+ await userEvent.click(canvas.getByRole("button", { name: "Account" }));
28
+ const page = within(canvasElement.ownerDocument.body);
29
+ await expect(page.getByTestId("account-menu-email")).toHaveTextContent(
30
+ EMAIL,
31
+ );
32
+ await expect(
33
+ page.getByRole("menuitem", { name: "Sign out" }),
34
+ ).toBeVisible();
35
+ },
36
+ };
37
+
38
+ export const NoEmail: Story = {
39
+ args: { email: null },
40
+ play: async ({ canvasElement }) => {
41
+ const canvas = within(canvasElement);
42
+ await userEvent.click(canvas.getByRole("button", { name: "Account" }));
43
+ const page = within(canvasElement.ownerDocument.body);
44
+ await expect(page.queryByTestId("account-menu-email")).toBeNull();
45
+ await expect(
46
+ page.getByRole("menuitem", { name: "Sign out" }),
47
+ ).toBeVisible();
48
+ },
49
+ };
50
+
51
+ export const KeyboardReachesSignOut: Story = {
52
+ args: { onSignOut: fn() },
53
+ render: (args) => (
54
+ <div className="flex h-48 items-start justify-end gap-2 p-4">
55
+ <AccountMenu {...args} />
56
+ <button type="button">After the menu</button>
57
+ </div>
58
+ ),
59
+ play: async ({ args, canvasElement }) => {
60
+ const canvas = within(canvasElement);
61
+ const page = within(canvasElement.ownerDocument.body);
62
+ const trigger = canvas.getByRole("button", { name: "Account" });
63
+
64
+ await userEvent.tab();
65
+ await expect(trigger).toHaveFocus();
66
+ await userEvent.keyboard("{Enter}");
67
+ const signOut = await page.findByRole("menuitem", { name: "Sign out" });
68
+ await waitFor(() => expect(signOut).toHaveFocus());
69
+
70
+ await userEvent.keyboard("{Escape}");
71
+ await expect(page.queryByRole("menuitem")).toBeNull();
72
+ await expect(trigger).toHaveFocus();
73
+
74
+ await userEvent.keyboard("{Enter}");
75
+ await waitFor(() =>
76
+ expect(page.getByRole("menuitem", { name: "Sign out" })).toHaveFocus(),
77
+ );
78
+ await userEvent.keyboard("{Enter}");
79
+ await expect(args.onSignOut).toHaveBeenCalledOnce();
80
+ await expect(trigger).toHaveFocus();
81
+ },
82
+ };
83
+
84
+ export const InTopBar: Story = {
85
+ render: (args) => (
86
+ <header className="flex h-pane-header shrink-0 items-center gap-1 border-b border-line bg-surface px-3">
87
+ <div className="flex-1" />
88
+ <AccountMenu {...args} />
89
+ </header>
90
+ ),
91
+ };
@@ -0,0 +1,78 @@
1
+ import { LogOut } from "lucide-react";
2
+ import { useEffect, useRef } from "react";
3
+ import { Avatar } from "./avatar.js";
4
+ import {
5
+ PopoverMenuPanel,
6
+ PopoverMenuPortal,
7
+ PopoverMenuRow,
8
+ usePopoverMenuState,
9
+ } from "./popover-menu.js";
10
+
11
+ export interface AccountMenuProps {
12
+ email: string | null;
13
+ onSignOut: () => void;
14
+ }
15
+
16
+ export function AccountMenu({ email, onSignOut }: AccountMenuProps) {
17
+ const triggerRef = useRef<HTMLButtonElement>(null);
18
+ const { open, setOpen, containerRef, panelRef, getAnchor } =
19
+ usePopoverMenuState("account-menu", () => triggerRef.current?.focus());
20
+
21
+ useEffect(() => {
22
+ if (!open) return;
23
+ const frame = requestAnimationFrame(() =>
24
+ panelRef.current
25
+ ?.querySelector<HTMLElement>('[role="menuitem"]')
26
+ ?.focus(),
27
+ );
28
+ return () => cancelAnimationFrame(frame);
29
+ }, [open, panelRef]);
30
+
31
+ const displayName = email ?? "Account";
32
+
33
+ return (
34
+ <div ref={containerRef} className="relative">
35
+ <button
36
+ ref={triggerRef}
37
+ type="button"
38
+ aria-label="Account"
39
+ aria-haspopup="menu"
40
+ aria-expanded={open}
41
+ onClick={() => setOpen((value) => !value)}
42
+ className="inline-flex min-h-11 min-w-11 items-center justify-center rounded-md p-1.5 text-fg-muted transition-colors hover:bg-surface-raised hover:text-fg"
43
+ >
44
+ <Avatar name={displayName} email={email ?? undefined} size="sm" />
45
+ </button>
46
+ <PopoverMenuPortal
47
+ open={open}
48
+ align="end"
49
+ panelRef={panelRef}
50
+ getAnchor={getAnchor}
51
+ >
52
+ <PopoverMenuPanel ref={panelRef} label={displayName}>
53
+ {email && (
54
+ <>
55
+ <div
56
+ className="truncate px-4 py-2 text-xs text-fg-muted"
57
+ title={email}
58
+ data-testid="account-menu-email"
59
+ >
60
+ {email}
61
+ </div>
62
+ <hr className="my-1 h-px border-0 bg-line" />
63
+ </>
64
+ )}
65
+ <PopoverMenuRow
66
+ label="Sign out"
67
+ icon={<LogOut className="size-4" />}
68
+ onSelect={() => {
69
+ setOpen(false);
70
+ triggerRef.current?.focus();
71
+ onSignOut();
72
+ }}
73
+ />
74
+ </PopoverMenuPanel>
75
+ </PopoverMenuPortal>
76
+ </div>
77
+ );
78
+ }
@@ -0,0 +1,175 @@
1
+ import type { Decorator, Meta, StoryObj } from "@storybook/react";
2
+ import { type ComponentProps, type MouseEvent, useState } from "react";
3
+ import { expect, fireEvent, userEvent, within } from "storybook/test";
4
+ import { NavLinkSurface } from "./nav-link-surface.js";
5
+
6
+ const PHONE_WIDTH = 390;
7
+
8
+ const phoneFrame: Decorator = (Story) => (
9
+ <div
10
+ className="relative overflow-hidden rounded-lg border border-line"
11
+ style={{ width: PHONE_WIDTH, height: 844 }}
12
+ >
13
+ <Story />
14
+ </div>
15
+ );
16
+
17
+ const meta: Meta = {
18
+ title: "Design System/Primitives/NavLinkSurface",
19
+ parameters: { layout: "centered" },
20
+ };
21
+ export default meta;
22
+
23
+ type Story = StoryObj;
24
+
25
+ type NavLinkVariant = NonNullable<
26
+ ComponentProps<typeof NavLinkSurface>["variant"]
27
+ >;
28
+
29
+ const variants: NavLinkVariant[] = ["nav", "row", "inline"];
30
+
31
+ const destinations = [
32
+ { id: "brief", href: "/mail/brief", label: "Daily brief" },
33
+ { id: "flagged", href: "/mail/flagged", label: "Starred" },
34
+ { id: "outbox", href: "/mail/outbox", label: "Outbox" },
35
+ ];
36
+
37
+ const NOTHING_ACTIVATED = "nothing activated";
38
+
39
+ function NavLinkMatrix({
40
+ width = 320,
41
+ shown = variants,
42
+ }: {
43
+ width?: number;
44
+ shown?: NavLinkVariant[];
45
+ }) {
46
+ const [activated, setActivated] = useState(NOTHING_ACTIVATED);
47
+
48
+ const activate =
49
+ (label: string) => (event: MouseEvent<HTMLAnchorElement>) => {
50
+ event.preventDefault();
51
+ setActivated(event.metaKey ? `${label} with Meta` : label);
52
+ };
53
+
54
+ return (
55
+ <div
56
+ className="flex flex-col gap-5 bg-canvas p-4 text-fg"
57
+ style={{ width }}
58
+ >
59
+ {shown.map((variant) => (
60
+ <section className="flex flex-col items-start gap-1" key={variant}>
61
+ <h3 className="text-2xs uppercase tracking-wider text-fg-subtle">
62
+ {variant}
63
+ </h3>
64
+ {destinations.map((destination, index) => (
65
+ <NavLinkSurface
66
+ current={index === 0 ? "page" : undefined}
67
+ data-testid={`link-${variant}-${destination.id}`}
68
+ href={destination.href}
69
+ key={destination.id}
70
+ onClick={activate(destination.label)}
71
+ variant={variant}
72
+ >
73
+ {variant === "row" ? (
74
+ <span className="flex-1 px-3 py-2">{destination.label}</span>
75
+ ) : (
76
+ destination.label
77
+ )}
78
+ </NavLinkSurface>
79
+ ))}
80
+ </section>
81
+ ))}
82
+ <p className="text-xs text-fg-muted" data-testid="last-activation">
83
+ {activated}
84
+ </p>
85
+ </div>
86
+ );
87
+ }
88
+
89
+ export const Variants: Story = {
90
+ render: () => <NavLinkMatrix />,
91
+ };
92
+
93
+ export const Phone: Story = {
94
+ parameters: { layout: "centered", viewport: { value: "mobile" } },
95
+ decorators: [phoneFrame],
96
+ render: () => <NavLinkMatrix shown={["nav"]} width={PHONE_WIDTH} />,
97
+ };
98
+
99
+ export const IsARealAnchor: Story = {
100
+ render: () => <NavLinkMatrix />,
101
+ play: async ({ canvasElement }) => {
102
+ const canvas = within(canvasElement);
103
+ for (const variant of variants) {
104
+ for (const destination of destinations) {
105
+ const link = canvas.getByTestId(`link-${variant}-${destination.id}`);
106
+ await expect(link.tagName).toBe("A");
107
+ await expect(link).toHaveAttribute("href", destination.href);
108
+ }
109
+ }
110
+ await expect(canvas.getAllByRole("link")).toHaveLength(
111
+ variants.length * destinations.length,
112
+ );
113
+ },
114
+ };
115
+
116
+ export const MarksTheCurrentDestination: Story = {
117
+ render: () => <NavLinkMatrix />,
118
+ play: async ({ canvasElement }) => {
119
+ const canvas = within(canvasElement);
120
+ await expect(canvas.getByTestId("link-nav-brief")).toHaveAttribute(
121
+ "aria-current",
122
+ "page",
123
+ );
124
+ await expect(canvas.getByTestId("link-nav-flagged")).not.toHaveAttribute(
125
+ "aria-current",
126
+ );
127
+
128
+ await userEvent.click(canvas.getByTestId("link-nav-flagged"));
129
+
130
+ await expect(canvas.getByTestId("link-nav-brief")).toHaveAttribute(
131
+ "aria-current",
132
+ "page",
133
+ );
134
+ await expect(canvas.getByTestId("link-nav-flagged")).not.toHaveAttribute(
135
+ "aria-current",
136
+ );
137
+ },
138
+ };
139
+
140
+ export const ActivatesOnTabThenEnter: Story = {
141
+ render: () => <NavLinkMatrix />,
142
+ play: async ({ canvasElement }) => {
143
+ const canvas = within(canvasElement);
144
+ await expect(canvas.getByTestId("last-activation")).toHaveTextContent(
145
+ NOTHING_ACTIVATED,
146
+ );
147
+
148
+ await userEvent.tab();
149
+ await expect(canvas.getByTestId("link-nav-brief")).toHaveFocus();
150
+ await userEvent.keyboard("{Enter}");
151
+
152
+ await expect(canvas.getByTestId("last-activation")).toHaveTextContent(
153
+ "Daily brief",
154
+ );
155
+ await expect(canvas.getByTestId("link-nav-brief")).toHaveFocus();
156
+ },
157
+ };
158
+
159
+ export const PassesModifiedClicksThrough: Story = {
160
+ render: () => <NavLinkMatrix />,
161
+ play: async ({ canvasElement }) => {
162
+ const canvas = within(canvasElement);
163
+ const link = canvas.getByTestId("link-nav-outbox");
164
+
165
+ await userEvent.click(link);
166
+ await expect(canvas.getByTestId("last-activation")).toHaveTextContent(
167
+ "Outbox",
168
+ );
169
+
170
+ fireEvent.click(link, { metaKey: true });
171
+ await expect(canvas.getByTestId("last-activation")).toHaveTextContent(
172
+ "Outbox with Meta",
173
+ );
174
+ },
175
+ };
@@ -112,6 +112,57 @@ function useAnchoredPlacement(
112
112
  return style;
113
113
  }
114
114
 
115
+ export interface PopoverMenuState {
116
+ open: boolean;
117
+ setOpen: (open: boolean | ((open: boolean) => boolean)) => void;
118
+ containerRef: RefObject<HTMLDivElement | null>;
119
+ panelRef: RefObject<HTMLDivElement | null>;
120
+ getAnchor: () => PopoverMenuAnchor | null;
121
+ }
122
+
123
+ export function usePopoverMenuState(
124
+ id: string,
125
+ onBack?: () => void,
126
+ ): PopoverMenuState {
127
+ const [open, setOpen] = useState(false);
128
+ const containerRef = useRef<HTMLDivElement>(null);
129
+ const panelRef = useRef<HTMLDivElement>(null);
130
+
131
+ useOverlayScope({
132
+ id,
133
+ open,
134
+ answers: {
135
+ back: () => {
136
+ setOpen(false);
137
+ onBack?.();
138
+ },
139
+ },
140
+ });
141
+
142
+ useEffect(() => {
143
+ if (!open) return;
144
+ const onPointer = (event: MouseEvent) => {
145
+ const target = event.target as Node;
146
+ if (
147
+ containerRef.current?.contains(target) ||
148
+ panelRef.current?.contains(target)
149
+ )
150
+ return;
151
+ setOpen(false);
152
+ };
153
+ document.addEventListener("mousedown", onPointer);
154
+ return () => document.removeEventListener("mousedown", onPointer);
155
+ }, [open]);
156
+
157
+ return {
158
+ open,
159
+ setOpen,
160
+ containerRef,
161
+ panelRef,
162
+ getAnchor: () => containerRef.current?.getBoundingClientRect() ?? null,
163
+ };
164
+ }
165
+
115
166
  export interface PopoverMenuPortalProps {
116
167
  open: boolean;
117
168
  align?: "start" | "end";
@@ -290,30 +341,8 @@ export function PopoverMenu({
290
341
  nested = false,
291
342
  children,
292
343
  }: PopoverMenuProps) {
293
- const [open, setOpen] = useState(false);
294
- const containerRef = useRef<HTMLDivElement>(null);
295
- const panelRef = useRef<HTMLDivElement>(null);
296
-
297
- useOverlayScope({
298
- id: "popover-menu",
299
- open,
300
- answers: { back: () => setOpen(false) },
301
- });
302
-
303
- useEffect(() => {
304
- if (!open) return;
305
- const onPointer = (event: MouseEvent) => {
306
- const target = event.target as Node;
307
- if (
308
- containerRef.current?.contains(target) ||
309
- panelRef.current?.contains(target)
310
- )
311
- return;
312
- setOpen(false);
313
- };
314
- document.addEventListener("mousedown", onPointer);
315
- return () => document.removeEventListener("mousedown", onPointer);
316
- }, [open]);
344
+ const { open, setOpen, containerRef, panelRef, getAnchor } =
345
+ usePopoverMenuState("popover-menu");
317
346
 
318
347
  if (items.length === 0 && !children) return null;
319
348
 
@@ -340,7 +369,7 @@ export function PopoverMenu({
340
369
  open={open}
341
370
  align={align}
342
371
  panelRef={panelRef}
343
- getAnchor={() => containerRef.current?.getBoundingClientRect() ?? null}
372
+ getAnchor={getAnchor}
344
373
  >
345
374
  <PopoverMenuPanel ref={panelRef}>
346
375
  {items.map((item) => (
@@ -3,7 +3,7 @@ import { describe, it } from "node:test";
3
3
  import { createElement } from "react";
4
4
  import { renderToString } from "react-dom/server";
5
5
  import type { ThreadRowData } from "./app-shell-types.js";
6
- import { SwipeableRow, type SwipePeek } from "./swipeable-row.js";
6
+ import { commitPeek, SwipeableRow, type SwipePeek } from "./swipeable-row.js";
7
7
 
8
8
  const thread: ThreadRowData = {
9
9
  id: "thread-1",
@@ -98,3 +98,18 @@ describe("SwipeableRow", () => {
98
98
  );
99
99
  });
100
100
  });
101
+
102
+ describe("commitPeek — drag-release snap rule", () => {
103
+ it("snaps back to none when the drag is short of half the action width", () => {
104
+ assert.equal(commitPeek(0), "none");
105
+ assert.equal(commitPeek(35), "none", "just under half (36) stays closed");
106
+ assert.equal(commitPeek(-35), "none");
107
+ });
108
+
109
+ it("commits to a side once the drag passes half the action width", () => {
110
+ assert.equal(commitPeek(36), "leading", "dragged right past half");
111
+ assert.equal(commitPeek(72), "leading", "fully dragged right");
112
+ assert.equal(commitPeek(-36), "trailing", "dragged left past half");
113
+ assert.equal(commitPeek(-72), "trailing", "fully dragged left");
114
+ });
115
+ });
@@ -278,11 +278,16 @@ export function ServerFields({
278
278
  {onSecurityChange ? (
279
279
  <SecuritySelect
280
280
  id={securityId}
281
+ disabled={readOnly}
281
282
  value={security}
282
283
  onValueChange={onSecurityChange}
283
284
  />
284
285
  ) : (
285
- <SecuritySelect id={securityId} defaultValue={security} />
286
+ <SecuritySelect
287
+ id={securityId}
288
+ disabled={readOnly}
289
+ defaultValue={security}
290
+ />
286
291
  )}
287
292
  </div>
288
293
  </div>
package/src/index.ts CHANGED
@@ -16,6 +16,10 @@ export {
16
16
  isThreadCategory,
17
17
  type ThreadCategory,
18
18
  } from "./category-presentation.js";
19
+ export {
20
+ AccountMenu,
21
+ type AccountMenuProps,
22
+ } from "./components/account-menu.js";
19
23
  export {
20
24
  type AccountServiceChange,
21
25
  type AccountServiceChangeCopy,
@@ -80,7 +84,6 @@ export {
80
84
  AppPasswordHint,
81
85
  type AppPasswordHintProps,
82
86
  } from "./components/app-password-hint.js";
83
- export { AppShell } from "./components/app-shell.js";
84
87
  export {
85
88
  type AppShellLayoutContext,
86
89
  AppShellSlotted,
@@ -630,6 +633,8 @@ export {
630
633
  type PopoverMenuProps,
631
634
  PopoverMenuRow,
632
635
  type PopoverMenuRowProps,
636
+ type PopoverMenuState,
637
+ usePopoverMenuState,
633
638
  } from "./components/popover-menu.js";
634
639
  export {
635
640
  ProgressBar,
@@ -1,441 +0,0 @@
1
- import assert from "node:assert/strict";
2
- import { describe, it } from "node:test";
3
- import { createElement } from "react";
4
- import { renderToString } from "react-dom/server";
5
- import { AppShell } from "./app-shell.js";
6
- import type { AppShellProps, ThreadSection } from "./app-shell-types.js";
7
- import { commitPeek } from "./swipeable-row.js";
8
-
9
- const baseAccounts: AppShellProps["accounts"] = [
10
- {
11
- id: "acc",
12
- label: "Personal",
13
- email: "me@example.com",
14
- mailboxes: [{ id: "mbx_inbox", name: "Inbox", unseen: 2 }],
15
- },
16
- ];
17
-
18
- const labelledSection: ThreadSection = {
19
- id: "sec",
20
- label: "Today",
21
- threads: [
22
- {
23
- id: "t1",
24
- accountId: "acc",
25
- fromName: "Ada Lovelace",
26
- fromEmail: "ada@example.com",
27
- subject: "Hello",
28
- snippet: "First message",
29
- timeLabel: "09:00",
30
- },
31
- ],
32
- };
33
-
34
- const render = (overrides: Partial<AppShellProps>) =>
35
- renderToString(
36
- createElement(AppShell, {
37
- accounts: baseAccounts,
38
- selectedNavId: "mbx_inbox",
39
- listTitle: "Inbox",
40
- sections: [labelledSection],
41
- ...overrides,
42
- }),
43
- );
44
-
45
- const intelligence: AppShellProps["intelligence"] = {
46
- sender: {
47
- name: "Ada Lovelace",
48
- email: "ada@example.com",
49
- trust: "wellknown",
50
- firstSeenLabel: "Jan 2025",
51
- },
52
- authenticity: {
53
- verdict: "aligned",
54
- fromDomain: "example.com",
55
- summary: "Signed by example.com, matches the sender.",
56
- },
57
- category: { value: "personal" },
58
- similar: [],
59
- };
60
-
61
- const thread: AppShellProps["thread"] = {
62
- subject: "Hello",
63
- messages: [
64
- {
65
- id: "m1",
66
- fromName: "Ada Lovelace",
67
- fromEmail: "ada@example.com",
68
- toLabel: "me",
69
- dateLabel: "09:00",
70
- snippet: "First message",
71
- bodyHtml: "<p>First message</p>",
72
- expanded: true,
73
- },
74
- ],
75
- };
76
-
77
- // Section labels are a desktop-list affordance; the narrow touch surface is a
78
- // single flat list (see the narrow-view block below). The shell reflows by its
79
- // OWN width now, seeded for SSR via `initialWidth`, so these seed the container
80
- // to desktop to exercise the sectioned-vs-flat distinction itself.
81
- describe("AppShell flat list (#5/#7)", () => {
82
- it("renders section labels in the default sectioned list", () => {
83
- const html = render({ initialWidth: 1100 });
84
- assert.match(html, /Today/, "sectioned list shows its label");
85
- });
86
-
87
- it("suppresses section labels in a flat mailbox", () => {
88
- const html = render({ flatList: true, initialWidth: 1100 });
89
- assert.doesNotMatch(
90
- html,
91
- />Today</,
92
- "flat list is one continuous list, no section headers",
93
- );
94
- assert.match(html, /Ada Lovelace/, "rows still render");
95
- });
96
- });
97
-
98
- /**
99
- * Pane-count-by-width is owned by `resolvePaneLayout` — see
100
- * pane-layout.render.test.ts for the boundary cases. This block only confirms
101
- * the rendered shell *wires to* that helper: the reading pane and intelligence
102
- * rail actually appear/disappear in the HTML as the seeded container width
103
- * crosses the two thresholds (no duplicate enumeration of the boundaries).
104
- */
105
- describe("AppShell render honors the pane layout (#784)", () => {
106
- const readingPaneProps: Partial<AppShellProps> = {
107
- flatList: true,
108
- selectedThreadId: "m1",
109
- thread,
110
- intelligence,
111
- };
112
- // The desktop reading-pane toolbar keeps the kit's default shortcut hints;
113
- // the mobile pane passes its own labels without them.
114
- const readingPaneMarker = /title="Reply \(r\)"/;
115
- // "Known sender" is the wellknown trust label, rendered only by the rail.
116
- const intelligenceMarker = /Known sender/;
117
-
118
- // The shell reflows by its OWN width (container query / ResizeObserver),
119
- // seeded for SSR via `initialWidth`.
120
- it("list-only below 1024: neither reading pane nor rail in the HTML", () => {
121
- const html = render({ ...readingPaneProps, initialWidth: 800 });
122
- assert.match(html, /Ada Lovelace/, "the list still renders");
123
- assert.doesNotMatch(html, readingPaneMarker, "reading pane is absent");
124
- assert.doesNotMatch(html, intelligenceMarker, "rail is absent");
125
- });
126
-
127
- it("reading pane appears at 1024, rail still held until 1280", () => {
128
- const html = render({ ...readingPaneProps, initialWidth: 1100 });
129
- assert.match(html, readingPaneMarker, "reading pane is present");
130
- assert.doesNotMatch(html, intelligenceMarker, "rail holds until ≥1280px");
131
- });
132
-
133
- it("rail joins the reading pane at 1280", () => {
134
- const html = render({ ...readingPaneProps, initialWidth: 1400 });
135
- assert.match(html, readingPaneMarker, "reading pane is present");
136
- assert.match(html, intelligenceMarker, "rail joins at xl");
137
- });
138
- });
139
-
140
- describe("AppShell nav: pane vs slide-over by width (#784)", () => {
141
- // The nav sidebar's own items — present only when the nav renders.
142
- const navMarker = /Daily brief/;
143
- // The list-header folders button opens the slide-over at narrow widths.
144
- const navTriggerMarker = /aria-label="Open folders"/;
145
-
146
- it("below 1024px: nav is not a persistent pane, reached via the trigger", () => {
147
- const html = render({ flatList: true, initialWidth: 800 });
148
- assert.doesNotMatch(
149
- html,
150
- navMarker,
151
- "nav is not in the persistent layout (drawer is closed)",
152
- );
153
- assert.match(html, navTriggerMarker, "the folders trigger is present");
154
- });
155
-
156
- it("≥1024px: nav is a persistent pane, no trigger", () => {
157
- const html = render({ flatList: true, initialWidth: 1100 });
158
- assert.match(html, navMarker, "nav renders as a pane");
159
- assert.doesNotMatch(
160
- html,
161
- navTriggerMarker,
162
- "no folders trigger when the nav is a pane",
163
- );
164
- });
165
- });
166
-
167
- describe("AppShell narrow message view: width-gated in-place swap", () => {
168
- const withThread: Partial<AppShellProps> = {
169
- flatList: true,
170
- selectedThreadId: "m1",
171
- thread,
172
- intelligence,
173
- };
174
- // The dedicated message view's back affordance — present only when the
175
- // narrow single pane is showing the message view.
176
- const messageViewMarker = /aria-label="Back to messages"/;
177
- // The desktop reading-pane toolbar — present only at/above 1024.
178
- const readingPaneMarker = /title="Reply \(r\)"/;
179
-
180
- it("below 1024 defaults to the list, not the message view", () => {
181
- const html = render({ ...withThread, initialWidth: 800 });
182
- assert.doesNotMatch(html, messageViewMarker, "starts on the list");
183
- assert.match(html, /Ada Lovelace/, "the list renders");
184
- });
185
-
186
- it("below 1024 the message view takes over the single pane when opened", () => {
187
- const html = render({
188
- ...withThread,
189
- initialWidth: 800,
190
- initialNarrowView: "message",
191
- });
192
- assert.match(html, messageViewMarker, "the message view is shown");
193
- assert.doesNotMatch(
194
- html,
195
- readingPaneMarker,
196
- "no desktop reading pane at narrow width",
197
- );
198
- });
199
-
200
- it("at/above 1024 the swap is ignored — thread fills the reading pane", () => {
201
- const html = render({
202
- ...withThread,
203
- initialWidth: 1100,
204
- initialNarrowView: "message",
205
- });
206
- assert.match(
207
- html,
208
- readingPaneMarker,
209
- "the reading pane renders the thread",
210
- );
211
- assert.doesNotMatch(
212
- html,
213
- messageViewMarker,
214
- "the narrow message view never appears once the reading pane fits",
215
- );
216
- });
217
- });
218
-
219
- describe("AppShell narrow touch triage (#swipe/selection/pull)", () => {
220
- // The pull-to-refresh affordance + swipe action labels live only in the
221
- // narrow touch list body. The touch gate is container-derived (the shell's
222
- // own width), seeded for SSR via `initialWidth`.
223
- it("below 1024 the ready list is the touch surface (pull-to-refresh)", () => {
224
- const html = render({ flatList: true, initialWidth: 800 });
225
- assert.match(
226
- html,
227
- /Pull to refresh/,
228
- "the pull-to-refresh hint is present",
229
- );
230
- });
231
-
232
- it("at/above 1024 the desktop list has no touch chrome", () => {
233
- const html = render({ flatList: true, initialWidth: 1100 });
234
- assert.doesNotMatch(
235
- html,
236
- /Pull to refresh/,
237
- "no pull-to-refresh on the desktop list",
238
- );
239
- });
240
- });
241
-
242
- describe("AppShell touch-state seeds (story/SSR affordance)", () => {
243
- // A two-row flat list so the seeds (first-two-checked / peek the 2nd row)
244
- // have rows to land on.
245
- const twoRows: ThreadSection = {
246
- id: "inbox",
247
- threads: [
248
- {
249
- id: "r1",
250
- accountId: "acc",
251
- fromName: "Ada Lovelace",
252
- fromEmail: "ada@example.com",
253
- subject: "First",
254
- snippet: "one",
255
- timeLabel: "09:00",
256
- },
257
- {
258
- id: "r2",
259
- accountId: "acc",
260
- fromName: "Grace Hopper",
261
- fromEmail: "grace@example.com",
262
- subject: "Second",
263
- snippet: "two",
264
- timeLabel: "09:05",
265
- },
266
- ],
267
- };
268
- const touchBase: Partial<AppShellProps> = {
269
- flatList: true,
270
- initialWidth: 390,
271
- sections: [twoRows],
272
- };
273
-
274
- const count = (html: string, re: RegExp) => (html.match(re) ?? []).length;
275
- // The swipe-action backgrounds. `bg-accent-2` must not match `bg-accent-2-soft`
276
- // (the row's active highlight), so require a non-`-`/letter boundary after it.
277
- const trailingAction = /bg-danger/g;
278
- const leadingAction = /bg-accent-2(?![-a-z])/g;
279
-
280
- // Regression (the bug the user caught): at REST every row was leaking its
281
- // trailing delete action because the transparent row didn't cover the layer
282
- // behind it. No row is peeked here, so zero action zones may be visible.
283
- it("at rest shows NO swipe-action zone on any row", () => {
284
- const html = render(touchBase);
285
- assert.equal(
286
- count(html, trailingAction),
287
- 0,
288
- "no trailing (delete) action visible at rest",
289
- );
290
- assert.equal(
291
- count(html, leadingAction),
292
- 0,
293
- "no leading (toggle-read) action visible at rest",
294
- );
295
- });
296
-
297
- it("draws the consumer's selection on the touch rows", () => {
298
- const html = render({
299
- ...touchBase,
300
- selection: {
301
- selectedIds: new Set(["r1", "r2"]),
302
- onToggle: () => undefined,
303
- },
304
- });
305
- assert.equal(
306
- count(html, /aria-checked="true"/g),
307
- 2,
308
- "both ticked rows show a checked box",
309
- );
310
- // Selection mode is not a swipe — no action zones revealed.
311
- assert.equal(
312
- count(html, trailingAction),
313
- 0,
314
- "no swipe action in selection",
315
- );
316
- assert.equal(count(html, leadingAction), 0, "no swipe action in selection");
317
- });
318
-
319
- it("peek-trailing reveals exactly one row's delete action, no leading", () => {
320
- const html = render({ ...touchBase, initialTouchState: "peek-trailing" });
321
- assert.match(html, /translateX\(-72px\)/, "the second row is peeked left");
322
- assert.equal(
323
- count(html, trailingAction),
324
- 1,
325
- "exactly one trailing action is revealed",
326
- );
327
- assert.equal(count(html, leadingAction), 0, "no leading action leaks");
328
- // the revealed action is a real button that performs the action
329
- assert.match(
330
- html,
331
- /<button[^>]*aria-label="Delete message"/,
332
- "delete action is a tappable button",
333
- );
334
- });
335
-
336
- it("peek-leading reveals exactly one row's toggle-read action, no trailing", () => {
337
- const html = render({ ...touchBase, initialTouchState: "peek-leading" });
338
- assert.match(html, /translateX\(72px\)/, "the second row is peeked right");
339
- assert.equal(
340
- count(html, leadingAction),
341
- 1,
342
- "exactly one leading action is revealed",
343
- );
344
- assert.equal(count(html, trailingAction), 0, "no trailing action leaks");
345
- assert.match(
346
- html,
347
- /<button[^>]*aria-label="Mark as (read|unread)"/,
348
- "toggle-read action is a tappable button",
349
- );
350
- });
351
-
352
- it("the selection bar is the list pane's header", () => {
353
- const html = render({
354
- ...touchBase,
355
- listTitle: "Inbox",
356
- selectionBar: createElement(
357
- "div",
358
- { "data-testid": "custom-bar" },
359
- "Deleting 1,200 of 3,412…",
360
- ),
361
- });
362
- assert.match(html, /Deleting 1,200 of 3,412…/, "the bar renders");
363
- assert.doesNotMatch(
364
- html,
365
- /<h1[^>]*>Inbox<\/h1>/,
366
- "the pane's own title header stands down",
367
- );
368
- });
369
-
370
- it("leaves the always-visible checkbox to the touch tier", () => {
371
- const html = render({
372
- ...touchBase,
373
- initialWidth: 1100,
374
- selection: {
375
- selectedIds: new Set(["r1"]),
376
- onToggle: () => undefined,
377
- },
378
- });
379
- assert.match(html, /aria-label="Deselect message"/, "the row is ticked");
380
- assert.doesNotMatch(
381
- html,
382
- /translateX/,
383
- "desktop rows carry no swipe-triage layer",
384
- );
385
- });
386
- });
387
-
388
- describe("AppShell list states (#5/#7)", () => {
389
- it("renders the skeleton when loading, not the rows", () => {
390
- const html = render({ flatList: true, listState: "loading" });
391
- assert.match(html, /animate-pulse/);
392
- assert.doesNotMatch(html, /Ada Lovelace/, "rows replaced by skeleton");
393
- });
394
-
395
- it("renders the empty mailbox copy", () => {
396
- const html = render({ flatList: true, listState: "empty", sections: [] });
397
- assert.match(html, /No messages in this mailbox/);
398
- });
399
-
400
- it("renders the search-empty copy when a query is active", () => {
401
- const html = render({
402
- flatList: true,
403
- listState: "empty",
404
- sections: [],
405
- searchQuery: "invoice",
406
- });
407
- assert.match(html, /No messages match your search/);
408
- });
409
-
410
- it("fails hard on error with retry + report, never a disabled control", () => {
411
- const html = render({
412
- flatList: true,
413
- listState: "error",
414
- sections: [],
415
- onRetry: () => {},
416
- onReportError: () => {},
417
- });
418
- assert.match(html, /role="alert"/);
419
- assert.match(html, /Couldn&#x27;t load messages/);
420
- assert.match(html, /Retry/);
421
- assert.match(html, /Report a problem/);
422
- assert.doesNotMatch(html, /\sdisabled[\s=>]/);
423
- });
424
- });
425
-
426
- // The interactive swipe is a pointer drag; its release rule is `commitPeek`,
427
- // kept pure so it's testable without a DOM (SSR can't fire pointer events).
428
- describe("commitPeek — drag-release snap rule", () => {
429
- it("snaps back to none when the drag is short of half the action width", () => {
430
- assert.equal(commitPeek(0), "none");
431
- assert.equal(commitPeek(35), "none", "just under half (36) stays closed");
432
- assert.equal(commitPeek(-35), "none");
433
- });
434
-
435
- it("commits to a side once the drag passes half the action width", () => {
436
- assert.equal(commitPeek(36), "leading", "dragged right past half");
437
- assert.equal(commitPeek(72), "leading", "fully dragged right");
438
- assert.equal(commitPeek(-36), "trailing", "dragged left past half");
439
- assert.equal(commitPeek(-72), "trailing", "fully dragged left");
440
- });
441
- });
@@ -1,323 +0,0 @@
1
- import { FolderInput } from "lucide-react";
2
- import { useState } from "react";
3
- import type { BriefCategoryFilter } from "../category-presentation.js";
4
- import {
5
- type BriefFilterId,
6
- narrowBriefSections,
7
- } from "../lib/brief-filters.js";
8
- import { AppShellSlotted, useAppShellLayout } from "./app-shell-slotted.js";
9
- import type { AppShellProps, NarrowView } from "./app-shell-types.js";
10
- import type { BriefFilterControl } from "./brief-sections.js";
11
- import { Button } from "./button.js";
12
- import { IntelligencePanel } from "./intelligence-panel.js";
13
- import { MessageListPane } from "./message-list-pane.js";
14
- import {
15
- type MobileReadingMessageActions,
16
- MobileReadingPane,
17
- } from "./mobile-reading-pane.js";
18
- import { NavSidebar } from "./nav-sidebar.js";
19
- import { ReadingPane } from "./reading-pane.js";
20
-
21
- const noop = () => undefined;
22
-
23
- /**
24
- * Preview wiring for the narrow-width reading view: the data-driven shell has no
25
- * per-message handlers, so the mock supplies no-op verbs and a folder-picker
26
- * slot. The live client passes real handlers in the #960 follow-up.
27
- */
28
- const mobileReadingActions: MobileReadingMessageActions = {
29
- onToggleExpand: noop,
30
- onReply: noop,
31
- onReplyAll: noop,
32
- onForward: noop,
33
- onToggleStar: noop,
34
- onDelete: noop,
35
- onToggleRead: noop,
36
- moveSlot: () => (
37
- <Button
38
- variant="ghost"
39
- size="sm"
40
- icon={<FolderInput className="size-5" />}
41
- aria-label="Move to folder"
42
- title="Move to folder"
43
- className="min-h-11 min-w-11 px-0"
44
- />
45
- ),
46
- };
47
-
48
- /* ------------------------------------------------------------------ */
49
- /* Data-driven shell: maps thread/sections/intelligence props into the */
50
- /* slots of AppShellSlotted, which owns the responsive panel layout */
51
- /* and the 1024/1280 breakpoints. This component is the kit's preview / */
52
- /* Storybook surface; the layout lives in exactly one place (slotted). */
53
- /* ------------------------------------------------------------------ */
54
-
55
- export function AppShell({
56
- accounts,
57
- initialWidth,
58
- selectedNavId,
59
- briefUnseen,
60
- listTitle,
61
- listMeta,
62
- sections,
63
- briefFilters,
64
- flatList,
65
- listState,
66
- searchQuery,
67
- onRetry,
68
- onReportError,
69
- briefCategory,
70
- onSelectBriefCategory,
71
- selectedThreadId,
72
- thread,
73
- initialNarrowView = "list",
74
- initialTouchState,
75
- selection,
76
- keyboard,
77
- selectionBar,
78
- intelligence,
79
- intelligenceOpen = true,
80
- density,
81
- onSelectNav,
82
- onSelectThread,
83
- onToggleIntelligence,
84
- }: AppShellProps) {
85
- /* Below the reading boundary the single pane swaps in place between the list
86
- and a dedicated message view; above it the thread fills the reading pane and
87
- narrowView is unused. */
88
- const [narrowView, setNarrowView] = useState<NarrowView>(initialNarrowView);
89
- /* Category lives here when uncontrolled so the brief and the nav expando
90
- share one axis; a controlled `briefCategory`/`onSelectBriefCategory` pair
91
- overrides it. */
92
- const [internalCategory, setInternalCategory] = useState<BriefCategoryFilter>(
93
- briefCategory ?? "all",
94
- );
95
- const activeCategory = briefCategory ?? internalCategory;
96
- const selectCategory = (category: BriefCategoryFilter) => {
97
- setInternalCategory(category);
98
- onSelectBriefCategory?.(category);
99
- };
100
- /* The list draws the brief's chips and its category pills and applies
101
- neither (#314). This shell holds the rows, so it answers both here —
102
- otherwise a chip would tick and nothing on screen would move. */
103
- const [briefChips, setBriefChips] = useState<ReadonlySet<BriefFilterId>>(
104
- new Set(),
105
- );
106
- const toggleBriefChip = (id: BriefFilterId) =>
107
- setBriefChips((prev) => {
108
- const next = new Set(prev);
109
- if (next.has(id)) next.delete(id);
110
- else next.add(id);
111
- return next;
112
- });
113
- const clearBriefFilters = () => {
114
- selectCategory("all");
115
- setBriefChips(new Set());
116
- };
117
- const listSections = briefFilters
118
- ? narrowBriefSections(sections ?? [], activeCategory, briefChips)
119
- : sections;
120
-
121
- const nav = (
122
- <NavSidebar
123
- accounts={accounts}
124
- selectedNavId={selectedNavId}
125
- briefUnseen={briefUnseen}
126
- onSelectNav={onSelectNav}
127
- />
128
- );
129
-
130
- const list = (
131
- <AppShellList
132
- thread={thread}
133
- intelligence={intelligence}
134
- narrowView={narrowView}
135
- onBackToList={() => setNarrowView("list")}
136
- listTitle={listTitle}
137
- listMeta={listMeta}
138
- sections={listSections}
139
- briefFilters={briefFilters}
140
- flatList={flatList}
141
- listState={listState}
142
- searchQuery={searchQuery}
143
- onRetry={onRetry}
144
- onReportError={onReportError}
145
- briefCategory={activeCategory}
146
- selectedThreadId={selectedThreadId}
147
- density={density}
148
- onSelectThread={(id) => {
149
- setNarrowView("message");
150
- onSelectThread?.(id);
151
- }}
152
- onSelectBriefCategory={selectCategory}
153
- activeFilters={briefChips}
154
- onToggleFilter={toggleBriefChip}
155
- onClearFilters={clearBriefFilters}
156
- initialTouchState={initialTouchState}
157
- selection={selection}
158
- keyboard={keyboard}
159
- selectionBar={selectionBar}
160
- />
161
- );
162
-
163
- const reading = (
164
- <AppShellReading
165
- thread={thread}
166
- intelligence={intelligence}
167
- intelligenceOpen={intelligenceOpen}
168
- onToggleIntelligence={onToggleIntelligence}
169
- />
170
- );
171
-
172
- return (
173
- <AppShellSlotted
174
- initialWidth={initialWidth}
175
- nav={nav}
176
- list={list}
177
- reading={reading}
178
- intelligence={
179
- intelligence ? (
180
- <IntelligencePanel
181
- data={intelligence}
182
- onClose={onToggleIntelligence}
183
- className="h-full w-full border-l-0"
184
- />
185
- ) : undefined
186
- }
187
- intelligenceOpen={intelligenceOpen}
188
- hasThread={Boolean(thread)}
189
- density={density}
190
- />
191
- );
192
- }
193
-
194
- /* ------------------------------------------------------------------ */
195
- /* Slot adapters: read the slotted shell's layout context so they */
196
- /* render the right narrow/wide variant inside each pane. */
197
- /* ------------------------------------------------------------------ */
198
-
199
- function AppShellList({
200
- thread,
201
- intelligence,
202
- narrowView,
203
- onBackToList,
204
- listTitle,
205
- listMeta,
206
- sections,
207
- briefFilters,
208
- flatList,
209
- listState,
210
- searchQuery,
211
- onRetry,
212
- onReportError,
213
- briefCategory,
214
- selectedThreadId,
215
- density,
216
- onSelectThread,
217
- onSelectBriefCategory,
218
- activeFilters,
219
- onToggleFilter,
220
- onClearFilters,
221
- initialTouchState,
222
- selection,
223
- keyboard,
224
- selectionBar,
225
- }: Pick<
226
- AppShellProps,
227
- | "thread"
228
- | "intelligence"
229
- | "listTitle"
230
- | "listMeta"
231
- | "sections"
232
- | "briefFilters"
233
- | "flatList"
234
- | "listState"
235
- | "searchQuery"
236
- | "onRetry"
237
- | "onReportError"
238
- | "selectedThreadId"
239
- | "density"
240
- | "onSelectThread"
241
- | "initialTouchState"
242
- | "selection"
243
- | "keyboard"
244
- | "selectionBar"
245
- > & {
246
- narrowView: NarrowView;
247
- onBackToList: () => void;
248
- briefCategory: BriefCategoryFilter;
249
- onSelectBriefCategory: (category: BriefCategoryFilter) => void;
250
- } & BriefFilterControl) {
251
- const layout = useAppShellLayout();
252
- const showReadingPane = layout?.showReadingPane ?? false;
253
- const showNavPane = layout?.showNavPane ?? true;
254
-
255
- /* Below the reading boundary, opening a thread swaps the single pane for a
256
- dedicated message view; at/above it the reading pane carries the thread. */
257
- if (!showReadingPane && narrowView === "message" && thread) {
258
- return (
259
- <MobileReadingPane
260
- thread={thread}
261
- intelligence={intelligence}
262
- onBack={onBackToList}
263
- actions={mobileReadingActions}
264
- />
265
- );
266
- }
267
-
268
- return (
269
- <MessageListPane
270
- listTitle={listTitle}
271
- listMeta={listMeta}
272
- sections={sections ?? []}
273
- briefFilters={briefFilters}
274
- flatList={flatList}
275
- listState={listState}
276
- searchQuery={searchQuery}
277
- onRetry={onRetry}
278
- onReportError={onReportError}
279
- briefFilter={{
280
- briefCategory,
281
- onSelectBriefCategory,
282
- activeFilters,
283
- onToggleFilter,
284
- onClearFilters,
285
- }}
286
- selectedThreadId={selectedThreadId}
287
- density={density}
288
- onSelectThread={onSelectThread}
289
- onOpenNav={showNavPane ? undefined : layout?.openNav}
290
- isDesktop={showReadingPane}
291
- initialTouchState={initialTouchState}
292
- selection={selection}
293
- keyboard={keyboard}
294
- selectionBar={selectionBar}
295
- />
296
- );
297
- }
298
-
299
- function AppShellReading({
300
- thread,
301
- intelligence,
302
- intelligenceOpen,
303
- onToggleIntelligence,
304
- }: Pick<
305
- AppShellProps,
306
- "thread" | "intelligence" | "intelligenceOpen" | "onToggleIntelligence"
307
- >) {
308
- const layout = useAppShellLayout();
309
- const isWide = layout?.showIntelligencePane ?? false;
310
- const showIntelligence =
311
- isWide &&
312
- Boolean(intelligence) &&
313
- Boolean(intelligenceOpen) &&
314
- Boolean(thread);
315
- return (
316
- <ReadingPane
317
- thread={thread}
318
- intelligenceOpen={showIntelligence}
319
- onToggleIntelligence={onToggleIntelligence}
320
- canToggleIntelligence={isWide && Boolean(intelligence) && Boolean(thread)}
321
- />
322
- );
323
- }