@luxalgo/vela-ui 0.3.0 → 0.4.1

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 (177) hide show
  1. package/CHANGELOG.md +165 -132
  2. package/LICENSE +201 -201
  3. package/NOTICE +28 -28
  4. package/README.md +86 -86
  5. package/cli/engine.mjs +282 -282
  6. package/cli/index.mjs +154 -154
  7. package/dist/button.js +2 -2
  8. package/dist/callout-bubble.js +3 -3
  9. package/dist/checkbox.js +3 -3
  10. package/dist/{chunk-OJ2SEMN6.js → chunk-5A54GODF.js} +2 -2
  11. package/dist/{chunk-UEO6W37Z.js → chunk-7LYWI32I.js} +2 -2
  12. package/dist/{chunk-IOOYDSSK.js → chunk-BIU66EHS.js} +2 -2
  13. package/dist/{chunk-KKS6NEGI.js → chunk-BWSOMG3G.js} +1 -1
  14. package/dist/{chunk-DXDCKZ2M.js → chunk-CZRHHVSB.js} +1 -1
  15. package/dist/{chunk-C3PXY2SW.js → chunk-EDYD5XKJ.js} +9 -0
  16. package/dist/chunk-GUIYFQ27.js +30 -0
  17. package/dist/{chunk-WWHNUKSZ.js → chunk-JEGB72M4.js} +8 -8
  18. package/dist/{chunk-B2EZB5ZG.js → chunk-ODPGOUQT.js} +4 -3
  19. package/dist/{chunk-TBXUF5YX.js → chunk-RH53NQGE.js} +18 -4
  20. package/dist/{chunk-OQXFQMZM.js → chunk-TGJNHUYV.js} +2 -2
  21. package/dist/collapsible.js +2 -2
  22. package/dist/color-picker.js +4 -4
  23. package/dist/context-menu.js +4 -4
  24. package/dist/date-picker.js +1 -1
  25. package/dist/dialog.js +4 -4
  26. package/dist/donut.d.ts +1 -1
  27. package/dist/drawer.js +1 -1
  28. package/dist/dropdown-menu.d.ts +2 -0
  29. package/dist/dropdown-menu.js +4 -4
  30. package/dist/empty.js +1 -1
  31. package/dist/field.js +9 -9
  32. package/dist/{stat.d.ts → figure.d.ts} +9 -9
  33. package/dist/figure.js +41 -0
  34. package/dist/glyph-select.js +4 -4
  35. package/dist/hover-card.js +1 -1
  36. package/dist/icons.js +1 -1
  37. package/dist/index.d.ts +2 -2
  38. package/dist/index.js +1 -1
  39. package/dist/input-group.js +2 -2
  40. package/dist/item.js +1 -1
  41. package/dist/manifest.json +75 -74
  42. package/dist/number-input.js +3 -3
  43. package/dist/popover.js +2 -2
  44. package/dist/select.d.ts +5 -1
  45. package/dist/select.js +5 -5
  46. package/dist/slider.js +1 -1
  47. package/dist/sort-button.js +2 -2
  48. package/dist/switch.js +1 -1
  49. package/dist/tabs.js +2 -2
  50. package/dist/{theme-Ct-q58xz.d.ts → theme-TefB8vtl.d.ts} +2 -2
  51. package/dist/theme.d.ts +2 -2
  52. package/dist/theme.js +1 -1
  53. package/dist/theme.schema.json +30 -30
  54. package/dist/toast.d.ts +2 -2
  55. package/dist/toast.js +2 -2
  56. package/dist/toggle-group.js +2 -2
  57. package/dist/tooltip.js +1 -1
  58. package/dist/zag.d.ts +11 -2
  59. package/dist/zag.js +1 -1
  60. package/docs/theming.md +217 -217
  61. package/docs/what-to-change.md +20 -20
  62. package/docs/writing-a-component.md +250 -250
  63. package/llms.txt +3 -3
  64. package/package.json +90 -90
  65. package/registry/badge.ts +119 -119
  66. package/registry/bar-chart.ts +215 -215
  67. package/registry/button.ts +387 -387
  68. package/registry/callout-bubble.ts +347 -347
  69. package/registry/card.ts +379 -379
  70. package/registry/checkbox.ts +234 -234
  71. package/registry/collapsible.ts +271 -271
  72. package/registry/color-picker.ts +582 -582
  73. package/registry/context-menu.ts +208 -208
  74. package/registry/data-table.ts +215 -215
  75. package/registry/date-picker.ts +483 -483
  76. package/registry/dialog.ts +551 -551
  77. package/registry/donut.ts +145 -145
  78. package/registry/drawer.ts +636 -636
  79. package/registry/dropdown-menu.ts +765 -762
  80. package/registry/empty.ts +91 -91
  81. package/registry/field.ts +584 -584
  82. package/registry/{stat.ts → figure.ts} +96 -96
  83. package/registry/glyph-select.ts +268 -268
  84. package/registry/hover-card.ts +222 -222
  85. package/registry/input-group.ts +229 -229
  86. package/registry/input.ts +181 -181
  87. package/registry/item.ts +376 -376
  88. package/registry/kbd.ts +64 -64
  89. package/registry/line-chart.ts +218 -218
  90. package/registry/month-grid.ts +328 -328
  91. package/registry/number-input.ts +443 -443
  92. package/registry/popover.ts +368 -368
  93. package/registry/scatter-chart.ts +221 -221
  94. package/registry/select.ts +629 -620
  95. package/registry/slider.ts +259 -259
  96. package/registry/sort-button.ts +189 -189
  97. package/registry/sparkline.ts +114 -114
  98. package/registry/switch.ts +205 -205
  99. package/registry/tabs.ts +426 -426
  100. package/registry/text-area.ts +186 -186
  101. package/registry/toast.ts +965 -965
  102. package/registry/toggle-group.ts +295 -295
  103. package/registry/tooltip.ts +156 -156
  104. package/registry/treemap.ts +847 -847
  105. package/skills/theming-vela-ui/SKILL.md +137 -137
  106. package/skills/using-vela-ui-components/SKILL.md +141 -139
  107. package/skills/writing-vela-ui-components/SKILL.md +163 -163
  108. package/src/components/badge.ts +119 -119
  109. package/src/components/bar-chart.ts +215 -215
  110. package/src/components/button.ts +387 -387
  111. package/src/components/callout-bubble.ts +347 -347
  112. package/src/components/card.ts +379 -379
  113. package/src/components/checkbox.ts +234 -234
  114. package/src/components/collapsible.ts +271 -271
  115. package/src/components/color-picker.ts +582 -582
  116. package/src/components/context-menu.ts +208 -208
  117. package/src/components/data-table.ts +215 -215
  118. package/src/components/date-picker.ts +483 -483
  119. package/src/components/dialog.ts +551 -551
  120. package/src/components/donut.ts +145 -145
  121. package/src/components/drawer.ts +636 -636
  122. package/src/components/dropdown-menu.ts +765 -762
  123. package/src/components/empty.ts +91 -91
  124. package/src/components/field.ts +584 -584
  125. package/src/components/{stat.ts → figure.ts} +96 -96
  126. package/src/components/glyph-select.ts +268 -268
  127. package/src/components/hover-card.ts +222 -222
  128. package/src/components/input-group.ts +229 -229
  129. package/src/components/input.ts +181 -181
  130. package/src/components/item.ts +376 -376
  131. package/src/components/kbd.ts +64 -64
  132. package/src/components/line-chart.ts +218 -218
  133. package/src/components/month-grid.ts +328 -328
  134. package/src/components/number-input.ts +443 -443
  135. package/src/components/popover.ts +368 -368
  136. package/src/components/scatter-chart.ts +221 -221
  137. package/src/components/select.ts +629 -620
  138. package/src/components/slider.ts +259 -259
  139. package/src/components/sort-button.ts +189 -189
  140. package/src/components/sparkline.ts +114 -114
  141. package/src/components/switch.ts +205 -205
  142. package/src/components/tabs.ts +426 -426
  143. package/src/components/text-area.ts +186 -186
  144. package/src/components/toast.ts +965 -965
  145. package/src/components/toggle-group.ts +295 -295
  146. package/src/components/tooltip.ts +156 -156
  147. package/src/components/treemap.ts +847 -847
  148. package/src/index.ts +24 -24
  149. package/src/lib/calendar.ts +117 -117
  150. package/src/lib/chart.ts +72 -72
  151. package/src/lib/color.ts +89 -89
  152. package/src/lib/component-index.ts +163 -163
  153. package/src/lib/css.ts +48 -48
  154. package/src/lib/define.ts +45 -45
  155. package/src/lib/dispose.ts +36 -36
  156. package/src/lib/h.ts +55 -55
  157. package/src/lib/headless.ts +16 -16
  158. package/src/lib/i18n.ts +30 -30
  159. package/src/lib/icons.ts +253 -244
  160. package/src/lib/kit-text.ts +26 -26
  161. package/src/lib/page.ts +24 -24
  162. package/src/lib/palette.ts +81 -81
  163. package/src/lib/placement.ts +188 -188
  164. package/src/lib/scope.ts +135 -135
  165. package/src/lib/styles.ts +53 -53
  166. package/src/lib/surface-events.ts +31 -31
  167. package/src/lib/surface-exit.ts +87 -87
  168. package/src/lib/t.ts +68 -68
  169. package/src/lib/theme.ts +684 -670
  170. package/src/lib/tokens.ts +110 -110
  171. package/src/lib/variants.ts +32 -32
  172. package/src/lib/zag.ts +61 -46
  173. package/stylelint/index.mjs +60 -60
  174. package/stylelint/lint.mjs +81 -81
  175. package/stylelint/plugin.mjs +115 -115
  176. package/dist/chunk-P4MTEMT7.js +0 -23
  177. package/dist/stat.js +0 -41
@@ -1,483 +1,483 @@
1
- // DatePicker: a month calendar with month and year panels behind its header. The header month
2
- // and year switch to their panel; picking a year leads to its months and picking a month back
3
- // to its days. Dates travel as local `YYYY-MM-DD` strings. Names, digits and the first day of
4
- // the week follow the `i18n` translator's locale (English, weeks from Sunday, without one);
5
- // the calendar is always Gregorian. The picker is content only: its host (a popover, a panel)
6
- // owns the surface around it.
7
- import { calendarSettings, monthNames, plainInteger, weekdayNames, yearBeforeMonth, yearLabel } from '../lib/calendar';
8
- import { msg, textOf } from '../lib/i18n';
9
- import type { Translator } from '../lib/i18n';
10
- import { iconEl } from '../lib/icons';
11
- import { css, defineStyles } from '../lib/css';
12
- import { defineComponent } from '../lib/define';
13
- import { h } from '../lib/h';
14
- import { t } from '../lib/t';
15
-
16
- export type DatePickerPanel = 'date' | 'month' | 'year';
17
-
18
- export interface DatePickerControllerOptions {
19
- /** The selected date (`YYYY-MM-DD`); the calendar opens on its month. */
20
- value?: string;
21
- /** "Today" for the today ring and the initial month when nothing is selected. */
22
- today?: Date;
23
- /** The translator whose locale names the months and weekdays, picks the first day of
24
- * the week and the digits: `chart.i18n` inside a chart, `createTranslator(...)`
25
- * elsewhere. Default: English, weeks starting on Sunday. */
26
- i18n?: Translator;
27
- }
28
-
29
- /** One cell of the current panel. `blank` cells pad the first week of a month. */
30
- export interface DatePickerCell {
31
- label: string;
32
- /** The day (`YYYY-MM-DD`) on the date panel; the month index or the year otherwise. */
33
- value: string | number;
34
- checked: boolean;
35
- today: boolean;
36
- /** A padding year outside the decade on the year panel. */
37
- outside?: boolean;
38
- blank?: boolean;
39
- }
40
-
41
- export interface DatePickerController {
42
- readonly panel: DatePickerPanel;
43
- readonly year: number;
44
- readonly month: number;
45
- readonly value: string | null;
46
- /** Whether the locale writes the year before the month (the header's switch order). */
47
- readonly yearFirst: boolean;
48
- /** The weekday column labels, starting on the locale's first day of the week. */
49
- weekdays(): string[];
50
- /** Header text: the month switch (hidden off the date panel) and the year switch. */
51
- header(): { month: string; monthVisible: boolean; year: string; yearDisabled: boolean };
52
- /** What the arrows step on the current panel. */
53
- navLabels(): { prev: string; next: string };
54
- cells(): DatePickerCell[];
55
- /** One month, one year or ten, depending on the panel. */
56
- step(dir: 1 | -1): void;
57
- showMonths(): void;
58
- showYears(): void;
59
- /** Activate a cell: a day returns its date (the pick); a month or year only navigates. */
60
- choose(cell: DatePickerCell): string | null;
61
- /** Rewrite the selection without emitting (and open on its month). */
62
- setValue(value: string | null): void;
63
- }
64
-
65
- const NAV = {
66
- prevMonth: msg('ui.datePicker.previousMonth', 'Previous month'),
67
- nextMonth: msg('ui.datePicker.nextMonth', 'Next month'),
68
- prevYear: msg('ui.datePicker.previousYear', 'Previous year'),
69
- nextYear: msg('ui.datePicker.nextYear', 'Next year'),
70
- prevDecade: msg('ui.datePicker.previousDecade', 'Previous decade'),
71
- nextDecade: msg('ui.datePicker.nextDecade', 'Next decade'),
72
- };
73
-
74
- /** `YYYY-MM-DD` for a local date. */
75
- export function isoDate(d: Date): string {
76
- return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
77
- }
78
-
79
- /** Accept `YYYY-MM-DD` or `YYYY-M-D` and return a padded ISO date, or null if unusable. */
80
- export function normalizeDateInput(raw: string): string | null {
81
- const m = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(raw.trim());
82
- if (!m) return null;
83
- const y = Number(m[1]);
84
- const mo = Number(m[2]);
85
- const d = Number(m[3]);
86
- const dt = new Date(y, mo - 1, d);
87
- if (dt.getFullYear() !== y || dt.getMonth() !== mo - 1 || dt.getDate() !== d) return null;
88
- return isoDate(dt);
89
- }
90
-
91
- function parseIsoDate(raw: string | null | undefined): Date | null {
92
- const iso = raw ? normalizeDateInput(raw) : null;
93
- if (!iso) return null;
94
- const [y, mo, d] = iso.split('-').map(Number);
95
- return new Date(y!, mo! - 1, d!);
96
- }
97
-
98
- /** The calendar's panels, navigation and selection, without DOM. */
99
- export function datePickerController(opts: DatePickerControllerOptions = {}): DatePickerController {
100
- const today = opts.today ?? new Date();
101
- let selected = parseIsoDate(opts.value);
102
- let year = selected?.getFullYear() ?? today.getFullYear();
103
- let month = selected?.getMonth() ?? today.getMonth();
104
- let panel: DatePickerPanel = 'date';
105
- const i18n = opts.i18n ?? null;
106
- const settings = calendarSettings(i18n);
107
- // Without a translator the picker keeps its historical Sunday-first grid.
108
- const weekStart = opts.i18n?.weekStart ?? 0;
109
- const monthsLong = monthNames(settings, 'long');
110
- const monthsShort = monthNames(settings, 'short');
111
- const num = (n: number): string => plainInteger(settings, n);
112
-
113
- const decade = (): number => Math.floor(year / 10) * 10;
114
-
115
- return {
116
- get panel() {
117
- return panel;
118
- },
119
- get year() {
120
- return year;
121
- },
122
- get month() {
123
- return month;
124
- },
125
- get value() {
126
- return selected ? isoDate(selected) : null;
127
- },
128
- yearFirst: yearBeforeMonth(settings),
129
- weekdays() {
130
- const names = weekdayNames(settings);
131
- return Array.from({ length: 7 }, (_, i) => names[(weekStart + i) % 7]!);
132
- },
133
- header() {
134
- return {
135
- month: monthsLong[month] ?? '',
136
- monthVisible: panel === 'date',
137
- year: panel === 'year' ? `${num(decade())}-${num(decade() + 9)}` : yearLabel(settings, year),
138
- yearDisabled: panel === 'year', // in the decade panel the year reads as its title
139
- };
140
- },
141
- navLabels() {
142
- if (panel === 'date') return { prev: textOf(i18n, NAV.prevMonth), next: textOf(i18n, NAV.nextMonth) };
143
- if (panel === 'month') return { prev: textOf(i18n, NAV.prevYear), next: textOf(i18n, NAV.nextYear) };
144
- return { prev: textOf(i18n, NAV.prevDecade), next: textOf(i18n, NAV.nextDecade) };
145
- },
146
- cells() {
147
- const out: DatePickerCell[] = [];
148
- if (panel === 'date') {
149
- const startPad = (new Date(year, month, 1).getDay() - weekStart + 7) % 7;
150
- const days = new Date(year, month + 1, 0).getDate();
151
- const todayIso = isoDate(today);
152
- const selectedIso = selected ? isoDate(selected) : '';
153
- for (let i = 0; i < startPad; i++) out.push({ label: '', value: '', checked: false, today: false, blank: true });
154
- for (let day = 1; day <= days; day++) {
155
- const iso = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
156
- out.push({ label: num(day), value: iso, checked: iso === selectedIso, today: iso === todayIso });
157
- }
158
- return out;
159
- }
160
- if (panel === 'month') {
161
- for (let m = 0; m < 12; m++) {
162
- out.push({
163
- label: monthsShort[m] ?? '',
164
- value: m,
165
- checked: selected?.getFullYear() === year && selected.getMonth() === m,
166
- today: today.getFullYear() === year && today.getMonth() === m,
167
- });
168
- }
169
- return out;
170
- }
171
- // One padding year on each side, so the decade fills the same 3×4 grid as the months.
172
- const d = decade();
173
- for (let y = d - 1; y <= d + 10; y++) {
174
- out.push({ label: num(y), value: y, checked: selected?.getFullYear() === y, today: today.getFullYear() === y, outside: y < d || y > d + 9 });
175
- }
176
- return out;
177
- },
178
- step(dir) {
179
- if (panel === 'date') {
180
- month += dir;
181
- if (month < 0) {
182
- month = 11;
183
- year -= 1;
184
- }
185
- if (month > 11) {
186
- month = 0;
187
- year += 1;
188
- }
189
- } else {
190
- year += panel === 'month' ? dir : dir * 10;
191
- }
192
- },
193
- showMonths() {
194
- panel = 'month';
195
- },
196
- showYears() {
197
- panel = 'year';
198
- },
199
- choose(cell) {
200
- if (cell.blank) return null;
201
- if (panel === 'date') {
202
- selected = parseIsoDate(String(cell.value));
203
- return selected ? isoDate(selected) : null;
204
- }
205
- if (panel === 'month') {
206
- month = Number(cell.value);
207
- panel = 'date';
208
- return null;
209
- }
210
- year = Number(cell.value);
211
- panel = 'month';
212
- return null;
213
- },
214
- setValue(value) {
215
- selected = parseIsoDate(value);
216
- if (selected) {
217
- year = selected.getFullYear();
218
- month = selected.getMonth();
219
- }
220
- panel = 'date';
221
- },
222
- };
223
- }
224
-
225
- export const datePickerDef = defineComponent({
226
- name: 'date-picker',
227
- parts: ['root', 'head', 'title', 'switch', 'nav', 'week', 'grid', 'cells', 'blank', 'day', 'cell'],
228
- settings: { radius: t.radius.sm, 'today-ring': `inset 0 0 0 1px ${t.border.strong}` },
229
- });
230
-
231
- export interface DatePickerOptions extends DatePickerControllerOptions {
232
- /** A day was picked (`YYYY-MM-DD`). */
233
- onPick?: (value: string) => void;
234
- }
235
-
236
- export type DatePickerProps = DatePickerOptions;
237
-
238
- const CHOOSE_MONTH = msg('ui.datePicker.chooseMonth', 'Choose month');
239
- const CHOOSE_YEAR = msg('ui.datePicker.chooseYear', 'Choose year');
240
-
241
- const injectStyles = defineStyles(
242
- 'vela-date-picker-styles',
243
- css`
244
- @layer vela.ui {
245
- [data-slot='date-picker'] {
246
- color: ${t.fg};
247
- font: 14px ${t.font};
248
- user-select: none;
249
- }
250
- [data-slot='date-picker-head'] {
251
- display: flex;
252
- align-items: center;
253
- justify-content: space-between;
254
- gap: 8px;
255
- margin-bottom: 8px;
256
- }
257
- [data-slot='date-picker-title'] {
258
- flex: 1;
259
- display: flex;
260
- align-items: center;
261
- justify-content: center;
262
- gap: 2px;
263
- min-width: 0;
264
- }
265
- [data-slot='date-picker-switch'] {
266
- border: none;
267
- background: transparent;
268
- color: ${t.fg.bright};
269
- font: inherit;
270
- font-weight: 600;
271
- font-size: 14px;
272
- padding: 2px 6px;
273
- border-radius: ${datePickerDef.vars.radius};
274
- cursor: pointer;
275
-
276
- &:disabled {
277
- cursor: default;
278
- }
279
- &:not(:disabled):hover {
280
- background: ${t.hover};
281
- }
282
- }
283
- [data-slot='date-picker-nav'] {
284
- width: 24px;
285
- height: 24px;
286
- border: none;
287
- background: transparent;
288
- color: ${t.fg.muted};
289
- border-radius: ${datePickerDef.vars.radius};
290
- padding: 0;
291
- cursor: pointer;
292
- display: inline-flex;
293
- align-items: center;
294
- justify-content: center;
295
- font-size: 14px;
296
-
297
- &:hover {
298
- background: ${t.hover};
299
- color: ${t.fg.bright};
300
- }
301
- }
302
- [data-slot='date-picker-week'],
303
- [data-slot='date-picker-grid'] {
304
- grid-template-columns: repeat(7, 28px);
305
- gap: 2px;
306
- }
307
- [data-slot='date-picker-week']:where(:not([hidden])),
308
- [data-slot='date-picker-grid'] {
309
- display: grid;
310
- }
311
- [data-slot='date-picker-week'] {
312
- margin-bottom: 4px;
313
- color: ${t.fg.muted};
314
- font-size: 11px;
315
- text-align: center;
316
-
317
- & > span {
318
- line-height: 20px;
319
- }
320
- }
321
- [data-slot='date-picker-blank'] {
322
- width: 28px;
323
- height: 28px;
324
- }
325
- [data-slot='date-picker-day'] {
326
- width: 28px;
327
- height: 28px;
328
- border: none;
329
- background: transparent;
330
- color: inherit;
331
- border-radius: ${datePickerDef.vars.radius};
332
- padding: 0;
333
- cursor: pointer;
334
- font: inherit;
335
- font-size: 14px;
336
-
337
- &:hover {
338
- background: ${t.hover};
339
- }
340
- &[data-checked] {
341
- background: ${t.hover.strong};
342
- color: ${t.fg.bright};
343
- }
344
- &[data-today]:not([data-checked]) {
345
- box-shadow: ${datePickerDef.vars['today-ring']};
346
- }
347
- }
348
- [data-slot='date-picker-cells'] {
349
- display: grid;
350
- grid-template-columns: repeat(3, 1fr);
351
- gap: 4px;
352
- width: calc(7 * 28px + 6 * 2px);
353
- }
354
- [data-slot='date-picker-cell'] {
355
- height: 36px;
356
- border: none;
357
- background: transparent;
358
- color: inherit;
359
- border-radius: ${datePickerDef.vars.radius};
360
- padding: 0 4px;
361
- cursor: pointer;
362
- font: inherit;
363
- font-size: 14px;
364
-
365
- &:hover {
366
- background: ${t.hover};
367
- }
368
- &[data-checked] {
369
- background: ${t.hover.strong};
370
- color: ${t.fg.bright};
371
- }
372
- &[data-today]:not([data-checked]) {
373
- box-shadow: ${datePickerDef.vars['today-ring']};
374
- }
375
- &[data-outside] {
376
- opacity: 0.45;
377
- }
378
- }
379
- }
380
- `,
381
- );
382
-
383
- export class DatePicker {
384
- readonly el: HTMLDivElement;
385
- private readonly ctrl: DatePickerController;
386
- private readonly prev: HTMLButtonElement;
387
- private readonly next: HTMLButtonElement;
388
- private readonly monthBtn: HTMLButtonElement;
389
- private readonly yearBtn: HTMLButtonElement;
390
- private readonly week: HTMLDivElement;
391
- private readonly grid: HTMLDivElement;
392
-
393
- constructor(private readonly opts: DatePickerOptions = {}) {
394
- const doc = document;
395
- injectStyles(doc);
396
- this.ctrl = datePickerController(opts);
397
- const button = (className: string, part: string): HTMLButtonElement => h('button', { className, slot: part, attrs: { type: 'button' } });
398
- this.prev = button('vela-date-picker-nav', datePickerDef.slot('nav'));
399
- this.prev.append(iconEl('chevron-left', doc));
400
- this.next = button('vela-date-picker-nav', datePickerDef.slot('nav'));
401
- this.next.append(iconEl('chevron-right', doc));
402
- const i18n = opts.i18n ?? null;
403
- this.monthBtn = button('vela-date-picker-switch', datePickerDef.slot('switch'));
404
- this.monthBtn.setAttribute('aria-label', textOf(i18n, CHOOSE_MONTH));
405
- this.yearBtn = button('vela-date-picker-switch', datePickerDef.slot('switch'));
406
- this.yearBtn.setAttribute('aria-label', textOf(i18n, CHOOSE_YEAR));
407
- const title = h('div', { className: 'vela-date-picker-title', slot: datePickerDef.slot('title') }, this.ctrl.yearFirst ? [this.yearBtn, this.monthBtn] : [this.monthBtn, this.yearBtn]);
408
- const head = h('div', { className: 'vela-date-picker-head', slot: datePickerDef.slot('head') }, this.prev, title, this.next);
409
- this.week = h(
410
- 'div',
411
- { className: 'vela-date-picker-week', slot: datePickerDef.slot('week') },
412
- this.ctrl.weekdays().map((d) => h('span', { text: d })),
413
- );
414
- this.grid = h('div');
415
-
416
- // Every control stops propagation: the picker usually sits in a popover whose
417
- // outside-dismiss must not read a panel switch as a click elsewhere.
418
- const on = (el: HTMLElement, run: () => void): void =>
419
- el.addEventListener('click', (e) => {
420
- e.stopPropagation();
421
- run();
422
- this.paint();
423
- });
424
- on(this.prev, () => this.ctrl.step(-1));
425
- on(this.next, () => this.ctrl.step(1));
426
- on(this.monthBtn, () => this.ctrl.showMonths());
427
- on(this.yearBtn, () => this.ctrl.showYears());
428
-
429
- this.el = h('div', { className: 'vela-date-picker', slot: datePickerDef.slot('root') }, head, this.week, this.grid);
430
- this.paint();
431
- }
432
-
433
- get value(): string | null {
434
- return this.ctrl.value;
435
- }
436
-
437
- /** Rewrite the selection without emitting (the calendar opens on its month). */
438
- setValue(value: string | null): void {
439
- this.ctrl.setValue(value);
440
- this.paint();
441
- }
442
-
443
- destroy(): void {}
444
-
445
- private paint(): void {
446
- const doc = this.el.ownerDocument;
447
- const head = this.ctrl.header();
448
- this.monthBtn.hidden = !head.monthVisible;
449
- this.monthBtn.textContent = head.month;
450
- this.yearBtn.textContent = head.year;
451
- this.yearBtn.disabled = head.yearDisabled;
452
- const nav = this.ctrl.navLabels();
453
- this.prev.setAttribute('aria-label', nav.prev);
454
- this.next.setAttribute('aria-label', nav.next);
455
- const dates = this.ctrl.panel === 'date';
456
- this.week.hidden = !dates;
457
- this.grid.className = dates ? 'vela-date-picker-grid' : 'vela-date-picker-cells';
458
- this.grid.setAttribute('data-slot', datePickerDef.slot(dates ? 'grid' : 'cells'));
459
- this.grid.replaceChildren(...this.ctrl.cells().map((cell) => this.cellEl(doc, cell, dates)));
460
- }
461
-
462
- private cellEl(doc: Document, cell: DatePickerCell, dates: boolean): HTMLElement {
463
- if (cell.blank) return h('span', { className: 'vela-date-picker-blank', slot: datePickerDef.slot('blank') });
464
- const b = h('button', {
465
- className: dates ? 'vela-date-picker-day' : 'vela-date-picker-cell',
466
- slot: datePickerDef.slot(dates ? 'day' : 'cell'),
467
- attrs: { type: 'button' },
468
- data: { checked: cell.checked ? '1' : null, today: cell.today ? '1' : null, outside: cell.outside ? '1' : null },
469
- text: cell.label,
470
- });
471
- b.addEventListener('click', (e) => {
472
- e.stopPropagation();
473
- const picked = this.ctrl.choose(cell);
474
- if (picked) this.opts.onPick?.(picked);
475
- else this.paint();
476
- });
477
- return b;
478
- }
479
- }
480
-
481
- export function createDatePicker(props: DatePickerProps = {}): DatePicker {
482
- return new DatePicker(props);
483
- }
1
+ // DatePicker: a month calendar with month and year panels behind its header. The header month
2
+ // and year switch to their panel; picking a year leads to its months and picking a month back
3
+ // to its days. Dates travel as local `YYYY-MM-DD` strings. Names, digits and the first day of
4
+ // the week follow the `i18n` translator's locale (English, weeks from Sunday, without one);
5
+ // the calendar is always Gregorian. The picker is content only: its host (a popover, a panel)
6
+ // owns the surface around it.
7
+ import { calendarSettings, monthNames, plainInteger, weekdayNames, yearBeforeMonth, yearLabel } from '../lib/calendar';
8
+ import { msg, textOf } from '../lib/i18n';
9
+ import type { Translator } from '../lib/i18n';
10
+ import { iconEl } from '../lib/icons';
11
+ import { css, defineStyles } from '../lib/css';
12
+ import { defineComponent } from '../lib/define';
13
+ import { h } from '../lib/h';
14
+ import { t } from '../lib/t';
15
+
16
+ export type DatePickerPanel = 'date' | 'month' | 'year';
17
+
18
+ export interface DatePickerControllerOptions {
19
+ /** The selected date (`YYYY-MM-DD`); the calendar opens on its month. */
20
+ value?: string;
21
+ /** "Today" for the today ring and the initial month when nothing is selected. */
22
+ today?: Date;
23
+ /** The translator whose locale names the months and weekdays, picks the first day of
24
+ * the week and the digits: `chart.i18n` inside a chart, `createTranslator(...)`
25
+ * elsewhere. Default: English, weeks starting on Sunday. */
26
+ i18n?: Translator;
27
+ }
28
+
29
+ /** One cell of the current panel. `blank` cells pad the first week of a month. */
30
+ export interface DatePickerCell {
31
+ label: string;
32
+ /** The day (`YYYY-MM-DD`) on the date panel; the month index or the year otherwise. */
33
+ value: string | number;
34
+ checked: boolean;
35
+ today: boolean;
36
+ /** A padding year outside the decade on the year panel. */
37
+ outside?: boolean;
38
+ blank?: boolean;
39
+ }
40
+
41
+ export interface DatePickerController {
42
+ readonly panel: DatePickerPanel;
43
+ readonly year: number;
44
+ readonly month: number;
45
+ readonly value: string | null;
46
+ /** Whether the locale writes the year before the month (the header's switch order). */
47
+ readonly yearFirst: boolean;
48
+ /** The weekday column labels, starting on the locale's first day of the week. */
49
+ weekdays(): string[];
50
+ /** Header text: the month switch (hidden off the date panel) and the year switch. */
51
+ header(): { month: string; monthVisible: boolean; year: string; yearDisabled: boolean };
52
+ /** What the arrows step on the current panel. */
53
+ navLabels(): { prev: string; next: string };
54
+ cells(): DatePickerCell[];
55
+ /** One month, one year or ten, depending on the panel. */
56
+ step(dir: 1 | -1): void;
57
+ showMonths(): void;
58
+ showYears(): void;
59
+ /** Activate a cell: a day returns its date (the pick); a month or year only navigates. */
60
+ choose(cell: DatePickerCell): string | null;
61
+ /** Rewrite the selection without emitting (and open on its month). */
62
+ setValue(value: string | null): void;
63
+ }
64
+
65
+ const NAV = {
66
+ prevMonth: msg('ui.datePicker.previousMonth', 'Previous month'),
67
+ nextMonth: msg('ui.datePicker.nextMonth', 'Next month'),
68
+ prevYear: msg('ui.datePicker.previousYear', 'Previous year'),
69
+ nextYear: msg('ui.datePicker.nextYear', 'Next year'),
70
+ prevDecade: msg('ui.datePicker.previousDecade', 'Previous decade'),
71
+ nextDecade: msg('ui.datePicker.nextDecade', 'Next decade'),
72
+ };
73
+
74
+ /** `YYYY-MM-DD` for a local date. */
75
+ export function isoDate(d: Date): string {
76
+ return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
77
+ }
78
+
79
+ /** Accept `YYYY-MM-DD` or `YYYY-M-D` and return a padded ISO date, or null if unusable. */
80
+ export function normalizeDateInput(raw: string): string | null {
81
+ const m = /^(\d{4})-(\d{1,2})-(\d{1,2})$/.exec(raw.trim());
82
+ if (!m) return null;
83
+ const y = Number(m[1]);
84
+ const mo = Number(m[2]);
85
+ const d = Number(m[3]);
86
+ const dt = new Date(y, mo - 1, d);
87
+ if (dt.getFullYear() !== y || dt.getMonth() !== mo - 1 || dt.getDate() !== d) return null;
88
+ return isoDate(dt);
89
+ }
90
+
91
+ function parseIsoDate(raw: string | null | undefined): Date | null {
92
+ const iso = raw ? normalizeDateInput(raw) : null;
93
+ if (!iso) return null;
94
+ const [y, mo, d] = iso.split('-').map(Number);
95
+ return new Date(y!, mo! - 1, d!);
96
+ }
97
+
98
+ /** The calendar's panels, navigation and selection, without DOM. */
99
+ export function datePickerController(opts: DatePickerControllerOptions = {}): DatePickerController {
100
+ const today = opts.today ?? new Date();
101
+ let selected = parseIsoDate(opts.value);
102
+ let year = selected?.getFullYear() ?? today.getFullYear();
103
+ let month = selected?.getMonth() ?? today.getMonth();
104
+ let panel: DatePickerPanel = 'date';
105
+ const i18n = opts.i18n ?? null;
106
+ const settings = calendarSettings(i18n);
107
+ // Without a translator the picker keeps its historical Sunday-first grid.
108
+ const weekStart = opts.i18n?.weekStart ?? 0;
109
+ const monthsLong = monthNames(settings, 'long');
110
+ const monthsShort = monthNames(settings, 'short');
111
+ const num = (n: number): string => plainInteger(settings, n);
112
+
113
+ const decade = (): number => Math.floor(year / 10) * 10;
114
+
115
+ return {
116
+ get panel() {
117
+ return panel;
118
+ },
119
+ get year() {
120
+ return year;
121
+ },
122
+ get month() {
123
+ return month;
124
+ },
125
+ get value() {
126
+ return selected ? isoDate(selected) : null;
127
+ },
128
+ yearFirst: yearBeforeMonth(settings),
129
+ weekdays() {
130
+ const names = weekdayNames(settings);
131
+ return Array.from({ length: 7 }, (_, i) => names[(weekStart + i) % 7]!);
132
+ },
133
+ header() {
134
+ return {
135
+ month: monthsLong[month] ?? '',
136
+ monthVisible: panel === 'date',
137
+ year: panel === 'year' ? `${num(decade())}-${num(decade() + 9)}` : yearLabel(settings, year),
138
+ yearDisabled: panel === 'year', // in the decade panel the year reads as its title
139
+ };
140
+ },
141
+ navLabels() {
142
+ if (panel === 'date') return { prev: textOf(i18n, NAV.prevMonth), next: textOf(i18n, NAV.nextMonth) };
143
+ if (panel === 'month') return { prev: textOf(i18n, NAV.prevYear), next: textOf(i18n, NAV.nextYear) };
144
+ return { prev: textOf(i18n, NAV.prevDecade), next: textOf(i18n, NAV.nextDecade) };
145
+ },
146
+ cells() {
147
+ const out: DatePickerCell[] = [];
148
+ if (panel === 'date') {
149
+ const startPad = (new Date(year, month, 1).getDay() - weekStart + 7) % 7;
150
+ const days = new Date(year, month + 1, 0).getDate();
151
+ const todayIso = isoDate(today);
152
+ const selectedIso = selected ? isoDate(selected) : '';
153
+ for (let i = 0; i < startPad; i++) out.push({ label: '', value: '', checked: false, today: false, blank: true });
154
+ for (let day = 1; day <= days; day++) {
155
+ const iso = `${year}-${String(month + 1).padStart(2, '0')}-${String(day).padStart(2, '0')}`;
156
+ out.push({ label: num(day), value: iso, checked: iso === selectedIso, today: iso === todayIso });
157
+ }
158
+ return out;
159
+ }
160
+ if (panel === 'month') {
161
+ for (let m = 0; m < 12; m++) {
162
+ out.push({
163
+ label: monthsShort[m] ?? '',
164
+ value: m,
165
+ checked: selected?.getFullYear() === year && selected.getMonth() === m,
166
+ today: today.getFullYear() === year && today.getMonth() === m,
167
+ });
168
+ }
169
+ return out;
170
+ }
171
+ // One padding year on each side, so the decade fills the same 3×4 grid as the months.
172
+ const d = decade();
173
+ for (let y = d - 1; y <= d + 10; y++) {
174
+ out.push({ label: num(y), value: y, checked: selected?.getFullYear() === y, today: today.getFullYear() === y, outside: y < d || y > d + 9 });
175
+ }
176
+ return out;
177
+ },
178
+ step(dir) {
179
+ if (panel === 'date') {
180
+ month += dir;
181
+ if (month < 0) {
182
+ month = 11;
183
+ year -= 1;
184
+ }
185
+ if (month > 11) {
186
+ month = 0;
187
+ year += 1;
188
+ }
189
+ } else {
190
+ year += panel === 'month' ? dir : dir * 10;
191
+ }
192
+ },
193
+ showMonths() {
194
+ panel = 'month';
195
+ },
196
+ showYears() {
197
+ panel = 'year';
198
+ },
199
+ choose(cell) {
200
+ if (cell.blank) return null;
201
+ if (panel === 'date') {
202
+ selected = parseIsoDate(String(cell.value));
203
+ return selected ? isoDate(selected) : null;
204
+ }
205
+ if (panel === 'month') {
206
+ month = Number(cell.value);
207
+ panel = 'date';
208
+ return null;
209
+ }
210
+ year = Number(cell.value);
211
+ panel = 'month';
212
+ return null;
213
+ },
214
+ setValue(value) {
215
+ selected = parseIsoDate(value);
216
+ if (selected) {
217
+ year = selected.getFullYear();
218
+ month = selected.getMonth();
219
+ }
220
+ panel = 'date';
221
+ },
222
+ };
223
+ }
224
+
225
+ export const datePickerDef = defineComponent({
226
+ name: 'date-picker',
227
+ parts: ['root', 'head', 'title', 'switch', 'nav', 'week', 'grid', 'cells', 'blank', 'day', 'cell'],
228
+ settings: { radius: t.radius.sm, 'today-ring': `inset 0 0 0 1px ${t.border.strong}` },
229
+ });
230
+
231
+ export interface DatePickerOptions extends DatePickerControllerOptions {
232
+ /** A day was picked (`YYYY-MM-DD`). */
233
+ onPick?: (value: string) => void;
234
+ }
235
+
236
+ export type DatePickerProps = DatePickerOptions;
237
+
238
+ const CHOOSE_MONTH = msg('ui.datePicker.chooseMonth', 'Choose month');
239
+ const CHOOSE_YEAR = msg('ui.datePicker.chooseYear', 'Choose year');
240
+
241
+ const injectStyles = defineStyles(
242
+ 'vela-date-picker-styles',
243
+ css`
244
+ @layer vela.ui {
245
+ [data-slot='date-picker'] {
246
+ color: ${t.fg};
247
+ font: 14px ${t.font};
248
+ user-select: none;
249
+ }
250
+ [data-slot='date-picker-head'] {
251
+ display: flex;
252
+ align-items: center;
253
+ justify-content: space-between;
254
+ gap: 8px;
255
+ margin-bottom: 8px;
256
+ }
257
+ [data-slot='date-picker-title'] {
258
+ flex: 1;
259
+ display: flex;
260
+ align-items: center;
261
+ justify-content: center;
262
+ gap: 2px;
263
+ min-width: 0;
264
+ }
265
+ [data-slot='date-picker-switch'] {
266
+ border: none;
267
+ background: transparent;
268
+ color: ${t.fg.bright};
269
+ font: inherit;
270
+ font-weight: 600;
271
+ font-size: 14px;
272
+ padding: 2px 6px;
273
+ border-radius: ${datePickerDef.vars.radius};
274
+ cursor: pointer;
275
+
276
+ &:disabled {
277
+ cursor: default;
278
+ }
279
+ &:not(:disabled):hover {
280
+ background: ${t.hover};
281
+ }
282
+ }
283
+ [data-slot='date-picker-nav'] {
284
+ width: 24px;
285
+ height: 24px;
286
+ border: none;
287
+ background: transparent;
288
+ color: ${t.fg.muted};
289
+ border-radius: ${datePickerDef.vars.radius};
290
+ padding: 0;
291
+ cursor: pointer;
292
+ display: inline-flex;
293
+ align-items: center;
294
+ justify-content: center;
295
+ font-size: 14px;
296
+
297
+ &:hover {
298
+ background: ${t.hover};
299
+ color: ${t.fg.bright};
300
+ }
301
+ }
302
+ [data-slot='date-picker-week'],
303
+ [data-slot='date-picker-grid'] {
304
+ grid-template-columns: repeat(7, 28px);
305
+ gap: 2px;
306
+ }
307
+ [data-slot='date-picker-week']:where(:not([hidden])),
308
+ [data-slot='date-picker-grid'] {
309
+ display: grid;
310
+ }
311
+ [data-slot='date-picker-week'] {
312
+ margin-bottom: 4px;
313
+ color: ${t.fg.muted};
314
+ font-size: 11px;
315
+ text-align: center;
316
+
317
+ & > span {
318
+ line-height: 20px;
319
+ }
320
+ }
321
+ [data-slot='date-picker-blank'] {
322
+ width: 28px;
323
+ height: 28px;
324
+ }
325
+ [data-slot='date-picker-day'] {
326
+ width: 28px;
327
+ height: 28px;
328
+ border: none;
329
+ background: transparent;
330
+ color: inherit;
331
+ border-radius: ${datePickerDef.vars.radius};
332
+ padding: 0;
333
+ cursor: pointer;
334
+ font: inherit;
335
+ font-size: 14px;
336
+
337
+ &:hover {
338
+ background: ${t.hover};
339
+ }
340
+ &[data-checked] {
341
+ background: ${t.hover.strong};
342
+ color: ${t.fg.bright};
343
+ }
344
+ &[data-today]:not([data-checked]) {
345
+ box-shadow: ${datePickerDef.vars['today-ring']};
346
+ }
347
+ }
348
+ [data-slot='date-picker-cells'] {
349
+ display: grid;
350
+ grid-template-columns: repeat(3, 1fr);
351
+ gap: 4px;
352
+ width: calc(7 * 28px + 6 * 2px);
353
+ }
354
+ [data-slot='date-picker-cell'] {
355
+ height: 36px;
356
+ border: none;
357
+ background: transparent;
358
+ color: inherit;
359
+ border-radius: ${datePickerDef.vars.radius};
360
+ padding: 0 4px;
361
+ cursor: pointer;
362
+ font: inherit;
363
+ font-size: 14px;
364
+
365
+ &:hover {
366
+ background: ${t.hover};
367
+ }
368
+ &[data-checked] {
369
+ background: ${t.hover.strong};
370
+ color: ${t.fg.bright};
371
+ }
372
+ &[data-today]:not([data-checked]) {
373
+ box-shadow: ${datePickerDef.vars['today-ring']};
374
+ }
375
+ &[data-outside] {
376
+ opacity: 0.45;
377
+ }
378
+ }
379
+ }
380
+ `,
381
+ );
382
+
383
+ export class DatePicker {
384
+ readonly el: HTMLDivElement;
385
+ private readonly ctrl: DatePickerController;
386
+ private readonly prev: HTMLButtonElement;
387
+ private readonly next: HTMLButtonElement;
388
+ private readonly monthBtn: HTMLButtonElement;
389
+ private readonly yearBtn: HTMLButtonElement;
390
+ private readonly week: HTMLDivElement;
391
+ private readonly grid: HTMLDivElement;
392
+
393
+ constructor(private readonly opts: DatePickerOptions = {}) {
394
+ const doc = document;
395
+ injectStyles(doc);
396
+ this.ctrl = datePickerController(opts);
397
+ const button = (className: string, part: string): HTMLButtonElement => h('button', { className, slot: part, attrs: { type: 'button' } });
398
+ this.prev = button('vela-date-picker-nav', datePickerDef.slot('nav'));
399
+ this.prev.append(iconEl('chevron-left', doc));
400
+ this.next = button('vela-date-picker-nav', datePickerDef.slot('nav'));
401
+ this.next.append(iconEl('chevron-right', doc));
402
+ const i18n = opts.i18n ?? null;
403
+ this.monthBtn = button('vela-date-picker-switch', datePickerDef.slot('switch'));
404
+ this.monthBtn.setAttribute('aria-label', textOf(i18n, CHOOSE_MONTH));
405
+ this.yearBtn = button('vela-date-picker-switch', datePickerDef.slot('switch'));
406
+ this.yearBtn.setAttribute('aria-label', textOf(i18n, CHOOSE_YEAR));
407
+ const title = h('div', { className: 'vela-date-picker-title', slot: datePickerDef.slot('title') }, this.ctrl.yearFirst ? [this.yearBtn, this.monthBtn] : [this.monthBtn, this.yearBtn]);
408
+ const head = h('div', { className: 'vela-date-picker-head', slot: datePickerDef.slot('head') }, this.prev, title, this.next);
409
+ this.week = h(
410
+ 'div',
411
+ { className: 'vela-date-picker-week', slot: datePickerDef.slot('week') },
412
+ this.ctrl.weekdays().map((d) => h('span', { text: d })),
413
+ );
414
+ this.grid = h('div');
415
+
416
+ // Every control stops propagation: the picker usually sits in a popover whose
417
+ // outside-dismiss must not read a panel switch as a click elsewhere.
418
+ const on = (el: HTMLElement, run: () => void): void =>
419
+ el.addEventListener('click', (e) => {
420
+ e.stopPropagation();
421
+ run();
422
+ this.paint();
423
+ });
424
+ on(this.prev, () => this.ctrl.step(-1));
425
+ on(this.next, () => this.ctrl.step(1));
426
+ on(this.monthBtn, () => this.ctrl.showMonths());
427
+ on(this.yearBtn, () => this.ctrl.showYears());
428
+
429
+ this.el = h('div', { className: 'vela-date-picker', slot: datePickerDef.slot('root') }, head, this.week, this.grid);
430
+ this.paint();
431
+ }
432
+
433
+ get value(): string | null {
434
+ return this.ctrl.value;
435
+ }
436
+
437
+ /** Rewrite the selection without emitting (the calendar opens on its month). */
438
+ setValue(value: string | null): void {
439
+ this.ctrl.setValue(value);
440
+ this.paint();
441
+ }
442
+
443
+ destroy(): void {}
444
+
445
+ private paint(): void {
446
+ const doc = this.el.ownerDocument;
447
+ const head = this.ctrl.header();
448
+ this.monthBtn.hidden = !head.monthVisible;
449
+ this.monthBtn.textContent = head.month;
450
+ this.yearBtn.textContent = head.year;
451
+ this.yearBtn.disabled = head.yearDisabled;
452
+ const nav = this.ctrl.navLabels();
453
+ this.prev.setAttribute('aria-label', nav.prev);
454
+ this.next.setAttribute('aria-label', nav.next);
455
+ const dates = this.ctrl.panel === 'date';
456
+ this.week.hidden = !dates;
457
+ this.grid.className = dates ? 'vela-date-picker-grid' : 'vela-date-picker-cells';
458
+ this.grid.setAttribute('data-slot', datePickerDef.slot(dates ? 'grid' : 'cells'));
459
+ this.grid.replaceChildren(...this.ctrl.cells().map((cell) => this.cellEl(doc, cell, dates)));
460
+ }
461
+
462
+ private cellEl(doc: Document, cell: DatePickerCell, dates: boolean): HTMLElement {
463
+ if (cell.blank) return h('span', { className: 'vela-date-picker-blank', slot: datePickerDef.slot('blank') });
464
+ const b = h('button', {
465
+ className: dates ? 'vela-date-picker-day' : 'vela-date-picker-cell',
466
+ slot: datePickerDef.slot(dates ? 'day' : 'cell'),
467
+ attrs: { type: 'button' },
468
+ data: { checked: cell.checked ? '1' : null, today: cell.today ? '1' : null, outside: cell.outside ? '1' : null },
469
+ text: cell.label,
470
+ });
471
+ b.addEventListener('click', (e) => {
472
+ e.stopPropagation();
473
+ const picked = this.ctrl.choose(cell);
474
+ if (picked) this.opts.onPick?.(picked);
475
+ else this.paint();
476
+ });
477
+ return b;
478
+ }
479
+ }
480
+
481
+ export function createDatePicker(props: DatePickerProps = {}): DatePicker {
482
+ return new DatePicker(props);
483
+ }