@remit/ui 0.0.180 → 0.0.182

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 (35) hide show
  1. package/package.json +1 -1
  2. package/src/category-presentation.test.ts +76 -0
  3. package/src/category-presentation.ts +147 -0
  4. package/src/components/app-shell-types.ts +4 -63
  5. package/src/components/app-shell.tsx +2 -5
  6. package/src/components/bottom-sheet.stories.tsx +56 -0
  7. package/src/components/bottom-sheet.tsx +3 -2
  8. package/src/components/brief-section.tsx +1 -0
  9. package/src/components/brief-sections.render.test.ts +3 -3
  10. package/src/components/brief-sections.stories.tsx +2 -5
  11. package/src/components/brief-sections.tsx +8 -22
  12. package/src/components/category-badge.render.test.ts +21 -9
  13. package/src/components/category-badge.stories.tsx +3 -2
  14. package/src/components/category-badge.tsx +5 -39
  15. package/src/components/category-presentation.stories.tsx +2 -6
  16. package/src/components/confirm-dialog.tsx +10 -20
  17. package/src/components/dialog.stories.tsx +156 -0
  18. package/src/components/dialog.tsx +3 -2
  19. package/src/components/flow-screen.focus.test.ts +107 -0
  20. package/src/components/flow-screen.tsx +101 -75
  21. package/src/components/intelligence-panel.render.test.ts +21 -3
  22. package/src/components/intelligence-panel.tsx +6 -2
  23. package/src/components/message-row.render.test.ts +2 -1
  24. package/src/components/message-row.tsx +3 -2
  25. package/src/components/self-update-progress-overlay.tsx +7 -48
  26. package/src/components/slide-panel.tsx +7 -1
  27. package/src/filter-presets.ts +4 -24
  28. package/src/index.ts +14 -9
  29. package/src/lib/brief-filter-query.ts +1 -1
  30. package/src/lib/brief-filters.ts +1 -1
  31. package/src/lib/overlay-scope.ts +13 -1
  32. package/src/lib/use-modal-focus.test.ts +520 -0
  33. package/src/lib/use-modal-focus.ts +158 -0
  34. package/src/lib/use-initial-focus.test.ts +0 -78
  35. package/src/lib/use-initial-focus.ts +0 -36
@@ -1,7 +1,8 @@
1
1
  import { AlertOctagon, Check, Loader2 } from "lucide-react";
2
- import { type RefObject, useEffect, useRef } from "react";
2
+ import { useRef } from "react";
3
3
  import { cn } from "../lib/cn.js";
4
4
  import { useOverlayScope } from "../lib/overlay-scope.js";
5
+ import { useModalFocus } from "../lib/use-modal-focus.js";
5
6
  import { Button } from "./button.js";
6
7
  import {
7
8
  type UpdatePhase,
@@ -11,51 +12,6 @@ import {
11
12
 
12
13
  const phaseOrder: UpdatePhase[] = ["preparing", "restarting", "reconnecting"];
13
14
 
14
- const FOCUSABLE =
15
- 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';
16
-
17
- /**
18
- * A screen whose purpose is to stop interaction has to stop it for the
19
- * keyboard too. Focus moves in on mount and Tab cycles inside, so nothing
20
- * behind the overlay can be reached while the server is gone.
21
- */
22
- function useBlockingFocus(ref: RefObject<HTMLDivElement | null>) {
23
- useEffect(() => {
24
- const container = ref.current;
25
- if (!container) return;
26
-
27
- const focusables = () =>
28
- Array.from(container.querySelectorAll<HTMLElement>(FOCUSABLE));
29
-
30
- (focusables()[0] ?? container).focus();
31
-
32
- const onKeyDown = (event: KeyboardEvent) => {
33
- if (event.key !== "Tab") return;
34
- const items = focusables();
35
- if (items.length === 0) {
36
- event.preventDefault();
37
- container.focus();
38
- return;
39
- }
40
- const first = items[0];
41
- const last = items[items.length - 1];
42
- const active = document.activeElement;
43
- if (event.shiftKey && (active === first || !container.contains(active))) {
44
- event.preventDefault();
45
- last.focus();
46
- return;
47
- }
48
- if (!event.shiftKey && (active === last || !container.contains(active))) {
49
- event.preventDefault();
50
- first.focus();
51
- }
52
- };
53
-
54
- window.addEventListener("keydown", onKeyDown, true);
55
- return () => window.removeEventListener("keydown", onKeyDown, true);
56
- }, [ref]);
57
- }
58
-
59
15
  const overlayShell =
60
16
  "fixed inset-0 z-50 flex flex-col items-center justify-center gap-6 bg-canvas p-6 text-center outline-none";
61
17
 
@@ -76,7 +32,10 @@ export function SelfUpdateProgressOverlay({
76
32
  elapsedSeconds,
77
33
  }: SelfUpdateProgressOverlayProps) {
78
34
  const ref = useRef<HTMLDivElement>(null);
79
- useBlockingFocus(ref);
35
+ // A screen whose purpose is to stop interaction has to stop it for the
36
+ // keyboard too: it has nothing to Tab to, so focus rests on the screen itself
37
+ // and stays there while the server is gone.
38
+ useModalFocus(ref, true);
80
39
  // Nothing to answer: the update is running and there is no way out of it, so
81
40
  // every shortcut is contained rather than acting on a mailbox that is gone.
82
41
  useOverlayScope({ id: "self-update", open: true });
@@ -163,7 +122,7 @@ export function SelfUpdateUnreachableScreen({
163
122
  onRetryConnection,
164
123
  }: SelfUpdateUnreachableScreenProps) {
165
124
  const ref = useRef<HTMLDivElement>(null);
166
- useBlockingFocus(ref);
125
+ useModalFocus(ref, true);
167
126
  const minutes = Math.max(1, Math.round(elapsedSeconds / 60));
168
127
 
169
128
  return (
@@ -1,7 +1,8 @@
1
1
  import { X } from "lucide-react";
2
- import type { ReactNode } from "react";
2
+ import { type ReactNode, useRef } from "react";
3
3
  import { cn } from "../lib/cn.js";
4
4
  import { useOverlayScope } from "../lib/overlay-scope.js";
5
+ import { useModalFocus } from "../lib/use-modal-focus.js";
5
6
 
6
7
  /* ------------------------------------------------------------------ */
7
8
  /* SlidePanel: right-edge slide-over for a focused sub-task (editing */
@@ -37,6 +38,9 @@ export function SlidePanel({
37
38
  answers: { back: onClose },
38
39
  });
39
40
 
41
+ const panelRef = useRef<HTMLDivElement>(null);
42
+ useModalFocus(panelRef, isOpen);
43
+
40
44
  return (
41
45
  <>
42
46
  {/* Click-to-dismiss scrim: a pointer shortcut for the header's Close
@@ -52,6 +56,7 @@ export function SlidePanel({
52
56
  />
53
57
 
54
58
  <div
59
+ ref={panelRef}
55
60
  className={cn(
56
61
  "safe-area-frame fixed top-0 right-0 z-50 flex h-full w-full flex-col border-l border-line bg-canvas shadow-xl sm:w-[400px] sm:max-w-[90vw]",
57
62
  "transform transition-transform duration-200 ease-out",
@@ -62,6 +67,7 @@ export function SlidePanel({
62
67
  aria-hidden={!isOpen}
63
68
  inert={!isOpen}
64
69
  aria-labelledby="slide-panel-title"
70
+ tabIndex={-1}
65
71
  >
66
72
  <div className="flex h-14 shrink-0 items-center justify-between border-b border-line px-4">
67
73
  <h2 id="slide-panel-title" className="font-semibold">
@@ -1,3 +1,4 @@
1
+ import { categoryChips } from "./category-presentation.js";
1
2
  import type {
2
3
  FilterSheetCategory,
3
4
  FilterSheetFilter,
@@ -27,27 +28,6 @@ export interface FilterPreset {
27
28
  sources?: FilterSheetSource[];
28
29
  }
29
30
 
30
- /**
31
- * Content-type categories, mirroring the `MessageCategory` enum
32
- * (@remit/remit-imap) by value. The leading "all" clears the category. Per
33
- * message, not per mailbox — so they apply in the brief and an inbox alike.
34
- *
35
- * `uncategorized` is a category of its own here, never folded into `personal`
36
- * (issue #45): mail the classifier has not reached is a pending state with a
37
- * name, and it carries its own label and tone so the two can never read alike.
38
- * It sits after `Personal` to match `briefCategories`' order.
39
- */
40
- const MESSAGE_CATEGORIES: FilterSheetCategory[] = [
41
- { id: "all", label: "All", tone: "neutral" },
42
- { id: "personal", label: "Personal", tone: "accent" },
43
- { id: "uncategorized", label: "Unclassified", tone: "neutral" },
44
- { id: "transactional", label: "Transactional", tone: "positive" },
45
- { id: "newsletter", label: "Newsletter", tone: "neutral" },
46
- { id: "marketing", label: "Marketing", tone: "warning" },
47
- { id: "social", label: "Social", tone: "warning" },
48
- { id: "automated", label: "Automated", tone: "neutral" },
49
- ];
50
-
51
31
  const UNREAD: FilterSheetFilter = { id: "unread", label: "Unread" };
52
32
  // `flagged` is the wire name (IMAP \Flagged); the user-facing label is "Starred".
53
33
  const FLAGGED: FilterSheetFilter = { id: "flagged", label: "Starred" };
@@ -78,7 +58,7 @@ export function briefFilterConfig(
78
58
  accounts: FilterAccount[] = [],
79
59
  ): FilterPreset {
80
60
  return {
81
- categories: [...MESSAGE_CATEGORIES],
61
+ categories: [...categoryChips],
82
62
  filters: briefFilterChips,
83
63
  sources: accountSources(accounts),
84
64
  };
@@ -90,7 +70,7 @@ export function briefFilterConfig(
90
70
  */
91
71
  export function inboxFilterConfig(): FilterPreset {
92
72
  return {
93
- categories: [...MESSAGE_CATEGORIES],
73
+ categories: [...categoryChips],
94
74
  filters: [UNREAD, FLAGGED, HAS_ATTACHMENT],
95
75
  };
96
76
  }
@@ -102,7 +82,7 @@ export function inboxFilterConfig(): FilterPreset {
102
82
  */
103
83
  export function flaggedFilterConfig(): FilterPreset {
104
84
  return {
105
- categories: [...MESSAGE_CATEGORIES],
85
+ categories: [...categoryChips],
106
86
  filters: [UNREAD, HAS_ATTACHMENT],
107
87
  };
108
88
  }
package/src/index.ts CHANGED
@@ -3,6 +3,19 @@
3
3
  // own bookkeeping; a plain object spread silently drops one side's handler
4
4
  // instead of chaining them) without importing react-aria directly.
5
5
  export { mergeProps } from "react-aria";
6
+ export {
7
+ type BriefCategoryFilter,
8
+ CATEGORY_PRESENTATION,
9
+ CATEGORY_SECTION_ORDER,
10
+ type CategoryPresentation,
11
+ categoryChips,
12
+ categoryLabels,
13
+ categoryTone,
14
+ getCategoryLabel,
15
+ isBriefCategory,
16
+ isThreadCategory,
17
+ type ThreadCategory,
18
+ } from "./category-presentation.js";
6
19
  export {
7
20
  AddressDisplay,
8
21
  type AddressDisplayProps,
@@ -47,13 +60,8 @@ export {
47
60
  } from "./components/app-shell-slotted.js";
48
61
  export {
49
62
  type AppShellProps,
50
- type BriefCategoryFilter,
51
- briefCategories,
52
- categoryTone,
53
63
  type Density,
54
64
  INTELLIGENCE_MIN_WIDTH,
55
- isBriefCategory,
56
- isThreadCategory,
57
65
  type MessageListKeyboard,
58
66
  type MessageListSelection,
59
67
  type NarrowView,
@@ -66,7 +74,6 @@ export {
66
74
  type PaneLayout,
67
75
  READING_PANE_MIN_WIDTH,
68
76
  resolvePaneLayout,
69
- type ThreadCategory,
70
77
  type ThreadData,
71
78
  type ThreadMessageData,
72
79
  type ThreadRowData,
@@ -222,8 +229,6 @@ export {
222
229
  export {
223
230
  CategoryBadge,
224
231
  type CategoryBadgeProps,
225
- getCategoryLabel,
226
- type MessageCategory,
227
232
  } from "./components/category-badge.js";
228
233
  export { Checkbox, type CheckboxProps } from "./components/checkbox.js";
229
234
  export {
@@ -1128,7 +1133,6 @@ export {
1128
1133
  type SuggestKeyState,
1129
1134
  suggestKeyAction,
1130
1135
  } from "./lib/suggest-keys.js";
1131
- export { useInitialFocus } from "./lib/use-initial-focus.js";
1132
1136
  export { type ListCursor, useListCursor } from "./lib/use-list-cursor.js";
1133
1137
  export {
1134
1138
  type ListKeyboard,
@@ -1141,6 +1145,7 @@ export {
1141
1145
  useLongPress,
1142
1146
  } from "./lib/use-long-press.js";
1143
1147
  export { useMatchMedia } from "./lib/use-match-media.js";
1148
+ export { useModalFocus } from "./lib/use-modal-focus.js";
1144
1149
  export {
1145
1150
  MESSAGE_ROW_SELECTOR,
1146
1151
  useRenderedRowIds,
@@ -25,7 +25,7 @@
25
25
  import {
26
26
  type BriefCategoryFilter,
27
27
  isBriefCategory,
28
- } from "../components/app-shell-types.js";
28
+ } from "../category-presentation.js";
29
29
  import type { BriefFilterId } from "./brief-filters.js";
30
30
  import {
31
31
  searchTokenTerm,
@@ -11,8 +11,8 @@
11
11
  * anywhere, so the host applies them with `matchesBriefFilters` before it hands
12
12
  * the rows down. One table for both, rather than one per surface (#314).
13
13
  */
14
+ import type { BriefCategoryFilter } from "../category-presentation.js";
14
15
  import type {
15
- BriefCategoryFilter,
16
16
  ThreadRowData,
17
17
  ThreadSection,
18
18
  } from "../components/app-shell-types.js";
@@ -70,6 +70,18 @@ let entries: ScopeEntry[] = [];
70
70
  let renderedOverlays = 0;
71
71
  const nextDepth = (): number => ++renderedOverlays;
72
72
 
73
+ /**
74
+ * This surface's position in the React tree, as the stack orders it.
75
+ *
76
+ * Shared with the focus trap, which needs the same ordering for the same
77
+ * reason: registration order puts an inner surface underneath the one
78
+ * containing it, and a sibling raised later underneath the one already up.
79
+ */
80
+ export function useOverlayDepth(): number {
81
+ const [depth] = useState(nextDepth);
82
+ return depth;
83
+ }
84
+
73
85
  const byDepth = (a: ScopeEntry, b: ScopeEntry): number => a.depth - b.depth;
74
86
 
75
87
  /**
@@ -192,7 +204,7 @@ export function useOverlayScope({
192
204
 
193
205
  // Numbered during the first render, where React is still going parent before
194
206
  // child — the one moment nesting is legible from inside a hook.
195
- const [depth] = useState(nextDepth);
207
+ const depth = useOverlayDepth();
196
208
 
197
209
  useEffect(() => {
198
210
  if (!open) return;