@remit/ui 0.0.164 → 0.0.165

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 (28) hide show
  1. package/package.json +1 -1
  2. package/src/components/calendar-clash-strip.render.test.ts +51 -0
  3. package/src/components/calendar-clash-strip.stories.tsx +56 -0
  4. package/src/components/calendar-clash-strip.tsx +64 -0
  5. package/src/components/calendar-invite-card.render.test.ts +110 -0
  6. package/src/components/calendar-invite-card.stories.tsx +132 -0
  7. package/src/components/calendar-invite-card.tsx +288 -0
  8. package/src/components/calendar-parse-badge.render.test.ts +40 -0
  9. package/src/components/calendar-parse-badge.stories.tsx +46 -0
  10. package/src/components/calendar-parse-badge.tsx +59 -0
  11. package/src/components/calendar-slot-offers.render.test.ts +67 -0
  12. package/src/components/calendar-slot-offers.stories.tsx +79 -0
  13. package/src/components/calendar-slot-offers.tsx +67 -0
  14. package/src/components/calendar-suggestion-deck.render.test.ts +69 -0
  15. package/src/components/calendar-suggestion-deck.stories.tsx +165 -0
  16. package/src/components/calendar-suggestion-deck.tsx +116 -0
  17. package/src/components/calendar-types.ts +57 -0
  18. package/src/components/event-suggestion-card.tsx +8 -1
  19. package/src/components/intelligence-calendar-fixtures.ts +384 -0
  20. package/src/components/intelligence-calendar.deck-zone-gate.test.ts +142 -0
  21. package/src/components/intelligence-calendar.render.test.ts +122 -0
  22. package/src/components/intelligence-calendar.tsx +288 -0
  23. package/src/components/intelligence-panel-calendar.stories.tsx +401 -0
  24. package/src/components/intelligence-panel.render.test.ts +64 -1
  25. package/src/components/intelligence-panel.tab-strip.test.ts +163 -0
  26. package/src/components/intelligence-panel.tsx +239 -174
  27. package/src/components/intelligence-section.tsx +24 -0
  28. package/src/index.ts +40 -0
@@ -10,12 +10,19 @@ import {
10
10
  Star,
11
11
  X,
12
12
  } from "lucide-react";
13
- import type { ReactElement, ReactNode } from "react";
13
+ import { type ReactElement, type ReactNode, useId, useState } from "react";
14
14
  import { cn } from "../lib/cn.js";
15
15
  import { categoryTone, type ThreadCategory } from "./app-shell-types.js";
16
16
  import { Avatar } from "./avatar.js";
17
17
  import { Badge } from "./badge.js";
18
18
  import { Button } from "./button.js";
19
+ import {
20
+ IntelligenceCalendar,
21
+ type IntelligenceCalendarActions,
22
+ type IntelligenceCalendarData,
23
+ } from "./intelligence-calendar.js";
24
+ import { IntelligenceSection } from "./intelligence-section.js";
25
+ import { SegmentedControl } from "./segmented-control.js";
19
26
 
20
27
  /* ------------------------------------------------------------------ */
21
28
  /* The fourth pane: mail intelligence. Driven by real backend signals */
@@ -165,6 +172,32 @@ export interface IntelligenceQuickActions {
165
172
  */
166
173
  export type SimilarState = "loading" | "error" | "ready";
167
174
 
175
+ /**
176
+ * The two halves of the panel. Sender is what this message is; Calendar is what
177
+ * it would cost. They are tabs rather than one long column because the second
178
+ * half only matters while a decision about time is open, and because both hosts
179
+ * — the rail at 1280 and up, the drawer below it — mount this same component
180
+ * and so inherit whatever the strip does.
181
+ */
182
+ export type IntelligenceTabId = "sender" | "calendar";
183
+
184
+ const tabOptions: { value: IntelligenceTabId; label: string }[] = [
185
+ { value: "sender", label: "Sender" },
186
+ { value: "calendar", label: "Calendar" },
187
+ ];
188
+
189
+ /**
190
+ * The calendar tab's data and its callbacks, which arrive together or not at
191
+ * all: a tab whose buttons cannot be serviced is a row of dead controls, so a
192
+ * host with no calendar wiring gets no tab strip.
193
+ */
194
+ export interface IntelligenceCalendarSurface {
195
+ data: IntelligenceCalendarData;
196
+ actions: IntelligenceCalendarActions;
197
+ /** The event the day list shows as selected; empty when none is. */
198
+ selectedEventId?: string;
199
+ }
200
+
168
201
  export interface IntelligencePanelProps {
169
202
  data: IntelligenceData;
170
203
  onClose?: () => void;
@@ -202,6 +235,15 @@ export interface IntelligencePanelProps {
202
235
  reportSpamPending?: boolean;
203
236
  /** True while a "Not spam" (undo) press is in flight. Same treatment as `reportSpamPending`. */
204
237
  notSpamPending?: boolean;
238
+ /** The calendar half. Omit it and the panel is the Sender stack alone. */
239
+ calendar?: IntelligenceCalendarSurface;
240
+ /** The tab showing. Omit to let the panel hold the choice itself. */
241
+ tab?: IntelligenceTabId;
242
+ onTabChange?: (tab: IntelligenceTabId) => void;
243
+ /** Which tab a panel holding its own choice opens on. */
244
+ defaultTab?: IntelligenceTabId;
245
+ /** Larger hit targets, for the drawer host on a touch screen. */
246
+ touch?: boolean;
205
247
  }
206
248
 
207
249
  const trustLabel: Record<
@@ -213,27 +255,6 @@ const trustLabel: Record<
213
255
  vip: { label: "VIP", tone: "accent" },
214
256
  };
215
257
 
216
- function Section({
217
- label,
218
- children,
219
- className,
220
- }: {
221
- label: string;
222
- children: ReactNode;
223
- className?: string;
224
- }) {
225
- return (
226
- <section
227
- className={cn("border-b border-line px-row-inset py-3", className)}
228
- >
229
- <h3 className="text-2xs font-semibold uppercase tracking-wider text-fg-subtle">
230
- {label}
231
- </h3>
232
- <div className="mt-2">{children}</div>
233
- </section>
234
- );
235
- }
236
-
237
258
  function SenderCard({ sender }: { sender: SenderIntel }) {
238
259
  const trust = trustLabel[sender.trust];
239
260
  // Engagement clause renders only when counters are present. When the API
@@ -397,8 +418,18 @@ export function IntelligencePanel({
397
418
  hideCloseButton = false,
398
419
  reportSpamPending = false,
399
420
  notSpamPending = false,
421
+ calendar,
422
+ tab,
423
+ onTabChange,
424
+ defaultTab = "sender",
425
+ touch,
400
426
  }: IntelligencePanelProps) {
401
427
  const { sender, authenticity, category, flags = {}, similar } = data;
428
+ const [ownTab, setOwnTab] = useState<IntelligenceTabId>(defaultTab);
429
+ const tabStripName = useId();
430
+ const activeTab = tab ?? ownTab;
431
+ const calendarTab =
432
+ calendar !== undefined && activeTab === "calendar" ? calendar : undefined;
402
433
 
403
434
  return (
404
435
  <aside
@@ -423,169 +454,203 @@ export function IntelligencePanel({
423
454
  )}
424
455
  </header>
425
456
 
426
- <Section label="Sender">
427
- <SenderCard sender={sender} />
428
- </Section>
457
+ {calendar && (
458
+ <div className="flex shrink-0 justify-center border-b border-line px-row-inset py-2">
459
+ <SegmentedControl
460
+ name={tabStripName}
461
+ aria-label="What this panel is showing"
462
+ size="sm"
463
+ options={tabOptions}
464
+ value={activeTab}
465
+ onChange={(next) => {
466
+ if (tab === undefined) setOwnTab(next);
467
+ onTabChange?.(next);
468
+ }}
469
+ />
470
+ </div>
471
+ )}
429
472
 
430
- <Section label="Authenticity">
431
- <Authenticity auth={authenticity} onShowSimilar={onShowSimilar} />
432
- </Section>
473
+ {calendarTab && (
474
+ <IntelligenceCalendar
475
+ data={calendarTab.data}
476
+ actions={calendarTab.actions}
477
+ selectedEventId={calendarTab.selectedEventId}
478
+ touch={touch}
479
+ />
480
+ )}
433
481
 
434
- <Section label="Category">
435
- <div className="flex items-center gap-2">
436
- <Badge tone={categoryTone[category.value]}>{category.value}</Badge>
437
- {category.overridden && (
438
- <span className="text-2xs text-fg-subtle">your override</span>
439
- )}
440
- <button
441
- type="button"
442
- className={cn(
443
- "ml-auto text-2xs text-accent hover:underline",
444
- !actions?.onReclassify &&
445
- "cursor-not-allowed opacity-50 hover:no-underline",
446
- )}
447
- disabled={!actions?.onReclassify}
448
- onClick={actions?.onReclassify}
449
- >
450
- reclassify
451
- </button>
452
- </div>
453
- </Section>
482
+ {calendarTab === undefined && (
483
+ <>
484
+ <IntelligenceSection label="Sender">
485
+ <SenderCard sender={sender} />
486
+ </IntelligenceSection>
454
487
 
455
- <Section label="Quick actions">
456
- <div className="flex flex-wrap gap-1.5">
457
- <QuickAction
458
- icon={<Star className="size-3.5" />}
459
- label="VIP"
460
- active={flags.vip}
461
- onClick={actions?.onToggleVip}
462
- />
463
- <QuickAction
464
- icon={<BellOff className="size-3.5" />}
465
- label="Mute"
466
- active={flags.muted}
467
- onClick={actions?.onToggleMute}
468
- />
469
- {actions?.onNotSpam && (
470
- <QuickAction
471
- icon={<MailCheck className="size-3.5" />}
472
- label={notSpamPending ? "Undoing…" : "Not spam"}
473
- active
474
- onClick={actions.onNotSpam}
475
- pending={notSpamPending}
476
- />
477
- )}
478
- {actions?.onReportSpam && (
479
- <QuickAction
480
- icon={<ShieldX className="size-3.5" />}
481
- label={reportSpamPending ? "Reporting…" : "Report spam"}
482
- danger
483
- onClick={actions.onReportSpam}
484
- pending={reportSpamPending}
485
- />
486
- )}
487
- <QuickAction
488
- icon={<MailX className="size-3.5" />}
489
- label="Unsubscribe"
490
- active={flags.unsubscribed}
491
- onClick={actions?.onToggleUnsubscribe}
492
- />
493
- </div>
494
- {actions?.onNotSpam && (
495
- <p className="mt-1.5 text-2xs text-fg-subtle">
496
- You reported this message as spam
497
- </p>
498
- )}
499
- </Section>
488
+ <IntelligenceSection label="Authenticity">
489
+ <Authenticity auth={authenticity} onShowSimilar={onShowSimilar} />
490
+ </IntelligenceSection>
500
491
 
501
- {(similarState !== "ready" || similar.length > 0) && (
502
- <Section label="Similar messages">
503
- {similarState === "loading" ? (
504
- <div className="animate-pulse space-y-2">
505
- {Array.from({ length: 3 }).map((_, i) => (
506
- // biome-ignore lint/suspicious/noArrayIndexKey: list is static, no stable id
507
- <div key={i} className="space-y-1">
508
- <div className="h-3 w-3/4 rounded bg-surface-sunken" />
509
- <div className="h-2.5 w-1/2 rounded bg-surface-sunken" />
510
- </div>
511
- ))}
492
+ <IntelligenceSection label="Category">
493
+ <div className="flex items-center gap-2">
494
+ <Badge tone={categoryTone[category.value]}>
495
+ {category.value}
496
+ </Badge>
497
+ {category.overridden && (
498
+ <span className="text-2xs text-fg-subtle">your override</span>
499
+ )}
500
+ <button
501
+ type="button"
502
+ className={cn(
503
+ "ml-auto text-2xs text-accent hover:underline",
504
+ !actions?.onReclassify &&
505
+ "cursor-not-allowed opacity-50 hover:no-underline",
506
+ )}
507
+ disabled={!actions?.onReclassify}
508
+ onClick={actions?.onReclassify}
509
+ >
510
+ reclassify
511
+ </button>
512
512
  </div>
513
- ) : similarState === "error" ? (
514
- <p className="text-xs text-fg-subtle">
515
- Similarity search unavailable
516
- </p>
517
- ) : (
518
- <ul className="-mx-1 space-y-1">
519
- {similar.map((s) => {
520
- const rowClass =
521
- "block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken";
522
- const ariaLabel = `Open message from ${s.fromName || "unknown sender"}: ${s.subject}`;
523
- const inner = (
524
- <>
525
- <div className="flex items-baseline justify-between gap-2">
526
- <span className="truncate text-xs font-medium text-fg">
527
- {s.fromName}
528
- </span>
529
- <span className="shrink-0 text-2xs text-fg-subtle tabular-nums">
530
- {s.timeLabel}
531
- </span>
532
- </div>
533
- <div className="truncate text-xs text-fg-muted">
534
- {s.subject}
513
+ </IntelligenceSection>
514
+
515
+ <IntelligenceSection label="Quick actions">
516
+ <div className="flex flex-wrap gap-1.5">
517
+ <QuickAction
518
+ icon={<Star className="size-3.5" />}
519
+ label="VIP"
520
+ active={flags.vip}
521
+ onClick={actions?.onToggleVip}
522
+ />
523
+ <QuickAction
524
+ icon={<BellOff className="size-3.5" />}
525
+ label="Mute"
526
+ active={flags.muted}
527
+ onClick={actions?.onToggleMute}
528
+ />
529
+ {actions?.onNotSpam && (
530
+ <QuickAction
531
+ icon={<MailCheck className="size-3.5" />}
532
+ label={notSpamPending ? "Undoing…" : "Not spam"}
533
+ active
534
+ onClick={actions.onNotSpam}
535
+ pending={notSpamPending}
536
+ />
537
+ )}
538
+ {actions?.onReportSpam && (
539
+ <QuickAction
540
+ icon={<ShieldX className="size-3.5" />}
541
+ label={reportSpamPending ? "Reporting…" : "Report spam"}
542
+ danger
543
+ onClick={actions.onReportSpam}
544
+ pending={reportSpamPending}
545
+ />
546
+ )}
547
+ <QuickAction
548
+ icon={<MailX className="size-3.5" />}
549
+ label="Unsubscribe"
550
+ active={flags.unsubscribed}
551
+ onClick={actions?.onToggleUnsubscribe}
552
+ />
553
+ </div>
554
+ {actions?.onNotSpam && (
555
+ <p className="mt-1.5 text-2xs text-fg-subtle">
556
+ You reported this message as spam
557
+ </p>
558
+ )}
559
+ </IntelligenceSection>
560
+
561
+ {(similarState !== "ready" || similar.length > 0) && (
562
+ <IntelligenceSection label="Similar messages">
563
+ {similarState === "loading" ? (
564
+ <div className="animate-pulse space-y-2">
565
+ {Array.from({ length: 3 }).map((_, i) => (
566
+ // biome-ignore lint/suspicious/noArrayIndexKey: list is static, no stable id
567
+ <div key={i} className="space-y-1">
568
+ <div className="h-3 w-3/4 rounded bg-surface-sunken" />
569
+ <div className="h-2.5 w-1/2 rounded bg-surface-sunken" />
535
570
  </div>
536
- <span className="mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle">
537
- {matchTone[s.matched]}
538
- </span>
539
- </>
540
- );
541
- return (
542
- <li key={s.id}>
543
- {similarLinkComponent ? (
544
- similarLinkComponent({
545
- mailboxId: s.mailboxId,
546
- threadId: s.threadId,
547
- messageId: s.id,
548
- className: rowClass,
549
- ariaLabel,
550
- children: inner,
551
- })
552
- ) : (
553
- <div className={rowClass}>{inner}</div>
554
- )}
555
- </li>
556
- );
557
- })}
558
- </ul>
571
+ ))}
572
+ </div>
573
+ ) : similarState === "error" ? (
574
+ <p className="text-xs text-fg-subtle">
575
+ Similarity search unavailable
576
+ </p>
577
+ ) : (
578
+ <ul className="-mx-1 space-y-1">
579
+ {similar.map((s) => {
580
+ const rowClass =
581
+ "block w-full rounded-md px-1 py-1 text-left hover:bg-surface-sunken";
582
+ const ariaLabel = `Open message from ${s.fromName || "unknown sender"}: ${s.subject}`;
583
+ const inner = (
584
+ <>
585
+ <div className="flex items-baseline justify-between gap-2">
586
+ <span className="truncate text-xs font-medium text-fg">
587
+ {s.fromName}
588
+ </span>
589
+ <span className="shrink-0 text-2xs text-fg-subtle tabular-nums">
590
+ {s.timeLabel}
591
+ </span>
592
+ </div>
593
+ <div className="truncate text-xs text-fg-muted">
594
+ {s.subject}
595
+ </div>
596
+ <span className="mt-1 inline-block rounded-full bg-surface-sunken px-1.5 py-px text-2xs text-fg-subtle">
597
+ {matchTone[s.matched]}
598
+ </span>
599
+ </>
600
+ );
601
+ return (
602
+ <li key={s.id}>
603
+ {similarLinkComponent ? (
604
+ similarLinkComponent({
605
+ mailboxId: s.mailboxId,
606
+ threadId: s.threadId,
607
+ messageId: s.id,
608
+ className: rowClass,
609
+ ariaLabel,
610
+ children: inner,
611
+ })
612
+ ) : (
613
+ <div className={rowClass}>{inner}</div>
614
+ )}
615
+ </li>
616
+ );
617
+ })}
618
+ </ul>
619
+ )}
620
+ </IntelligenceSection>
559
621
  )}
560
- </Section>
561
- )}
562
622
 
563
- <Section label="Coming soon" className="border-b-0 opacity-70">
564
- <div className="space-y-2">
565
- <div className="flex items-start gap-2 rounded-md border border-dashed border-line p-2">
566
- <Sparkles className="mt-0.5 size-3.5 shrink-0 text-fg-subtle" />
567
- <div>
568
- <div className="text-xs font-medium text-fg-muted">
569
- Suggested actions
570
- </div>
571
- <div className="text-2xs text-fg-subtle">
572
- "Create a filter for messages like this" — on-device model
573
- </div>
574
- </div>
575
- </div>
576
- <div className="flex items-start gap-2 rounded-md border border-dashed border-line p-2">
577
- <Sparkles className="mt-0.5 size-3.5 shrink-0 text-fg-subtle" />
578
- <div>
579
- <div className="text-xs font-medium text-fg-muted">
580
- Thread summary
623
+ <IntelligenceSection
624
+ label="Coming soon"
625
+ className="border-b-0 opacity-70"
626
+ >
627
+ <div className="space-y-2">
628
+ <div className="flex items-start gap-2 rounded-md border border-dashed border-line p-2">
629
+ <Sparkles className="mt-0.5 size-3.5 shrink-0 text-fg-subtle" />
630
+ <div>
631
+ <div className="text-xs font-medium text-fg-muted">
632
+ Suggested actions
633
+ </div>
634
+ <div className="text-2xs text-fg-subtle">
635
+ "Create a filter for messages like this" — on-device model
636
+ </div>
637
+ </div>
581
638
  </div>
582
- <div className="text-2xs text-fg-subtle">
583
- One-paragraph digest — Bedrock
639
+ <div className="flex items-start gap-2 rounded-md border border-dashed border-line p-2">
640
+ <Sparkles className="mt-0.5 size-3.5 shrink-0 text-fg-subtle" />
641
+ <div>
642
+ <div className="text-xs font-medium text-fg-muted">
643
+ Thread summary
644
+ </div>
645
+ <div className="text-2xs text-fg-subtle">
646
+ One-paragraph digest — Bedrock
647
+ </div>
648
+ </div>
584
649
  </div>
585
650
  </div>
586
- </div>
587
- </div>
588
- </Section>
651
+ </IntelligenceSection>
652
+ </>
653
+ )}
589
654
  </aside>
590
655
  );
591
656
  }
@@ -0,0 +1,24 @@
1
+ import type { ReactNode } from "react";
2
+ import { cn } from "../lib/cn.js";
3
+
4
+ /** One labelled band of the intelligence panel, shared by both its tabs. */
5
+ export function IntelligenceSection({
6
+ label,
7
+ children,
8
+ className,
9
+ }: {
10
+ label: string;
11
+ children: ReactNode;
12
+ className?: string;
13
+ }) {
14
+ return (
15
+ <section
16
+ className={cn("border-b border-line px-row-inset py-3", className)}
17
+ >
18
+ <h3 className="text-2xs font-semibold uppercase tracking-wider text-fg-subtle">
19
+ {label}
20
+ </h3>
21
+ <div className="mt-2">{children}</div>
22
+ </section>
23
+ );
24
+ }
package/src/index.ts CHANGED
@@ -143,6 +143,10 @@ export {
143
143
  type ButtonLinkProps,
144
144
  type ButtonProps,
145
145
  } from "./components/button.js";
146
+ export {
147
+ CalendarClashStrip,
148
+ type CalendarClashStripProps,
149
+ } from "./components/calendar-clash-strip.js";
146
150
  export {
147
151
  CalendarEventChip,
148
152
  type CalendarEventChipProps,
@@ -155,10 +159,28 @@ export {
155
159
  CalendarGrid,
156
160
  type CalendarGridProps,
157
161
  } from "./components/calendar-grid.js";
162
+ export {
163
+ CalendarInviteCard,
164
+ type CalendarInviteCardProps,
165
+ } from "./components/calendar-invite-card.js";
158
166
  export {
159
167
  CalendarList,
160
168
  type CalendarListProps,
161
169
  } from "./components/calendar-list.js";
170
+ export {
171
+ CalendarParseBadge,
172
+ type CalendarParseBadgeProps,
173
+ calendarParseLabel,
174
+ calendarParseNote,
175
+ } from "./components/calendar-parse-badge.js";
176
+ export {
177
+ CalendarSlotOffers,
178
+ type CalendarSlotOffersProps,
179
+ } from "./components/calendar-slot-offers.js";
180
+ export {
181
+ CalendarSuggestionDeck,
182
+ type CalendarSuggestionDeckProps,
183
+ } from "./components/calendar-suggestion-deck.js";
162
184
  export {
163
185
  CalendarDateNav,
164
186
  type CalendarDateNavProps,
@@ -170,10 +192,15 @@ export {
170
192
  export {
171
193
  type AgendaParse,
172
194
  type CalendarAttendee,
195
+ type CalendarClash,
173
196
  type CalendarColorId,
174
197
  type CalendarDay,
175
198
  type CalendarDescriptor,
176
199
  type CalendarEventData,
200
+ type CalendarInvite,
201
+ type CalendarInviteState,
202
+ type CalendarParseMethod,
203
+ type CalendarProposal,
177
204
  type CalendarSlotPick,
178
205
  type CalendarViewId,
179
206
  type ChoicePicks,
@@ -410,12 +437,24 @@ export {
410
437
  type InputProps,
411
438
  type InputVariant,
412
439
  } from "./components/input.js";
440
+ export {
441
+ type CalendarDayEntry,
442
+ type CalendarInviteIntel,
443
+ type CalendarProseIntel,
444
+ type CalendarSuggestionIntel,
445
+ IntelligenceCalendar,
446
+ type IntelligenceCalendarActions,
447
+ type IntelligenceCalendarData,
448
+ type IntelligenceCalendarProps,
449
+ } from "./components/intelligence-calendar.js";
413
450
  export {
414
451
  type AuthenticityIntel,
452
+ type IntelligenceCalendarSurface,
415
453
  type IntelligenceData,
416
454
  IntelligencePanel,
417
455
  type IntelligencePanelProps,
418
456
  type IntelligenceQuickActions,
457
+ type IntelligenceTabId,
419
458
  type MatchedChunk,
420
459
  type SenderFlagsIntel,
421
460
  type SenderIntel,
@@ -425,6 +464,7 @@ export {
425
464
  type SimilarMessageLinkProps,
426
465
  type SimilarState,
427
466
  } from "./components/intelligence-panel.js";
467
+ export { IntelligenceSection } from "./components/intelligence-section.js";
428
468
  export {
429
469
  IntelligenceToggle,
430
470
  type IntelligenceToggleProps,