@remit/ui 0.0.211 → 0.0.213

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.
@@ -1,411 +0,0 @@
1
- /**
2
- * The rule the offered choices do not cover.
3
- *
4
- * Every second Tuesday, Mondays and Thursdays until October, thirteen times and
5
- * then stop — a picker of derived choices cannot express any of those, and the
6
- * alternative is asking someone to type an RRULE. So the parts of a rule are
7
- * controls: how often, which days, and when it stops. What comes out is still a
8
- * sentence.
9
- */
10
-
11
- import { ChevronDown, ChevronUp } from "lucide-react";
12
- import { useId } from "react";
13
- import { cn } from "../lib/cn.js";
14
- import {
15
- type CustomRecurrence,
16
- dayOfMonthLabel,
17
- ordinalWeekdayLabel,
18
- type RecurrenceEnd,
19
- type RecurrenceUnit,
20
- WEEKDAY_INITIALS,
21
- weekdayName,
22
- } from "../lib/recurrence.js";
23
- import { Button } from "./button.js";
24
- import { Dialog } from "./dialog.js";
25
- import { Input } from "./input.js";
26
- import { Select } from "./select.js";
27
-
28
- const UNITS: RecurrenceUnit[] = ["day", "week", "month", "year"];
29
- const MAX_INTERVAL = 99;
30
- const MAX_COUNT = 999;
31
-
32
- /** What the counted ending shows before anyone counts: a field, not a gap. */
33
- const SUGGESTED_COUNT = 13;
34
-
35
- export interface CustomRecurrenceEditorProps {
36
- value: CustomRecurrence;
37
- onChange: (next: CustomRecurrence) => void;
38
- /** The event's own day — what the monthly readings are derived from. */
39
- date: string;
40
- /** The date the "on" ending offers before anyone picks one. */
41
- suggestedEndDate: string;
42
- touch?: boolean;
43
- className?: string;
44
- }
45
-
46
- /** The heading names the group it sits over, so the group points back at it. */
47
- function Section({
48
- label,
49
- children,
50
- }: {
51
- label: string;
52
- children: (labelId: string) => React.ReactNode;
53
- }) {
54
- const labelId = useId();
55
- return (
56
- <div className="flex flex-col gap-2">
57
- <span
58
- id={labelId}
59
- className="text-2xs font-semibold uppercase tracking-wider text-fg-subtle"
60
- >
61
- {label}
62
- </span>
63
- {children(labelId)}
64
- </div>
65
- );
66
- }
67
-
68
- function Stepper({
69
- value,
70
- min,
71
- max,
72
- onChange,
73
- label,
74
- touch,
75
- }: {
76
- value: number;
77
- min: number;
78
- max: number;
79
- onChange: (next: number) => void;
80
- label: string;
81
- touch?: boolean;
82
- }) {
83
- const clamp = (next: number) => Math.min(Math.max(next, min), max);
84
- return (
85
- <div className="flex items-stretch gap-1">
86
- <Input
87
- type="number"
88
- inputMode="numeric"
89
- min={min}
90
- max={max}
91
- value={String(value)}
92
- aria-label={label}
93
- onChange={(e) => onChange(clamp(Number(e.target.value) || min))}
94
- className={cn("own-steppers w-20 tabular-nums", touch && "min-h-11")}
95
- />
96
- <div className="flex flex-col justify-between">
97
- <button
98
- type="button"
99
- aria-label={`${label} up`}
100
- onClick={() => onChange(clamp(value + 1))}
101
- className="flex h-4 w-6 items-center justify-center rounded-xs text-fg-subtle outline-none hover:text-fg focus-visible:ring-2 focus-visible:ring-ring"
102
- >
103
- <ChevronUp className="size-3.5" />
104
- </button>
105
- <button
106
- type="button"
107
- aria-label={`${label} down`}
108
- onClick={() => onChange(clamp(value - 1))}
109
- className="flex h-4 w-6 items-center justify-center rounded-xs text-fg-subtle outline-none hover:text-fg focus-visible:ring-2 focus-visible:ring-ring"
110
- >
111
- <ChevronDown className="size-3.5" />
112
- </button>
113
- </div>
114
- </div>
115
- );
116
- }
117
-
118
- export function CustomRecurrenceEditor({
119
- value,
120
- onChange,
121
- date,
122
- suggestedEndDate,
123
- touch,
124
- className,
125
- }: CustomRecurrenceEditorProps) {
126
- const endsName = useId();
127
- const monthlyName = useId();
128
- const set = (patch: Partial<CustomRecurrence>) =>
129
- onChange({ ...value, ...patch });
130
- const setEnds = (ends: RecurrenceEnd) => set({ ends });
131
-
132
- const endDate =
133
- value.ends.kind === "onDate" ? value.ends.date : suggestedEndDate;
134
- const endCount =
135
- value.ends.kind === "afterCount" ? value.ends.count : SUGGESTED_COUNT;
136
-
137
- return (
138
- <div className={cn("flex flex-col gap-5", className)}>
139
- <div className="flex flex-wrap items-center gap-2">
140
- <span className="text-sm text-fg">Repeat every</span>
141
- <Stepper
142
- value={value.interval}
143
- min={1}
144
- max={MAX_INTERVAL}
145
- onChange={(interval) => set({ interval })}
146
- label="Repeat every"
147
- touch={touch}
148
- />
149
- <Select
150
- aria-label="Unit"
151
- value={value.unit}
152
- onChange={(e) => set({ unit: e.target.value as RecurrenceUnit })}
153
- className={cn("w-32", touch && "min-h-11")}
154
- >
155
- {UNITS.map((unit) => (
156
- <option key={unit} value={unit}>
157
- {value.interval > 1 ? `${unit}s` : unit}
158
- </option>
159
- ))}
160
- </Select>
161
- </div>
162
-
163
- {value.unit === "week" && (
164
- <Section label="Repeat on">
165
- {(labelId) => (
166
- <fieldset
167
- aria-labelledby={labelId}
168
- className="flex min-w-0 gap-1.5"
169
- >
170
- {WEEKDAY_INITIALS.map((initial, index) => {
171
- const on = value.weekdays.includes(index);
172
- return (
173
- <label
174
- key={weekdayName(index)}
175
- className={cn(
176
- "inline-flex flex-1 cursor-pointer items-center justify-center rounded-full text-xs font-medium transition-colors",
177
- "has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring",
178
- touch ? "h-11 max-w-11" : "h-9 max-w-9",
179
- on
180
- ? "bg-accent text-accent-fg"
181
- : "bg-surface-sunken text-fg-muted hover:bg-surface-raised hover:text-fg",
182
- )}
183
- >
184
- <input
185
- type="checkbox"
186
- checked={on}
187
- aria-label={weekdayName(index)}
188
- onChange={() =>
189
- set({
190
- weekdays: on
191
- ? value.weekdays.filter((day) => day !== index)
192
- : [...value.weekdays, index],
193
- })
194
- }
195
- className="sr-only"
196
- />
197
- {initial}
198
- </label>
199
- );
200
- })}
201
- </fieldset>
202
- )}
203
- </Section>
204
- )}
205
-
206
- {value.unit === "month" && (
207
- <Section label="Repeat on">
208
- {(labelId) => (
209
- <div
210
- role="radiogroup"
211
- aria-labelledby={labelId}
212
- className="flex flex-col gap-1.5"
213
- >
214
- {(
215
- [
216
- ["dayOfMonth", dayOfMonthLabel(date)],
217
- ["weekdayOfMonth", ordinalWeekdayLabel(date)],
218
- ] as const
219
- ).map(([mode, label]) => (
220
- <label
221
- key={mode}
222
- htmlFor={`${monthlyName}-${mode}`}
223
- className={cn(
224
- "flex cursor-pointer items-center gap-2.5 rounded-md px-1 text-sm text-fg",
225
- "has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring",
226
- touch ? "min-h-11" : "min-h-9",
227
- )}
228
- >
229
- <Radio
230
- id={`${monthlyName}-${mode}`}
231
- name={monthlyName}
232
- checked={value.monthlyMode === mode}
233
- onChange={() => set({ monthlyMode: mode })}
234
- />
235
- on {label}
236
- </label>
237
- ))}
238
- </div>
239
- )}
240
- </Section>
241
- )}
242
-
243
- <Section label="Ends">
244
- {(labelId) => (
245
- <div
246
- role="radiogroup"
247
- aria-labelledby={labelId}
248
- className="flex flex-col gap-1.5"
249
- >
250
- <label
251
- htmlFor={`${endsName}-never`}
252
- className={cn(
253
- "flex cursor-pointer items-center gap-2.5 rounded-md px-1 text-sm text-fg",
254
- "has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring",
255
- touch ? "min-h-11" : "min-h-9",
256
- )}
257
- >
258
- <Radio
259
- id={`${endsName}-never`}
260
- name={endsName}
261
- checked={value.ends.kind === "never"}
262
- onChange={() => setEnds({ kind: "never" })}
263
- />
264
- Never
265
- </label>
266
-
267
- <div
268
- className={cn(
269
- "flex items-center gap-2.5 px-1",
270
- touch ? "min-h-11" : "min-h-9",
271
- )}
272
- >
273
- <label
274
- htmlFor={`${endsName}-on`}
275
- className="flex cursor-pointer items-center gap-2.5 text-sm text-fg"
276
- >
277
- <Radio
278
- id={`${endsName}-on`}
279
- name={endsName}
280
- checked={value.ends.kind === "onDate"}
281
- onChange={() => setEnds({ kind: "onDate", date: endDate })}
282
- />
283
- On
284
- </label>
285
- <Input
286
- type="date"
287
- value={endDate}
288
- aria-label="Ends on"
289
- onChange={(e) =>
290
- setEnds({ kind: "onDate", date: e.target.value })
291
- }
292
- onFocus={() => setEnds({ kind: "onDate", date: endDate })}
293
- className={cn(
294
- "w-40",
295
- touch && "min-h-11",
296
- value.ends.kind !== "onDate" && "opacity-55",
297
- )}
298
- />
299
- </div>
300
-
301
- <div
302
- className={cn(
303
- "flex flex-wrap items-center gap-2.5 px-1",
304
- touch ? "min-h-11" : "min-h-9",
305
- )}
306
- >
307
- <label
308
- htmlFor={`${endsName}-after`}
309
- className="flex cursor-pointer items-center gap-2.5 text-sm text-fg"
310
- >
311
- <Radio
312
- id={`${endsName}-after`}
313
- name={endsName}
314
- checked={value.ends.kind === "afterCount"}
315
- onChange={() =>
316
- setEnds({ kind: "afterCount", count: endCount })
317
- }
318
- />
319
- After
320
- </label>
321
- <div
322
- className={cn(value.ends.kind !== "afterCount" && "opacity-55")}
323
- >
324
- <Stepper
325
- value={endCount}
326
- min={1}
327
- max={MAX_COUNT}
328
- onChange={(count) => setEnds({ kind: "afterCount", count })}
329
- label="Occurrences"
330
- touch={touch}
331
- />
332
- </div>
333
- <span className="text-sm text-fg-muted">occurrences</span>
334
- </div>
335
- </div>
336
- )}
337
- </Section>
338
- </div>
339
- );
340
- }
341
-
342
- export interface CustomRecurrenceDialogProps
343
- extends CustomRecurrenceEditorProps {
344
- open: boolean;
345
- onCancel: () => void;
346
- onDone: () => void;
347
- }
348
-
349
- /**
350
- * On a screen with a pane there is one editing surface and nothing floats over
351
- * it — except this. A custom rule is a decision nested inside the form rather
352
- * than a second form, so it is a small card over the pane that stays readable
353
- * behind it, and it leaves as soon as it is answered.
354
- */
355
- export function CustomRecurrenceDialog({
356
- open,
357
- onCancel,
358
- onDone,
359
- ...editor
360
- }: CustomRecurrenceDialogProps) {
361
- return (
362
- <Dialog
363
- open={open}
364
- onClose={onCancel}
365
- title="Custom recurrence"
366
- className="max-w-sm"
367
- >
368
- <div className="flex flex-col gap-5 p-5">
369
- <h3 className="text-lg font-semibold text-fg">Custom recurrence</h3>
370
- <CustomRecurrenceEditor {...editor} />
371
- <div className="flex items-center justify-end gap-2">
372
- <Button variant="ghost" onClick={onCancel}>
373
- Cancel
374
- </Button>
375
- <Button variant="primary" onClick={onDone}>
376
- Done
377
- </Button>
378
- </div>
379
- </div>
380
- </Dialog>
381
- );
382
- }
383
-
384
- function Radio({
385
- id,
386
- name,
387
- checked,
388
- onChange,
389
- }: {
390
- id: string;
391
- name: string;
392
- checked: boolean;
393
- onChange: () => void;
394
- }) {
395
- return (
396
- <span className="relative inline-flex">
397
- <input
398
- id={id}
399
- type="radio"
400
- name={name}
401
- checked={checked}
402
- onChange={onChange}
403
- className={cn(
404
- "peer size-5 shrink-0 cursor-pointer appearance-none rounded-full border border-line-strong bg-surface outline-none transition-colors",
405
- "checked:border-accent focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-surface",
406
- )}
407
- />
408
- <span className="pointer-events-none absolute inset-0 m-auto hidden size-2.5 rounded-full bg-accent peer-checked:block" />
409
- </span>
410
- );
411
- }
@@ -1,40 +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 { parseEventPhrase } from "../lib/event-phrase.js";
6
- import { EventQuickEntry } from "./event-quick-entry.js";
7
-
8
- const NOW = new Date(2026, 5, 10, 9, 30);
9
-
10
- const render = (phrase: string) =>
11
- renderToString(
12
- createElement(EventQuickEntry, {
13
- value: phrase,
14
- onChange: () => undefined,
15
- parse: parseEventPhrase(phrase, NOW),
16
- onCommit: () => undefined,
17
- }),
18
- );
19
-
20
- describe("EventQuickEntry", () => {
21
- it("attributes each reading to the words it came from", () => {
22
- const html = render("lunch with Jane friday 1pm");
23
- assert.match(html, /lunch/);
24
- assert.match(html, /friday 1pm/);
25
- assert.match(html, /Jane/);
26
- });
27
-
28
- it("says what it assumed", () => {
29
- assert.match(render("standup tomorrow 9:30"), /No length given/);
30
- });
31
-
32
- it("says what it could not settle", () => {
33
- assert.match(render("design review monday"), /No time given/);
34
- });
35
-
36
- it("shows no reading before anything is typed", () => {
37
- const html = render("");
38
- assert.doesNotMatch(html, /WHEN|When<\/span>/);
39
- });
40
- });
@@ -1,57 +0,0 @@
1
- import type { Meta, StoryObj } from "@storybook/react-vite";
2
- import { useState } from "react";
3
- import { parseEventPhrase } from "../lib/event-phrase.js";
4
- import { EventQuickEntry } from "./event-quick-entry.js";
5
-
6
- /**
7
- * Typing a sentence is the fastest way to make an event, and the machine's
8
- * reading of that sentence is on screen while you type — each field next to the
9
- * words it came from, with anything assumed or missing said out loud. The
10
- * correction happens before the event exists.
11
- */
12
- const meta: Meta<typeof EventQuickEntry> = {
13
- title: "Design System/Calendar/Quick entry",
14
- tags: ["proposed"],
15
- component: EventQuickEntry,
16
- parameters: { layout: "padded" },
17
- };
18
- export default meta;
19
-
20
- type Story = StoryObj<typeof EventQuickEntry>;
21
-
22
- /** Wednesday 10 June 2026 — the same fixed "now" as the mail fixtures. */
23
- const NOW = new Date(2026, 5, 10, 9, 30);
24
-
25
- function Live({ initial }: { initial: string }) {
26
- const [phrase, setPhrase] = useState(initial);
27
- return (
28
- <div className="max-w-md">
29
- <EventQuickEntry
30
- value={phrase}
31
- onChange={setPhrase}
32
- parse={parseEventPhrase(phrase, NOW)}
33
- onCommit={() => {}}
34
- />
35
- </div>
36
- );
37
- }
38
-
39
- /** Type into it. Every keystroke moves the reading below the field. */
40
- export const Typing: Story = {
41
- render: () => <Live initial="lunch with Jane friday 1pm" />,
42
- };
43
-
44
- /** A length in the phrase is read; without one the reader says it picked an hour. */
45
- export const WithLength: Story = {
46
- render: () => <Live initial="dentist next tuesday 15:00 for 45m" />,
47
- };
48
-
49
- /** No time in the sentence, so no time in the event — and it says so. */
50
- export const MissingTime: Story = {
51
- render: () => <Live initial="design review monday" />,
52
- };
53
-
54
- /** Nothing typed yet: the reading stays out of the way until there is one. */
55
- export const Empty: Story = {
56
- render: () => <Live initial="" />,
57
- };
@@ -1,159 +0,0 @@
1
- import { AlertTriangle, Info, Wand2 } from "lucide-react";
2
- import { cn } from "../lib/cn.js";
3
- import type { PhraseParse } from "../lib/event-phrase.js";
4
-
5
- export interface EventQuickEntryProps {
6
- value: string;
7
- onChange: (value: string) => void;
8
- /** The reading of `value`, recomputed by the caller on every keystroke. */
9
- parse: PhraseParse;
10
- /** Commits the reading to the form. */
11
- onCommit: () => void;
12
- placeholder?: string;
13
- touch?: boolean;
14
- className?: string;
15
- }
16
-
17
- interface ReadingProps {
18
- label: string;
19
- value: string;
20
- source: string;
21
- }
22
-
23
- function Reading({ label, value, source }: ReadingProps) {
24
- return (
25
- <div className="flex min-w-0 items-baseline gap-1.5">
26
- <span className="shrink-0 text-2xs uppercase tracking-wider text-fg-subtle">
27
- {label}
28
- </span>
29
- <span className="truncate text-xs font-medium text-fg">{value}</span>
30
- {source !== "" && (
31
- <span className="shrink-0 rounded-xs bg-accent-2-soft px-1 text-2xs text-accent-2">
32
- {source}
33
- </span>
34
- )}
35
- </div>
36
- );
37
- }
38
-
39
- /**
40
- * Typing is the fastest way to make an event, so the field takes a sentence.
41
- * What it does with the sentence is on screen while you type: every reading is
42
- * shown next to the words it was taken from, and anything the reader filled in
43
- * or could not settle is said out loud. Correcting the machine happens before
44
- * the event exists, not after it is on the grid.
45
- */
46
- export function EventQuickEntry({
47
- value,
48
- onChange,
49
- parse,
50
- onCommit,
51
- placeholder = "lunch with Jane friday 1pm",
52
- touch,
53
- className,
54
- }: EventQuickEntryProps) {
55
- const hasReading = value.trim() !== "";
56
- const endTime =
57
- parse.startTime === ""
58
- ? ""
59
- : ` – ${clockAfter(parse.startTime, parse.durationMinutes)}`;
60
-
61
- return (
62
- <div className={cn("flex flex-col gap-2", className)}>
63
- <div
64
- className={cn(
65
- "flex items-center gap-2 rounded-md border border-line bg-surface-sunken px-3 focus-within:border-line-strong focus-within:ring-2 focus-within:ring-ring/30",
66
- touch ? "min-h-11" : "h-9",
67
- )}
68
- >
69
- <Wand2 className="size-4 shrink-0 text-fg-subtle" aria-hidden />
70
- <input
71
- value={value}
72
- aria-label="Describe the event"
73
- placeholder={placeholder}
74
- onChange={(e) => onChange(e.target.value)}
75
- onKeyDown={(e) => {
76
- if (e.key === "Enter") onCommit();
77
- }}
78
- className="min-w-0 flex-1 bg-transparent text-sm text-fg outline-none placeholder:text-fg-subtle"
79
- />
80
- </div>
81
-
82
- {hasReading && (
83
- <div className="flex flex-col gap-1 rounded-md border border-line bg-surface px-2.5 py-2">
84
- <Reading
85
- label="What"
86
- value={parse.title === "" ? "—" : parse.title}
87
- source=""
88
- />
89
- <Reading
90
- label="When"
91
- value={`${formatDay(parse.date)}${
92
- parse.startTime === "" ? "" : ` ${parse.startTime}${endTime}`
93
- }`}
94
- source={[parse.dateText, parse.startTimeText]
95
- .filter((part) => part !== "")
96
- .join(" ")}
97
- />
98
- {parse.durationText !== "" && (
99
- <Reading
100
- label="Long"
101
- value={formatDuration(parse.durationMinutes)}
102
- source={parse.durationText}
103
- />
104
- )}
105
- {parse.attendees.length > 0 && (
106
- <Reading
107
- label="Who"
108
- value={parse.attendees.join(", ")}
109
- source={parse.attendeesText}
110
- />
111
- )}
112
- {parse.assumptions.map((note) => (
113
- <p
114
- key={note}
115
- className="flex items-center gap-1.5 text-2xs text-fg-subtle"
116
- >
117
- <Info className="size-3 shrink-0" aria-hidden />
118
- {note}
119
- </p>
120
- ))}
121
- {parse.unresolved.map((note) => (
122
- <p
123
- key={note}
124
- className="flex items-center gap-1.5 text-2xs text-warning"
125
- >
126
- <AlertTriangle className="size-3 shrink-0" aria-hidden />
127
- {note}
128
- </p>
129
- ))}
130
- </div>
131
- )}
132
- </div>
133
- );
134
- }
135
-
136
- function clockAfter(clock: string, minutes: number): string {
137
- const [hours, mins] = clock.split(":").map(Number);
138
- const total = (hours * 60 + mins + minutes) % 1440;
139
- return `${String(Math.floor(total / 60)).padStart(2, "0")}:${String(
140
- total % 60,
141
- ).padStart(2, "0")}`;
142
- }
143
-
144
- function formatDay(iso: string): string {
145
- if (iso === "") return "—";
146
- const [year, month, day] = iso.split("-").map(Number);
147
- return new Date(year, month - 1, day).toLocaleDateString("en-GB", {
148
- weekday: "short",
149
- day: "numeric",
150
- month: "short",
151
- });
152
- }
153
-
154
- function formatDuration(minutes: number): string {
155
- if (minutes === 0) return "—";
156
- if (minutes % 60 === 0) return `${minutes / 60}h`;
157
- if (minutes < 60) return `${minutes}m`;
158
- return `${Math.floor(minutes / 60)}h ${minutes % 60}m`;
159
- }