ochreui 0.0.0-stage → 0.0.2

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 (168) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +153 -2
  3. package/cli/ochreui.mjs +601 -0
  4. package/mcp/core.mjs +126 -0
  5. package/mcp/docs.json +906 -0
  6. package/mcp/server.mjs +23 -0
  7. package/package.json +393 -3
  8. package/registry/agent-team.ts +350 -0
  9. package/registry/avatar.ts +300 -0
  10. package/registry/badge.ts +207 -0
  11. package/registry/breadcrumb.ts +435 -0
  12. package/registry/button.ts +238 -0
  13. package/registry/card.ts +221 -0
  14. package/registry/change-summary.ts +200 -0
  15. package/registry/checkbox.ts +204 -0
  16. package/registry/code-block.ts +332 -0
  17. package/registry/color-picker.ts +720 -0
  18. package/registry/comment-thread.ts +503 -0
  19. package/registry/context-menu.ts +281 -0
  20. package/registry/cover-flow.ts +623 -0
  21. package/registry/date-picker.ts +799 -0
  22. package/registry/decision-inbox.ts +340 -0
  23. package/registry/dialog.ts +577 -0
  24. package/registry/dropdown-menu.ts +864 -0
  25. package/registry/email-draft.ts +916 -0
  26. package/registry/empty-calendar.ts +199 -0
  27. package/registry/empty-state.ts +164 -0
  28. package/registry/enrichment-orbit.ts +164 -0
  29. package/registry/filter-menu.ts +541 -0
  30. package/registry/form-field.ts +308 -0
  31. package/registry/frost-cloud.ts +381 -0
  32. package/registry/ghosted-chat.ts +210 -0
  33. package/registry/glow-cloud.ts +402 -0
  34. package/registry/grid-background.ts +164 -0
  35. package/registry/hover-card.ts +401 -0
  36. package/registry/icon-button.ts +133 -0
  37. package/registry/index.json +2124 -0
  38. package/registry/integration-beam.ts +588 -0
  39. package/registry/integration-grid.ts +209 -0
  40. package/registry/kbd.ts +176 -0
  41. package/registry/layer-stack.ts +351 -0
  42. package/registry/lead-sourcing.ts +285 -0
  43. package/registry/logo-cluster.ts +239 -0
  44. package/registry/logo-marquee.ts +505 -0
  45. package/registry/message-actions.ts +833 -0
  46. package/registry/model-orbit.ts +583 -0
  47. package/registry/model-wheel.ts +372 -0
  48. package/registry/notification-stack.ts +301 -0
  49. package/registry/number-input.ts +552 -0
  50. package/registry/number-ticker.ts +261 -0
  51. package/registry/ochre.css +917 -0
  52. package/registry/otp-input.ts +704 -0
  53. package/registry/overlay.ts +312 -0
  54. package/registry/pagination.ts +362 -0
  55. package/registry/popover.ts +296 -0
  56. package/registry/profile-menu.ts +332 -0
  57. package/registry/progress-tracker.ts +291 -0
  58. package/registry/rating.ts +461 -0
  59. package/registry/reaction-bar.ts +322 -0
  60. package/registry/region-map.ts +537 -0
  61. package/registry/resizable.ts +489 -0
  62. package/registry/scroll-area.ts +271 -0
  63. package/registry/segmented-control.ts +433 -0
  64. package/registry/select.ts +769 -0
  65. package/registry/separator.ts +97 -0
  66. package/registry/shimmer-loader.ts +211 -0
  67. package/registry/side-folder.ts +152 -0
  68. package/registry/skeleton.ts +136 -0
  69. package/registry/skill/INSTRUCTIONS.md +11 -0
  70. package/registry/skill/SKILL.md +65 -0
  71. package/registry/skill/checklist.md +45 -0
  72. package/registry/skill/references/agent-team.md +105 -0
  73. package/registry/skill/references/avatar.md +88 -0
  74. package/registry/skill/references/badge.md +92 -0
  75. package/registry/skill/references/breadcrumb.md +99 -0
  76. package/registry/skill/references/button.md +82 -0
  77. package/registry/skill/references/card.md +111 -0
  78. package/registry/skill/references/catalog.md +114 -0
  79. package/registry/skill/references/change-summary.md +103 -0
  80. package/registry/skill/references/checkbox.md +105 -0
  81. package/registry/skill/references/code-block.md +109 -0
  82. package/registry/skill/references/color-picker.md +138 -0
  83. package/registry/skill/references/comment-thread.md +164 -0
  84. package/registry/skill/references/context-menu.md +205 -0
  85. package/registry/skill/references/cover-flow.md +128 -0
  86. package/registry/skill/references/date-picker.md +154 -0
  87. package/registry/skill/references/decision-inbox.md +126 -0
  88. package/registry/skill/references/dialog.md +155 -0
  89. package/registry/skill/references/dropdown-menu.md +144 -0
  90. package/registry/skill/references/email-draft.md +182 -0
  91. package/registry/skill/references/empty-calendar.md +74 -0
  92. package/registry/skill/references/empty-state.md +118 -0
  93. package/registry/skill/references/enrichment-orbit.md +71 -0
  94. package/registry/skill/references/filter-menu.md +143 -0
  95. package/registry/skill/references/form-field.md +118 -0
  96. package/registry/skill/references/frost-cloud.md +80 -0
  97. package/registry/skill/references/ghosted-chat.md +75 -0
  98. package/registry/skill/references/glow-cloud.md +84 -0
  99. package/registry/skill/references/grid-background.md +76 -0
  100. package/registry/skill/references/hover-card.md +125 -0
  101. package/registry/skill/references/icon-button.md +99 -0
  102. package/registry/skill/references/integration-beam.md +107 -0
  103. package/registry/skill/references/integration-grid.md +100 -0
  104. package/registry/skill/references/kbd.md +65 -0
  105. package/registry/skill/references/layer-stack.md +115 -0
  106. package/registry/skill/references/lead-sourcing.md +92 -0
  107. package/registry/skill/references/logo-cluster.md +92 -0
  108. package/registry/skill/references/logo-marquee.md +123 -0
  109. package/registry/skill/references/message-actions.md +146 -0
  110. package/registry/skill/references/model-orbit.md +106 -0
  111. package/registry/skill/references/model-wheel.md +84 -0
  112. package/registry/skill/references/notification-stack.md +138 -0
  113. package/registry/skill/references/number-input.md +117 -0
  114. package/registry/skill/references/number-ticker.md +73 -0
  115. package/registry/skill/references/otp-input.md +142 -0
  116. package/registry/skill/references/pagination.md +112 -0
  117. package/registry/skill/references/popover.md +143 -0
  118. package/registry/skill/references/profile-menu.md +123 -0
  119. package/registry/skill/references/progress-tracker.md +122 -0
  120. package/registry/skill/references/rating.md +111 -0
  121. package/registry/skill/references/reaction-bar.md +128 -0
  122. package/registry/skill/references/region-map.md +109 -0
  123. package/registry/skill/references/resizable.md +127 -0
  124. package/registry/skill/references/scroll-area.md +113 -0
  125. package/registry/skill/references/segmented-control.md +96 -0
  126. package/registry/skill/references/select.md +122 -0
  127. package/registry/skill/references/separator.md +69 -0
  128. package/registry/skill/references/shimmer-loader.md +83 -0
  129. package/registry/skill/references/side-folder.md +75 -0
  130. package/registry/skill/references/skeleton.md +95 -0
  131. package/registry/skill/references/smart-recommendation.md +132 -0
  132. package/registry/skill/references/spinner.md +84 -0
  133. package/registry/skill/references/switch.md +79 -0
  134. package/registry/skill/references/tab-overload.md +70 -0
  135. package/registry/skill/references/tag-input.md +126 -0
  136. package/registry/skill/references/team-invite.md +94 -0
  137. package/registry/skill/references/testimonial-wall.md +110 -0
  138. package/registry/skill/references/text-area.md +115 -0
  139. package/registry/skill/references/text-field.md +126 -0
  140. package/registry/skill/references/text-reveal.md +71 -0
  141. package/registry/skill/references/thinking-loader.md +87 -0
  142. package/registry/skill/references/time-picker.md +122 -0
  143. package/registry/skill/references/tips-panel.md +115 -0
  144. package/registry/skill/references/toggle-group.md +98 -0
  145. package/registry/skill/references/tool-call-card.md +151 -0
  146. package/registry/skill/references/tooltip.md +94 -0
  147. package/registry/skill/references/tree-view.md +172 -0
  148. package/registry/skill/theming.md +57 -0
  149. package/registry/smart-recommendation.ts +415 -0
  150. package/registry/spinner.ts +67 -0
  151. package/registry/switch.ts +146 -0
  152. package/registry/tab-overload.ts +211 -0
  153. package/registry/tag-input.ts +620 -0
  154. package/registry/team-invite.ts +248 -0
  155. package/registry/testimonial-wall.ts +521 -0
  156. package/registry/text-area.ts +432 -0
  157. package/registry/text-field.ts +415 -0
  158. package/registry/text-reveal.ts +175 -0
  159. package/registry/theme.ts +68 -0
  160. package/registry/thinking-loader.ts +302 -0
  161. package/registry/time-picker.ts +828 -0
  162. package/registry/tips-panel.ts +312 -0
  163. package/registry/toggle-group.ts +357 -0
  164. package/registry/tool-call-card.ts +578 -0
  165. package/registry/tooltip.ts +486 -0
  166. package/registry/tree-view.ts +454 -0
  167. package/styles/base.css +500 -0
  168. package/styles/tokens.css +415 -0
@@ -0,0 +1,799 @@
1
+ // Ochre (https://ochreui.dev), MIT License, Copyright (c) 2026 Ochre. Keep this notice in copies of this file.
2
+ /**
3
+ * Date Picker, from Ochre (https://ochreui.dev).
4
+ * Needs ochre.css (`npx ochreui init`) and overlay.ts (`npx ochreui add overlay`).
5
+ *
6
+ * <ui-date-picker label="First run" hint="Runs on weekdays only.">
7
+ * <button uiDatePicker [formField]="form.firstRun" [minDate]="today" [isDateDisabled]="weekend"></button>
8
+ * </ui-date-picker>
9
+ * Your own <button> is the field; the directive owns the value (a Date at local midnight, or null) and works with
10
+ * signal forms, reactive forms, ngModel and [(value)]. UiCalendar is the month grid on its own, for inline use.
11
+ *
12
+ * Public styling hooks (set them on the element or any ancestor):
13
+ * --ui-text-field-edge resting edge (default: the hairline), shared with Text Field and Select
14
+ * --ui-text-field-edge-hover edge on hover
15
+ * --ui-text-field-edge-focus edge while the card is open (default: the input border)
16
+ * --ui-text-field-radius corners (default 7px; Classic 10px)
17
+ * --ui-date-picker-radius card corners (default 10px; Classic 16px)
18
+ * --ui-date-picker-cell one day's cell (default 32px; Classic 34px; touch 40px)
19
+ * --ui-date-picker-day the day inside it (default 28px; Classic 30px; touch 36px)
20
+ * --ui-date-picker-selected-bg chosen day's chip (default: ink; Classic: sky blue)
21
+ * --ui-date-picker-selected-fg its number
22
+ * --ui-date-picker-today today's number (default: the blue of the today dot; Classic: ink)
23
+ */
24
+ import {
25
+ Component,
26
+ DOCUMENT,
27
+ DestroyRef,
28
+ Directive,
29
+ ElementRef,
30
+ LOCALE_ID,
31
+ PLATFORM_ID,
32
+ afterNextRender,
33
+ afterRenderEffect,
34
+ booleanAttribute,
35
+ computed,
36
+ contentChild,
37
+ effect,
38
+ forwardRef,
39
+ inject,
40
+ input,
41
+ isDevMode,
42
+ linkedSignal,
43
+ model,
44
+ signal,
45
+ untracked,
46
+ viewChild,
47
+ } from '@angular/core';
48
+ import { isPlatformBrowser } from '@angular/common';
49
+ import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
50
+ import { OverlayRef } from './overlay';
51
+
52
+ export type DateRule = (date: Date) => boolean;
53
+ export type WeekDay = 0 | 1 | 2 | 3 | 4 | 5 | 6;
54
+ export type DatePickerSize = 'sm' | 'md' | 'lg';
55
+
56
+ export interface CalendarLabels {
57
+ previousMonth: string;
58
+ nextMonth: string;
59
+ }
60
+
61
+ export interface DatePickerLabels extends CalendarLabels {
62
+ optional: string;
63
+ placeholder: string;
64
+ }
65
+
66
+ const LABELS: DatePickerLabels = { previousMonth: 'Previous month', nextMonth: 'Next month', optional: 'Optional', placeholder: 'Pick a date' };
67
+ const OFFSET = 6;
68
+
69
+ let nextId = 0;
70
+
71
+ /** The same day at local midnight. */
72
+ export const startOfDay = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate());
73
+ const addDays = (d: Date, n: number) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
74
+ const monthOf = (d: Date) => new Date(d.getFullYear(), d.getMonth(), 1);
75
+ /** The same date `n` months later, on the month's last day when it is shorter. */
76
+ const addMonths = (d: Date, n: number) =>
77
+ new Date(d.getFullYear(), d.getMonth() + n, Math.min(d.getDate(), new Date(d.getFullYear(), d.getMonth() + n + 1, 0).getDate()));
78
+
79
+ /** `YYYY-MM-DD` from the local date, never shifted through UTC. What a native form submits. */
80
+ export function toIsoDay(d: Date) {
81
+ const two = (n: number) => String(n).padStart(2, '0');
82
+ return `${String(d.getFullYear()).padStart(4, '0')}-${two(d.getMonth() + 1)}-${two(d.getDate())}`;
83
+ }
84
+
85
+ const formats = new Map<string, Intl.DateTimeFormat>();
86
+ function format(locale: string, opts: Intl.DateTimeFormatOptions) {
87
+ const key = locale + JSON.stringify(opts);
88
+ let f = formats.get(key);
89
+ if (!f) formats.set(key, (f = new Intl.DateTimeFormat(locale, opts)));
90
+ return f;
91
+ }
92
+
93
+ /** The locale's first day of the week: from the browser when it knows, else Sunday for US English and Monday elsewhere. */
94
+ function firstDay(locale: string): WeekDay {
95
+ try {
96
+ type Week = { firstDay?: number };
97
+ const l = new Intl.Locale(locale) as Intl.Locale & { getWeekInfo?(): Week; weekInfo?: Week };
98
+ const first = (l.getWeekInfo?.() ?? l.weekInfo)?.firstDay;
99
+ if (first) return (first % 7) as WeekDay;
100
+ } catch {}
101
+ return /^en(-US)?$/i.test(locale) ? 0 : 1;
102
+ }
103
+
104
+ interface Day {
105
+ date: Date;
106
+ key: number;
107
+ text: string;
108
+ name: string;
109
+ out: boolean;
110
+ off: boolean;
111
+ today: boolean;
112
+ chosen: boolean;
113
+ }
114
+
115
+ const CHEVRON = 'M10 3.5 5.5 8l4.5 4.5';
116
+
117
+ /** One month: a header with the month arrows, the weekday row and always six weeks. Arrow keys move a single tab stop. */
118
+ @Component({
119
+ selector: 'ui-calendar',
120
+ host: { '[id]': 'id()' },
121
+ template: `
122
+ <div style="display: flex; align-items: center; gap: var(--ui-space-1)">
123
+ <button type="button" class="ui-btn-icon arr" [disabled]="!canPrev()" [attr.aria-label]="t().previousMonth" (click)="go(-1)">
124
+ <svg class="ui-icon" viewBox="0 0 16 16" aria-hidden="true"><path [attr.d]="chevron" /></svg>
125
+ </button>
126
+ <div #heading [id]="id() + '-title'" aria-live="polite" style="flex: 1; min-inline-size: 0; overflow: hidden; text-align: center; white-space: nowrap; font-size: calc(var(--ui-text-base) + 0.5px * var(--_t)); font-weight: calc(500 + 100 * var(--_t))">
127
+ {{ title() }}
128
+ </div>
129
+ <button type="button" class="ui-btn-icon arr" [disabled]="!canNext()" [attr.aria-label]="t().nextMonth" (click)="go(1)">
130
+ <svg class="ui-icon next" viewBox="0 0 16 16" aria-hidden="true"><path [attr.d]="chevron" /></svg>
131
+ </button>
132
+ </div>
133
+ <div #grid role="grid" style="display: grid" [attr.aria-labelledby]="id() + '-title'" (keydown)="key($event)">
134
+ <div role="row" style="display: grid; grid-template-columns: repeat(7, var(--_c))">
135
+ @for (h of heads(); track $index) {
136
+ <span role="columnheader" class="wd" [attr.aria-label]="h[1]" style="display: grid; place-items: center; block-size: calc(var(--ui-space-6) + 2px * var(--_t)); color: var(--ui-text-muted); font-size: calc(var(--ui-text-xs) - 1px + 1px * var(--_t)); font-weight: var(--ui-weight-medium); letter-spacing: calc(0.5px - 0.5px * var(--_t))"><span aria-hidden="true">{{ h[0] }}</span></span>
137
+ }
138
+ </div>
139
+ <div #body role="rowgroup">
140
+ @for (w of weeks(); track $index) {
141
+ <div role="row" style="display: grid; grid-template-columns: repeat(7, var(--_c))">
142
+ @for (d of w; track d.key) {
143
+ <span role="gridcell" [attr.tabindex]="d.key === focus().getTime() ? 0 : -1" [attr.aria-label]="d.name" [attr.aria-selected]="d.chosen"
144
+ [attr.aria-disabled]="d.off || null" [attr.aria-current]="d.today ? 'date' : null" [attr.data-out]="d.out || null" (click)="press(d)"
145
+ >{{ d.text }}@if (d.today) {<span class="dot" style="position: absolute; inset-inline: 0; inset-block-end: calc(3px + 1px * var(--_t)); inline-size: calc(4px - 1px * var(--_t)); aspect-ratio: 1; margin-inline: auto; border-radius: 50%"></span>}</span>
146
+ }
147
+ </div>
148
+ }
149
+ </div>
150
+ </div>
151
+ `,
152
+ styles: `
153
+ :host {
154
+ --_t: var(--ui-look-tray, 0);
155
+ --_m: var(--ui-motion-scale);
156
+ --_c: var(--ui-date-picker-cell, calc(var(--ui-space-8) + 2px * var(--_t)));
157
+ --_d: var(--ui-date-picker-day, calc(var(--ui-space-6) + 4px + 2px * var(--_t)));
158
+ --_r: calc(var(--ui-radius-sm) + 3px * var(--_t));
159
+ display: grid;
160
+ gap: var(--ui-space-1);
161
+ inline-size: max-content;
162
+ color: var(--ui-text);
163
+ font: var(--ui-text-base) / var(--ui-leading-base) var(--ui-font-sans);
164
+ }
165
+ .arr { --_s: calc(var(--ui-space-6) + 4px + 2px * var(--_t)); position: relative; border-radius: var(--_r); transition-duration: calc(140ms * var(--_m)); }
166
+ .arr:disabled { opacity: 0.35; cursor: default; }
167
+ .next, .arr:dir(rtl) svg { scale: -1 1; }
168
+ .arr:dir(rtl) .next { scale: 1; }
169
+ .wd { text-transform: uppercase; }
170
+ @container style(--ui-look-tray: 1) { .wd { text-transform: none; } }
171
+ @keyframes pop { from { scale: 0.8; } }
172
+ [role='gridcell'] {
173
+ --_h: calc((120ms + 80ms * var(--_t)) * var(--_m)) var(--ui-ease-out);
174
+ position: relative;
175
+ display: grid;
176
+ place-items: center;
177
+ inline-size: var(--_d);
178
+ block-size: var(--_d);
179
+ margin: calc((var(--_c) - var(--_d)) / 2);
180
+ border-radius: var(--_r);
181
+ font-size: calc(var(--ui-text-base) - 0.5px * var(--_t));
182
+ font-variant-numeric: tabular-nums;
183
+ user-select: none;
184
+ -webkit-tap-highlight-color: transparent;
185
+ transition: background-color var(--_h), color var(--_h), scale calc(160ms * var(--_m)) var(--ui-ease-out);
186
+ }
187
+ [data-out] { color: var(--ui-text-muted); }
188
+ [aria-current] { color: var(--ui-date-picker-today, color-mix(in srgb, var(--ui-text) calc(100% * var(--_t)), var(--ui-hue-blue))); font-weight: calc(500 + 100 * var(--_t)); }
189
+ .dot { background: color-mix(in srgb, color-mix(in srgb, var(--ui-text-muted) 50%, transparent) calc(100% * var(--_t)), var(--ui-hue-blue)); }
190
+ [aria-disabled] { color: color-mix(in srgb, var(--ui-text) 29%, var(--ui-bg-overlay)); }
191
+ [role='gridcell']:not([aria-disabled]) { cursor: pointer; }
192
+ @media (hover: hover) {
193
+ [role='gridcell']:not([aria-disabled], [aria-selected='true']):hover { background: color-mix(in srgb, var(--ui-text) 6%, transparent); }
194
+ }
195
+ [role='gridcell']:not([aria-disabled]):active { scale: 0.94; }
196
+ [aria-selected='true'] {
197
+ background: var(--ui-date-picker-selected-bg, color-mix(in srgb, light-dark(color-mix(in oklab, var(--ui-hue-blue) 70%, var(--ui-bg-overlay)), var(--ui-info)) calc(100% * var(--_t)), var(--ui-bg-neutral-solid)));
198
+ color: var(--ui-date-picker-selected-fg, var(--ui-text-on-neutral));
199
+ font-weight: calc(500 + 100 * var(--_t));
200
+ animation: pop calc(380ms * var(--_m)) var(--ui-ease-spring);
201
+ }
202
+ [aria-selected='true'] .dot { background: currentColor; }
203
+ [role='gridcell']:focus-visible { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset-inset); }
204
+ @media (pointer: coarse) {
205
+ :host { --_c: var(--ui-date-picker-cell, var(--ui-space-10)); --_d: var(--ui-date-picker-day, calc(var(--ui-space-8) + 4px)); }
206
+ .arr::before { content: ''; position: absolute; inset: -6px; }
207
+ }
208
+ @media (forced-colors: active) {
209
+ [aria-disabled] { color: GrayText; }
210
+ .dot { forced-color-adjust: none; background: CanvasText; }
211
+ [aria-selected='true'] { forced-color-adjust: none; background: Highlight; color: HighlightText; }
212
+ [aria-selected='true'] .dot { background: HighlightText; }
213
+ }
214
+ `,
215
+ })
216
+ export class UiCalendar {
217
+ /** The chosen day, at local midnight. Bind `[(value)]`; it changes when a day is picked. */
218
+ readonly value = model<Date | null>(null);
219
+ /** Earlier days can't be picked, and the previous-month arrow stops at its month. */
220
+ readonly minDate = input<Date | null | undefined>(null);
221
+ /** Later days can't be picked. Ignored when it lies before `minDate`. */
222
+ readonly maxDate = input<Date | null | undefined>(null);
223
+ /** Rules out single days, such as weekends or holidays. They stay visible and focusable. */
224
+ readonly isDateDisabled = input<DateRule | null | undefined>(null);
225
+ /** BCP 47 locale for the names, the digits and the week. Default: the app's `LOCALE_ID`. */
226
+ readonly locale = input<string | null | undefined>(null);
227
+ /** 0 is Sunday, 6 is Saturday. Default: the locale's. */
228
+ readonly weekStartsOn = input<WeekDay | null | undefined>(null);
229
+ /** Where the today marker sits. Default: the real today. */
230
+ readonly today = input<Date | null | undefined>(null);
231
+ /** Words to translate: the two arrow names. */
232
+ readonly labels = input<Partial<CalendarLabels>>({});
233
+ readonly id = input(`ui-calendar-${nextId++}`);
234
+
235
+ private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
236
+ private readonly appLocale = inject(LOCALE_ID);
237
+ private readonly grid = viewChild.required<ElementRef<HTMLElement>>('grid');
238
+ private readonly body = viewChild.required<ElementRef<HTMLElement>>('body');
239
+ private readonly titleEl = viewChild.required<ElementRef<HTMLElement>>('heading');
240
+ protected readonly chevron = CHEVRON;
241
+ protected readonly t = computed(() => ({ ...LABELS, ...this.labels() }));
242
+ private readonly loc = computed(() => this.locale() || this.appLocale);
243
+ private readonly lo = computed(() => {
244
+ const d = this.minDate();
245
+ return d ? startOfDay(d) : null;
246
+ });
247
+ private readonly hi = computed(() => {
248
+ const d = this.maxDate();
249
+ const lo = this.lo();
250
+ return d && !(lo && d < lo) ? startOfDay(d) : null;
251
+ });
252
+ private readonly now = computed(() => startOfDay(this.today() ?? new Date()));
253
+ private readonly start = computed(() => {
254
+ const v = this.value();
255
+ return v ? startOfDay(v) : this.clamp(this.now());
256
+ });
257
+ private readonly weekStart = computed(() => this.weekStartsOn() ?? firstDay(this.loc()));
258
+
259
+ /** The day holding the tab stop. */
260
+ readonly focus = linkedSignal(() => this.start());
261
+ /** The first of the month shown. */
262
+ readonly view = linkedSignal(() => monthOf(this.start()));
263
+ protected readonly back = signal(false);
264
+ private pending = false;
265
+
266
+ protected readonly title = computed(() => format(this.loc(), { month: 'long', year: 'numeric' }).format(this.view()));
267
+ protected readonly canPrev = computed(() => !this.lo() || this.view() > monthOf(this.lo()!));
268
+ protected readonly canNext = computed(() => !this.hi() || this.view() < monthOf(this.hi()!));
269
+ protected readonly heads = computed(() => {
270
+ const loc = this.loc();
271
+ const short = format(loc, { weekday: 'short' });
272
+ const narrow = format(loc, { weekday: 'narrow' });
273
+ const long = format(loc, { weekday: 'long' });
274
+ return Array.from({ length: 7 }, (_, i) => {
275
+ const d = new Date(2026, 0, 4 + ((this.weekStart() + i) % 7));
276
+ const s = short.format(d).replace('.', '');
277
+ return [/^\p{Script=Latin}/u.test(s) ? s.slice(0, 2) : narrow.format(d), long.format(d)];
278
+ });
279
+ });
280
+ protected readonly weeks = computed(() => {
281
+ const view = this.view();
282
+ const loc = this.loc();
283
+ const name = format(loc, { dateStyle: 'full' });
284
+ const num = new Intl.NumberFormat(loc, { useGrouping: false });
285
+ const first = addDays(view, -((view.getDay() - this.weekStart() + 7) % 7));
286
+ const now = this.now().getTime();
287
+ const chosen = this.value() ? startOfDay(this.value()!).getTime() : NaN;
288
+ return Array.from({ length: 6 }, (_, w) =>
289
+ Array.from({ length: 7 }, (_, i): Day => {
290
+ const date = addDays(first, w * 7 + i);
291
+ const key = date.getTime();
292
+ return {
293
+ date,
294
+ key,
295
+ text: num.format(date.getDate()),
296
+ name: name.format(date),
297
+ out: date.getMonth() !== view.getMonth(),
298
+ off: !this.pickable(date),
299
+ today: key === now,
300
+ chosen: key === chosen,
301
+ };
302
+ }),
303
+ );
304
+ });
305
+
306
+ constructor() {
307
+ afterRenderEffect(() => {
308
+ this.view();
309
+ untracked(() => this.enter());
310
+ });
311
+ afterRenderEffect(() => {
312
+ this.focus();
313
+ this.view();
314
+ if (this.pending) untracked(() => this.focusDay());
315
+ });
316
+ }
317
+
318
+ /** True when `date` is inside the bounds and not ruled out. */
319
+ pickable(date: Date) {
320
+ const lo = this.lo();
321
+ const hi = this.hi();
322
+ return !(lo && date < lo) && !(hi && date > hi) && !this.isDateDisabled()?.(date);
323
+ }
324
+
325
+ /** Moves focus to the day holding the tab stop. */
326
+ focusDay() {
327
+ this.pending = false;
328
+ this.grid().nativeElement.querySelector<HTMLElement>('[tabindex="0"]')?.focus({ preventScroll: true });
329
+ }
330
+
331
+ /** Shows the previous (-1) or next (1) month; the tab stop keeps its day of the month. */
332
+ go(months: number) {
333
+ this.show(monthOf(addMonths(this.view(), months)));
334
+ this.focus.set(this.clamp(addMonths(this.focus(), months)));
335
+ }
336
+
337
+ protected press(d: Day) {
338
+ if (!d.off) this.value.set(d.date);
339
+ else this.move(d.date, false);
340
+ }
341
+
342
+ protected key(e: KeyboardEvent) {
343
+ const f = this.focus();
344
+ const back = this.host.ownerDocument.defaultView?.getComputedStyle(this.host).direction === 'rtl' ? -1 : 1;
345
+ const into = (f.getDay() - this.weekStart() + 7) % 7;
346
+ const steps: Record<string, () => Date> = {
347
+ ArrowLeft: () => addDays(f, -back),
348
+ ArrowRight: () => addDays(f, back),
349
+ ArrowUp: () => addDays(f, -7),
350
+ ArrowDown: () => addDays(f, 7),
351
+ PageUp: () => addMonths(f, e.shiftKey ? -12 : -1),
352
+ PageDown: () => addMonths(f, e.shiftKey ? 12 : 1),
353
+ Home: () => addDays(f, -into),
354
+ End: () => addDays(f, 6 - into),
355
+ };
356
+ if (e.key === 'Enter' || e.key === ' ') {
357
+ e.preventDefault();
358
+ if (this.pickable(f)) this.value.set(f);
359
+ return;
360
+ }
361
+ const step = steps[e.key];
362
+ if (!step || e.altKey || e.ctrlKey || e.metaKey) return;
363
+ e.preventDefault();
364
+ this.move(this.clamp(step()), true);
365
+ }
366
+
367
+ /** The month slides in from the side you went to while the title fades in. */
368
+ private enter() {
369
+ const view = this.host.ownerDocument.defaultView;
370
+ if (!view) return;
371
+ const style = view.getComputedStyle(this.host);
372
+ const read = (name: string) => parseFloat(style.getPropertyValue(name));
373
+ const scale = read('--ui-motion-scale');
374
+ const motion = Number.isNaN(scale) ? 1 : scale;
375
+ if (!motion) return;
376
+ const tray = read('--ui-look-tray') || 0;
377
+ const easing = style.getPropertyValue('--ui-ease-out').trim() || 'ease-out';
378
+ const x = (12 + 2 * tray) * (this.back() ? -1 : 1) * (style.direction === 'rtl' ? -1 : 1);
379
+ this.body().nativeElement.animate?.([{ opacity: 0, translate: `${x}px 0` }, {}], { duration: (260 + 40 * tray) * motion, easing });
380
+ this.titleEl().nativeElement.animate?.([{ opacity: 0 }, {}], { duration: (220 + 20 * tray) * motion, easing });
381
+ }
382
+
383
+ private move(date: Date, focus: boolean) {
384
+ this.show(monthOf(date));
385
+ this.focus.set(date);
386
+ this.pending = focus;
387
+ }
388
+
389
+ private show(month: Date) {
390
+ const v = this.view();
391
+ if (month.getTime() === v.getTime()) return;
392
+ this.back.set(month < v);
393
+ this.view.set(month);
394
+ }
395
+
396
+ private clamp(d: Date) {
397
+ const lo = this.lo();
398
+ const hi = this.hi();
399
+ return lo && d < lo ? lo : hi && d > hi ? hi : d;
400
+ }
401
+ }
402
+
403
+ /** Put it on the empty `<button>` inside a `<ui-date-picker>`. It owns the value, the ARIA and the keys. */
404
+ @Directive({
405
+ selector: 'button[uiDatePicker]',
406
+ exportAs: 'uiDatePicker',
407
+ providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: forwardRef(() => UiDatePickerTrigger), multi: true }],
408
+ host: {
409
+ type: 'button',
410
+ 'aria-haspopup': 'dialog',
411
+ style:
412
+ 'position: absolute; inset: 0; box-sizing: border-box; margin: 0; padding: 0 var(--_pe) 0 var(--_ps); border: 0; border-radius: inherit; outline: 0; background: none; color: var(--_fg); font: inherit; text-align: start; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent',
413
+ '[id]': 'id()',
414
+ '[attr.name]': 'null',
415
+ '[attr.required]': 'null',
416
+ '[attr.aria-labelledby]': 'labelledBy()',
417
+ '[attr.aria-expanded]': 'open()',
418
+ '[attr.aria-controls]': 'open() ? field.panelId : null',
419
+ '[attr.aria-describedby]': 'describedBy()',
420
+ '[attr.aria-invalid]': 'field.invalid() || null',
421
+ '[attr.aria-required]': 'required() || null',
422
+ '[textContent]': 'display()',
423
+ '(click)': 'field.toggle()',
424
+ '(keydown)': 'field.key($event)',
425
+ '(blur)': 'open() || onTouched()',
426
+ '(document:reset)': 'formReset($event)',
427
+ },
428
+ })
429
+ export class UiDatePickerTrigger implements ControlValueAccessor {
430
+ /** The chosen day at local midnight; `null` shows the placeholder. Bind `[(value)]`, `[formField]`, `formControlName` or `ngModel`. */
431
+ readonly value = model<Date | null>(null);
432
+ /** Whether the card is showing. Bind `[(open)]` to open it from code; that never moves focus. */
433
+ readonly open = model(false);
434
+ /** Earlier days can't be picked. Not `min`: signal forms keep that name for numbers. */
435
+ readonly minDate = input<Date | null | undefined>(null);
436
+ /** Later days can't be picked. Ignored when it lies before `minDate`. */
437
+ readonly maxDate = input<Date | null | undefined>(null);
438
+ /** Rules out single days, such as weekends or holidays. They stay visible. */
439
+ readonly isDateDisabled = input<DateRule | null | undefined>(null);
440
+ /** BCP 47 locale for the names, the digits, the week and the shown value. Default: the app's `LOCALE_ID`. */
441
+ readonly locale = input<string | null | undefined>(null);
442
+ /** 0 is Sunday, 6 is Saturday. Default: the locale's. */
443
+ readonly weekStartsOn = input<WeekDay | null | undefined>(null);
444
+ /** Where the today marker sits. Default: the real today. */
445
+ readonly today = input<Date | null | undefined>(null);
446
+ /** Shown in grey while nothing is chosen. Default: `labels.placeholder`. */
447
+ readonly placeholder = input<string>();
448
+ /** Submits the day as `YYYY-MM-DD` with a native form, through a hidden input. */
449
+ readonly name = input<string>();
450
+ /** Sets `aria-required`. Signal forms set it from the schema. */
451
+ readonly required = input(false, { transform: booleanAttribute });
452
+ readonly id = input(`ui-date-picker-${nextId++}`);
453
+ /** Your own descriptions, kept alongside the field's. Set it as `aria-describedby="…"`, not `[attr.aria-describedby]`. */
454
+ readonly ariaDescribedby = input<string>(undefined, { alias: 'aria-describedby' });
455
+
456
+ readonly el = inject<ElementRef<HTMLButtonElement>>(ElementRef).nativeElement;
457
+ protected readonly field = inject(UiDatePicker);
458
+ readonly disabled = signal(false);
459
+ private readonly appLocale = inject(LOCALE_ID);
460
+ private readonly named = this.el.hasAttribute('aria-label') || this.el.hasAttribute('aria-labelledby');
461
+ private onChange: (v: Date | null) => void = () => {};
462
+ /** Marks the field touched: on blur while closed, and when the card closes. */
463
+ onTouched: () => void = () => {};
464
+ private initial: Date | null = null;
465
+
466
+ readonly display = computed(() => {
467
+ const v = this.value();
468
+ if (!v) return this.placeholder() || this.field.t().placeholder;
469
+ return format(this.locale() || this.appLocale, { weekday: 'short', month: 'short', day: 'numeric', year: 'numeric' }).format(v);
470
+ });
471
+ protected readonly labelledBy = computed(() => (!this.named && this.field.label() ? `${this.field.labelId} ${this.id()}` : null));
472
+ protected readonly describedBy = computed(
473
+ () => [this.ariaDescribedby(), ...this.field.describers()].filter(Boolean).join(' ') || null,
474
+ );
475
+
476
+ constructor() {
477
+ const destroy = inject(DestroyRef);
478
+ afterNextRender(() => {
479
+ const el = this.el;
480
+ this.initial = this.value();
481
+ const read = () => this.disabled.set(el.disabled);
482
+ read();
483
+ const view = el.ownerDocument.defaultView;
484
+ if (!view?.MutationObserver) return;
485
+ const watch = new view.MutationObserver(read);
486
+ watch.observe(el, { attributes: true, attributeFilter: ['disabled'] });
487
+ destroy.onDestroy(() => watch.disconnect());
488
+ });
489
+ let shown: string | undefined;
490
+ afterRenderEffect(() => {
491
+ const text = this.display();
492
+ if (shown !== undefined && text !== shown) untracked(() => this.field.rise(this.el));
493
+ shown = text;
494
+ });
495
+ }
496
+
497
+ /** Sets the value as a pick does: forms hear it. */
498
+ choose(v: Date | null) {
499
+ const d = v && startOfDay(v);
500
+ this.value.set(d);
501
+ this.onChange(d);
502
+ }
503
+
504
+ /** With a name, a native form reset puts back the day it started with. */
505
+ protected formReset(event: Event) {
506
+ if (!this.name() || event.target !== this.el.form) return;
507
+ setTimeout(() => {
508
+ if (event.defaultPrevented) return;
509
+ this.open.set(false);
510
+ this.choose(this.initial);
511
+ });
512
+ }
513
+
514
+ writeValue(v: Date | null | undefined) {
515
+ this.value.set(v ? startOfDay(v) : null);
516
+ }
517
+
518
+ registerOnChange(fn: (v: Date | null) => void) {
519
+ this.onChange = fn;
520
+ }
521
+
522
+ registerOnTouched(fn: () => void) {
523
+ this.onTouched = fn;
524
+ }
525
+
526
+ setDisabledState(disabled: boolean) {
527
+ this.el.disabled = disabled;
528
+ this.disabled.set(disabled);
529
+ }
530
+ }
531
+
532
+ const space = (n: string) => `var(--ui-space-${n})`;
533
+ const SIZES: Record<DatePickerSize, Record<string, string>> = {
534
+ sm: { '--_h0': 'var(--ui-control-h-sm)', '--_ht': `calc(${space('8')} + ${space('0-5')})` },
535
+ md: { '--_h0': 'var(--ui-control-h-md)', '--_ht': `calc(${space('8')} + ${space('1-5')})` },
536
+ lg: { '--_h0': `calc(var(--ui-control-h-md) + ${space('1')})`, '--_ht': `calc(${space('10')} + ${space('0-5')})` },
537
+ };
538
+
539
+ @Component({
540
+ selector: 'ui-date-picker',
541
+ imports: [UiCalendar],
542
+ host: {
543
+ '[attr.data-size]': 'size()',
544
+ '[attr.data-open]': 'open() || null',
545
+ '[attr.data-invalid]': 'invalid() || null',
546
+ '[attr.data-disabled]': 'trigger()?.disabled() || null',
547
+ '[attr.data-empty]': '!trigger()?.value() || null',
548
+ '[style]': 'sizes[size()]',
549
+ },
550
+ template: `
551
+ @if (label()) {
552
+ <div class="top" style="display: flex; align-items: baseline; gap: var(--ui-space-1-5)">
553
+ <label style="font-weight: var(--ui-weight-medium)" [id]="labelId" [for]="trigger()?.id()" (click)="focusTrigger($event)">{{ label() }}@if (optional()) {<span class="ui-sr"> ({{ t().optional }})</span>}</label>
554
+ @if (optional()) {<span class="opt" aria-hidden="true">{{ t().optional }}</span>}
555
+ </div>
556
+ }
557
+ <div #box class="box" style="-webkit-tap-highlight-color: transparent" [attr.data-nudge]="nudge() || null" (animationend)="$event.target === $event.currentTarget && nudge.set(false)" (animationcancel)="$event.target === $event.currentTarget && nudge.set(false)">
558
+ <ng-content select="button" />
559
+ <svg class="ui-icon" viewBox="0 0 16 16" aria-hidden="true" style="position: absolute; inset-block: 0; margin-block: auto; color: var(--ui-icon); pointer-events: none; inset-inline-start: var(--_s); inline-size: var(--ui-icon-md); block-size: var(--ui-icon-md)">
560
+ <path d="M4.5 3h7a2 2 0 0 1 2 2v6.5a2 2 0 0 1-2 2h-7a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2zM2.5 6.5h11M5.5 1.75v2.5M10.5 1.75v2.5M5.5 9h.01M8 9h.01M10.5 9h.01M5.5 11.25h.01M8 11.25h.01M10.5 11.25h.01" />
561
+ </svg>
562
+ <svg class="chev ui-icon" viewBox="0 0 16 16" aria-hidden="true" style="position: absolute; inset-block: 0; margin-block: auto; color: var(--ui-icon); pointer-events: none; inset-inline-end: calc(var(--_x) + 1px); inline-size: var(--ui-icon-sm); block-size: var(--ui-icon-sm); stroke-width: 1.8; transition: rotate calc(var(--ui-duration-4) * 0.8) var(--ui-ease-out)"><path d="M4.5 6.25 8 9.75l3.5-3.5" /></svg>
563
+ </div>
564
+ <div #card class="card" style="position: fixed; inset: auto; z-index: var(--ui-z-popover); box-sizing: border-box; margin: 0; padding: calc(var(--ui-space-2) + 2px * var(--_t) - 1px); overflow: hidden auto; border: 1px solid transparent; border-radius: var(--ui-date-picker-radius, calc(var(--ui-radius-sm) + 4px + 6px * var(--_t))); background: var(--ui-bg-overlay); color: var(--ui-text); font-size: var(--ui-text-base); -webkit-tap-highlight-color: transparent" popover="manual" role="dialog" aria-modal="false" [id]="panelId" [attr.aria-labelledby]="panelId + '-cal-title'">
565
+ @if (open() && trigger(); as tr) {
566
+ <ui-calendar [id]="panelId + '-cal'" [value]="tr.value()" [minDate]="tr.minDate()" [maxDate]="tr.maxDate()" [isDateDisabled]="tr.isDateDisabled()"
567
+ [locale]="tr.locale()" [weekStartsOn]="tr.weekStartsOn()" [today]="tr.today()" [labels]="t()" (valueChange)="pick($event)" />
568
+ }
569
+ </div>
570
+ <div class="foot" [class.ui-sr]="!message()">
571
+ <p #msg style="margin: 0" [id]="messageId" dir="auto" aria-live="polite">{{ message() }}</p>
572
+ </div>
573
+ @if (trigger()?.name(); as name) {<input type="hidden" [name]="name" [value]="submitted()" />}
574
+ `,
575
+ styles: `
576
+ :host {
577
+ --_t: var(--ui-look-tray, 0);
578
+ --_h: calc(var(--_h0) + var(--ui-space-1) * var(--_t));
579
+ --_e: var(--ui-text-field-edge, var(--ui-hairline));
580
+ --_w: calc(0.5px + 0.5px * var(--_t));
581
+ --_s: calc(var(--ui-space-2-5) + 2px * var(--_t) - 1px);
582
+ --_x: calc(var(--ui-space-2) + 2px * var(--_t) - 1px);
583
+ --_ps: calc(var(--_s) + var(--ui-icon-md) + var(--ui-space-2));
584
+ --_pe: calc(var(--_x) + var(--ui-icon-md) + var(--ui-space-2));
585
+ --_fg: var(--ui-text);
586
+ display: flex;
587
+ flex-direction: column;
588
+ gap: calc(var(--ui-space-1-5) + 1px * var(--_t));
589
+ min-inline-size: 0;
590
+ color: var(--ui-text);
591
+ font: var(--ui-text-base) / var(--ui-leading-base) var(--ui-font-sans);
592
+ }
593
+ :host([data-empty]) {
594
+ --_fg: light-dark(
595
+ color-mix(in srgb, var(--ui-text-muted) calc(44.5% - 6.5% * var(--_t)), var(--ui-bg-surface)),
596
+ color-mix(in srgb, var(--ui-text-muted) calc(47.5% - 11% * var(--_t)), var(--ui-bg-surface))
597
+ );
598
+ }
599
+ .top, .foot { padding-inline: calc(2px * var(--_t)); }
600
+ .opt, .foot { color: var(--ui-text-muted); font-size: calc(var(--ui-text-sm) + 0.5px * var(--_t)); line-height: calc(var(--ui-leading-xs) + 1px * var(--_t)); }
601
+ .box {
602
+ position: relative;
603
+ box-sizing: border-box;
604
+ block-size: var(--_h);
605
+ border: 1px solid transparent;
606
+ border-radius: var(--ui-text-field-radius, calc(var(--ui-radius-sm) + 1px + 3px * var(--_t)));
607
+ background: var(--_fill, var(--ui-bg-surface));
608
+ box-shadow: 0 0 0 var(--_w) var(--_e), 0 1px 2px color-mix(in srgb, var(--ui-gray-1000) 6%, transparent);
609
+ font-size: calc(var(--ui-text-base) + 0.5px * var(--_t));
610
+ cursor: pointer;
611
+ transition: var(--ui-duration-2) var(--ui-ease-out);
612
+ transition-property: box-shadow, background;
613
+ }
614
+ @media (hover: hover) { .box:hover { --_e: var(--ui-text-field-edge-hover, color-mix(in srgb, var(--ui-text) 18%, transparent)); } }
615
+ .box:has(:focus-visible) { outline: var(--ui-focus-width) solid var(--ui-focus-ring); outline-offset: var(--ui-focus-offset); }
616
+ :host([data-open]) .box { --_w: 1px; --_e: var(--ui-text-field-edge-focus, var(--ui-border-input)); }
617
+ :host([data-invalid]) .box {
618
+ --_w: 1px;
619
+ --_e: color-mix(in srgb, var(--ui-danger) 55%, transparent);
620
+ --_fill: color-mix(in srgb, var(--ui-danger-soft) calc(50% * var(--_t)), var(--ui-bg-surface));
621
+ }
622
+ :host([data-invalid][data-open]) .box { --_e: var(--ui-danger); }
623
+ :host([data-disabled]) { opacity: var(--ui-disabled-opacity); }
624
+ :host([data-disabled]) .box { cursor: not-allowed; --_e: var(--ui-hairline); }
625
+ .box[data-nudge] { animation: ui-nudge calc(var(--ui-duration-4) * 1.07) var(--ui-ease-out); }
626
+ :host([data-open]) .chev { rotate: 180deg; }
627
+ :host([data-invalid]) p { color: var(--ui-danger); }
628
+ .card { --_y: calc(var(--ui-space-1) * -1); box-shadow: var(--ui-shadow-md); transition: calc((200ms + 20ms * var(--_t)) * var(--ui-motion-scale)) var(--ui-ease-out); transition-property: opacity, scale, translate; }
629
+ @container style(--ui-look-tray: 1) { .card { box-shadow: var(--ui-shadow-lg); } }
630
+ .card:not([data-open]) { display: none !important; }
631
+ .card[data-side='top'] { --_y: var(--ui-space-1); }
632
+ .card[data-enter] { opacity: 0; scale: 0.98; translate: 0 var(--_y); transition: none; }
633
+ @media (pointer: coarse) {
634
+ :host { --_h: calc(var(--_ht) + 2px * var(--_t)); }
635
+ .box { font-size: var(--ui-text-field-touch); }
636
+ }
637
+ @media (forced-colors: active) {
638
+ :host([data-invalid]) .box { outline: 1px solid CanvasText; }
639
+ :host([data-open]) .box { outline: 2px solid Highlight; }
640
+ }
641
+ `,
642
+ })
643
+ export class UiDatePicker {
644
+ /** Shown above the field and read with the chosen day as its name. Clicking it focuses the field. */
645
+ readonly label = input<string>();
646
+ /** A quiet line under the field. The error takes its place while there is one. */
647
+ readonly hint = input<string>();
648
+ /** Marks the field invalid and shows this message where the hint was. */
649
+ readonly error = input<string | null | undefined>();
650
+ /** 28, 32 or 36px tall; Classic 32, 36 or 40px. Taller, with 16px text, on touch screens. */
651
+ readonly size = input<DatePickerSize>('md');
652
+ /** Adds "Optional" after the label. */
653
+ readonly optional = input(false, { transform: booleanAttribute });
654
+ /** Words to translate: the "Optional" tag, the placeholder and the two month arrows. */
655
+ readonly labels = input<Partial<DatePickerLabels>>({});
656
+
657
+ readonly trigger = contentChild(UiDatePickerTrigger);
658
+ protected readonly sizes = SIZES;
659
+ readonly t = computed(() => ({ ...LABELS, ...this.labels() }));
660
+ private readonly uid = nextId++;
661
+ readonly panelId = `ui-date-picker-card-${this.uid}`;
662
+ readonly labelId = `ui-date-picker-label-${this.uid}`;
663
+ protected readonly messageId = `ui-date-picker-msg-${this.uid}`;
664
+
665
+ readonly invalid = computed(() => !!this.error());
666
+ protected readonly message = computed(() => this.error() || this.hint() || '');
667
+ readonly describers = computed(() => (this.message() ? [this.messageId] : []));
668
+ readonly open = computed(() => !!this.trigger()?.open());
669
+ protected readonly submitted = computed(() => {
670
+ const v = this.trigger()?.value();
671
+ return v ? toIsoDay(v) : '';
672
+ });
673
+ protected readonly nudge = signal(false);
674
+
675
+ private readonly box = viewChild.required<ElementRef<HTMLElement>>('box');
676
+ private readonly card = viewChild.required<ElementRef<HTMLElement>>('card');
677
+ private readonly calendar = viewChild(UiCalendar);
678
+ private readonly msg = viewChild<ElementRef<HTMLElement>>('msg');
679
+ private readonly doc = inject(DOCUMENT);
680
+ private readonly host = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
681
+ private readonly browser = isPlatformBrowser(inject(PLATFORM_ID));
682
+ private overlay?: OverlayRef;
683
+ private focusOnOpen = false;
684
+ private restore = true;
685
+ private shown = false;
686
+
687
+ constructor() {
688
+ const destroy = inject(DestroyRef);
689
+ let was: boolean | undefined;
690
+ effect(() => {
691
+ const now = this.invalid();
692
+ if (now && was === false) this.nudge.set(true);
693
+ was = now;
694
+ });
695
+ effect(() => {
696
+ if (this.trigger()?.disabled()) untracked(() => this.close(false));
697
+ });
698
+ let shown: string | undefined;
699
+ afterRenderEffect(() => {
700
+ const text = this.message();
701
+ const p = this.msg()?.nativeElement;
702
+ const motion = this.motion();
703
+ if (shown !== undefined && text !== shown && p?.animate && motion) {
704
+ p.animate([{ opacity: 0, filter: 'blur(2px)', transform: 'translateY(-2px)' }, {}], { duration: 260 * motion, easing: 'ease-out' });
705
+ }
706
+ shown = text;
707
+ });
708
+ afterRenderEffect(() => {
709
+ const on = this.open();
710
+ untracked(() => this.sync(on));
711
+ });
712
+ afterNextRender(() => {
713
+ const el = this.trigger()?.el;
714
+ if (isDevMode() && el && !this.label() && !el.hasAttribute('aria-label') && !el.hasAttribute('aria-labelledby')) {
715
+ console.warn('ui-date-picker: give it a label, or an aria-label on the button.', el);
716
+ }
717
+ });
718
+ destroy.onDestroy(() => this.overlay?.hide(false));
719
+ }
720
+
721
+ toggle() {
722
+ if (this.open()) this.close(true);
723
+ else this.show();
724
+ }
725
+
726
+ /** Opens the card with focus on the chosen day, else today, else the nearest day that can be picked. */
727
+ show() {
728
+ const t = this.trigger();
729
+ if (!t || t.disabled()) return;
730
+ this.focusOnOpen = true;
731
+ t.open.set(true);
732
+ }
733
+
734
+ /** Closes it; with `restore`, focus goes back to the field if it was in the card. */
735
+ close(restore: boolean) {
736
+ this.restore = restore;
737
+ this.trigger()?.open.set(false);
738
+ }
739
+
740
+ key(e: KeyboardEvent) {
741
+ if (e.key === 'ArrowDown' && !e.altKey && !this.open()) {
742
+ e.preventDefault();
743
+ this.show();
744
+ }
745
+ }
746
+
747
+ /** The new value fades in, rising a few px (Classic: a little more, with a blur clearing). */
748
+ rise(el: HTMLElement) {
749
+ const motion = this.motion();
750
+ if (!el.animate || !motion) return;
751
+ const style = this.doc.defaultView!.getComputedStyle(this.host);
752
+ const tray = parseFloat(style.getPropertyValue('--ui-look-tray')) || 0;
753
+ el.animate([{ opacity: 0, transform: `translateY(${3 + tray}px)`, filter: `blur(${2 * tray}px)` }, {}], {
754
+ duration: (240 + 20 * tray) * motion,
755
+ easing: style.getPropertyValue('--ui-ease-out').trim() || 'ease-out',
756
+ });
757
+ }
758
+
759
+ protected pick(date: Date | null) {
760
+ this.trigger()?.choose(date);
761
+ this.close(true);
762
+ }
763
+
764
+ protected focusTrigger(event: MouseEvent) {
765
+ event.preventDefault();
766
+ this.trigger()?.el.focus();
767
+ }
768
+
769
+ private sync(on: boolean) {
770
+ if (!this.browser) return;
771
+ this.overlay ??= new OverlayRef(this.card().nativeElement, this.doc, {
772
+ anchor: () => this.box().nativeElement,
773
+ trigger: () => this.trigger()?.el ?? null,
774
+ side: () => 'bottom',
775
+ align: () => 'start',
776
+ offset: () => OFFSET,
777
+ dismiss: (reason) => this.close(reason === 'escape' || reason === 'trigger'),
778
+ });
779
+ if (!on) {
780
+ this.overlay.hide(this.restore);
781
+ this.restore = true;
782
+ if (this.shown) this.trigger()?.onTouched();
783
+ this.shown = false;
784
+ return;
785
+ }
786
+ this.shown = true;
787
+ this.overlay.show(false);
788
+ if (this.focusOnOpen) this.calendar()?.focusDay();
789
+ this.focusOnOpen = false;
790
+ }
791
+
792
+ /** 0 under reduced motion, otherwise the app's motion scale (1 by default). */
793
+ private motion() {
794
+ const view = this.doc.defaultView;
795
+ if (!view?.matchMedia || view.matchMedia('(prefers-reduced-motion: reduce)').matches) return 0;
796
+ const scale = parseFloat(view.getComputedStyle(this.host).getPropertyValue('--ui-motion-scale'));
797
+ return Number.isNaN(scale) ? 1 : scale;
798
+ }
799
+ }