@remit/ui 0.0.61 → 0.0.63

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.61",
3
+ "version": "0.0.63",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "src"
@@ -0,0 +1,44 @@
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 { BlockedReason } from "./blocked-reason.js";
6
+
7
+ const REASON = "Pick a destination first.";
8
+
9
+ /**
10
+ * Nothing disables (#477 1.7), so a dimmed control has to say what it is missing
11
+ * two ways: a description that is there for as long as the block is, and an
12
+ * announcement that happens when the control is pressed.
13
+ *
14
+ * They are separate elements because a live region announces what is written
15
+ * into it. One element that already holds the reason and gains `role="status"`
16
+ * on the press has nothing written into it, so nothing is announced — which is
17
+ * how a wizard comes to have a visual-only answer to "why can't I continue".
18
+ */
19
+ describe("BlockedReason", () => {
20
+ it("describes the control before anything is pressed, silently", () => {
21
+ const html = renderToString(
22
+ createElement(BlockedReason, { id: "reason", reason: REASON }),
23
+ );
24
+ assert.match(html, /<p id="reason"[^>]*sr-only/);
25
+ assert.match(html, new RegExp(REASON));
26
+ // The live region is mounted and empty: there is nothing to announce yet.
27
+ assert.match(html, /role="status"[^>]*><\/span>/);
28
+ });
29
+
30
+ it("shows and announces the same reason once it has been pressed", () => {
31
+ const html = renderToString(
32
+ createElement(BlockedReason, {
33
+ id: "reason",
34
+ reason: REASON,
35
+ nudged: true,
36
+ className: "text-warning",
37
+ }),
38
+ );
39
+ assert.doesNotMatch(html, /role="status"[^>]*><\/span>/);
40
+ assert.match(html, new RegExp(`role="status"[^>]*>${REASON}`));
41
+ assert.doesNotMatch(html, /<p id="reason"[^>]*sr-only/);
42
+ assert.match(html, /text-warning/);
43
+ });
44
+ });
@@ -0,0 +1,41 @@
1
+ import { cn } from "../lib/cn.js";
2
+
3
+ export interface BlockedReasonProps {
4
+ /** What `aria-describedby` on the dimmed control points at. */
5
+ id: string;
6
+ reason: string;
7
+ /** The control was pressed while blocked, so the reason comes on screen. */
8
+ nudged?: boolean;
9
+ className?: string;
10
+ }
11
+
12
+ /**
13
+ * What a dimmed control is still missing (#477 1.7). Nothing disables, so the
14
+ * reason has to reach the user two ways, and they are not the same element.
15
+ *
16
+ * The description carries the reason for as long as it applies, so anything
17
+ * reading the control through the accessibility tree finds it without pressing
18
+ * anything; the press is what unhides it.
19
+ *
20
+ * The announcement is a live region that is mounted with the block and empty
21
+ * until the press, because a live region announces what is written into it and
22
+ * not what it was already holding. Marking the description live at the moment
23
+ * it becomes visible announces nothing.
24
+ */
25
+ export function BlockedReason({
26
+ id,
27
+ reason,
28
+ nudged,
29
+ className,
30
+ }: BlockedReasonProps) {
31
+ return (
32
+ <>
33
+ <p id={id} className={cn(className, !nudged && "sr-only")}>
34
+ {reason}
35
+ </p>
36
+ <span role="status" aria-live="polite" className="sr-only">
37
+ {nudged ? reason : ""}
38
+ </span>
39
+ </>
40
+ );
41
+ }
@@ -261,6 +261,16 @@ export const ruleBlockedCopy = {
261
261
  recounting: "Recounting matches — save once the count settles.",
262
262
  } as const;
263
263
 
264
+ /**
265
+ * What the count region says when there is no count to be had. The vector-free
266
+ * matcher will not read message bodies, so a `HasWords` clause cannot be counted
267
+ * before it is saved — which is a different answer from a count of zero, and
268
+ * the only one that keeps an empty sample from reading as "this matches
269
+ * nothing".
270
+ */
271
+ export const UNCOUNTABLE_PREDICATE_REASON =
272
+ "Can't count matches — “has the words” reads message bodies, which only a saved rule does.";
273
+
264
274
  /**
265
275
  * Why the count on screen is not yet the count that will be applied, or
266
276
  * `undefined` once it has settled. This is what makes RFC 038's
@@ -1,6 +1,6 @@
1
1
  import { Menu } from "lucide-react";
2
2
  import type { ReactNode } from "react";
3
- import { useRef, useState } from "react";
3
+ import { useMemo, useRef, useState } from "react";
4
4
  import { LIST_ROW_SELECTOR, useRovingFocus } from "../lib/roving-focus.js";
5
5
  import type { AppShellProps, TouchSeed } from "./app-shell-types.js";
6
6
  import { BriefSections } from "./brief-sections.js";
@@ -125,7 +125,27 @@ export function MessageListPane({
125
125
  ? new Set(seededRows.slice(0, 2).map((t) => t.id))
126
126
  : new Set(),
127
127
  );
128
+ // What the fallback bar's verbs have done to the mock rows. A demo bar whose
129
+ // Trash only closes the bar is a Trash that deletes nothing, which is the one
130
+ // thing a selection bar must never be — so these verbs act on the rows the
131
+ // mock owns, the same way `refresh` below fakes a refresh visibly.
132
+ const [trashedIds, setTrashedIds] = useState<ReadonlySet<string>>(new Set());
133
+ const [readIds, setReadIds] = useState<ReadonlySet<string>>(new Set());
128
134
  const [refreshing, setRefreshing] = useState(false);
135
+ const touchSections = useMemo(
136
+ () =>
137
+ trashedIds.size === 0 && readIds.size === 0
138
+ ? sections
139
+ : sections.map((section) => ({
140
+ ...section,
141
+ threads: section.threads
142
+ .filter((thread) => !trashedIds.has(thread.id))
143
+ .map((thread) =>
144
+ readIds.has(thread.id) ? { ...thread, isRead: true } : thread,
145
+ ),
146
+ })),
147
+ [sections, trashedIds, readIds],
148
+ );
129
149
  const initialPeek: SwipePeek | undefined =
130
150
  initialTouchState === "peek-trailing"
131
151
  ? "trailing"
@@ -150,6 +170,14 @@ export function MessageListPane({
150
170
  setSelectionMode(false);
151
171
  setCheckedIds(new Set());
152
172
  };
173
+ const trashChecked = () => {
174
+ setTrashedIds((prev) => new Set([...prev, ...checkedIds]));
175
+ cancelSelection();
176
+ };
177
+ const markCheckedRead = () => {
178
+ setReadIds((prev) => new Set([...prev, ...checkedIds]));
179
+ cancelSelection();
180
+ };
153
181
  const refresh = () => {
154
182
  setRefreshing(true);
155
183
  setTimeout(() => setRefreshing(false), 1400);
@@ -168,8 +196,8 @@ export function MessageListPane({
168
196
  title={listTitle}
169
197
  count={checkedIds.size}
170
198
  onCancel={cancelSelection}
171
- onMarkRead={cancelSelection}
172
- onDelete={cancelSelection}
199
+ onMarkRead={markCheckedRead}
200
+ onDelete={trashChecked}
173
201
  />
174
202
  ) : hideHeader ? null : (
175
203
  <header className="flex h-pane-header shrink-0 items-center gap-2 border-b border-line px-row-inset">
@@ -230,7 +258,7 @@ export function MessageListPane({
230
258
  listBody
231
259
  ) : touchTriage ? (
232
260
  <TouchListBody
233
- sections={sections}
261
+ sections={touchSections}
234
262
  selectedThreadId={selectedThreadId}
235
263
  selectionMode={selectionMode}
236
264
  checkedIds={checkedIds}
@@ -186,7 +186,7 @@ function Harness({
186
186
  sections,
187
187
  preset,
188
188
  scope,
189
- makeFilterDisabledReason,
189
+ makeFilterBlockedReason,
190
190
  suggestions = [],
191
191
  }: {
192
192
  initialValue?: string;
@@ -196,7 +196,7 @@ function Harness({
196
196
  preset: Preset;
197
197
  scope?: SearchScope;
198
198
  /** Renders the conversion inert with a reason; it is offered either way. */
199
- makeFilterDisabledReason?: string;
199
+ makeFilterBlockedReason?: string;
200
200
  /** Completions for the term being typed. */
201
201
  suggestions?: Suggestion[];
202
202
  }) {
@@ -282,7 +282,7 @@ function Harness({
282
282
  scope={scope}
283
283
  makeFilter={{
284
284
  onClick: () => undefined,
285
- disabledReason: makeFilterDisabledReason,
285
+ blockedReason: makeFilterBlockedReason,
286
286
  }}
287
287
  suggest={{
288
288
  comboboxProps: suggest.comboboxProps,
@@ -343,9 +343,9 @@ export const ScopedSearch: Story = {
343
343
  };
344
344
 
345
345
  /**
346
- * A query with nothing a filter could match on: the conversion is offered inert
347
- * with the reason, rather than withheld and leaving the row to appear and vanish
348
- * as the user types.
346
+ * A query with nothing a filter could match on: the conversion stays offered and
347
+ * dimmed, rather than withheld and leaving the row to appear and vanish as the
348
+ * user types. Pressing it puts the reason on screen.
349
349
  */
350
350
  export const NothingToConvert: Story = {
351
351
  render: () => (
@@ -353,7 +353,7 @@ export const NothingToConvert: Story = {
353
353
  initialValue="has:attachment"
354
354
  sections={resultSections}
355
355
  preset="inbox"
356
- makeFilterDisabledReason="Add a sender or words to filter on"
356
+ makeFilterBlockedReason="Add a sender or words to filter on"
357
357
  />
358
358
  ),
359
359
  };
@@ -99,16 +99,17 @@ describe("SearchResults", () => {
99
99
  assert.doesNotMatch(html, /disabled=""/);
100
100
  });
101
101
 
102
- it("disables the filter offer with its reason when nothing converts", () => {
102
+ it("keeps the filter offer pressable when nothing converts, carrying its reason", () => {
103
103
  const html = renderToString(
104
104
  createElement(SearchResults, {
105
105
  value: "has:attachment",
106
106
  sections: [{ id: "results", label: "Results", results: [] }],
107
- makeFilter: { onClick: noop, disabledReason: "Add a sender or words" },
107
+ makeFilter: { onClick: noop, blockedReason: "Add a sender or words" },
108
108
  }),
109
109
  );
110
110
  assert.match(html, /Make this a filter/);
111
- assert.match(html, /disabled/);
111
+ assert.doesNotMatch(html, /disabled/);
112
+ assert.match(html, /aria-describedby/);
112
113
  assert.match(html, /Add a sender or words/);
113
114
  });
114
115
 
@@ -190,15 +190,18 @@ export const WithMakeFilter: Story = {
190
190
  ),
191
191
  };
192
192
 
193
- /** The filter offer disabled — a search of only non-clause facets has nothing to convert. */
194
- export const MakeFilterDisabled: Story = {
193
+ /**
194
+ * The filter offer dimmed — a search of only non-clause facets has nothing to
195
+ * convert. It stays pressable, and pressing it puts the reason on screen.
196
+ */
197
+ export const MakeFilterBlocked: Story = {
195
198
  render: () => (
196
199
  <Harness
197
200
  value="has:attachment"
198
201
  sections={resultSections}
199
202
  makeFilter={{
200
203
  onClick: () => {},
201
- disabledReason: "Add a sender or words to filter on",
204
+ blockedReason: "Add a sender or words to filter on",
202
205
  }}
203
206
  />
204
207
  ),
@@ -1,6 +1,7 @@
1
1
  import { ChevronDown, Clock, Filter } from "lucide-react";
2
- import { useState } from "react";
2
+ import { useId, useState } from "react";
3
3
  import { cn } from "../lib/cn.js";
4
+ import { BlockedReason } from "./blocked-reason.js";
4
5
  import type { FolderRole } from "./folder-role.js";
5
6
  import { type SearchResult, SearchResultRow } from "./search-result-row.js";
6
7
  import { SearchTokenChips } from "./search-token-chip.js";
@@ -86,21 +87,22 @@ export interface SearchResultsProps {
86
87
  scope?: SearchScope;
87
88
  /**
88
89
  * "Make this a filter" (RFC 038 D5) — offered above the results while a query
89
- * is active, converting the search to a pre-filled rule. Omit to drop the
90
- * affordance; a `disabledReason` renders it inert with the reason (a search of
91
- * only non-clause facets has nothing to convert).
90
+ * is active, opening the selection wizard on clauses derived from it. Omit to
91
+ * drop the affordance; a `blockedReason` dims it and states what is missing (a
92
+ * search of only non-clause facets has nothing to convert).
92
93
  */
93
94
  makeFilter?: MakeFilterActionProps;
94
95
  }
95
96
 
96
97
  export interface MakeFilterActionProps {
97
98
  onClick: () => void;
98
- /** Renders the action inert and states why, e.g. nothing in the query converts. */
99
- disabledReason?: string;
99
+ /** What the query is still missing. Dims the action; never disables it. */
100
+ blockedReason?: string;
100
101
  }
101
102
 
102
103
  /**
103
- * "Make this a filter" — the conversion entry offered while a search is active.
104
+ * "Make this a filter" — the wizard's second entry, offered while a search is
105
+ * active.
104
106
  *
105
107
  * A standalone row rather than a part of the results body, because a search is
106
108
  * shown in more than one way: the read-only `SearchResults` panel, and a list
@@ -108,34 +110,47 @@ export interface MakeFilterActionProps {
108
110
  * not to either rendering, so the caller mounts it above whichever body is up and
109
111
  * it stays put when the body swaps. `SearchResults` renders it inline as a
110
112
  * convenience for callers that show only the panel.
113
+ *
114
+ * Nothing disables (#477 1.7). A query with nothing to convert dims the action
115
+ * and leaves it pressable — pressing it is what brings the reason on screen,
116
+ * which `disabled` would take away along with the control itself.
111
117
  */
112
118
  export function MakeFilterAction({
113
119
  onClick,
114
- disabledReason,
120
+ blockedReason,
115
121
  }: MakeFilterActionProps) {
116
- const disabled = disabledReason !== undefined;
122
+ const reasonId = useId();
123
+ const [nudged, setNudged] = useState(false);
117
124
  return (
118
125
  <div className="border-b border-line px-row-inset py-1.5">
119
126
  <button
120
127
  type="button"
121
- onClick={onClick}
122
- disabled={disabled}
123
- title={disabledReason}
128
+ onClick={() => {
129
+ if (blockedReason) {
130
+ setNudged(true);
131
+ return;
132
+ }
133
+ onClick();
134
+ }}
135
+ aria-describedby={blockedReason ? reasonId : undefined}
124
136
  className={cn(
125
137
  "flex w-full items-center gap-1.5 rounded-md px-2 py-1.5 text-left text-xs font-medium transition-colors",
126
- disabled
127
- ? "cursor-not-allowed text-fg-subtle"
138
+ blockedReason
139
+ ? "text-fg-subtle opacity-55"
128
140
  : "text-accent hover:bg-surface-sunken",
129
141
  )}
130
142
  >
131
143
  <Filter className="size-3.5 shrink-0" aria-hidden="true" />
132
144
  <span>Make this a filter</span>
133
- {disabled && (
134
- <span className="ml-auto truncate text-2xs font-normal text-fg-subtle">
135
- {disabledReason}
136
- </span>
137
- )}
138
145
  </button>
146
+ {blockedReason && (
147
+ <BlockedReason
148
+ id={reasonId}
149
+ reason={blockedReason}
150
+ nudged={nudged}
151
+ className="px-2 pt-1 text-2xs text-warning"
152
+ />
153
+ )}
139
154
  </div>
140
155
  );
141
156
  }
@@ -286,12 +301,7 @@ export function SearchResults({
286
301
  const chips = tokens && tokens.length > 0 && (
287
302
  <SearchTokenChips tokens={tokens} />
288
303
  );
289
- const filterAction = makeFilter && (
290
- <MakeFilterAction
291
- onClick={makeFilter.onClick}
292
- disabledReason={makeFilter.disabledReason}
293
- />
294
- );
304
+ const filterAction = makeFilter && <MakeFilterAction {...makeFilter} />;
295
305
 
296
306
  if (loading) {
297
307
  return (
@@ -236,12 +236,10 @@ export const EscalationAvailable: Story = {
236
236
  * query's total, not a materialized id count, and the notice offers a way
237
237
  * back to the bounded selection.
238
238
  *
239
- * Every verb the bar carries stays available here (#114). An escalated
240
- * selection is a predicate rather than an id list, so the web-client runs
241
- * move and mark-read by paging that predicate the same way delete does —
242
- * from the bar's side nothing changes, which is the point: an escalated
243
- * selection that could only be deleted forced anyone wanting to file those
244
- * messages back to the loaded page.
239
+ * Every verb the bar carries stays available here (#114), and every one of
240
+ * them opens the wizard, which names the predicate and states its count before
241
+ * anything runs (#508). From the bar's side nothing changes, which is the
242
+ * point: an escalated selection is a selection.
245
243
  */
246
244
  export const Escalated: Story = {
247
245
  args: {
@@ -306,22 +304,6 @@ export const DeletingWithProgress: Story = {
306
304
  },
307
305
  };
308
306
 
309
- /**
310
- * After a bulk delete finishes with some batches failed: the count reflects
311
- * only what's still selected — the failures — not the original selection,
312
- * and Retry is a real button naming how many.
313
- */
314
- export const PartialFailure: Story = {
315
- args: {
316
- count: 340,
317
- notice: {
318
- tone: "danger",
319
- text: "3,072 moved to Trash. 340 couldn't be deleted.",
320
- action: { label: "Retry 340", onClick: () => undefined },
321
- },
322
- },
323
- };
324
-
325
307
  /**
326
308
  * A move over an escalated selection: same chunked run as a delete, worded for
327
309
  * the action that is running and toned as ordinary progress rather than
@@ -345,18 +327,3 @@ export const MarkingReadWithProgress: Story = {
345
327
  progress: { value: 1200, max: 3412, tone: "info" },
346
328
  },
347
329
  };
348
-
349
- /**
350
- * Partial failure of a move rather than a delete: the notice names the action
351
- * that ran, and Retry resends that same action against what is still selected.
352
- */
353
- export const PartialFailureMove: Story = {
354
- args: {
355
- count: 340,
356
- notice: {
357
- tone: "danger",
358
- text: "3,072 moved. 340 couldn't be moved.",
359
- action: { label: "Retry 340", onClick: () => undefined },
360
- },
361
- },
362
- };
@@ -45,12 +45,6 @@ export interface SelectionTopBarProps {
45
45
  * a selection spanning accounts, or a surface with no owning mailbox.
46
46
  */
47
47
  onMove?: () => void;
48
- /**
49
- * The Move verb for a selection the wizard cannot take: an escalated
50
- * predicate, which no bounded list of ids stands in for, so it keeps the
51
- * caller's own folder picker. Rendered only in `onMove`'s place.
52
- */
53
- moveSlot?: ReactNode;
54
48
  /** Opens Organize for the selection. Omitted where organize cannot be
55
49
  * scoped to one account. */
56
50
  onOrganize?: () => void;
@@ -124,7 +118,7 @@ export interface SelectionTopBarProps {
124
118
  /**
125
119
  * Toned status line below the action row, sometimes carrying an action
126
120
  * button — a cross-account move restriction, a "Select all N matching…"
127
- * escalation, a "Stop" during counting, or a partial-failure "Retry N".
121
+ * escalation, or a "Stop" during counting.
128
122
  */
129
123
  notice?: SelectionTopBarNotice;
130
124
  }
@@ -172,7 +166,6 @@ export function SelectionTopBar({
172
166
  onCancel,
173
167
  onDelete,
174
168
  onMove,
175
- moveSlot,
176
169
  onOrganize,
177
170
  onJunk,
178
171
  onMarkRead,
@@ -278,19 +271,16 @@ export function SelectionTopBar({
278
271
  aria-busy={isBusy || undefined}
279
272
  className="shrink-0"
280
273
  />
281
- {!isBusy &&
282
- (onMove ? (
283
- <Button
284
- variant="ghost"
285
- size="touch"
286
- icon={<FolderInput className="size-5" />}
287
- onClick={onMove}
288
- aria-label="Move selected messages"
289
- className="shrink-0"
290
- />
291
- ) : (
292
- moveSlot
293
- ))}
274
+ {!isBusy && onMove && (
275
+ <Button
276
+ variant="ghost"
277
+ size="touch"
278
+ icon={<FolderInput className="size-5" />}
279
+ onClick={onMove}
280
+ aria-label="Move selected messages"
281
+ className="shrink-0"
282
+ />
283
+ )}
294
284
  {!isBusy && onOrganize && (
295
285
  <Button
296
286
  variant="ghost"