@dinachi/cli 1.1.0 → 1.3.0

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 (45) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/dist/index.js +244 -72
  3. package/package.json +5 -1
  4. package/templates/agent/agent.tsx +35 -18
  5. package/templates/alert/alert.tsx +345 -0
  6. package/templates/alert/index.ts +16 -0
  7. package/templates/ask-bar/ask-bar.tsx +1061 -0
  8. package/templates/ask-bar/index.ts +1 -0
  9. package/templates/autocomplete/autocomplete.tsx +0 -1
  10. package/templates/breadcrumb/breadcrumb.tsx +606 -0
  11. package/templates/breadcrumb/index.ts +9 -0
  12. package/templates/calendar/calendar.tsx +1155 -0
  13. package/templates/calendar/index.ts +15 -0
  14. package/templates/combobox/combobox.tsx +0 -1
  15. package/templates/command-items/command-items.tsx +69 -0
  16. package/templates/command-items/index.ts +1 -0
  17. package/templates/command-palette/command-palette.tsx +954 -0
  18. package/templates/command-palette/index.ts +1 -0
  19. package/templates/comparison-table/comparison-table.tsx +540 -0
  20. package/templates/comparison-table/index.ts +15 -0
  21. package/templates/data-table/data-table.tsx +2077 -0
  22. package/templates/data-table/index.ts +14 -0
  23. package/templates/date-picker/date-picker.tsx +527 -0
  24. package/templates/date-picker/index.ts +2 -0
  25. package/templates/date-range-picker/date-range-picker.tsx +504 -0
  26. package/templates/date-range-picker/index.ts +2 -0
  27. package/templates/detail-list/detail-list.tsx +419 -0
  28. package/templates/detail-list/index.ts +12 -0
  29. package/templates/heat-table/heat-table.tsx +613 -0
  30. package/templates/heat-table/index.ts +9 -0
  31. package/templates/menu/menu.tsx +8 -3
  32. package/templates/month-picker/index.ts +1 -0
  33. package/templates/month-picker/month-picker.tsx +351 -0
  34. package/templates/omnibar/index.ts +1 -0
  35. package/templates/omnibar/omnibar.tsx +1009 -0
  36. package/templates/pagination/index.ts +8 -0
  37. package/templates/pagination/pagination.tsx +389 -0
  38. package/templates/table/index.ts +13 -0
  39. package/templates/table/table.tsx +265 -0
  40. package/templates/time-slots/index.ts +1 -0
  41. package/templates/time-slots/time-slots.tsx +589 -0
  42. package/templates/week-strip/index.ts +1 -0
  43. package/templates/week-strip/week-strip.tsx +329 -0
  44. package/templates/year-view/index.ts +1 -0
  45. package/templates/year-view/year-view.tsx +362 -0
@@ -0,0 +1,504 @@
1
+ "use client"
2
+
3
+ import * as React from "react";
4
+ import { format, type Locale } from "date-fns";
5
+ import { CalendarDays, ChevronDown } from "lucide-react";
6
+ import { cn } from "@/lib/utils";
7
+ import { type Agent, AgentProvider, changeAsAgent, useAgentControl, useAgentState, useMergedRef } from "@/components/ui/agent";
8
+ import { Button } from "@/components/ui/button";
9
+ import {
10
+ Calendar,
11
+ type CalendarChangeDetails,
12
+ type CalendarProps,
13
+ type DateRange,
14
+ addDays,
15
+ dayFirst,
16
+ daysBetween,
17
+ fromISODate,
18
+ isSameDay,
19
+ parseDate,
20
+ startOfDay,
21
+ toISODate,
22
+ } from "@/components/ui/calendar";
23
+ import { Drawer, DrawerContent, DrawerTitle, DrawerTrigger } from "@/components/ui/drawer";
24
+ import { Popover, PopoverPopup, PopoverPortal, PopoverPositioner, PopoverTrigger } from "@/components/ui/popover";
25
+
26
+ /** The picker is one control to an agent, so the parts inside it don't register their own. */
27
+ const Unlisted = ({ children }: { children: React.ReactNode }) => (
28
+ <AgentProvider agent={null as unknown as Agent}>{children}</AgentProvider>
29
+ );
30
+
31
+ const WIDE = "(min-width: 768px)";
32
+ const EMPTY: DateRange = { from: null, to: null };
33
+
34
+ function usePresentation(presentation: "auto" | "popover" | "drawer"): "popover" | "drawer" {
35
+ const wide = React.useSyncExternalStore(
36
+ (onChange) => {
37
+ const query = window.matchMedia?.(WIDE);
38
+ query?.addEventListener("change", onChange);
39
+ return () => query?.removeEventListener("change", onChange);
40
+ },
41
+ () => window.matchMedia?.(WIDE).matches ?? true,
42
+ () => true
43
+ );
44
+ return presentation === "auto" ? (wide ? "popover" : "drawer") : presentation;
45
+ }
46
+
47
+ function changeDetails(reason: string, event?: Event): CalendarChangeDetails {
48
+ const details: CalendarChangeDetails = {
49
+ reason,
50
+ event,
51
+ isCanceled: false,
52
+ cancel() {
53
+ details.isCanceled = true;
54
+ },
55
+ };
56
+ return details;
57
+ }
58
+
59
+ const sameRange = (a: DateRange, b: DateRange) => isSameDay(a.from, b.from) && isSameDay(a.to, b.to);
60
+
61
+ export interface DateRangePreset {
62
+ label: string;
63
+ value: DateRange;
64
+ }
65
+
66
+ /** Today, yesterday, the last 7 and 30 days, this month so far and last month. */
67
+ export function pastPresets(today: Date): DateRangePreset[] {
68
+ const t = startOfDay(today);
69
+ const y = t.getFullYear();
70
+ const m = t.getMonth();
71
+ return [
72
+ { label: "Today", value: { from: t, to: t } },
73
+ { label: "Yesterday", value: { from: addDays(t, -1), to: addDays(t, -1) } },
74
+ { label: "Last 7 days", value: { from: addDays(t, -6), to: t } },
75
+ { label: "Last 30 days", value: { from: addDays(t, -29), to: t } },
76
+ { label: "This month", value: { from: new Date(y, m, 1), to: t } },
77
+ { label: "Last month", value: { from: new Date(y, m - 1, 1), to: new Date(y, m, 0) } },
78
+ ];
79
+ }
80
+
81
+ export interface DateRangePickerProps
82
+ extends Omit<React.ComponentProps<"button">, "value" | "defaultValue" | "onChange" | "dir" | "children" | "type"> {
83
+ value?: DateRange;
84
+ defaultValue?: DateRange;
85
+ /** Called on Apply, not while a range is being picked. */
86
+ onValueChange?: (value: DateRange, details: CalendarChangeDetails) => void;
87
+ min?: Date;
88
+ max?: Date;
89
+ isDateDisabled?: (date: Date) => boolean;
90
+ weekNumbers?: boolean;
91
+ locale?: Locale;
92
+ weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
93
+ dir?: "ltr" | "rtl";
94
+ /** Defaults to the current day. */
95
+ today?: Date;
96
+ /** Ranges one press away. Defaults to `pastPresets(today)`; pass `[]` for none. */
97
+ presets?: DateRangePreset[];
98
+ /** How a range reads on the trigger and in the footer. Defaults to `11 to 17 Nov 2026`. */
99
+ formatRange?: (range: { from: Date; to: Date }) => string;
100
+ /** How long a range reads in the footer. Defaults to its days, counting both ends: `3 days`. */
101
+ formatLength?: (range: { from: Date; to: Date }) => string;
102
+ /** Lets a range end on the first disabled day after its start, as a stay checks out on a booked night. */
103
+ allowDisabledEnd?: boolean;
104
+ /** Called as the range being picked changes, before Apply. `range-blocked` means it restarted past a disabled day. */
105
+ onDraftChange?: (draft: DateRange, details: CalendarChangeDetails) => void;
106
+ open?: boolean;
107
+ defaultOpen?: boolean;
108
+ onOpenChange?: (open: boolean) => void;
109
+ /** `auto` uses a popover from 768px up and a drawer below. */
110
+ presentation?: "auto" | "popover" | "drawer";
111
+ /** Names the popover and titles the drawer. */
112
+ label?: string;
113
+ placeholder?: string;
114
+ /** Submits the range as YYYY-MM-DD/YYYY-MM-DD. */
115
+ name?: string;
116
+ required?: boolean;
117
+ /** Passed to the calendar. */
118
+ layout?: CalendarProps["layout"];
119
+ numberOfMonths?: number;
120
+ captionLayout?: CalendarProps["captionLayout"];
121
+ renderDay?: CalendarProps["renderDay"];
122
+ dayClassName?: CalendarProps["dayClassName"];
123
+ describeDay?: CalendarProps["describeDay"];
124
+ }
125
+
126
+ /**
127
+ * A button that names the range it holds, opening presets beside a calendar. Nothing
128
+ * changes until Apply; Cancel, Esc and a click outside leave the range as it was.
129
+ */
130
+ const DateRangePicker = React.forwardRef<HTMLButtonElement, DateRangePickerProps>((props, ref) => {
131
+ const {
132
+ value: valueProp,
133
+ defaultValue,
134
+ onValueChange,
135
+ min,
136
+ max,
137
+ isDateDisabled,
138
+ weekNumbers,
139
+ locale,
140
+ weekStartsOn = locale?.options?.weekStartsOn ?? 1,
141
+ dir,
142
+ today: todayProp,
143
+ presets: presetsProp,
144
+ formatRange,
145
+ formatLength,
146
+ allowDisabledEnd = false,
147
+ onDraftChange,
148
+ open: openProp,
149
+ defaultOpen = false,
150
+ onOpenChange,
151
+ layout,
152
+ numberOfMonths,
153
+ captionLayout,
154
+ renderDay,
155
+ dayClassName,
156
+ describeDay,
157
+ presentation: presentationProp = "auto",
158
+ label = "Date range",
159
+ placeholder = "Pick dates",
160
+ name,
161
+ required,
162
+ disabled,
163
+ className,
164
+ "aria-label": name_,
165
+ ...buttonProps
166
+ } = props;
167
+
168
+ const today = React.useMemo(() => startOfDay(todayProp ?? new Date()), [todayProp ? toISODate(todayProp) : null]);
169
+ const presentation = usePresentation(presentationProp);
170
+ const [value, change] = useAgentState<DateRange, CalendarChangeDetails>(valueProp, defaultValue ?? EMPTY, onValueChange);
171
+ const [openState, setOpenState] = React.useState(defaultOpen);
172
+ const open = openProp ?? openState;
173
+ const setOpen = (next: boolean) => {
174
+ if (openProp === undefined) setOpenState(next);
175
+ if (next !== open) onOpenChange?.(next);
176
+ };
177
+ // Why the last press restarted the range, until the next one.
178
+ const [notice, setNotice] = React.useState<string | null>(null);
179
+ const [draft, setDraft] = React.useState<DateRange>(value);
180
+ const [custom, setCustom] = React.useState(false);
181
+ const trigger = React.useRef<HTMLButtonElement>(null);
182
+ // A range picked by hand keeps its dates as its name, even when a preset covers the same days.
183
+ const [handPicked, setHandPicked] = React.useState<string | null>(null);
184
+
185
+ const fmtDay = (d: Date) => format(d, "d MMM", { locale });
186
+ const fmtLength =
187
+ formatLength ??
188
+ (({ from, to }: { from: Date; to: Date }) => {
189
+ const n = daysBetween(from, to) + 1;
190
+ return `${n} ${n === 1 ? "day" : "days"}`;
191
+ });
192
+ const fmt =
193
+ formatRange ??
194
+ (({ from, to }: { from: Date; to: Date }) => {
195
+ const end = format(to, "d MMM yyyy", { locale });
196
+ if (isSameDay(from, to)) return format(to, "EEE, d MMM yyyy", { locale });
197
+ if (from.getFullYear() !== to.getFullYear()) return `${format(from, "d MMM yyyy", { locale })} to ${end}`;
198
+ return `${format(from, from.getMonth() === to.getMonth() ? "d" : "d MMM", { locale })} to ${end}`;
199
+ });
200
+
201
+ /** Why `d` can't be in a range. */
202
+ const refusal = (d: Date): string | null => {
203
+ if (min && d < startOfDay(min)) return `The earliest is ${toISODate(startOfDay(min))}.`;
204
+ if (max && d > startOfDay(max)) return `The latest is ${toISODate(startOfDay(max))}.`;
205
+ if (isDateDisabled?.(d)) return `${toISODate(d)} can't be picked.`;
206
+ return null;
207
+ };
208
+ /** The first day inside a range that can't be picked. */
209
+ const crossing = (r: DateRange): Date | null => {
210
+ for (let d = addDays(r.from!, 1); d < r.to!; d = addDays(d, 1)) if (isDateDisabled?.(d)) return d;
211
+ return null;
212
+ };
213
+ const rangeRefusal = (r: DateRange): string | null => {
214
+ const endOK = allowDisabledEnd && !refusal(r.from!) && isDateDisabled?.(r.to!) && !(max && r.to! > startOfDay(max));
215
+ const ends = refusal(r.from!) ?? (endOK ? null : refusal(r.to!));
216
+ if (ends) return ends;
217
+ const d = crossing(r);
218
+ return d ? `The range can't run across ${toISODate(d)}, which can't be picked.` : null;
219
+ };
220
+ /** What the footer says about a range that can't be applied, in the picker's own words. */
221
+ const said = (r: DateRange): string | null => {
222
+ if (!r.from || !r.to || !rangeRefusal(r)) return null;
223
+ const d = crossing(r);
224
+ return d ? `Can't run across ${format(d, "EEE d MMM", { locale })}` : "Some of these days can't be picked";
225
+ };
226
+ const inBounds = (r: DateRange) => !(min && r.from! < startOfDay(min)) && !(max && r.to! > startOfDay(max));
227
+ // Presets outside the bounds never apply here; one that runs across a disabled day shows, unavailable.
228
+ const allPresets = (presetsProp ?? pastPresets(today)).filter((p) => p.value.from && p.value.to && inBounds(p.value));
229
+ const presets = allPresets.filter((p) => !rangeRefusal(p.value));
230
+
231
+ const presetOf = (r: DateRange) => allPresets.find((p) => sameRange(p.value, r));
232
+ const picked = custom ? undefined : presetOf(draft);
233
+ const complete = !!(value.from && value.to);
234
+ const problem = complete ? rangeRefusal(value) : null;
235
+ const valueKey = `${value.from ? toISODate(value.from) : ""}/${value.to ? toISODate(value.to) : ""}`;
236
+ const applied = handPicked === valueKey ? undefined : presetOf(value);
237
+
238
+ // A value set from outside while the picker is open restarts the draft from it.
239
+ const [seen, setSeen] = React.useState(valueKey);
240
+ if (seen !== valueKey) {
241
+ setSeen(valueKey);
242
+ setDraft(value);
243
+ setCustom(complete && !applied);
244
+ }
245
+
246
+ const reset = () => {
247
+ setDraft(value);
248
+ setCustom(complete && !applied);
249
+ setNotice(null);
250
+ };
251
+ // Opening under control starts the draft afresh, as opening by the trigger does.
252
+ const [wasOpen, setWasOpen] = React.useState(open);
253
+ if (wasOpen !== open) {
254
+ setWasOpen(open);
255
+ if (open) reset();
256
+ }
257
+ const openWith = (next: boolean) => {
258
+ if (next) reset();
259
+ setOpen(next);
260
+ };
261
+ const changeDraft = (r: DateRange, details: CalendarChangeDetails) => {
262
+ onDraftChange?.(r, details);
263
+ if (details.isCanceled) return;
264
+ setDraft(r);
265
+ };
266
+ const apply = () => {
267
+ if (!draft.from || !draft.to || rangeRefusal(draft)) return;
268
+ if (!sameRange(draft, value)) {
269
+ const details = changeDetails("apply");
270
+ change(draft, details);
271
+ if (!details.isCanceled) setHandPicked(custom ? `${toISODate(draft.from!)}/${toISODate(draft.to!)}` : null);
272
+ }
273
+ setOpen(false);
274
+ };
275
+ const pickPreset = (p?: DateRangePreset) => {
276
+ setCustom(!p);
277
+ setNotice(null);
278
+ changeDraft(p ? p.value : EMPTY, changeDetails("preset-press"));
279
+ };
280
+
281
+ /* ---- agent ---- */
282
+ const read = (text: string) =>
283
+ fromISODate(text) ?? parseDate(text, { today, order: dayFirst(locale) ? "day-first" : "month-first", weekStartsOn, min, max });
284
+ const commit = (r: DateRange, details: CalendarChangeDetails) => {
285
+ if (!sameRange(r, value)) change(r, details);
286
+ };
287
+ useAgentControl(() => ({
288
+ kind: "date",
289
+ element: trigger.current,
290
+ value: complete ? [toISODate(value.from!), toISODate(value.to!)] : undefined,
291
+ multiple: true,
292
+ disabled,
293
+ required,
294
+ invalid: !!problem || undefined,
295
+ errors: problem ? [problem] : undefined,
296
+ items: presets.map((p) => p.label),
297
+ actions: {
298
+ setValue: (wanted: unknown) => {
299
+ const preset = typeof wanted === "string" && presets.find((p) => p.label.toLowerCase() === wanted.trim().toLowerCase());
300
+ if (preset) return changeAsAgent(commit, preset.value);
301
+ const parts = Array.isArray(wanted)
302
+ ? wanted
303
+ : typeof wanted === "string"
304
+ ? /^\d{4}-\d\d-\d\d\/\d{4}-\d\d-\d\d$/.test(wanted.trim()) ? wanted.split("/") : wanted.split(/\s*,\s*|\s+to\s+/i)
305
+ : [];
306
+ const [from, to] = parts.map((p) => (p instanceof Date ? (isNaN(p.getTime()) ? null : startOfDay(p)) : typeof p === "string" ? read(p) : null));
307
+ if (parts.length !== 2 || !from || !to)
308
+ return `Send two dates, as ["YYYY-MM-DD", "YYYY-MM-DD"] or "21 nov to 24 nov", or one of: ${presets.map((p) => p.label).join(", ")}.`;
309
+ if (to < from) return `The end, ${toISODate(to)}, has to be on or after the start, ${toISODate(from)}.`;
310
+ return rangeRefusal({ from, to }) ?? changeAsAgent(commit, { from, to });
311
+ },
312
+ clear: () => changeAsAgent(commit, EMPTY),
313
+ },
314
+ }));
315
+
316
+ /* ---- render ---- */
317
+ const triggerButton = (
318
+ <button
319
+ {...buttonProps}
320
+ ref={useMergedRef(ref, trigger)}
321
+ type="button"
322
+ disabled={disabled}
323
+ aria-invalid={problem ? true : undefined}
324
+ data-invalid={problem ? "" : undefined}
325
+ data-slot="date-range-picker"
326
+ data-agent-label={name_}
327
+ className={cn(
328
+ "inline-flex h-9 max-w-full items-center gap-2 rounded-md border border-input bg-transparent px-3 text-sm shadow-xs dark:bg-input/30",
329
+ "hover:bg-accent focus-visible:outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:border-ring",
330
+ "disabled:pointer-events-none disabled:opacity-50",
331
+ "aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",
332
+ className
333
+ )}
334
+ >
335
+ <CalendarDays className="size-4 shrink-0 text-muted-foreground" aria-hidden />
336
+ {/* Named this way, the button still reads out the range it holds. */}
337
+ {name_ && <span className="sr-only">{name_}:</span>}{" "}
338
+ <span className={cn("truncate font-medium", !complete && "font-normal text-muted-foreground")}>
339
+ {applied ? applied.label : complete ? fmt({ from: value.from!, to: value.to! }) : placeholder}
340
+ </span>{" "}
341
+ {applied && <span className="truncate text-muted-foreground">{fmt({ from: value.from!, to: value.to! })}</span>}
342
+ <ChevronDown className="ms-auto size-4 shrink-0 text-muted-foreground" aria-hidden />
343
+ </button>
344
+ );
345
+
346
+ const [hover, setHover] = React.useState<DateRange | null>(null);
347
+ const shown = draft.from && !draft.to && hover?.from && hover.to ? hover : draft;
348
+ const refused = shown === draft ? said(draft) : null;
349
+ const warning = refused ?? (shown === draft && draft.from && !draft.to ? notice : null);
350
+ const readout = warning ? (
351
+ <span className="text-destructive">{warning}</span>
352
+ ) : !shown.from ? (
353
+ <span className="text-muted-foreground">Pick a start</span>
354
+ ) : !shown.to ? (
355
+ <>
356
+ {fmtDay(shown.from)} <span className="text-muted-foreground">to ...</span>
357
+ </>
358
+ ) : (
359
+ <>
360
+ {fmt({ from: shown.from, to: shown.to })}
361
+ {presentation === "drawer" ? <br /> : " "}
362
+ <span className="text-muted-foreground">
363
+ {presentation === "popover" && "· "}
364
+ {fmtLength({ from: shown.from, to: shown.to })}
365
+ </span>
366
+ </>
367
+ );
368
+
369
+ const presetId = React.useId();
370
+ const choices = [...allPresets, { label: "Custom", value: EMPTY }].map((p, i) => {
371
+ const isCustom = i === allPresets.length;
372
+ const why = isCustom ? null : said(p.value);
373
+ return (
374
+ <React.Fragment key={p.label}>
375
+ <button
376
+ type="button"
377
+ aria-pressed={isCustom ? !picked && (custom || !!draft.from) : picked === p}
378
+ disabled={!!why}
379
+ aria-describedby={why ? `${presetId}-${i}` : undefined}
380
+ title={why ?? undefined}
381
+ data-slot="date-range-picker-preset"
382
+ onClick={() => pickPreset(isCustom ? undefined : p)}
383
+ className={cn(
384
+ "shrink-0 whitespace-nowrap text-[0.8125rem] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:opacity-50",
385
+ presentation === "popover"
386
+ ? "rounded-md px-2.5 py-1.5 text-start hover:bg-accent aria-pressed:bg-secondary aria-pressed:font-medium"
387
+ : "rounded-full border border-border bg-background px-3 py-1.5 aria-pressed:border-transparent aria-pressed:bg-primary aria-pressed:text-primary-foreground"
388
+ )}
389
+ >
390
+ {p.label}
391
+ </button>
392
+ {why && (
393
+ <span id={`${presetId}-${i}`} hidden>
394
+ {why}
395
+ </span>
396
+ )}
397
+ </React.Fragment>
398
+ );
399
+ });
400
+
401
+ const calendar = (height: string) => (
402
+ <Calendar
403
+ mode="range"
404
+ layout={layout}
405
+ numberOfMonths={numberOfMonths}
406
+ captionLayout={captionLayout}
407
+ allowDisabledEnd={allowDisabledEnd}
408
+ renderDay={renderDay}
409
+ dayClassName={dayClassName}
410
+ describeDay={describeDay}
411
+ min={min}
412
+ max={max}
413
+ isDateDisabled={isDateDisabled}
414
+ weekNumbers={weekNumbers}
415
+ locale={locale}
416
+ weekStartsOn={weekStartsOn}
417
+ dir={dir}
418
+ today={today}
419
+ value={draft}
420
+ onValueChange={(r, details) => {
421
+ const before = draft.from;
422
+ changeDraft(r, details);
423
+ if (details.isCanceled) return;
424
+ setCustom(true);
425
+ const d = details.reason === "range-blocked" && before ? crossing({ from: before, to: r.from }) : null;
426
+ setNotice(d ? `Can't run across ${format(d, "EEE d MMM", { locale })}` : null);
427
+ }}
428
+ onPreview={setHover}
429
+ className={height}
430
+ />
431
+ );
432
+
433
+ return (
434
+ <>
435
+ <Unlisted>
436
+ {presentation === "popover" ? (
437
+ <Popover open={open} onOpenChange={openWith}>
438
+ <PopoverTrigger render={triggerButton} />
439
+ <PopoverPortal>
440
+ <PopoverPositioner align="start" sideOffset={6}>
441
+ <PopoverPopup aria-label={label} data-slot="date-range-picker-popup" dir={dir} className={cn("grid p-0", allPresets.length > 0 ? "grid-cols-[9.375rem_auto]" : "grid-cols-[auto]")}>
442
+ {allPresets.length > 0 && (
443
+ <div data-slot="date-range-picker-presets" className="flex flex-col gap-0.5 border-e p-2">
444
+ {choices}
445
+ </div>
446
+ )}
447
+ <div className="p-2">{calendar("[--calendar-bg:var(--popover)] [--calendar-height:20rem]")}</div>
448
+ <div data-slot="date-range-picker-footer" className="col-span-full flex items-center gap-2 border-t px-3 py-2.5">
449
+ <p data-slot="date-range-picker-readout" aria-live="polite" className="me-auto text-[0.8125rem]">
450
+ {readout}
451
+ </p>
452
+ <Button variant="ghost" size="sm" data-slot="date-range-picker-cancel" onClick={() => setOpen(false)}>
453
+ Cancel
454
+ </Button>
455
+ <Button size="sm" data-slot="date-range-picker-apply" disabled={!draft.to || !!refused} onClick={apply}>
456
+ Apply
457
+ </Button>
458
+ </div>
459
+ </PopoverPopup>
460
+ </PopoverPositioner>
461
+ </PopoverPortal>
462
+ </Popover>
463
+ ) : (
464
+ <Drawer open={open} onOpenChange={openWith}>
465
+ <DrawerTrigger render={triggerButton} />
466
+ <DrawerContent side="bottom" data-slot="date-range-picker-popup" dir={dir} className="max-h-[92dvh] gap-0 rounded-t-2xl px-0 pb-0 pt-4">
467
+ <DrawerTitle className="px-5 pb-3 text-[1.0625rem] font-semibold">{label}</DrawerTitle>
468
+ {allPresets.length > 0 && (
469
+ <div data-slot="date-range-picker-presets" className="flex gap-2 overflow-x-auto px-5 pb-3 [scrollbar-width:none]">
470
+ {choices}
471
+ </div>
472
+ )}
473
+ <div className="px-3">{calendar("w-full [--calendar-bg:var(--background)] [--calendar-cell:2.75rem] [--calendar-height:23.75rem]")}</div>
474
+ <div data-slot="date-range-picker-footer" className="mt-1 flex items-center gap-3 border-t px-5 py-3">
475
+ <p data-slot="date-range-picker-readout" aria-live="polite" className="me-auto text-sm">
476
+ {readout}
477
+ </p>
478
+ <Button data-slot="date-range-picker-apply" disabled={!draft.to || !!refused} onClick={apply}>
479
+ Apply
480
+ </Button>
481
+ </div>
482
+ </DrawerContent>
483
+ </Drawer>
484
+ )}
485
+ </Unlisted>
486
+ {(name || required) && (
487
+ <input
488
+ aria-hidden
489
+ tabIndex={-1}
490
+ name={name}
491
+ required={required}
492
+ disabled={disabled}
493
+ value={complete ? `${toISODate(value.from!)}/${toISODate(value.to!)}` : ""}
494
+ onChange={() => {}}
495
+ onFocus={() => trigger.current?.focus()}
496
+ className="pointer-events-none absolute size-px opacity-0"
497
+ />
498
+ )}
499
+ </>
500
+ );
501
+ });
502
+ DateRangePicker.displayName = "DateRangePicker";
503
+
504
+ export { DateRangePicker };
@@ -0,0 +1,2 @@
1
+ export { DateRangePicker, pastPresets } from "./date-range-picker";
2
+ export type { DateRangePickerProps, DateRangePreset } from "./date-range-picker";