@remit/ui 0.0.210 → 0.0.212

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,107 +0,0 @@
1
- import type { Meta, StoryObj } from "@storybook/react-vite";
2
- import { useState } from "react";
3
- import {
4
- type CustomRecurrence,
5
- defaultCustomRecurrence,
6
- defaultEndDate,
7
- formatCustomRecurrence,
8
- } from "../lib/recurrence.js";
9
- import { CustomRecurrenceEditor } from "./custom-recurrence.js";
10
-
11
- const DATE = "2026-06-09";
12
- const START = "09:15";
13
-
14
- /**
15
- * The rule the derived choices cannot express. Every part of it is a control —
16
- * how often, which days, when it stops — and what comes out is the same
17
- * sentence the picker reads back. Nobody types an RRULE and nobody is shown
18
- * one; the line under each story is what the event would carry.
19
- */
20
- const meta: Meta<typeof CustomRecurrenceEditor> = {
21
- title: "Design System/Calendar/Custom recurrence",
22
- tags: ["proposed"],
23
- component: CustomRecurrenceEditor,
24
- parameters: { layout: "padded" },
25
- };
26
- export default meta;
27
-
28
- type Story = StoryObj<typeof CustomRecurrenceEditor>;
29
-
30
- function Editor({ seed, touch }: { seed: CustomRecurrence; touch?: boolean }) {
31
- const [rule, setRule] = useState(seed);
32
- return (
33
- <div className="flex max-w-sm flex-col gap-4 rounded-lg border border-line bg-surface p-5">
34
- <h3 className="text-lg font-semibold text-fg">Custom recurrence</h3>
35
- <CustomRecurrenceEditor
36
- value={rule}
37
- onChange={setRule}
38
- date={DATE}
39
- suggestedEndDate={defaultEndDate(DATE)}
40
- touch={touch}
41
- />
42
- <p className="border-t border-line pt-3 text-sm text-fg-muted">
43
- {formatCustomRecurrence(rule, DATE, START)}
44
- </p>
45
- </div>
46
- );
47
- }
48
-
49
- /** What it opens as: every week, on the day the event already sits on. */
50
- export const Weekly: Story = {
51
- render: () => <Editor seed={defaultCustomRecurrence(DATE)} />,
52
- };
53
-
54
- /**
55
- * Two days a week, fortnightly, until October. None of that is expressible as
56
- * a choice derived from a date, which is the whole reason this exists.
57
- */
58
- export const EveryOtherWeekUntilOctober: Story = {
59
- name: "Every other week, until October",
60
- render: () => (
61
- <Editor
62
- seed={{
63
- interval: 2,
64
- unit: "week",
65
- weekdays: [1, 4],
66
- monthlyMode: "dayOfMonth",
67
- ends: { kind: "onDate", date: "2026-10-03" },
68
- }}
69
- />
70
- ),
71
- };
72
-
73
- /**
74
- * A monthly rule means two different things about the same date — the ninth,
75
- * or the second Tuesday — and which one is meant is never derivable. So it is
76
- * asked rather than assumed.
77
- */
78
- export const MonthlyReadTwoWays: Story = {
79
- name: "Monthly, read two ways",
80
- render: () => (
81
- <Editor
82
- seed={{
83
- ...defaultCustomRecurrence(DATE),
84
- unit: "month",
85
- monthlyMode: "weekdayOfMonth",
86
- }}
87
- />
88
- ),
89
- };
90
-
91
- /** An ending counted rather than dated: thirteen times and then it stops. */
92
- export const EndsAfterCount: Story = {
93
- name: "Ends after a count",
94
- render: () => (
95
- <Editor
96
- seed={{
97
- ...defaultCustomRecurrence(DATE),
98
- ends: { kind: "afterCount", count: 13 },
99
- }}
100
- />
101
- ),
102
- };
103
-
104
- /** The same controls at thumb size, as the phone step renders them. */
105
- export const Touch: Story = {
106
- render: () => <Editor seed={defaultCustomRecurrence(DATE)} touch />,
107
- };
@@ -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
- };