@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.
- package/package.json +1 -1
- package/src/components/calendar-clash-strip.render.test.ts +51 -0
- package/src/components/calendar-clash-strip.stories.tsx +56 -0
- package/src/components/calendar-clash-strip.tsx +64 -0
- package/src/components/calendar-invite-card.render.test.ts +110 -0
- package/src/components/calendar-invite-card.stories.tsx +132 -0
- package/src/components/calendar-invite-card.tsx +288 -0
- package/src/components/calendar-parse-badge.render.test.ts +40 -0
- package/src/components/calendar-parse-badge.stories.tsx +46 -0
- package/src/components/calendar-parse-badge.tsx +59 -0
- package/src/components/calendar-slot-offers.render.test.ts +67 -0
- package/src/components/calendar-slot-offers.stories.tsx +79 -0
- package/src/components/calendar-slot-offers.tsx +67 -0
- package/src/components/calendar-suggestion-deck.render.test.ts +69 -0
- package/src/components/calendar-suggestion-deck.stories.tsx +165 -0
- package/src/components/calendar-suggestion-deck.tsx +116 -0
- package/src/components/calendar-types.ts +57 -0
- package/src/components/event-suggestion-card.tsx +8 -1
- package/src/components/intelligence-calendar-fixtures.ts +384 -0
- package/src/components/intelligence-calendar.deck-zone-gate.test.ts +142 -0
- package/src/components/intelligence-calendar.render.test.ts +122 -0
- package/src/components/intelligence-calendar.tsx +288 -0
- package/src/components/intelligence-panel-calendar.stories.tsx +401 -0
- package/src/components/intelligence-panel.render.test.ts +64 -1
- package/src/components/intelligence-panel.tab-strip.test.ts +163 -0
- package/src/components/intelligence-panel.tsx +239 -174
- package/src/components/intelligence-section.tsx +24 -0
- package/src/index.ts +40 -0
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Calendar,
|
|
3
|
+
Check,
|
|
4
|
+
Clock,
|
|
5
|
+
History,
|
|
6
|
+
MapPin,
|
|
7
|
+
Trash2,
|
|
8
|
+
X,
|
|
9
|
+
} from "lucide-react";
|
|
10
|
+
import type { ReactNode } from "react";
|
|
11
|
+
import { calendarColorClasses } from "../lib/calendar-color.js";
|
|
12
|
+
import { cn } from "../lib/cn.js";
|
|
13
|
+
import { RsvpBadge } from "./attendee-row.js";
|
|
14
|
+
import { Button } from "./button.js";
|
|
15
|
+
import { CalendarClashStrip } from "./calendar-clash-strip.js";
|
|
16
|
+
import { CalendarParseBadge } from "./calendar-parse-badge.js";
|
|
17
|
+
import type {
|
|
18
|
+
CalendarClash,
|
|
19
|
+
CalendarColorId,
|
|
20
|
+
CalendarInvite,
|
|
21
|
+
RsvpState,
|
|
22
|
+
} from "./calendar-types.js";
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* The invitation, rendered as the thing it is instead of an attachment nobody
|
|
26
|
+
* opens. What saying yes would cost is stated above the button — before the
|
|
27
|
+
* answer, not after it — and it is stated across accounts, which is where the
|
|
28
|
+
* collisions that actually hurt live.
|
|
29
|
+
*
|
|
30
|
+
* The button reads "Add to calendar" because that is all it does. This plan
|
|
31
|
+
* sends no iMIP reply, so the organiser learns nothing from it, and the card
|
|
32
|
+
* says so where the press happens rather than in a settings page.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export interface CalendarInviteCardProps {
|
|
36
|
+
invite: CalendarInvite;
|
|
37
|
+
/** Already formatted by the caller. */
|
|
38
|
+
whenText: string;
|
|
39
|
+
/** The calendar the event would land on. */
|
|
40
|
+
calendarName: string;
|
|
41
|
+
color: CalendarColorId;
|
|
42
|
+
/** Everything already booked over the proposed span. */
|
|
43
|
+
clashes: CalendarClash[];
|
|
44
|
+
rsvp: RsvpState;
|
|
45
|
+
onAdd: () => void;
|
|
46
|
+
onTentative: () => void;
|
|
47
|
+
onDecline: () => void;
|
|
48
|
+
onReopen: () => void;
|
|
49
|
+
onOfferOtherTimes: () => void;
|
|
50
|
+
/** Wired only for a cancellation the reader has not acted on. */
|
|
51
|
+
onRemove?: () => void;
|
|
52
|
+
/** Wired only when a later message carries a higher SEQUENCE. */
|
|
53
|
+
onOpenNewer?: () => void;
|
|
54
|
+
/**
|
|
55
|
+
* Replaces the guest tally — a host with a richer guest surface of its own
|
|
56
|
+
* passes it here rather than the card growing a second one.
|
|
57
|
+
*/
|
|
58
|
+
guests?: ReactNode;
|
|
59
|
+
touch?: boolean;
|
|
60
|
+
className?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const tallyOrder: RsvpState[] = [
|
|
64
|
+
"accepted",
|
|
65
|
+
"tentative",
|
|
66
|
+
"declined",
|
|
67
|
+
"noReply",
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
const tallyWord: Record<RsvpState, string> = {
|
|
71
|
+
accepted: "coming",
|
|
72
|
+
tentative: "maybe",
|
|
73
|
+
declined: "not coming",
|
|
74
|
+
noReply: "no reply",
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export function CalendarInviteCard({
|
|
78
|
+
invite,
|
|
79
|
+
whenText,
|
|
80
|
+
calendarName,
|
|
81
|
+
color,
|
|
82
|
+
clashes,
|
|
83
|
+
rsvp,
|
|
84
|
+
onAdd,
|
|
85
|
+
onTentative,
|
|
86
|
+
onDecline,
|
|
87
|
+
onReopen,
|
|
88
|
+
onOfferOtherTimes,
|
|
89
|
+
onRemove,
|
|
90
|
+
onOpenNewer,
|
|
91
|
+
guests,
|
|
92
|
+
touch,
|
|
93
|
+
className,
|
|
94
|
+
}: CalendarInviteCardProps) {
|
|
95
|
+
const hue = calendarColorClasses(color);
|
|
96
|
+
const stale = invite.state === "superseded" || invite.state === "cancelled";
|
|
97
|
+
const attendees = invite.proposed.attendees;
|
|
98
|
+
const tally = tallyOrder
|
|
99
|
+
.map((state) => ({
|
|
100
|
+
state,
|
|
101
|
+
count: attendees.filter((person) => person.rsvp === state).length,
|
|
102
|
+
}))
|
|
103
|
+
.filter((entry) => entry.count > 0)
|
|
104
|
+
.map((entry) => `${entry.count} ${tallyWord[entry.state]}`)
|
|
105
|
+
.join(" · ");
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<section
|
|
109
|
+
className={cn(
|
|
110
|
+
"flex flex-col gap-3 rounded-lg border border-line bg-surface-raised p-3",
|
|
111
|
+
className,
|
|
112
|
+
)}
|
|
113
|
+
>
|
|
114
|
+
<div className="flex items-center gap-2">
|
|
115
|
+
<span className={cn("size-2.5 shrink-0 rounded-full", hue.solid)} />
|
|
116
|
+
<span className="min-w-0 flex-1 truncate text-2xs uppercase tracking-wider text-fg-subtle">
|
|
117
|
+
Invitation from {invite.organizerName} · {calendarName}
|
|
118
|
+
</span>
|
|
119
|
+
<CalendarParseBadge method={invite.method} />
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
<div className={cn(stale && "opacity-60")}>
|
|
123
|
+
<h3 className="text-md font-semibold text-fg">
|
|
124
|
+
{invite.proposed.title}
|
|
125
|
+
</h3>
|
|
126
|
+
<p className="mt-1 flex items-center gap-2 text-sm text-fg">
|
|
127
|
+
<Clock className="size-4 shrink-0 text-fg-subtle" aria-hidden />
|
|
128
|
+
{whenText}
|
|
129
|
+
</p>
|
|
130
|
+
{invite.proposed.location !== "" && (
|
|
131
|
+
<p className="mt-1 flex items-center gap-2 text-sm text-fg-muted">
|
|
132
|
+
<MapPin className="size-4 shrink-0 text-fg-subtle" aria-hidden />
|
|
133
|
+
{invite.proposed.location}
|
|
134
|
+
</p>
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
{invite.state === "superseded" && (
|
|
139
|
+
<div className="flex items-start gap-2 rounded-md border border-warning/40 bg-warning-soft p-2">
|
|
140
|
+
<History
|
|
141
|
+
className="mt-0.5 size-4 shrink-0 text-warning"
|
|
142
|
+
aria-hidden
|
|
143
|
+
/>
|
|
144
|
+
<div className="min-w-0 flex-1">
|
|
145
|
+
<p className="text-xs font-semibold text-warning">
|
|
146
|
+
{invite.organizerName} has sent a newer version of this.
|
|
147
|
+
</p>
|
|
148
|
+
<p className="mt-1 text-xs text-fg">
|
|
149
|
+
This one is revision {invite.sequence} and is out of date. Answer
|
|
150
|
+
the newer one instead.
|
|
151
|
+
</p>
|
|
152
|
+
{onOpenNewer && (
|
|
153
|
+
<Button
|
|
154
|
+
variant="secondary"
|
|
155
|
+
size={touch ? "md" : "sm"}
|
|
156
|
+
onClick={onOpenNewer}
|
|
157
|
+
className={cn("mt-2", touch && "min-h-11")}
|
|
158
|
+
>
|
|
159
|
+
Open the newer invitation
|
|
160
|
+
</Button>
|
|
161
|
+
)}
|
|
162
|
+
</div>
|
|
163
|
+
</div>
|
|
164
|
+
)}
|
|
165
|
+
|
|
166
|
+
{invite.state === "cancelled" && (
|
|
167
|
+
<div className="flex items-start gap-2 rounded-md border border-danger/40 bg-danger-soft p-2">
|
|
168
|
+
<X className="mt-0.5 size-4 shrink-0 text-danger" aria-hidden />
|
|
169
|
+
<div className="min-w-0 flex-1">
|
|
170
|
+
<p className="text-xs font-semibold text-danger">
|
|
171
|
+
{invite.organizerName} cancelled this.
|
|
172
|
+
</p>
|
|
173
|
+
<p className="mt-1 text-xs text-fg">
|
|
174
|
+
It is still on your calendar. Nothing comes off it until you say
|
|
175
|
+
so.
|
|
176
|
+
</p>
|
|
177
|
+
{onRemove && (
|
|
178
|
+
<div className={cn("mt-2 flex gap-2", touch && "flex-wrap")}>
|
|
179
|
+
<Button
|
|
180
|
+
variant="primary"
|
|
181
|
+
size={touch ? "md" : "sm"}
|
|
182
|
+
icon={<Trash2 className="size-3.5" />}
|
|
183
|
+
onClick={onRemove}
|
|
184
|
+
className={cn(touch && "min-h-11 flex-1")}
|
|
185
|
+
>
|
|
186
|
+
Remove from calendar
|
|
187
|
+
</Button>
|
|
188
|
+
<Button
|
|
189
|
+
variant="secondary"
|
|
190
|
+
size={touch ? "md" : "sm"}
|
|
191
|
+
onClick={onReopen}
|
|
192
|
+
className={cn(touch && "min-h-11 flex-1")}
|
|
193
|
+
>
|
|
194
|
+
Keep it
|
|
195
|
+
</Button>
|
|
196
|
+
</div>
|
|
197
|
+
)}
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
)}
|
|
201
|
+
|
|
202
|
+
{!stale && <CalendarClashStrip clashes={clashes} />}
|
|
203
|
+
|
|
204
|
+
{guests ?? (
|
|
205
|
+
<p className="text-2xs uppercase tracking-wider text-fg-subtle">
|
|
206
|
+
{attendees.length} guests{tally === "" ? "" : ` · ${tally}`}
|
|
207
|
+
</p>
|
|
208
|
+
)}
|
|
209
|
+
|
|
210
|
+
{!stale &&
|
|
211
|
+
(rsvp === "noReply" ? (
|
|
212
|
+
<div className="flex flex-col gap-2 border-t border-line pt-3">
|
|
213
|
+
<div className={cn("flex gap-2", touch && "flex-wrap")}>
|
|
214
|
+
<Button
|
|
215
|
+
variant="primary"
|
|
216
|
+
size={touch ? "md" : "sm"}
|
|
217
|
+
icon={<Calendar className="size-3.5" />}
|
|
218
|
+
onClick={onAdd}
|
|
219
|
+
className={cn(touch && "min-h-11 flex-1")}
|
|
220
|
+
>
|
|
221
|
+
Add to calendar
|
|
222
|
+
</Button>
|
|
223
|
+
<Button
|
|
224
|
+
variant="secondary"
|
|
225
|
+
size={touch ? "md" : "sm"}
|
|
226
|
+
onClick={onTentative}
|
|
227
|
+
className={cn(touch && "min-h-11 flex-1")}
|
|
228
|
+
>
|
|
229
|
+
Maybe
|
|
230
|
+
</Button>
|
|
231
|
+
<Button
|
|
232
|
+
variant="secondary"
|
|
233
|
+
size={touch ? "md" : "sm"}
|
|
234
|
+
icon={<X className="size-3.5" />}
|
|
235
|
+
onClick={onDecline}
|
|
236
|
+
className={cn(touch && "min-h-11 flex-1")}
|
|
237
|
+
>
|
|
238
|
+
Decline
|
|
239
|
+
</Button>
|
|
240
|
+
</div>
|
|
241
|
+
<Button
|
|
242
|
+
variant="ghost"
|
|
243
|
+
size={touch ? "md" : "sm"}
|
|
244
|
+
onClick={onOfferOtherTimes}
|
|
245
|
+
className={cn("self-start", touch && "min-h-11 w-full")}
|
|
246
|
+
>
|
|
247
|
+
Offer other times
|
|
248
|
+
</Button>
|
|
249
|
+
<p className="text-2xs text-fg-subtle">
|
|
250
|
+
{invite.organizerName} is not notified. Reader writes this to your
|
|
251
|
+
calendar and sends no reply — tell them in the thread.
|
|
252
|
+
</p>
|
|
253
|
+
</div>
|
|
254
|
+
) : (
|
|
255
|
+
<div className="flex flex-col gap-2 border-t border-line pt-3">
|
|
256
|
+
<div className="flex flex-wrap items-center gap-3">
|
|
257
|
+
<span className="flex items-center gap-1.5 text-sm text-fg">
|
|
258
|
+
{rsvp === "declined" ? "You declined" : "On your calendar"}
|
|
259
|
+
<RsvpBadge rsvp={rsvp} />
|
|
260
|
+
</span>
|
|
261
|
+
<Button
|
|
262
|
+
variant="ghost"
|
|
263
|
+
size={touch ? "md" : "sm"}
|
|
264
|
+
onClick={onReopen}
|
|
265
|
+
className={touch ? "min-h-11" : ""}
|
|
266
|
+
>
|
|
267
|
+
Change
|
|
268
|
+
</Button>
|
|
269
|
+
{rsvp === "declined" && (
|
|
270
|
+
<Button
|
|
271
|
+
variant="secondary"
|
|
272
|
+
size={touch ? "md" : "sm"}
|
|
273
|
+
onClick={onOfferOtherTimes}
|
|
274
|
+
className={touch ? "min-h-11" : ""}
|
|
275
|
+
>
|
|
276
|
+
Offer other times
|
|
277
|
+
</Button>
|
|
278
|
+
)}
|
|
279
|
+
</div>
|
|
280
|
+
<p className="flex items-start gap-1.5 text-2xs text-fg-subtle">
|
|
281
|
+
<Check className="mt-0.5 size-3 shrink-0" aria-hidden />
|
|
282
|
+
{invite.organizerName} was not notified.
|
|
283
|
+
</p>
|
|
284
|
+
</div>
|
|
285
|
+
))}
|
|
286
|
+
</section>
|
|
287
|
+
);
|
|
288
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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 {
|
|
6
|
+
CalendarParseBadge,
|
|
7
|
+
calendarParseLabel,
|
|
8
|
+
calendarParseNote,
|
|
9
|
+
} from "./calendar-parse-badge.js";
|
|
10
|
+
import type { CalendarParseMethod } from "./calendar-types.js";
|
|
11
|
+
|
|
12
|
+
const methods: CalendarParseMethod[] = ["ics", "markup", "pattern"];
|
|
13
|
+
|
|
14
|
+
const render = (method: CalendarParseMethod) =>
|
|
15
|
+
renderToString(createElement(CalendarParseBadge, { method }));
|
|
16
|
+
|
|
17
|
+
describe("CalendarParseBadge", () => {
|
|
18
|
+
it("names the rung that answered", () => {
|
|
19
|
+
for (const method of methods) {
|
|
20
|
+
assert.match(render(method), new RegExp(calendarParseLabel[method]));
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("marks a stated field apart from a reading of the prose", () => {
|
|
25
|
+
assert.match(render("ics"), /text-positive/);
|
|
26
|
+
assert.match(render("pattern"), /text-warning/);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("carries a label and a note for every rung", () => {
|
|
30
|
+
for (const method of methods) {
|
|
31
|
+
assert.notEqual(calendarParseLabel[method], undefined, method);
|
|
32
|
+
assert.notEqual(calendarParseNote[method], undefined, method);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("says a prose reading can be wrong, where a copied field does not", () => {
|
|
37
|
+
assert.match(calendarParseNote.pattern, /can be wrong/);
|
|
38
|
+
assert.doesNotMatch(calendarParseNote.ics, /can be wrong/);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import {
|
|
3
|
+
CalendarParseBadge,
|
|
4
|
+
calendarParseNote,
|
|
5
|
+
} from "./calendar-parse-badge.js";
|
|
6
|
+
import type { CalendarParseMethod } from "./calendar-types.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Which rung of the ladder answered. The difference between a field the sender
|
|
10
|
+
* stated and a reading of their prose decides how hard the reader has to check,
|
|
11
|
+
* so the badge says which one it was.
|
|
12
|
+
*/
|
|
13
|
+
const meta: Meta<typeof CalendarParseBadge> = {
|
|
14
|
+
title: "Calendar/Parse badge",
|
|
15
|
+
component: CalendarParseBadge,
|
|
16
|
+
parameters: { layout: "padded" },
|
|
17
|
+
};
|
|
18
|
+
export default meta;
|
|
19
|
+
|
|
20
|
+
type Story = StoryObj<typeof CalendarParseBadge>;
|
|
21
|
+
|
|
22
|
+
const methods: CalendarParseMethod[] = ["ics", "markup", "pattern"];
|
|
23
|
+
|
|
24
|
+
/** The whole ladder at once, each with the note that belongs to it. */
|
|
25
|
+
export const EveryRung: Story = {
|
|
26
|
+
render: () => (
|
|
27
|
+
<div className="flex max-w-md flex-col gap-3">
|
|
28
|
+
{methods.map((method) => (
|
|
29
|
+
<div key={method} className="flex flex-col gap-1">
|
|
30
|
+
<CalendarParseBadge method={method} className="self-start" />
|
|
31
|
+
<p className="text-xs text-fg-muted">{calendarParseNote[method]}</p>
|
|
32
|
+
</div>
|
|
33
|
+
))}
|
|
34
|
+
</div>
|
|
35
|
+
),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** An attached invitation: the sender's own fields, copied. */
|
|
39
|
+
export const AttachedInvitation: Story = {
|
|
40
|
+
args: { method: "ics" },
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/** A reading of the prose, which is the rung that can be wrong. */
|
|
44
|
+
export const ReadFromTheWords: Story = {
|
|
45
|
+
args: { method: "pattern" },
|
|
46
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Code2, FileText, TextSearch } from "lucide-react";
|
|
2
|
+
import { cn } from "../lib/cn.js";
|
|
3
|
+
import type { CalendarParseMethod } from "./calendar-types.js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Which rung of the ladder answered. Saying so is not trivia: it is the
|
|
7
|
+
* difference between a fact the sender stated and a guess the reader made, and
|
|
8
|
+
* the reader is the one who has to decide how hard to check.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const calendarParseLabel: Record<CalendarParseMethod, string> = {
|
|
12
|
+
ics: "Attached invitation",
|
|
13
|
+
markup: "Structured markup",
|
|
14
|
+
pattern: "Read from the words",
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const calendarParseNote: Record<CalendarParseMethod, string> = {
|
|
18
|
+
ics: "A text/calendar part came with the mail. These are the sender's own fields, copied.",
|
|
19
|
+
markup:
|
|
20
|
+
"The mail carried a machine-readable booking block. The fields below are copied out of it.",
|
|
21
|
+
pattern:
|
|
22
|
+
"Nothing machine-readable came with this. The fields below are a reading of the prose, and a reading can be wrong.",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const icons: Record<CalendarParseMethod, typeof FileText> = {
|
|
26
|
+
ics: FileText,
|
|
27
|
+
markup: Code2,
|
|
28
|
+
pattern: TextSearch,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const tones: Record<CalendarParseMethod, string> = {
|
|
32
|
+
ics: "border-positive/50 text-positive",
|
|
33
|
+
markup: "border-accent-2/50 text-accent-2",
|
|
34
|
+
pattern: "border-warning/50 text-warning",
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export interface CalendarParseBadgeProps {
|
|
38
|
+
method: CalendarParseMethod;
|
|
39
|
+
className?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function CalendarParseBadge({
|
|
43
|
+
method,
|
|
44
|
+
className,
|
|
45
|
+
}: CalendarParseBadgeProps) {
|
|
46
|
+
const Icon = icons[method];
|
|
47
|
+
return (
|
|
48
|
+
<span
|
|
49
|
+
className={cn(
|
|
50
|
+
"inline-flex items-center gap-1 rounded-sm border px-1.5 py-0.5 text-2xs font-medium",
|
|
51
|
+
tones[method],
|
|
52
|
+
className,
|
|
53
|
+
)}
|
|
54
|
+
>
|
|
55
|
+
<Icon className="size-3" aria-hidden />
|
|
56
|
+
{calendarParseLabel[method]}
|
|
57
|
+
</span>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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 {
|
|
6
|
+
CalendarSlotOffers,
|
|
7
|
+
type CalendarSlotOffersProps,
|
|
8
|
+
} from "./calendar-slot-offers.js";
|
|
9
|
+
import type { CalendarSlotPick } from "./calendar-types.js";
|
|
10
|
+
|
|
11
|
+
const THURSDAY = "2026-06-11";
|
|
12
|
+
|
|
13
|
+
function slot(startTime: string, endTime: string): CalendarSlotPick {
|
|
14
|
+
return { date: THURSDAY, startTime, endTime, allDay: false };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const thursday: CalendarSlotPick[] = [
|
|
18
|
+
slot("10:45", "11:15"),
|
|
19
|
+
slot("15:15", "15:45"),
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
const base: CalendarSlotOffersProps = {
|
|
23
|
+
slots: thursday,
|
|
24
|
+
picked: new Set<string>(),
|
|
25
|
+
onToggle: () => undefined,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const render = (props: Partial<CalendarSlotOffersProps>) =>
|
|
29
|
+
renderToString(createElement(CalendarSlotOffers, { ...base, ...props }));
|
|
30
|
+
|
|
31
|
+
describe("CalendarSlotOffers", () => {
|
|
32
|
+
it("writes each gap as the span it is", () => {
|
|
33
|
+
const html = render({});
|
|
34
|
+
assert.match(html, /10:45/);
|
|
35
|
+
assert.match(html, /11:15/);
|
|
36
|
+
assert.match(html, /15:15/);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("marks a picked slot as pressed rather than by colour alone", () => {
|
|
40
|
+
const html = render({ picked: new Set(["15:15"]) });
|
|
41
|
+
assert.match(html, /aria-pressed="true"/);
|
|
42
|
+
assert.match(html, /aria-pressed="false"/);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("says the day has nothing at this length rather than drawing an empty row", () => {
|
|
46
|
+
const html = render({ slots: [] });
|
|
47
|
+
assert.match(html, /Nothing free that day at this length/);
|
|
48
|
+
assert.doesNotMatch(html, /<button/);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("takes the caller's words for an empty day", () => {
|
|
52
|
+
assert.match(
|
|
53
|
+
render({ slots: [], emptyText: "Thursday is full." }),
|
|
54
|
+
/Thursday is full/,
|
|
55
|
+
);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("scrolls the chips in a row instead of wrapping them", () => {
|
|
59
|
+
assert.match(render({ scroll: true }), /overflow-x-auto/);
|
|
60
|
+
assert.match(render({}), /flex-wrap/);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("gives a thumb a target it can hit", () => {
|
|
64
|
+
assert.match(render({ touch: true }), /min-h-11/);
|
|
65
|
+
assert.doesNotMatch(render({}), /min-h-11/);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { CalendarSlotOffers } from "./calendar-slot-offers.js";
|
|
4
|
+
import type { CalendarSlotPick } from "./calendar-types.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The day's free gaps as things to hand back, not as a grid to read off.
|
|
8
|
+
* Picking one is not a booking: it goes into a reply as plain text.
|
|
9
|
+
*/
|
|
10
|
+
const meta: Meta<typeof CalendarSlotOffers> = {
|
|
11
|
+
title: "Calendar/Slot offers",
|
|
12
|
+
component: CalendarSlotOffers,
|
|
13
|
+
parameters: { layout: "padded" },
|
|
14
|
+
};
|
|
15
|
+
export default meta;
|
|
16
|
+
|
|
17
|
+
type Story = StoryObj<typeof CalendarSlotOffers>;
|
|
18
|
+
|
|
19
|
+
const THURSDAY = "2026-06-11";
|
|
20
|
+
|
|
21
|
+
function slot(startTime: string, endTime: string): CalendarSlotPick {
|
|
22
|
+
return { date: THURSDAY, startTime, endTime, allDay: false };
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const thursday: CalendarSlotPick[] = [
|
|
26
|
+
slot("10:45", "11:15"),
|
|
27
|
+
slot("11:30", "12:00"),
|
|
28
|
+
slot("12:00", "12:30"),
|
|
29
|
+
slot("15:15", "15:45"),
|
|
30
|
+
slot("16:00", "16:30"),
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
function Offering({ touch, scroll }: { touch?: boolean; scroll?: boolean }) {
|
|
34
|
+
const [picked, setPicked] = useState<string[]>(["11:30"]);
|
|
35
|
+
return (
|
|
36
|
+
<div className="max-w-sm">
|
|
37
|
+
<CalendarSlotOffers
|
|
38
|
+
slots={thursday}
|
|
39
|
+
picked={new Set(picked)}
|
|
40
|
+
onToggle={(slotPick) =>
|
|
41
|
+
setPicked((prev) =>
|
|
42
|
+
prev.includes(slotPick.startTime)
|
|
43
|
+
? prev.filter((start) => start !== slotPick.startTime)
|
|
44
|
+
: [...prev, slotPick.startTime],
|
|
45
|
+
)
|
|
46
|
+
}
|
|
47
|
+
touch={touch}
|
|
48
|
+
scroll={scroll}
|
|
49
|
+
/>
|
|
50
|
+
<p className="mt-2 text-2xs text-fg-subtle">
|
|
51
|
+
{picked.length} would go into the reply. Nothing is booked.
|
|
52
|
+
</p>
|
|
53
|
+
</div>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The wrapping block, which is what a mouse gets. */
|
|
58
|
+
export const Wrapping: Story = {
|
|
59
|
+
render: () => <Offering />,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** A scrolling rail instead, for a panel too narrow to wrap into. */
|
|
63
|
+
export const Scrolling: Story = {
|
|
64
|
+
render: () => <Offering scroll />,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** Thumb-sized targets, which is the only difference touch makes. */
|
|
68
|
+
export const Touch: Story = {
|
|
69
|
+
render: () => <Offering touch />,
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/** A day with no gap at this length says so rather than drawing an empty row. */
|
|
73
|
+
export const NothingFree: Story = {
|
|
74
|
+
args: {
|
|
75
|
+
slots: [],
|
|
76
|
+
picked: new Set<string>(),
|
|
77
|
+
onToggle: () => undefined,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { cn } from "../lib/cn.js";
|
|
2
|
+
import type { CalendarSlotPick } from "./calendar-types.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The free slots, as things you can hand to someone rather than read off a
|
|
6
|
+
* grid. Picking one is not a booking: it goes into a reply as plain text, and
|
|
7
|
+
* onto the calendar only as a hold that releases itself.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export interface CalendarSlotOffersProps {
|
|
11
|
+
slots: CalendarSlotPick[];
|
|
12
|
+
/** Start clocks already ticked. */
|
|
13
|
+
picked: ReadonlySet<string>;
|
|
14
|
+
onToggle: (slot: CalendarSlotPick) => void;
|
|
15
|
+
/** What to say when the day has nothing at this length. */
|
|
16
|
+
emptyText?: string;
|
|
17
|
+
touch?: boolean;
|
|
18
|
+
/** Lays the chips out in a scrolling row rather than a wrapping block. */
|
|
19
|
+
scroll?: boolean;
|
|
20
|
+
className?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function CalendarSlotOffers({
|
|
24
|
+
slots,
|
|
25
|
+
picked,
|
|
26
|
+
onToggle,
|
|
27
|
+
emptyText = "Nothing free that day at this length.",
|
|
28
|
+
touch,
|
|
29
|
+
scroll,
|
|
30
|
+
className,
|
|
31
|
+
}: CalendarSlotOffersProps) {
|
|
32
|
+
if (slots.length === 0)
|
|
33
|
+
return (
|
|
34
|
+
<p className={cn("text-xs text-fg-muted", className)}>{emptyText}</p>
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
className={cn(
|
|
40
|
+
"flex gap-2",
|
|
41
|
+
scroll ? "overflow-x-auto pb-1" : "flex-wrap",
|
|
42
|
+
className,
|
|
43
|
+
)}
|
|
44
|
+
>
|
|
45
|
+
{slots.map((slot) => {
|
|
46
|
+
const on = picked.has(slot.startTime);
|
|
47
|
+
return (
|
|
48
|
+
<button
|
|
49
|
+
key={slot.startTime}
|
|
50
|
+
type="button"
|
|
51
|
+
aria-pressed={on}
|
|
52
|
+
onClick={() => onToggle(slot)}
|
|
53
|
+
className={cn(
|
|
54
|
+
"shrink-0 rounded-md border px-2 text-xs tabular-nums outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring",
|
|
55
|
+
touch ? "min-h-11 px-3" : "h-7",
|
|
56
|
+
on
|
|
57
|
+
? "border-accent bg-accent-soft font-semibold text-accent"
|
|
58
|
+
: "border-line bg-surface text-fg-muted hover:border-line-strong hover:text-fg",
|
|
59
|
+
)}
|
|
60
|
+
>
|
|
61
|
+
{slot.startTime} – {slot.endTime}
|
|
62
|
+
</button>
|
|
63
|
+
);
|
|
64
|
+
})}
|
|
65
|
+
</div>
|
|
66
|
+
);
|
|
67
|
+
}
|