@klinking/colander 0.0.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 (93) hide show
  1. package/dist/formats/date.cjs +49 -0
  2. package/dist/formats/date.d.cts +45 -0
  3. package/dist/formats/date.d.mts +45 -0
  4. package/dist/formats/date.mjs +2 -0
  5. package/dist/formats/object.cjs +49 -0
  6. package/dist/formats/object.d.cts +45 -0
  7. package/dist/formats/object.d.mts +45 -0
  8. package/dist/formats/object.mjs +2 -0
  9. package/dist/formats/plain-date-time.cjs +49 -0
  10. package/dist/formats/plain-date-time.d.cts +45 -0
  11. package/dist/formats/plain-date-time.d.mts +45 -0
  12. package/dist/formats/plain-date-time.mjs +2 -0
  13. package/dist/formats/plain-date.cjs +49 -0
  14. package/dist/formats/plain-date.d.cts +45 -0
  15. package/dist/formats/plain-date.d.mts +45 -0
  16. package/dist/formats/plain-date.mjs +2 -0
  17. package/dist/formats/plain-month-day.cjs +49 -0
  18. package/dist/formats/plain-month-day.d.cts +45 -0
  19. package/dist/formats/plain-month-day.d.mts +45 -0
  20. package/dist/formats/plain-month-day.mjs +2 -0
  21. package/dist/formats/plain-year-month.cjs +49 -0
  22. package/dist/formats/plain-year-month.d.cts +45 -0
  23. package/dist/formats/plain-year-month.d.mts +45 -0
  24. package/dist/formats/plain-year-month.mjs +2 -0
  25. package/dist/formats/zoned-date-time.cjs +49 -0
  26. package/dist/formats/zoned-date-time.d.cts +45 -0
  27. package/dist/formats/zoned-date-time.d.mts +45 -0
  28. package/dist/formats/zoned-date-time.mjs +2 -0
  29. package/dist/index.cjs +49 -0
  30. package/dist/index.d.cts +2 -0
  31. package/dist/index.d.mts +2 -0
  32. package/dist/index.mjs +2 -0
  33. package/dist/temporal-polyfill-DTx0VIX5.mjs +4556 -0
  34. package/dist/temporal-polyfill-DU8VfleL.cjs +4860 -0
  35. package/dist/weeks-view-context-BN6qR-83.d.mts +2022 -0
  36. package/dist/weeks-view-context-aHGgYkpt.d.cts +2022 -0
  37. package/package.json +89 -0
  38. package/src/calendar-context.ts +22 -0
  39. package/src/calendar-provider.test.tsx +123 -0
  40. package/src/calendar-provider.tsx +538 -0
  41. package/src/calendar-types.ts +212 -0
  42. package/src/compute-weeks-in-window.test.ts +83 -0
  43. package/src/compute-weeks-in-window.ts +40 -0
  44. package/src/context.ts +34 -0
  45. package/src/day-cell.tsx +635 -0
  46. package/src/drag-handle.tsx +137 -0
  47. package/src/formats/date.ts +110 -0
  48. package/src/formats/formats.test.ts +18 -0
  49. package/src/formats/object.ts +110 -0
  50. package/src/formats/plain-date-time.ts +110 -0
  51. package/src/formats/plain-date.ts +110 -0
  52. package/src/formats/plain-month-day.ts +110 -0
  53. package/src/formats/plain-year-month.ts +110 -0
  54. package/src/formats/zoned-date-time.ts +110 -0
  55. package/src/grid-header.tsx +141 -0
  56. package/src/grid.event-perf.test.tsx +282 -0
  57. package/src/grid.perf.test.tsx +467 -0
  58. package/src/grid.tsx +608 -0
  59. package/src/index.ts +116 -0
  60. package/src/keyboard.test.ts +498 -0
  61. package/src/keyboard.ts +142 -0
  62. package/src/month-separator.test.tsx +183 -0
  63. package/src/month-separator.tsx +238 -0
  64. package/src/month-view-context.ts +26 -0
  65. package/src/month-view-types.ts +89 -0
  66. package/src/month-view.test.tsx +1433 -0
  67. package/src/month-view.tsx +373 -0
  68. package/src/navigation.tsx +350 -0
  69. package/src/overflow.test.ts +124 -0
  70. package/src/overflow.ts +233 -0
  71. package/src/range-preview.tsx +90 -0
  72. package/src/resolve-first-week.test.ts +132 -0
  73. package/src/resolve-first-week.ts +145 -0
  74. package/src/root-selection.ts +621 -0
  75. package/src/selected-range.tsx +163 -0
  76. package/src/temporal-polyfill.test.ts +317 -0
  77. package/src/temporal-polyfill.ts +566 -0
  78. package/src/test-temporal.ts +17 -0
  79. package/src/types.ts +814 -0
  80. package/src/utils.bench.ts +183 -0
  81. package/src/utils.test.ts +983 -0
  82. package/src/utils.ts +493 -0
  83. package/src/view-context.ts +28 -0
  84. package/src/week-number.tsx +118 -0
  85. package/src/weeks-grid.tsx +265 -0
  86. package/src/weeks-keyboard.test.ts +222 -0
  87. package/src/weeks-keyboard.ts +156 -0
  88. package/src/weeks-navigation.tsx +209 -0
  89. package/src/weeks-view-context.ts +26 -0
  90. package/src/weeks-view-state.ts +421 -0
  91. package/src/weeks-view-types.ts +102 -0
  92. package/src/weeks-view.test.tsx +479 -0
  93. package/src/weeks-view.tsx +127 -0
package/src/types.ts ADDED
@@ -0,0 +1,814 @@
1
+ import type { useRender } from "@base-ui/react/use-render";
2
+ import type { Temporal } from "@js-temporal/polyfill";
3
+ import type { GridOrientation } from "./context";
4
+
5
+ /**
6
+ * Extracted from Base UI's `useRender.Parameters.stateAttributesMapping`.
7
+ * Base UI doesn't publicly export `StateAttributesMapping`, so we derive it
8
+ * from the public `useRender` namespace to avoid depending on internal paths.
9
+ */
10
+ export type StateAttributesMapping<State> = NonNullable<
11
+ useRender.Parameters<State, Element, true>["stateAttributesMapping"]
12
+ >;
13
+
14
+ /** Day of the week represented as a number: `0` = Sunday through `6` = Saturday. */
15
+ export type WeekStartDay = 0 | 1 | 2 | 3 | 4 | 5 | 6;
16
+
17
+ /**
18
+ * Controls how days from adjacent months are displayed in the calendar grid.
19
+ * - `"enabled"` — outside days are fully interactive (default).
20
+ * - `"readOnly"` — outside days are visible but disabled; range highlighting still paints through.
21
+ * - `"disabled"` — outside days are visible but disabled; no range highlighting or drag handles.
22
+ * - `"hidden"` — outside day cells are empty (`<td>` with `data-hidden` + `aria-hidden`).
23
+ */
24
+ export type OutsideDays = "enabled" | "readOnly" | "disabled" | "hidden";
25
+
26
+ /**
27
+ * Controls how clicking inside an existing range behaves.
28
+ * - `"start-end"` — Two-step: click sets start, second click sets end. Re-click resets.
29
+ * - `"nearest-end"` — Adjusts whichever boundary is closer; ties go to end (default).
30
+ * - `"nearest-start"` — Adjusts whichever boundary is closer; ties go to start.
31
+ * - `"adjust-end"` — Always moves the range end to the clicked date.
32
+ * - `"adjust-start"` — Always moves the range start to the clicked date.
33
+ * - `"reset"` — Collapses the range to a single-day selection on the clicked date.
34
+ */
35
+ export type RangeMode =
36
+ | "start-end"
37
+ | "nearest-end"
38
+ | "nearest-start"
39
+ | "adjust-end"
40
+ | "adjust-start"
41
+ | "reset";
42
+
43
+ /** Subset of the Temporal API surface consumed by the DatePicker. */
44
+ export type TemporalNamespace = {
45
+ Now: {
46
+ timeZoneId(): string;
47
+ zonedDateTimeISO(tz: string): Temporal.ZonedDateTime;
48
+ plainDateISO(): Temporal.PlainDate;
49
+ };
50
+ PlainDate: {
51
+ from(item: any, options?: { overflow?: string }): Temporal.PlainDate;
52
+ compare(a: Temporal.PlainDate, b: Temporal.PlainDate): number;
53
+ };
54
+ PlainDateTime: {
55
+ from(item: any, options?: { overflow?: string }): Temporal.PlainDateTime;
56
+ };
57
+ PlainMonthDay: {
58
+ from(item: any): Temporal.PlainMonthDay;
59
+ };
60
+ PlainYearMonth: {
61
+ from(item: any): Temporal.PlainYearMonth;
62
+ };
63
+ };
64
+
65
+ /** Plain JS object representation of a date with optional time and time zone fields. */
66
+ export interface PlainDateObject {
67
+ year?: number;
68
+ month?: number;
69
+ day?: number;
70
+ hour?: number;
71
+ minute?: number;
72
+ second?: number;
73
+ timeZone?: string;
74
+ }
75
+
76
+ /** Tagged union of all supported date value formats and their runtime values. */
77
+ export type DateValueObject =
78
+ | { format: "PlainDate"; value: Temporal.PlainDate }
79
+ | { format: "PlainDateTime"; value: Temporal.PlainDateTime }
80
+ | { format: "PlainMonthDay"; value: Temporal.PlainMonthDay }
81
+ | { format: "PlainTime"; value: Temporal.PlainTime }
82
+ | { format: "PlainYearMonth"; value: Temporal.PlainYearMonth }
83
+ | { format: "ZonedDateTime"; value: Temporal.ZonedDateTime }
84
+ | { format: "object"; value: PlainDateObject }
85
+ | { format: "Date"; value: Date };
86
+
87
+ /** Union of all supported value format discriminant strings. */
88
+ export type ValueFormat = DateValueObject["format"];
89
+
90
+ /** Extracts the {@link DateValueObject} variant matching a given format `F`. */
91
+ export type ValueForFormat<F extends ValueFormat> = Extract<DateValueObject, { format: F }>;
92
+
93
+ /** The runtime value type for a given format `F` (e.g. `Temporal.PlainDate` for `"PlainDate"`). */
94
+ export type RawValueForFormat<F extends ValueFormat> = ValueForFormat<F>["value"];
95
+
96
+ /** A start/end date pair for range selection, typed to the given format `F`. */
97
+ export type DateRange<F extends ValueFormat = ValueFormat> = {
98
+ start: RawValueForFormat<F> | null;
99
+ end: RawValueForFormat<F> | null;
100
+ };
101
+
102
+ /**
103
+ * Metadata passed as the second argument to `onValueChange`.
104
+ * @typeParam Previous - The type of the previous selection value.
105
+ */
106
+ export interface ValueChangeMeta<Previous> {
107
+ /** The specific date that was clicked, or `undefined` if the change was not triggered by a date selection (e.g. mode switch, out-of-bounds cleanup, drag). */
108
+ date?: Temporal.PlainDate;
109
+ /** The previous selection value before this change. */
110
+ previous: Previous;
111
+ }
112
+
113
+ /** Stable values (callbacks, config, refs) that don't change during interaction. */
114
+ export interface DatePickerStableContextValue {
115
+ /** Selects (or toggles) a date, respecting the current selection mode. */
116
+ onSelect: (date: Temporal.PlainDate) => void;
117
+ /** Programmatically sets the range boundaries (normalized so start <= end). */
118
+ setRange: (start: Temporal.PlainDate, end: Temporal.PlainDate) => void;
119
+ /** Moves the logically focused date in the grid. */
120
+ setFocusedDate: (date: Temporal.PlainDate) => void;
121
+ /** Navigates to the next calendar month. */
122
+ goToNextMonth: () => void;
123
+ /** Navigates to the previous calendar month. */
124
+ goToPrevMonth: () => void;
125
+ /** Tracks whether the grid currently holds DOM focus. */
126
+ setGridHasFocus: (v: boolean) => void;
127
+ /** Registers (or clears) the id of a label element for `aria-labelledby`, keyed by month index. */
128
+ setGridLabelId: (monthIndex: number, id: string | undefined) => void;
129
+ /** The active selection mode. */
130
+ selectionMode: "single" | "range" | "multiple";
131
+ /** Whether the entire calendar is disabled. */
132
+ disabled: boolean;
133
+ /** Whether the calendar is read-only. */
134
+ readOnly: boolean;
135
+ /** User-supplied predicate for individually disabled dates. */
136
+ isDateDisabled?: (date: Temporal.PlainDate) => boolean;
137
+ /** Earliest selectable date (resolved from the `min` prop). */
138
+ minValue?: Temporal.PlainDate;
139
+ /** Latest selectable date (resolved from the `max` prop). */
140
+ maxValue?: Temporal.PlainDate;
141
+ /** Resolved IANA time zone. */
142
+ timeZone: string;
143
+ /** Resolved BCP 47 locale. */
144
+ locale: string;
145
+ /** Resolved Temporal namespace. */
146
+ temporal: TemporalNamespace;
147
+ /** Ref tracking whether the grid has DOM focus (avoids state re-renders). */
148
+ gridFocusedRef: React.RefObject<boolean>;
149
+ /** Day the calendar week starts on. */
150
+ weekStartDay: WeekStartDay;
151
+ /** Number of simultaneously visible months. */
152
+ numberOfMonths: number;
153
+ /** How outside-month days are displayed. */
154
+ outsideDays: OutsideDays;
155
+ /** Active range selection mode. */
156
+ rangeMode: RangeMode;
157
+ /** Whether reversed ranges are auto-sorted instead of collapsed. */
158
+ preventRangeReversal: boolean;
159
+ /** Sets the hovered date for range preview. */
160
+ setHoveredDate: (date: Temporal.PlainDate | undefined) => void;
161
+ }
162
+
163
+ /** Pre-computed data for a single visible month. */
164
+ export interface MonthData {
165
+ /** Calendar year. */
166
+ year: number;
167
+ /** Calendar month (1–12). */
168
+ month: number;
169
+ /** 2D array of weeks (each week is an array of `PlainDate`). */
170
+ weeks: Temporal.PlainDate[][];
171
+ }
172
+
173
+ /** Volatile state that changes on interaction. */
174
+ export interface DatePickerStateContextValue {
175
+ /** The currently selected value as a tagged {@link DateValueObject}. */
176
+ selected: DateValueObject | undefined;
177
+ /** Flat array of all selected dates (plain dates, sorted). */
178
+ selectedDates: Temporal.PlainDate[];
179
+ /** Start of the current range selection, or `undefined`. */
180
+ rangeStart: Temporal.PlainDate | undefined;
181
+ /** End of the current range selection, or `undefined`. */
182
+ rangeEnd: Temporal.PlainDate | undefined;
183
+ /** The logically focused date in the grid. */
184
+ focusedDate: Temporal.PlainDate;
185
+ /** The date that should receive `tabIndex={0}` for roving tabindex. */
186
+ tabTargetDate: Temporal.PlainDate;
187
+ /** Date-time representing the viewed month with time from the selection. */
188
+ currentDateTime: Temporal.PlainDateTime;
189
+ /** 2D array of weeks for the currently viewed month (first visible month). */
190
+ weeks: Temporal.PlainDate[][];
191
+ /** Pre-computed data for all visible months (length = `numberOfMonths`). */
192
+ allMonths: MonthData[];
193
+ /** Number of simultaneously visible months. */
194
+ numberOfMonths: number;
195
+ /** Map of month index → label element id (for per-grid `aria-labelledby`). */
196
+ gridLabelIds: Record<number, string>;
197
+ /** The currently hovered date (for range preview). */
198
+ hoveredDate: Temporal.PlainDate | undefined;
199
+ /** Start of the computed preview range. */
200
+ previewStart: Temporal.PlainDate | undefined;
201
+ /** End of the computed preview range. */
202
+ previewEnd: Temporal.PlainDate | undefined;
203
+ /** The root component's state object for render functions. */
204
+ rootState: RootState;
205
+ }
206
+
207
+ /** Combined context value (backward compat). */
208
+ export interface DatePickerContextValue
209
+ extends DatePickerStableContextValue, DatePickerStateContextValue {}
210
+
211
+ /** State exposed by the `Root` component to its render function and descendants. */
212
+ export type RootState<F extends ValueFormat = ValueFormat> = {
213
+ /** `true` when at least one date is selected. */
214
+ hasSelection: boolean;
215
+ /** The primary selected value in the configured format, or `undefined`. */
216
+ selected: RawValueForFormat<F> | undefined;
217
+ /** All selected dates in the configured format (sorted oldest-first). */
218
+ selectedDates: RawValueForFormat<F>[];
219
+ /** Range start in the configured format, or `undefined`. */
220
+ rangeStart: RawValueForFormat<F> | undefined;
221
+ /** Range end in the configured format, or `undefined`. */
222
+ rangeEnd: RawValueForFormat<F> | undefined;
223
+ /** The currently focused `PlainDate` in the grid. */
224
+ focused: Temporal.PlainDate;
225
+ /** The month/year currently being viewed. */
226
+ viewing: Temporal.PlainYearMonth;
227
+ /** Resolved IANA time zone. */
228
+ timeZone: string;
229
+ /** Resolved BCP 47 locale. */
230
+ locale: string;
231
+ /** Whether the calendar is read-only. */
232
+ readOnly: boolean;
233
+ };
234
+
235
+ interface RootOwnPropsBase<F extends ValueFormat = ValueFormat> {
236
+ /**
237
+ * The value format used for date serialization. Determines the type of
238
+ * `value`, `defaultValue`, `min`, `max`, and callback parameters.
239
+ * @default "PlainDate"
240
+ */
241
+ format?: F;
242
+ /** Earliest selectable date. Dates before this are disabled. */
243
+ min?: RawValueForFormat<F>;
244
+ /** Latest selectable date. Dates after this are disabled. */
245
+ max?: RawValueForFormat<F>;
246
+ /**
247
+ * When `true`, the entire calendar is disabled. No dates can be selected
248
+ * or focused via keyboard.
249
+ * @default false
250
+ */
251
+ disabled?: boolean;
252
+ /**
253
+ * When `true`, the calendar is read-only. Keyboard navigation still works
254
+ * but selection (click, Enter, Space) is prevented.
255
+ * @default false
256
+ */
257
+ readOnly?: boolean;
258
+ /**
259
+ * Callback to disable individual dates. Return `true` to disable a date.
260
+ * Called in addition to `min`/`max` bounds checking.
261
+ */
262
+ isDateDisabled?: (date: Temporal.PlainDate) => boolean;
263
+ /**
264
+ * IANA time zone identifier used for date/time conversions.
265
+ * @default The system's current time zone.
266
+ */
267
+ timeZone?: string;
268
+ /**
269
+ * BCP 47 locale string used for formatting month names, weekday labels,
270
+ * and other locale-sensitive output.
271
+ * @default "en-US"
272
+ */
273
+ locale?: string;
274
+ /**
275
+ * Custom Temporal namespace for environments without native Temporal support.
276
+ * Typically the `Temporal` export from `@js-temporal/polyfill`. When using
277
+ * `@js-temporal/polyfill`.
278
+ */
279
+ temporal?: TemporalNamespace;
280
+ /**
281
+ * Day of the week the calendar grid starts on.
282
+ * `0` = Sunday, `1` = Monday, ..., `6` = Saturday.
283
+ * @default 0
284
+ */
285
+ weekStartDay?: WeekStartDay;
286
+ /**
287
+ * When `true`, the calendar always renders 6 week rows, padding with
288
+ * dates from adjacent months. Prevents layout shifts when navigating
289
+ * between months with different row counts.
290
+ * @default false
291
+ */
292
+ fixedWeeks?: boolean;
293
+ /**
294
+ * Called when the visible month changes — via navigation buttons,
295
+ * keyboard (PageUp/PageDown), or when `focusedDate` crosses a month
296
+ * boundary. Not called on initial mount.
297
+ */
298
+ onMonthChange?: (month: Temporal.PlainYearMonth) => void;
299
+ /**
300
+ * Number of months to display simultaneously. Each month is rendered
301
+ * by a separate `Grid` component with a `monthIndex` prop.
302
+ * @default 1
303
+ */
304
+ numberOfMonths?: number;
305
+ /**
306
+ * Controls how days from adjacent months are displayed.
307
+ * - `"enabled"` — fully interactive (default).
308
+ * - `"readOnly"` — visible but disabled; range highlighting paints through.
309
+ * - `"disabled"` — visible but disabled; no range highlighting or drag handles.
310
+ * - `"hidden"` — empty cells with `data-hidden` + `aria-hidden`.
311
+ * @default "enabled"
312
+ */
313
+ outsideDays?: OutsideDays;
314
+ }
315
+
316
+ /**
317
+ * Single-mode props when the component is controlled.
318
+ * Pass `value={null}` to clear the selection.
319
+ */
320
+ interface SingleControlledProps<F extends ValueFormat = ValueFormat> {
321
+ /** @default "single" */
322
+ selectionMode?: "single";
323
+ /** The controlled selected date. Pass `null` to clear the selection. */
324
+ value: RawValueForFormat<F> | null;
325
+ /** Not allowed in controlled mode. */
326
+ defaultValue?: never;
327
+ /** Called when the selected date changes. `null` means the selection was cleared. */
328
+ onValueChange?: (
329
+ value: RawValueForFormat<F> | null,
330
+ meta: ValueChangeMeta<RawValueForFormat<F> | null>,
331
+ ) => void;
332
+ }
333
+
334
+ /**
335
+ * Single-mode props when the component is uncontrolled.
336
+ * Omit `value` entirely — do not pass `value={undefined}`.
337
+ */
338
+ interface SingleUncontrolledProps<F extends ValueFormat = ValueFormat> {
339
+ /** @default "single" */
340
+ selectionMode?: "single";
341
+ /** Must be omitted for uncontrolled mode. */
342
+ value?: never;
343
+ /** The initial selected date (uncontrolled). */
344
+ defaultValue?: RawValueForFormat<F>;
345
+ /** Called when the selected date changes. `null` means the selection was cleared. */
346
+ onValueChange?: (
347
+ value: RawValueForFormat<F> | null,
348
+ meta: ValueChangeMeta<RawValueForFormat<F> | null>,
349
+ ) => void;
350
+ }
351
+
352
+ /**
353
+ * Range-mode props when the component is controlled.
354
+ * Pass `value={null}` to clear the selection.
355
+ */
356
+ interface RangeControlledProps<F extends ValueFormat = ValueFormat> {
357
+ selectionMode: "range";
358
+ /** The controlled selected range. Pass `null` to clear the selection. */
359
+ value: DateRange<F> | null;
360
+ /** Not allowed in controlled mode. */
361
+ defaultValue?: never;
362
+ /** Called when the selected range changes. `null` means the selection was cleared. */
363
+ onValueChange?: (value: DateRange<F> | null, meta: ValueChangeMeta<DateRange<F> | null>) => void;
364
+ /**
365
+ * Controls how clicking inside an existing range behaves.
366
+ * @default "nearest-end"
367
+ */
368
+ rangeMode?: RangeMode;
369
+ /**
370
+ * When `true`, reversed selections collapse to a single-day range
371
+ * instead of being auto-sorted.
372
+ * @default false
373
+ */
374
+ preventRangeReversal?: boolean;
375
+ /**
376
+ * Overrides the internally-computed preview range. `null` hides the preview.
377
+ * Only used when `selectionMode="range"`.
378
+ */
379
+ previewRange?: DateRange<F> | null;
380
+ /** Fires when the hovered date changes (on `pointerenter`/`pointerleave`). */
381
+ onHoveredDateChange?: (date: Temporal.PlainDate | undefined) => void;
382
+ }
383
+
384
+ /**
385
+ * Range-mode props when the component is uncontrolled.
386
+ * Omit `value` entirely — do not pass `value={undefined}`.
387
+ */
388
+ interface RangeUncontrolledProps<F extends ValueFormat = ValueFormat> {
389
+ selectionMode: "range";
390
+ /** Must be omitted for uncontrolled mode. */
391
+ value?: never;
392
+ /** The initial selected range (uncontrolled). */
393
+ defaultValue?: DateRange<F>;
394
+ /** Called when the selected range changes. `null` means the selection was cleared. */
395
+ onValueChange?: (value: DateRange<F> | null, meta: ValueChangeMeta<DateRange<F> | null>) => void;
396
+ /**
397
+ * Controls how clicking inside an existing range behaves.
398
+ * @default "nearest-end"
399
+ */
400
+ rangeMode?: RangeMode;
401
+ /**
402
+ * When `true`, reversed selections collapse to a single-day range
403
+ * instead of being auto-sorted.
404
+ * @default false
405
+ */
406
+ preventRangeReversal?: boolean;
407
+ /**
408
+ * Overrides the internally-computed preview range. `null` hides the preview.
409
+ * Only used when `selectionMode="range"`.
410
+ */
411
+ previewRange?: DateRange<F> | null;
412
+ /** Fires when the hovered date changes (on `pointerenter`/`pointerleave`). */
413
+ onHoveredDateChange?: (date: Temporal.PlainDate | undefined) => void;
414
+ }
415
+
416
+ /**
417
+ * Multiple-mode props when the component is controlled.
418
+ * Pass `value={[]}` to clear the selection.
419
+ */
420
+ interface MultipleControlledProps<F extends ValueFormat = ValueFormat> {
421
+ selectionMode: "multiple";
422
+ /** The controlled array of selected dates, sorted oldest-first. */
423
+ value: RawValueForFormat<F>[];
424
+ /** Not allowed in controlled mode. */
425
+ defaultValue?: never;
426
+ /** Called when the selected dates change. Clicking a selected date deselects it. */
427
+ onValueChange?: (
428
+ value: RawValueForFormat<F>[],
429
+ meta: ValueChangeMeta<RawValueForFormat<F>[]>,
430
+ ) => void;
431
+ }
432
+
433
+ /**
434
+ * Multiple-mode props when the component is uncontrolled.
435
+ * Omit `value` entirely — do not pass `value={undefined}`.
436
+ */
437
+ interface MultipleUncontrolledProps<F extends ValueFormat = ValueFormat> {
438
+ selectionMode: "multiple";
439
+ /** Must be omitted for uncontrolled mode. */
440
+ value?: never;
441
+ /** The initial array of selected dates (uncontrolled). */
442
+ defaultValue?: RawValueForFormat<F>[];
443
+ /** Called when the selected dates change. Clicking a selected date deselects it. */
444
+ onValueChange?: (
445
+ value: RawValueForFormat<F>[],
446
+ meta: ValueChangeMeta<RawValueForFormat<F>[]>,
447
+ ) => void;
448
+ }
449
+
450
+ /** Own props accepted by `Root`, combining base config with selection-mode-specific props. */
451
+ export type RootOwnProps<F extends ValueFormat = ValueFormat> = RootOwnPropsBase<F> &
452
+ (
453
+ | SingleControlledProps<F>
454
+ | SingleUncontrolledProps<F>
455
+ | RangeControlledProps<F>
456
+ | RangeUncontrolledProps<F>
457
+ | MultipleControlledProps<F>
458
+ | MultipleUncontrolledProps<F>
459
+ );
460
+
461
+ type AllRootOwnPropKeys =
462
+ | keyof RootOwnPropsBase
463
+ | keyof SingleControlledProps
464
+ | keyof SingleUncontrolledProps
465
+ | keyof RangeControlledProps
466
+ | keyof RangeUncontrolledProps
467
+ | keyof MultipleControlledProps
468
+ | keyof MultipleUncontrolledProps;
469
+
470
+ /** Full props for the `Root` component (own props + render element props). */
471
+ export type RootProps<F extends ValueFormat = ValueFormat> = Omit<
472
+ useRender.ComponentProps<"div", RootState<F>>,
473
+ AllRootOwnPropKeys
474
+ > &
475
+ RootOwnProps<F>;
476
+
477
+ /** State exposed by the `DateString` component. */
478
+ export type DateStringState<F extends ValueFormat = ValueFormat> = {
479
+ root: RootState<F>;
480
+ month: number;
481
+ year: number;
482
+ day: number;
483
+ };
484
+
485
+ /** Own props for the `DateString` component. */
486
+ export interface DateStringOwnProps {
487
+ /** BCP 47 locale(s) for date formatting. Falls back to the Root `locale`. */
488
+ locales?: string | string[];
489
+ /** `Intl.DateTimeFormat` options for customizing the output. */
490
+ options?: Intl.DateTimeFormatOptions;
491
+ }
492
+
493
+ /** Full props for the `DateString` component. */
494
+ export type DateStringProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
495
+ "span",
496
+ DateStringState<F>
497
+ > &
498
+ DateStringOwnProps;
499
+
500
+ /** State exposed by the `TimeString` component. */
501
+ export type TimeStringState<F extends ValueFormat = ValueFormat> = {
502
+ root: RootState<F>;
503
+ hour: number;
504
+ minute: number;
505
+ second: number;
506
+ };
507
+
508
+ /** Own props for the `TimeString` component. */
509
+ export interface TimeStringOwnProps {
510
+ /** BCP 47 locale(s) for time formatting. Falls back to the Root `locale`. */
511
+ locales?: string | string[];
512
+ /** `Intl.DateTimeFormat` options for customizing the output. */
513
+ options?: Intl.DateTimeFormatOptions;
514
+ }
515
+
516
+ /** Full props for the `TimeString` component. */
517
+ export type TimeStringProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
518
+ "span",
519
+ TimeStringState<F>
520
+ > &
521
+ TimeStringOwnProps;
522
+
523
+ /** State exposed by the `MonthYearString` component. */
524
+ export type MonthYearStringState<F extends ValueFormat = ValueFormat> = {
525
+ root: RootState<F>;
526
+ month: number;
527
+ year: number;
528
+ };
529
+
530
+ /** Own props for the `MonthYearString` component. */
531
+ export interface MonthYearStringOwnProps {
532
+ /** BCP 47 locale(s) for month/year formatting. Falls back to the Root `locale`. */
533
+ locales?: string | string[];
534
+ /** `Intl.DateTimeFormat` options for customizing the output. */
535
+ options?: Intl.DateTimeFormatOptions;
536
+ /** Which visible month to display (0-based). @default 0 */
537
+ monthIndex?: number;
538
+ }
539
+
540
+ /** Full props for the `MonthYearString` component. */
541
+ export type MonthYearStringProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
542
+ "span",
543
+ MonthYearStringState<F>
544
+ > &
545
+ MonthYearStringOwnProps;
546
+
547
+ /** State exposed by `PrevMonthButton` and `NextMonthButton`. */
548
+ export type NavButtonState<F extends ValueFormat = ValueFormat> = {
549
+ root: RootState<F>;
550
+ direction: "next" | "prev";
551
+ disabled: boolean;
552
+ target: Temporal.PlainYearMonth;
553
+ };
554
+
555
+ /** Full props for the `PrevMonthButton` component. */
556
+ export type PrevMonthButtonProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
557
+ "button",
558
+ NavButtonState<F>
559
+ >;
560
+ /** Full props for the `NextMonthButton` component. */
561
+ export type NextMonthButtonProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
562
+ "button",
563
+ NavButtonState<F>
564
+ >;
565
+
566
+ /** State exposed by the `GridHeaderCell` component. */
567
+ export type GridHeaderCellState<F extends ValueFormat = ValueFormat> = {
568
+ root: RootState<F>;
569
+ dayOfWeek: number;
570
+ long: string;
571
+ short: string;
572
+ narrow: string;
573
+ };
574
+
575
+ /** Own props for the `GridHeaderCell` component. */
576
+ export interface GridHeaderCellOwnProps {
577
+ /** 0-based column index. When omitted, all 7 weekday headers are rendered. */
578
+ index?: number;
579
+ }
580
+
581
+ /** Full props for the `GridHeaderCell` component. */
582
+ export type GridHeaderCellProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
583
+ "th",
584
+ GridHeaderCellState<F>
585
+ > &
586
+ GridHeaderCellOwnProps;
587
+
588
+ /** State exposed by the `GridHeader` component. */
589
+ export type GridHeaderState<F extends ValueFormat = ValueFormat> = {
590
+ root: RootState<F>;
591
+ };
592
+
593
+ /** Full props for the `GridHeader` component. */
594
+ export type GridHeaderProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
595
+ "thead",
596
+ GridHeaderState<F>
597
+ >;
598
+
599
+ /** State exposed by the `GridBody` component. */
600
+ export type GridBodyState<F extends ValueFormat = ValueFormat> = {
601
+ root: RootState<F>;
602
+ };
603
+
604
+ /** Full props for the `GridBody` component. */
605
+ export type GridBodyProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
606
+ "tbody",
607
+ GridBodyState<F>
608
+ >;
609
+
610
+ /** State exposed by the `Grid` component. */
611
+ export type GridState<F extends ValueFormat = ValueFormat> = {
612
+ root: RootState<F>;
613
+ month: number;
614
+ year: number;
615
+ orientation: GridOrientation;
616
+ };
617
+
618
+ /** Own props for the `Grid` component. */
619
+ export interface GridOwnProps {
620
+ /** Interaction mode. Currently only `"grid"` is supported. */
621
+ mode?: "grid";
622
+ /** Layout direction for keyboard navigation. @default "horizontal" */
623
+ orientation?: GridOrientation;
624
+ /** When `true`, the grid auto-focuses the tab-target cell on mount. */
625
+ autoFocus?: boolean;
626
+ /** Which visible month this grid displays (0-based). @default 0 */
627
+ monthIndex?: number;
628
+ }
629
+
630
+ /** Full props for the `Grid` component. */
631
+ export type GridProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
632
+ "table",
633
+ GridState<F>
634
+ > &
635
+ GridOwnProps;
636
+
637
+ /** State exposed by the `WeekTemplate` component. */
638
+ export type WeekTemplateState<F extends ValueFormat = ValueFormat> = {
639
+ root: RootState<F>;
640
+ weekIndex: number;
641
+ /** 1-based CSS grid row index for this week row (WeeksView only, undefined in MonthView). */
642
+ gridRowIndex: number | undefined;
643
+ };
644
+
645
+ /** Full props for the `WeekTemplate` component. */
646
+ export type WeekTemplateProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
647
+ "tr",
648
+ WeekTemplateState<F>
649
+ >;
650
+
651
+ /** State exposed by the `DayCellTemplate` component. */
652
+ export type DayCellTemplateState<F extends ValueFormat = ValueFormat> = {
653
+ root: RootState<F>;
654
+ date: Temporal.PlainDate;
655
+ columnIndex: number;
656
+ orientation: GridOrientation;
657
+ selected: boolean;
658
+ today: boolean;
659
+ disabled: boolean;
660
+ outsideMonth: boolean;
661
+ hidden: boolean;
662
+ focused: boolean;
663
+ rangeStart: boolean;
664
+ rangeEnd: boolean;
665
+ rangeBoundary: boolean;
666
+ /** Whether this cell is within the committed range. */
667
+ inRange: boolean;
668
+ /** 0-based index of this cell within the committed range, or `false` if not in range. */
669
+ rangeIndex: number | false;
670
+ /** Total number of days in the committed range, or `false` if not in range. */
671
+ rangeLength: number | false;
672
+ /** Whether the committed range has a defined start boundary. */
673
+ rangeHasStart: boolean;
674
+ /** Whether the committed range has a defined end boundary. */
675
+ rangeHasEnd: boolean;
676
+ /** Whether this cell is the start of the hover preview range. */
677
+ rangePreviewStart: boolean;
678
+ /** Whether this cell is the end of the hover preview range. */
679
+ rangePreviewEnd: boolean;
680
+ /** Whether this cell is a boundary of the hover preview range. */
681
+ rangePreviewBoundary: boolean;
682
+ /** Whether this cell is within the hover preview range. */
683
+ rangePreviewInRange: boolean;
684
+ /** 0-based index of this cell within the preview range, or `false` if not in preview range. */
685
+ rangePreviewIndex: number | false;
686
+ /** Total number of days in the preview range, or `false` if not in preview range. */
687
+ rangePreviewLength: number | false;
688
+ /** Whether the preview range has a defined start boundary. */
689
+ rangePreviewHasStart: boolean;
690
+ /** Whether the preview range has a defined end boundary. */
691
+ rangePreviewHasEnd: boolean;
692
+ };
693
+
694
+ /** State exposed by the `DayButton` component (same as `DayCellTemplateState`). */
695
+ export type DayButtonState<F extends ValueFormat = ValueFormat> = DayCellTemplateState<F>;
696
+
697
+ /** Own props for the `DayCellTemplate` component. */
698
+ export interface DayCellTemplateOwnProps {
699
+ /** Explicit date to render. When omitted, iterates over the current week's days. */
700
+ date?: Temporal.PlainDate;
701
+ }
702
+
703
+ /** Full props for the `DayCellTemplate` component. */
704
+ export type DayCellTemplateProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
705
+ "td",
706
+ DayCellTemplateState<F>
707
+ > &
708
+ DayCellTemplateOwnProps;
709
+
710
+ /** Own props for the `DayButton` component. */
711
+ export interface DayButtonOwnProps {
712
+ /** Explicit date for a standalone `DayButton`. Normally inherited from `DayCellTemplate`. */
713
+ date?: Temporal.PlainDate;
714
+ }
715
+
716
+ /** Full props for the `DayButton` component. */
717
+ export type DayButtonProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
718
+ "button",
719
+ DayButtonState<F>
720
+ > &
721
+ DayButtonOwnProps;
722
+
723
+ /** State exposed by the `RangeSelected` component. */
724
+ export type RangeSelectedState<F extends ValueFormat = ValueFormat> = {
725
+ root: RootState<F>;
726
+ active: boolean;
727
+ weekIndex: number;
728
+ startIndex: number;
729
+ endIndex: number;
730
+ startDate: string;
731
+ endDate: string;
732
+ extendsBefore: boolean;
733
+ extendsAfter: boolean;
734
+ hasStart: boolean;
735
+ hasEnd: boolean;
736
+ orientation: "horizontal" | "vertical";
737
+ };
738
+
739
+ /** Full props for the `RangeSelected` component. */
740
+ export type RangeSelectedProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
741
+ "td",
742
+ RangeSelectedState<F>
743
+ >;
744
+
745
+ /** State exposed by the `RangePreview` component (same shape as `RangeSelectedState`). */
746
+ export type RangePreviewState<F extends ValueFormat = ValueFormat> = RangeSelectedState<F>;
747
+
748
+ /** Full props for the `RangePreview` component (same shape as `RangeSelectedProps`). */
749
+ export type RangePreviewProps<F extends ValueFormat = ValueFormat> = RangeSelectedProps<F>;
750
+
751
+ /** Which end of a range the drag handle controls. */
752
+ export type DragHandleEdge = "start" | "end";
753
+
754
+ /** State exposed by the `RangeDragHandle` components. */
755
+ export type DragHandleState<F extends ValueFormat = ValueFormat> = {
756
+ root: RootState<F>;
757
+ active: boolean;
758
+ dragging: boolean;
759
+ edge: DragHandleEdge;
760
+ orientation: "horizontal" | "vertical";
761
+ };
762
+
763
+ /** Own props for the `RangeDragHandle` component. */
764
+ export interface DragHandleOwnProps {
765
+ /** Whether this handle is currently being dragged. */
766
+ dragging?: boolean;
767
+ /** Which boundary this handle controls. */
768
+ edge: DragHandleEdge;
769
+ }
770
+
771
+ /** Full props for the `RangeDragHandle` component. */
772
+ export type RangeDragHandleProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
773
+ "span",
774
+ DragHandleState<F>
775
+ > &
776
+ DragHandleOwnProps;
777
+
778
+ /** Props for `RangeStartDragHandle` (edge is fixed to `"start"`). */
779
+ export type RangeStartDragHandleProps<F extends ValueFormat = ValueFormat> = Omit<
780
+ RangeDragHandleProps<F>,
781
+ "edge"
782
+ >;
783
+
784
+ /** Props for `RangeEndDragHandle` (edge is fixed to `"end"`). */
785
+ export type RangeEndDragHandleProps<F extends ValueFormat = ValueFormat> = Omit<
786
+ RangeDragHandleProps<F>,
787
+ "edge"
788
+ >;
789
+
790
+ /** State exposed by the `WeekNumberCell` component. */
791
+ export type WeekNumberCellState<F extends ValueFormat = ValueFormat> = {
792
+ root: RootState<F>;
793
+ weekNumber: number;
794
+ };
795
+
796
+ /** Full props for the `WeekNumberCell` component. */
797
+ export type WeekNumberCellProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
798
+ "td",
799
+ WeekNumberCellState<F>
800
+ >;
801
+
802
+ /** State exposed by the `WeekNumberHeader` component. */
803
+ export type WeekNumberHeaderState<F extends ValueFormat = ValueFormat> = {
804
+ root: RootState<F>;
805
+ };
806
+
807
+ /** Full props for the `WeekNumberHeader` component. */
808
+ export type WeekNumberHeaderProps<F extends ValueFormat = ValueFormat> = useRender.ComponentProps<
809
+ "th",
810
+ WeekNumberHeaderState<F>
811
+ >;
812
+
813
+ /** Root props pre-narrowed to a specific format. */
814
+ export type TypedRootProps<F extends ValueFormat> = Omit<RootProps<F>, "format" | "temporal">;