@calcifer-design/ui 0.4.0 → 0.6.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 (133) hide show
  1. package/dist/components/Breadcrumb/Breadcrumb.d.ts +24 -0
  2. package/dist/components/Breadcrumb/Breadcrumb.js +48 -0
  3. package/dist/components/Breadcrumb/Breadcrumb.module.js +10 -0
  4. package/dist/components/Breadcrumb/Breadcrumb_module.css +49 -0
  5. package/dist/components/CardList/CardList.d.ts +30 -0
  6. package/dist/components/CardList/CardList.js +35 -0
  7. package/dist/components/CardList/CardList.module.js +7 -0
  8. package/dist/components/CardList/CardList_module.css +20 -0
  9. package/dist/components/DataGrid/DataGrid.d.ts +3 -0
  10. package/dist/components/DataGrid/DataGrid.js +436 -0
  11. package/dist/components/DataGrid/DataGrid.module.js +36 -0
  12. package/dist/components/DataGrid/DataGrid_module.css +367 -0
  13. package/dist/components/DataGrid/GridCardHeader.d.ts +16 -0
  14. package/dist/components/DataGrid/GridCardHeader.js +40 -0
  15. package/dist/components/DataGrid/GridCheckbox.d.ts +15 -0
  16. package/dist/components/DataGrid/GridCheckbox.js +25 -0
  17. package/dist/components/DataGrid/GridHeaderCell.d.ts +14 -0
  18. package/dist/components/DataGrid/GridHeaderCell.js +29 -0
  19. package/dist/components/DataGrid/GridHeaderRow.d.ts +35 -0
  20. package/dist/components/DataGrid/GridHeaderRow.js +56 -0
  21. package/dist/components/DataGrid/GridRow.d.ts +69 -0
  22. package/dist/components/DataGrid/GridRow.js +139 -0
  23. package/dist/components/DataGrid/GridStateRows.d.ts +24 -0
  24. package/dist/components/DataGrid/GridStateRows.js +59 -0
  25. package/dist/components/DataGrid/columns.d.ts +40 -0
  26. package/dist/components/DataGrid/columns.js +37 -0
  27. package/dist/components/DataGrid/labels.d.ts +20 -0
  28. package/dist/components/DataGrid/labels.js +25 -0
  29. package/dist/components/DataGrid/types.d.ts +88 -0
  30. package/dist/components/DataGrid/types.js +0 -0
  31. package/dist/components/DataGrid/useGridEntries.d.ts +17 -0
  32. package/dist/components/DataGrid/useGridEntries.js +40 -0
  33. package/dist/components/DataGrid/useGridHighlight.d.ts +16 -0
  34. package/dist/components/DataGrid/useGridHighlight.js +24 -0
  35. package/dist/components/DataGrid/useGridKeyboard.d.ts +50 -0
  36. package/dist/components/DataGrid/useGridKeyboard.js +242 -0
  37. package/dist/components/DataGrid/useGridMetrics.d.ts +13 -0
  38. package/dist/components/DataGrid/useGridMetrics.js +35 -0
  39. package/dist/components/DataGrid/useLatest.d.ts +7 -0
  40. package/dist/components/DataGrid/useLatest.js +9 -0
  41. package/dist/components/DataGrid/useLoadMore.d.ts +30 -0
  42. package/dist/components/DataGrid/useLoadMore.js +39 -0
  43. package/dist/components/DataGrid/useRowExpansion.d.ts +14 -0
  44. package/dist/components/DataGrid/useRowExpansion.js +21 -0
  45. package/dist/components/DataGrid/useRowSelection.d.ts +43 -0
  46. package/dist/components/DataGrid/useRowSelection.js +107 -0
  47. package/dist/components/DatePicker/Calendar.d.ts +19 -0
  48. package/dist/components/DatePicker/Calendar.js +207 -0
  49. package/dist/components/DatePicker/DatePicker.d.ts +72 -0
  50. package/dist/components/DatePicker/DatePicker.js +116 -0
  51. package/dist/components/DatePicker/DatePicker.module.js +14 -0
  52. package/dist/components/DatePicker/DatePicker_module.css +112 -0
  53. package/dist/components/DatePicker/calendarDate.d.ts +46 -0
  54. package/dist/components/DatePicker/calendarDate.js +117 -0
  55. package/dist/components/Descriptions/Descriptions.d.ts +25 -0
  56. package/dist/components/Descriptions/Descriptions.js +44 -0
  57. package/dist/components/Descriptions/Descriptions.module.js +8 -0
  58. package/dist/components/Descriptions/Descriptions_module.css +47 -0
  59. package/dist/components/Field/Field.d.ts +1 -1
  60. package/dist/components/Field/Field.js +7 -1
  61. package/dist/components/Field/PickerField.d.ts +41 -0
  62. package/dist/components/Field/PickerField.js +115 -0
  63. package/dist/components/Field/PickerField.module.js +8 -0
  64. package/dist/components/Field/PickerField_module.css +36 -0
  65. package/dist/components/FilterBar/FilterBar.d.ts +55 -0
  66. package/dist/components/FilterBar/FilterBar.js +138 -0
  67. package/dist/components/FilterBar/FilterBar.module.js +13 -0
  68. package/dist/components/FilterBar/FilterBar_module.css +98 -0
  69. package/dist/components/Form/Form.d.ts +48 -0
  70. package/dist/components/Form/Form.js +38 -0
  71. package/dist/components/Form/Form.module.js +5 -0
  72. package/dist/components/Form/FormContext.d.ts +15 -0
  73. package/dist/components/Form/FormContext.js +20 -0
  74. package/dist/components/Form/Form_module.css +6 -0
  75. package/dist/components/PageShell/PageShell.d.ts +27 -0
  76. package/dist/components/PageShell/PageShell.js +35 -0
  77. package/dist/components/PageShell/PageShell.module.js +9 -0
  78. package/dist/components/PageShell/PageShell_module.css +56 -0
  79. package/dist/components/Segmented/Segmented.d.ts +49 -0
  80. package/dist/components/Segmented/Segmented.js +55 -0
  81. package/dist/components/Segmented/Segmented.module.js +7 -0
  82. package/dist/components/Segmented/Segmented_module.css +75 -0
  83. package/dist/components/Steps/Steps.d.ts +30 -0
  84. package/dist/components/Steps/Steps.js +63 -0
  85. package/dist/components/Steps/Steps.module.js +10 -0
  86. package/dist/components/Steps/Steps_module.css +126 -0
  87. package/dist/components/TextArea/TextArea.d.ts +16 -0
  88. package/dist/components/TextArea/TextArea.js +28 -0
  89. package/dist/components/TextArea/TextArea.module.js +5 -0
  90. package/dist/components/TextArea/TextArea_module.css +12 -0
  91. package/dist/components/TimePicker/TimePicker.d.ts +19 -0
  92. package/dist/components/TimePicker/TimePicker.js +17 -0
  93. package/dist/components/Timeline/Timeline.d.ts +39 -0
  94. package/dist/components/Timeline/Timeline.js +109 -0
  95. package/dist/components/Timeline/Timeline.module.js +12 -0
  96. package/dist/components/Timeline/Timeline_module.css +99 -0
  97. package/dist/components/Toolbar/InsideToolbarContext.d.ts +6 -0
  98. package/dist/components/Toolbar/InsideToolbarContext.js +3 -0
  99. package/dist/components/Toolbar/Toolbar.d.ts +46 -0
  100. package/dist/components/Toolbar/Toolbar.js +43 -0
  101. package/dist/components/Toolbar/Toolbar.module.js +7 -0
  102. package/dist/components/Toolbar/Toolbar_module.css +26 -0
  103. package/dist/components/Tree/Tree.d.ts +81 -0
  104. package/dist/components/Tree/Tree.js +232 -0
  105. package/dist/components/Tree/Tree.module.js +12 -0
  106. package/dist/components/Tree/Tree_module.css +124 -0
  107. package/dist/components/Tree/treeIndex.d.ts +23 -0
  108. package/dist/components/Tree/treeIndex.js +33 -0
  109. package/dist/components/TreeSelect/TreeSelect.d.ts +61 -0
  110. package/dist/components/TreeSelect/TreeSelect.js +117 -0
  111. package/dist/components/TreeSelect/TreeSelect.module.js +7 -0
  112. package/dist/components/TreeSelect/TreeSelect_module.css +22 -0
  113. package/dist/components/Upload/Upload.d.ts +66 -0
  114. package/dist/components/Upload/Upload.js +287 -0
  115. package/dist/components/Upload/Upload.module.js +12 -0
  116. package/dist/components/Upload/Upload_module.css +96 -0
  117. package/dist/components/ViewField/ViewField.d.ts +26 -0
  118. package/dist/components/ViewField/ViewField.js +29 -0
  119. package/dist/components/ViewField/ViewField.module.js +6 -0
  120. package/dist/components/ViewField/ViewField_module.css +17 -0
  121. package/dist/hooks/useFormReset.d.ts +10 -0
  122. package/dist/hooks/useFormReset.js +34 -0
  123. package/dist/icons/CalendarIcon.d.ts +2 -0
  124. package/dist/icons/CalendarIcon.js +26 -0
  125. package/dist/icons/ChevronRightIcon.d.ts +6 -0
  126. package/dist/icons/ChevronRightIcon.js +17 -0
  127. package/dist/icons/RefreshIcon.d.ts +6 -0
  128. package/dist/icons/RefreshIcon.js +22 -0
  129. package/dist/index.d.ts +39 -0
  130. package/dist/index.js +19 -0
  131. package/dist/styles/pair.module.js +6 -0
  132. package/dist/styles/pair_module.css +18 -0
  133. package/package.json +4 -3
@@ -0,0 +1,207 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { ChevronDownIcon } from "../../icons/ChevronDownIcon.js";
4
+ import { IconButton } from "../IconButton/IconButton.js";
5
+ import { addDays, addMonths, dateFormatter, endOfWeek, firstOfMonth, isDateUnavailable, startOfWeek, todayIn, weeksOfMonth } from "./calendarDate.js";
6
+ import DatePicker_module from "./DatePicker.module.js";
7
+ const A_SUNDAY = '2023-01-01';
8
+ const SEARCH_LIMIT_IN_DAYS = 800;
9
+ function monthOf(date) {
10
+ return date.slice(0, 7);
11
+ }
12
+ function readingDirectionOf(element) {
13
+ return getComputedStyle(element).direction;
14
+ }
15
+ function Calendar({ gridRef, chosen, min, max, isDateDisabled, locale, weekStartsOn, previousMonthLabel, nextMonthLabel, onSelect }) {
16
+ const monthId = useId();
17
+ const [today] = useState(()=>todayIn(new Date()));
18
+ const gridHasFocus = useRef(false);
19
+ const headerRef = useRef(null);
20
+ const isUnavailable = (date)=>isDateUnavailable(date, {
21
+ min,
22
+ max,
23
+ isDateDisabled
24
+ });
25
+ const isReachable = (date)=>(null === min || monthOf(date) >= monthOf(min)) && (null === max || monthOf(date) <= monthOf(max));
26
+ const firstAvailableFrom = (start)=>{
27
+ let candidate = start;
28
+ for(let step = 0; step < SEARCH_LIMIT_IN_DAYS && isReachable(candidate); step += 1){
29
+ if (!isUnavailable(candidate)) return candidate;
30
+ candidate = addDays(candidate, 1);
31
+ }
32
+ return start;
33
+ };
34
+ const restingDate = ()=>{
35
+ if (null !== chosen && isReachable(chosen)) return chosen;
36
+ if (!isUnavailable(today)) return today;
37
+ if (null !== min && today < min) return firstAvailableFrom(min);
38
+ if (null !== max && today > max) {
39
+ const monthStart = firstOfMonth(max);
40
+ return firstAvailableFrom(null !== min && min > monthStart ? min : monthStart);
41
+ }
42
+ return firstAvailableFrom(firstOfMonth(today));
43
+ };
44
+ const restingDateIn = (month)=>{
45
+ if (null !== chosen && monthOf(chosen) === monthOf(month) && !isUnavailable(chosen)) return chosen;
46
+ if (monthOf(today) === monthOf(month) && !isUnavailable(today)) return today;
47
+ const available = firstAvailableFrom(firstOfMonth(month));
48
+ return monthOf(available) === monthOf(month) ? available : firstOfMonth(month);
49
+ };
50
+ const [movedDate, setMovedDate] = useState(null);
51
+ const [lastChosen, setLastChosen] = useState(chosen);
52
+ if (chosen !== lastChosen) {
53
+ setLastChosen(chosen);
54
+ setMovedDate(null);
55
+ }
56
+ const activeDate = null !== movedDate && isReachable(movedDate) ? movedDate : restingDate();
57
+ useLayoutEffect(()=>{
58
+ if (gridHasFocus.current) gridRef.current?.querySelector(`[data-date="${activeDate}"]`)?.focus();
59
+ }, [
60
+ activeDate,
61
+ gridRef
62
+ ]);
63
+ useLayoutEffect(()=>{
64
+ if (null !== headerRef.current) headerRef.current.dataset.direction = readingDirectionOf(headerRef.current);
65
+ });
66
+ const formatters = useMemo(()=>({
67
+ month: dateFormatter(locale, {
68
+ month: 'long',
69
+ year: 'numeric'
70
+ }),
71
+ day: dateFormatter(locale, {
72
+ day: 'numeric'
73
+ }),
74
+ fullDate: dateFormatter(locale, {
75
+ dateStyle: 'full'
76
+ }),
77
+ shortWeekday: dateFormatter(locale, {
78
+ weekday: 'short'
79
+ }),
80
+ longWeekday: dateFormatter(locale, {
81
+ weekday: 'long'
82
+ })
83
+ }), [
84
+ locale
85
+ ]);
86
+ const moveTo = (target)=>{
87
+ if (isReachable(target)) setMovedDate(target);
88
+ };
89
+ const handleKeyDown = (event)=>{
90
+ const inRightToLeft = 'rtl' === readingDirectionOf(event.currentTarget);
91
+ const monthStep = event.shiftKey ? 12 : 1;
92
+ const targets = {
93
+ ArrowLeft: ()=>addDays(activeDate, inRightToLeft ? 1 : -1),
94
+ ArrowRight: ()=>addDays(activeDate, inRightToLeft ? -1 : 1),
95
+ ArrowUp: ()=>addDays(activeDate, -7),
96
+ ArrowDown: ()=>addDays(activeDate, 7),
97
+ Home: ()=>startOfWeek(activeDate, weekStartsOn),
98
+ End: ()=>endOfWeek(activeDate, weekStartsOn),
99
+ PageUp: ()=>addMonths(activeDate, -monthStep),
100
+ PageDown: ()=>addMonths(activeDate, monthStep)
101
+ };
102
+ const target = targets[event.key];
103
+ if (target) {
104
+ event.preventDefault();
105
+ moveTo(target());
106
+ } else if ('Enter' === event.key || ' ' === event.key) {
107
+ event.preventDefault();
108
+ if (!isUnavailable(activeDate)) onSelect(activeDate);
109
+ }
110
+ };
111
+ const previousMonth = addMonths(firstOfMonth(activeDate), -1);
112
+ const nextMonth = addMonths(firstOfMonth(activeDate), 1);
113
+ const hasPreviousMonth = isReachable(previousMonth);
114
+ const hasNextMonth = isReachable(nextMonth);
115
+ return /*#__PURE__*/ jsxs(Fragment, {
116
+ children: [
117
+ /*#__PURE__*/ jsxs("div", {
118
+ ref: headerRef,
119
+ className: DatePicker_module.header,
120
+ children: [
121
+ /*#__PURE__*/ jsx(IconButton, {
122
+ className: DatePicker_module.previous,
123
+ size: "sm",
124
+ label: previousMonthLabel,
125
+ "aria-disabled": hasPreviousMonth ? void 0 : true,
126
+ onClick: ()=>{
127
+ if (hasPreviousMonth) setMovedDate(restingDateIn(previousMonth));
128
+ },
129
+ children: /*#__PURE__*/ jsx(ChevronDownIcon, {})
130
+ }),
131
+ /*#__PURE__*/ jsx("div", {
132
+ id: monthId,
133
+ className: DatePicker_module.month,
134
+ "aria-live": "polite",
135
+ "aria-atomic": "true",
136
+ children: formatters.month.format(activeDate)
137
+ }),
138
+ /*#__PURE__*/ jsx(IconButton, {
139
+ className: DatePicker_module.next,
140
+ size: "sm",
141
+ label: nextMonthLabel,
142
+ "aria-disabled": hasNextMonth ? void 0 : true,
143
+ onClick: ()=>{
144
+ if (hasNextMonth) setMovedDate(restingDateIn(nextMonth));
145
+ },
146
+ children: /*#__PURE__*/ jsx(ChevronDownIcon, {})
147
+ })
148
+ ]
149
+ }),
150
+ /*#__PURE__*/ jsx("div", {
151
+ className: DatePicker_module.gridSlot,
152
+ children: /*#__PURE__*/ jsxs("table", {
153
+ ref: gridRef,
154
+ role: "grid",
155
+ className: DatePicker_module.grid,
156
+ "aria-labelledby": monthId,
157
+ onKeyDown: handleKeyDown,
158
+ onFocus: ()=>{
159
+ gridHasFocus.current = true;
160
+ },
161
+ onBlur: (event)=>{
162
+ gridHasFocus.current = event.currentTarget.contains(event.relatedTarget);
163
+ },
164
+ children: [
165
+ /*#__PURE__*/ jsx("thead", {
166
+ children: /*#__PURE__*/ jsx("tr", {
167
+ children: Array.from({
168
+ length: 7
169
+ }, (_unused, offset)=>{
170
+ const weekday = addDays(A_SUNDAY, (weekStartsOn + offset) % 7);
171
+ return /*#__PURE__*/ jsx("th", {
172
+ scope: "col",
173
+ className: DatePicker_module.weekday,
174
+ "aria-label": formatters.longWeekday.format(weekday),
175
+ children: formatters.shortWeekday.format(weekday)
176
+ }, weekday);
177
+ })
178
+ })
179
+ }),
180
+ /*#__PURE__*/ jsx("tbody", {
181
+ children: weeksOfMonth(activeDate, weekStartsOn).map((week, weekIndex)=>/*#__PURE__*/ jsx("tr", {
182
+ children: week.map((date, dayIndex)=>null === date ? /*#__PURE__*/ jsx("td", {
183
+ role: "gridcell"
184
+ }, dayIndex) : /*#__PURE__*/ jsx("td", {
185
+ role: "gridcell",
186
+ className: DatePicker_module.day,
187
+ "data-date": date,
188
+ tabIndex: date === activeDate ? 0 : -1,
189
+ "aria-label": formatters.fullDate.format(date),
190
+ "aria-selected": date === chosen,
191
+ "aria-current": date === today ? 'date' : void 0,
192
+ "aria-disabled": isUnavailable(date) ? true : void 0,
193
+ onClick: ()=>{
194
+ if (isUnavailable(date)) setMovedDate(date);
195
+ else onSelect(date);
196
+ },
197
+ children: formatters.day.format(date)
198
+ }, date))
199
+ }, weekIndex))
200
+ })
201
+ ]
202
+ })
203
+ })
204
+ ]
205
+ });
206
+ }
207
+ export { Calendar };
@@ -0,0 +1,72 @@
1
+ import { type ReactNode } from 'react';
2
+ import type { FieldFrameProps } from '../Field/Field.js';
3
+ export interface DatePickerLabels {
4
+ /** The month button's name. */
5
+ previousMonth: string;
6
+ nextMonth: string;
7
+ /** The button that closes the calendar without choosing. */
8
+ close: string;
9
+ /** Joins the trigger's accessible name when the field is `required`. */
10
+ required: string;
11
+ /** Shown when `Form` submits a `required` picker with nothing chosen. */
12
+ requiredMessage: string;
13
+ /** Shown when `Form` submits a date that `min`, `max` or `isDateDisabled` refuses. */
14
+ unavailableMessage: string;
15
+ /** The clear button's name. Defaults to "Clear" and the field's own label. */
16
+ clear: string;
17
+ }
18
+ export interface DatePickerProps extends FieldFrameProps {
19
+ /** The visible label, and the start of the trigger's accessible name. */
20
+ label: string;
21
+ /** Sits under the trigger and joins its `aria-describedby`. */
22
+ description?: ReactNode;
23
+ /**
24
+ * Draws the required mark and adds the word to the trigger's name. `Form` refuses to submit while
25
+ * nothing is chosen, with `labels.requiredMessage` on the frame. A plain `<form>` is not blocked:
26
+ * the value travels in a hidden input, which has no constraints, so the app validates.
27
+ */
28
+ required?: boolean;
29
+ /**
30
+ * Controlled: `YYYY-MM-DD`, or `null` for nothing chosen. A string that does not name a real date
31
+ * (`''`, `2026-02-30`) reads as nothing chosen, and nothing is reported for it. A real date
32
+ * outside `min` and `max` or refused by `isDateDisabled` is still shown, because it is the app's
33
+ * value, and `Form` refuses to submit it, with `labels.unavailableMessage` on the frame. That
34
+ * covers a default value too, and a date a moved `min` has overtaken. A plain `<form>` is not
35
+ * blocked, for the reason `required` gives.
36
+ */
37
+ value?: string | null;
38
+ /**
39
+ * Uncontrolled: the first value, and the one a native reset of the surrounding form goes back to,
40
+ * with `onValueChange` told. A controlled `value` stays through a reset, as the parent's to change.
41
+ */
42
+ defaultValue?: string | null;
43
+ /** The chosen date or `null` once cleared, in one argument, and only for a real change. */
44
+ onValueChange?: (value: string | null) => void;
45
+ /** Called when focus leaves the trigger, for a form library's "touched". */
46
+ onBlur?: () => void;
47
+ /** The earliest date that can be chosen. Months entirely before it cannot be reached. */
48
+ min?: string;
49
+ /** The latest date that can be chosen. Months entirely after it cannot be reached. */
50
+ max?: string;
51
+ /** Marks more dates unavailable. They can still be reached by arrow key and read out. */
52
+ isDateDisabled?: (date: string) => boolean;
53
+ /**
54
+ * A BCP 47 tag for the month and day names, the digits and the calendar's direction. Left out,
55
+ * the browser's own; a tag it cannot read counts as left out. That default can differ between a
56
+ * server's render and the browser's, which passing `locale` avoids.
57
+ */
58
+ locale?: string;
59
+ /** The first column, 0 for Sunday to 6 for Saturday. Left out, what `locale` says. */
60
+ weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
61
+ /** Shows a button that clears the date, while there is one. */
62
+ clearable?: boolean;
63
+ /** Shown on the trigger while nothing is chosen. */
64
+ placeholder?: string;
65
+ /** The words the control says itself, for an app that is not in English. */
66
+ labels?: Partial<DatePickerLabels>;
67
+ }
68
+ /**
69
+ * A date field: a button showing the formatted date opens the WAI-ARIA date picker dialog, whose
70
+ * grid is ours because Base UI has no public calendar. Submits `YYYY-MM-DD` through a hidden input.
71
+ */
72
+ export declare function DatePicker({ label, name, description, error, required, disabled, value, defaultValue, onValueChange, onBlur, min, max, isDateDisabled, locale, weekStartsOn, clearable, placeholder, labels, }: DatePickerProps): import("react").JSX.Element;
@@ -0,0 +1,116 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { Popover } from "@base-ui/react/popover";
3
+ import { useRef, useState } from "react";
4
+ import { CalendarIcon } from "../../icons/CalendarIcon.js";
5
+ import popup_module from "../../styles/popup.module.js";
6
+ import { Button } from "../Button/Button.js";
7
+ import { PickerField } from "../Field/PickerField.js";
8
+ import { Calendar } from "./Calendar.js";
9
+ import { dateFormatter, directionOf, isDateUnavailable, parseIsoDate, usableLocale, weekStartOf } from "./calendarDate.js";
10
+ import DatePicker_module from "./DatePicker.module.js";
11
+ const DEFAULT_LABELS = {
12
+ previousMonth: 'Previous month',
13
+ nextMonth: 'Next month',
14
+ close: 'Close',
15
+ required: 'required',
16
+ requiredMessage: 'Choose a date.',
17
+ unavailableMessage: 'Choose an available date.'
18
+ };
19
+ function DatePicker({ label, name, description, error, required = false, disabled = false, value, defaultValue, onValueChange, onBlur, min, max, isDateDisabled, locale, weekStartsOn, clearable = false, placeholder = 'Choose a date', labels }) {
20
+ const gridRef = useRef(null);
21
+ const [heldValue, setHeldValue] = useState(()=>parseIsoDate(defaultValue));
22
+ const [open, setOpen] = useState(false);
23
+ if (open && disabled) setOpen(false);
24
+ const chosen = void 0 === value ? heldValue : parseIsoDate(value);
25
+ const words = {
26
+ ...DEFAULT_LABELS,
27
+ clear: `Clear ${label}`,
28
+ ...labels
29
+ };
30
+ const resolvedLocale = usableLocale(locale);
31
+ const firstWeekday = weekStartsOn ?? weekStartOf(resolvedLocale);
32
+ const earliest = parseIsoDate(min);
33
+ const latest = parseIsoDate(max);
34
+ const commit = (nextValue)=>{
35
+ setHeldValue(nextValue);
36
+ if (nextValue !== chosen) onValueChange?.(nextValue);
37
+ };
38
+ return /*#__PURE__*/ jsx(PickerField, {
39
+ label: label,
40
+ name: name,
41
+ description: description,
42
+ error: error,
43
+ required: required,
44
+ disabled: disabled,
45
+ value: chosen,
46
+ valueText: null === chosen ? placeholder : dateFormatter(resolvedLocale, {
47
+ dateStyle: 'medium'
48
+ }).format(chosen),
49
+ icon: /*#__PURE__*/ jsx(CalendarIcon, {}),
50
+ requiredWord: words.required,
51
+ validate: ()=>{
52
+ if (null === chosen) return required ? words.requiredMessage : null;
53
+ return isDateUnavailable(chosen, {
54
+ min: earliest,
55
+ max: latest,
56
+ isDateDisabled
57
+ }) ? words.unavailableMessage : null;
58
+ },
59
+ onReset: ()=>{
60
+ if (void 0 === value) commit(parseIsoDate(defaultValue));
61
+ },
62
+ clearable: clearable,
63
+ clearLabel: words.clear,
64
+ onClear: ()=>commit(null),
65
+ onBlur: onBlur,
66
+ open: open,
67
+ onOpenChange: setOpen,
68
+ modal: "trap-focus",
69
+ children: /*#__PURE__*/ jsx(Popover.Portal, {
70
+ children: /*#__PURE__*/ jsx(Popover.Positioner, {
71
+ className: popup_module.layer,
72
+ align: "start",
73
+ sideOffset: 8,
74
+ children: /*#__PURE__*/ jsxs(Popover.Popup, {
75
+ className: [
76
+ popup_module.surface,
77
+ DatePicker_module.popup
78
+ ].join(' '),
79
+ "data-popup": "popover",
80
+ "aria-label": label,
81
+ "aria-modal": "true",
82
+ dir: void 0 === resolvedLocale ? void 0 : directionOf(resolvedLocale),
83
+ initialFocus: ()=>gridRef.current?.querySelector('[tabindex="0"]') ?? true,
84
+ children: [
85
+ /*#__PURE__*/ jsx(Calendar, {
86
+ gridRef: gridRef,
87
+ chosen: chosen,
88
+ min: earliest,
89
+ max: latest,
90
+ isDateDisabled: isDateDisabled,
91
+ locale: resolvedLocale,
92
+ weekStartsOn: firstWeekday,
93
+ previousMonthLabel: words.previousMonth,
94
+ nextMonthLabel: words.nextMonth,
95
+ onSelect: (date)=>{
96
+ commit(date);
97
+ setOpen(false);
98
+ }
99
+ }),
100
+ /*#__PURE__*/ jsx("div", {
101
+ className: DatePicker_module.footer,
102
+ children: /*#__PURE__*/ jsx(Popover.Close, {
103
+ render: /*#__PURE__*/ jsx(Button, {
104
+ variant: "ghost",
105
+ size: "sm"
106
+ }),
107
+ children: words.close
108
+ })
109
+ })
110
+ ]
111
+ })
112
+ })
113
+ })
114
+ });
115
+ }
116
+ export { DatePicker };
@@ -0,0 +1,14 @@
1
+ import "./DatePicker_module.css";
2
+ const DatePicker_module = {
3
+ popup: "popup-KehYf",
4
+ header: "header-zwN0_",
5
+ month: "month-kmJCd",
6
+ previous: "previous-zWGPB",
7
+ next: "next-caCSG",
8
+ gridSlot: "gridSlot-XSqqc",
9
+ grid: "grid-OEI6m",
10
+ weekday: "weekday-BLI2K",
11
+ day: "day-DOQIC",
12
+ footer: "footer-rvxzg"
13
+ };
14
+ export default DatePicker_module;
@@ -0,0 +1,112 @@
1
+ .popup-KehYf {
2
+ width: 22rem;
3
+ }
4
+
5
+ .header-zwN0_ {
6
+ justify-content: space-between;
7
+ align-items: center;
8
+ gap: var(--space-2);
9
+ display: flex;
10
+ }
11
+
12
+ .month-kmJCd {
13
+ color: var(--color-text);
14
+ font-size: var(--text-md);
15
+ font-weight: 500;
16
+ line-height: var(--leading-snug);
17
+ text-align: center;
18
+ flex: 1;
19
+ }
20
+
21
+ .previous-zWGPB svg {
22
+ transform: rotate(90deg);
23
+ }
24
+
25
+ .next-caCSG svg, .header-zwN0_[data-direction="rtl"] .previous-zWGPB svg {
26
+ transform: rotate(-90deg);
27
+ }
28
+
29
+ .header-zwN0_[data-direction="rtl"] .next-caCSG svg {
30
+ transform: rotate(90deg);
31
+ }
32
+
33
+ .previous-zWGPB[aria-disabled="true"], .next-caCSG[aria-disabled="true"] {
34
+ cursor: not-allowed;
35
+ opacity: .45;
36
+ }
37
+
38
+ .gridSlot-XSqqc {
39
+ min-height: calc(7 * var(--size-touch));
40
+ }
41
+
42
+ .grid-OEI6m {
43
+ border-collapse: separate;
44
+ border-spacing: 0;
45
+ table-layout: fixed;
46
+ width: 100%;
47
+ }
48
+
49
+ .weekday-BLI2K {
50
+ height: var(--size-touch);
51
+ color: var(--color-text-muted);
52
+ font-size: var(--text-sm);
53
+ text-align: center;
54
+ padding: 0;
55
+ font-weight: 500;
56
+ }
57
+
58
+ .day-DOQIC {
59
+ height: var(--size-touch);
60
+ border-radius: var(--radius-md);
61
+ color: var(--color-text);
62
+ font-size: var(--text-md);
63
+ text-align: center;
64
+ cursor: pointer;
65
+ transition-property: background-color, color;
66
+ transition-duration: var(--motion-duration-1);
67
+ transition-timing-function: var(--motion-ease);
68
+ -webkit-tap-highlight-color: transparent;
69
+ padding: 0;
70
+ }
71
+
72
+ @media (hover: hover) {
73
+ .day-DOQIC:hover:not([aria-disabled="true"], [aria-selected="true"]) {
74
+ background: var(--color-surface-2);
75
+ }
76
+ }
77
+
78
+ .day-DOQIC[aria-current="date"] {
79
+ border: 1px solid var(--color-accent);
80
+ font-weight: 600;
81
+ }
82
+
83
+ .day-DOQIC[aria-selected="true"] {
84
+ background: var(--color-accent);
85
+ color: var(--color-accent-text);
86
+ }
87
+
88
+ .day-DOQIC[aria-disabled="true"] {
89
+ cursor: not-allowed;
90
+ opacity: .45;
91
+ text-decoration: line-through;
92
+ }
93
+
94
+ @media (forced-colors: active) {
95
+ .day-DOQIC[aria-selected="true"] {
96
+ forced-color-adjust: none;
97
+ color: highlighttext;
98
+ background: highlight;
99
+ outline-color: canvastext;
100
+ }
101
+
102
+ .day-DOQIC[aria-disabled="true"] {
103
+ opacity: 1;
104
+ color: graytext;
105
+ }
106
+ }
107
+
108
+ .footer-rvxzg {
109
+ justify-content: flex-end;
110
+ display: flex;
111
+ }
112
+
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Calendar arithmetic on `YYYY-MM-DD` strings, which is what `DatePicker` speaks in and which sort
3
+ * correctly as text. A date here is a day on a calendar, not an instant, so every calculation runs
4
+ * on UTC fields, where no day is ever 23 or 25 hours long and no midnight is ever skipped, and
5
+ * `Intl.DateTimeFormat` formats it back with `timeZone: 'UTC'`. The one place the local zone
6
+ * belongs is `todayIn`, because "today" is the user's. `toISOString` appears nowhere: on a local
7
+ * `Date` it is the classic way to shift a value by a day.
8
+ */
9
+ /** The date if `value` names a real one, else `null`: `2026-02-30`, `''` and `'soon'` do not. */
10
+ export declare function parseIsoDate(value: string | null | undefined): string | null;
11
+ /** What makes a date impossible to choose. Bounds are real dates or `null`, as `parseIsoDate` gives. */
12
+ export interface DateAvailability {
13
+ min: string | null;
14
+ max: string | null;
15
+ isDateDisabled: ((date: string) => boolean) | undefined;
16
+ }
17
+ /** The one test of a date against the bounds, for the grid and for validating a chosen value. */
18
+ export declare function isDateUnavailable(date: string, { min, max, isDateDisabled }: DateAvailability): boolean;
19
+ /** The date on the user's own calendar at `now`. */
20
+ export declare function todayIn(now: Date): string;
21
+ export declare function addDays(date: string, amount: number): string;
22
+ export declare function firstOfMonth(date: string): string;
23
+ export declare function lastOfMonth(date: string): string;
24
+ /** Moves whole months, and lands on the last day when the target month is too short. */
25
+ export declare function addMonths(date: string, amount: number): string;
26
+ /** 0 is Sunday, as `Date` and the prop have it. */
27
+ export declare function weekdayOf(date: string): number;
28
+ export declare function startOfWeek(date: string, weekStartsOn: number): string;
29
+ export declare function endOfWeek(date: string, weekStartsOn: number): string;
30
+ /** The month holding `date` as rows of seven, with `null` for the cells outside the month. */
31
+ export declare function weeksOfMonth(date: string, weekStartsOn: number): (string | null)[][];
32
+ /**
33
+ * A `DateTimeFormat` for calendar dates. Keep it the only way a date here becomes text. Always the
34
+ * Gregorian calendar, because that is what the arithmetic above lays out: a locale's own calendar,
35
+ * Persian for `fa-IR` or one named in the tag as `en-US-u-ca-hebrew`, would label those cells with
36
+ * the wrong month. The language and the digits stay the locale's.
37
+ */
38
+ export declare function dateFormatter(locale: string | undefined, options: Intl.DateTimeFormatOptions): {
39
+ format: (date: string) => string;
40
+ };
41
+ /** The locale if the platform can read it, else `undefined`: `''` and `en_US` would throw. */
42
+ export declare function usableLocale(locale: string | undefined): string | undefined;
43
+ /** Worked out from the script because `Intl.Locale`'s own text info is not in every browser. */
44
+ export declare function directionOf(locale: string): 'ltr' | 'rtl';
45
+ /** The locale's first day of the week where the platform knows it, 0 to 6; else Sunday. */
46
+ export declare function weekStartOf(locale: string | undefined): number;