@reliability-design/web 1.4.6 → 1.4.8

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 (148) hide show
  1. package/CHANGELOG.md +246 -49
  2. package/dist/components/rel-accordion/README.md +133 -132
  3. package/dist/components/rel-alert/README.md +145 -141
  4. package/dist/components/rel-autocomplete/README.md +172 -61
  5. package/dist/components/rel-avatar/README.md +118 -130
  6. package/dist/components/rel-badge/README.md +97 -93
  7. package/dist/components/rel-breadcrumb/README.md +96 -102
  8. package/dist/components/rel-button/README.md +190 -130
  9. package/dist/components/rel-calendar/README.md +109 -109
  10. package/dist/components/rel-card/README.md +75 -94
  11. package/dist/components/rel-cardmedia/README.md +100 -127
  12. package/dist/components/rel-carousel/README.md +186 -166
  13. package/dist/components/rel-checkbox/README.md +96 -75
  14. package/dist/components/rel-chip/README.md +138 -121
  15. package/dist/components/rel-container/README.md +107 -99
  16. package/dist/components/rel-date-picker/README.md +200 -289
  17. package/dist/components/rel-divider/README.md +88 -100
  18. package/dist/components/rel-drawer/README.md +187 -200
  19. package/dist/components/rel-kbd/README.md +141 -151
  20. package/dist/components/rel-layout/README.md +34 -0
  21. package/dist/components/rel-menu/README.md +180 -151
  22. package/dist/components/rel-menubar/README.md +218 -329
  23. package/dist/components/rel-otp/README.md +171 -440
  24. package/dist/components/rel-pagination/README.md +100 -424
  25. package/dist/components/rel-popover/README.md +203 -568
  26. package/dist/components/rel-progress/README.md +88 -110
  27. package/dist/components/rel-radio/README.md +131 -138
  28. package/dist/components/rel-range-picker/README.md +165 -0
  29. package/dist/components/rel-resizable/README.md +199 -140
  30. package/dist/components/rel-segmented-button/README.md +156 -141
  31. package/dist/components/rel-select/README.md +156 -93
  32. package/dist/components/rel-sheet/README.md +168 -224
  33. package/dist/components/rel-skeleton/README.md +104 -0
  34. package/dist/components/rel-slider/README.md +131 -135
  35. package/dist/components/rel-snackbar/README.md +168 -134
  36. package/dist/components/rel-stepper/README.md +162 -160
  37. package/dist/components/rel-switch/README.md +117 -102
  38. package/dist/components/rel-tab/README.md +173 -163
  39. package/dist/components/rel-textfield/README.md +176 -69
  40. package/dist/components/rel-time-picker/README.md +122 -157
  41. package/dist/components/rel-toast/README.md +165 -148
  42. package/dist/components/rel-tooltip/README.md +119 -111
  43. package/dist/components/rel-upload/README.md +220 -0
  44. package/dist/index.d.mts +1726 -447
  45. package/dist/index.d.ts +1726 -447
  46. package/dist/index.js +13715 -10870
  47. package/dist/index.js.map +1 -1
  48. package/dist/index.mjs +14018 -11163
  49. package/dist/index.mjs.map +1 -1
  50. package/dist/styles/focus-ring.ts +84 -0
  51. package/dist/styles/vars.css +892 -866
  52. package/dist/{vars-XNMTSRVN.css → vars-DXX6QOAG.css} +892 -866
  53. package/package.json +3 -2
  54. package/dist/components/rel-accordion/rel-accordion.ts +0 -336
  55. package/dist/components/rel-alert/rel-alert.ts +0 -305
  56. package/dist/components/rel-autocomplete/rel-autocomplete.ts +0 -720
  57. package/dist/components/rel-avatar/rel-avatar.ts +0 -142
  58. package/dist/components/rel-badge/rel-badge.ts +0 -175
  59. package/dist/components/rel-breadcrumb/rel-breadcrumb.ts +0 -106
  60. package/dist/components/rel-button/rel-button.ts +0 -560
  61. package/dist/components/rel-calendar/index.ts +0 -1
  62. package/dist/components/rel-calendar/rel-calendar.ts +0 -565
  63. package/dist/components/rel-card/rel-card.ts +0 -88
  64. package/dist/components/rel-cardmedia/rel-cardmedia.ts +0 -88
  65. package/dist/components/rel-carousel/index.ts +0 -1
  66. package/dist/components/rel-carousel/rel-carousel.ts +0 -723
  67. package/dist/components/rel-chart/README.md +0 -286
  68. package/dist/components/rel-chart/index.ts +0 -1
  69. package/dist/components/rel-chart/rel-chart.ts +0 -754
  70. package/dist/components/rel-checkbox/rel-checkbox.ts +0 -382
  71. package/dist/components/rel-chip/rel-chip.ts +0 -483
  72. package/dist/components/rel-container/rel-container.ts +0 -95
  73. package/dist/components/rel-date-picker/date-format.test.ts +0 -43
  74. package/dist/components/rel-date-picker/date-format.ts +0 -47
  75. package/dist/components/rel-date-picker/date-parse.test.ts +0 -116
  76. package/dist/components/rel-date-picker/date-parse.ts +0 -178
  77. package/dist/components/rel-date-picker/index.ts +0 -1
  78. package/dist/components/rel-date-picker/rel-date-picker.ts +0 -1676
  79. package/dist/components/rel-divider/rel-divider.ts +0 -54
  80. package/dist/components/rel-drawer/index.ts +0 -1
  81. package/dist/components/rel-drawer/rel-drawer-footer.ts +0 -27
  82. package/dist/components/rel-drawer/rel-drawer.ts +0 -607
  83. package/dist/components/rel-kbd/rel-kbd.ts +0 -188
  84. package/dist/components/rel-layout/rel-layout.ts +0 -49
  85. package/dist/components/rel-menu/rel-menu.ts +0 -541
  86. package/dist/components/rel-menubar/index.ts +0 -2
  87. package/dist/components/rel-menubar/rel-menubar-menu.css +0 -3
  88. package/dist/components/rel-menubar/rel-menubar-menu.ts +0 -17
  89. package/dist/components/rel-menubar/rel-menubar.ts +0 -777
  90. package/dist/components/rel-nav-menu/README.md +0 -289
  91. package/dist/components/rel-nav-menu/index.ts +0 -3
  92. package/dist/components/rel-nav-menu/rel-nav-menu-item.ts +0 -243
  93. package/dist/components/rel-nav-menu/rel-nav-menu-panel.ts +0 -72
  94. package/dist/components/rel-nav-menu/rel-nav-menu.ts +0 -270
  95. package/dist/components/rel-navbar/README.md +0 -126
  96. package/dist/components/rel-navbar/rel-navbar.ts +0 -105
  97. package/dist/components/rel-otp/index.ts +0 -1
  98. package/dist/components/rel-otp/rel-otp.ts +0 -527
  99. package/dist/components/rel-pagination/index.ts +0 -1
  100. package/dist/components/rel-pagination/rel-pagination.ts +0 -522
  101. package/dist/components/rel-popover/index.ts +0 -2
  102. package/dist/components/rel-popover/rel-popover-content.ts +0 -81
  103. package/dist/components/rel-popover/rel-popover.ts +0 -475
  104. package/dist/components/rel-progress/rel-progress.ts +0 -234
  105. package/dist/components/rel-radio/rel-radio.ts +0 -481
  106. package/dist/components/rel-range-picker/rel-range-picker.ts +0 -1688
  107. package/dist/components/rel-resizable/index.ts +0 -3
  108. package/dist/components/rel-resizable/rel-resizable-group.ts +0 -405
  109. package/dist/components/rel-resizable/rel-resizable-handle.ts +0 -150
  110. package/dist/components/rel-resizable/rel-resizable-panel.ts +0 -58
  111. package/dist/components/rel-segmented-button/rel-segmented-button.ts +0 -217
  112. package/dist/components/rel-select/rel-select.ts +0 -1416
  113. package/dist/components/rel-sheet/rel-sheet.ts +0 -610
  114. package/dist/components/rel-sidebar/README.md +0 -209
  115. package/dist/components/rel-sidebar/rel-sidebar.ts +0 -1191
  116. package/dist/components/rel-skeleton/rel-skeleton.ts +0 -143
  117. package/dist/components/rel-slider/rel-slider.ts +0 -673
  118. package/dist/components/rel-snackbar/rel-snackbar.ts +0 -329
  119. package/dist/components/rel-stepper/rel-stepper.ts +0 -567
  120. package/dist/components/rel-switch/rel-switch.ts +0 -199
  121. package/dist/components/rel-tab/rel-tab.ts +0 -264
  122. package/dist/components/rel-table/README.md +0 -178
  123. package/dist/components/rel-table/rel-table-body.ts +0 -22
  124. package/dist/components/rel-table/rel-table-caption.ts +0 -30
  125. package/dist/components/rel-table/rel-table-cell.ts +0 -43
  126. package/dist/components/rel-table/rel-table-footer.ts +0 -24
  127. package/dist/components/rel-table/rel-table-head.ts +0 -47
  128. package/dist/components/rel-table/rel-table-header.ts +0 -22
  129. package/dist/components/rel-table/rel-table-row.ts +0 -37
  130. package/dist/components/rel-table/rel-table.ts +0 -62
  131. package/dist/components/rel-textfield/rel-textfield.ts +0 -1054
  132. package/dist/components/rel-time-picker/rel-time-picker.ts +0 -1482
  133. package/dist/components/rel-time-picker/time-parse.test.ts +0 -67
  134. package/dist/components/rel-time-picker/time-parse.ts +0 -85
  135. package/dist/components/rel-toast/rel-toast.ts +0 -206
  136. package/dist/components/rel-tooltip/rel-tooltip.ts +0 -193
  137. package/dist/components/rel-topbar/rel-topbar-actions.ts +0 -27
  138. package/dist/components/rel-topbar/rel-topbar-brand.ts +0 -54
  139. package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +0 -69
  140. package/dist/components/rel-topbar/rel-topbar-dropdown.ts +0 -31
  141. package/dist/components/rel-topbar/rel-topbar-item.ts +0 -324
  142. package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +0 -27
  143. package/dist/components/rel-topbar/rel-topbar-profile.ts +0 -243
  144. package/dist/components/rel-topbar/rel-topbar-utilities.ts +0 -27
  145. package/dist/components/rel-topbar/rel-topbar.ts +0 -446
  146. package/dist/components/rel-upload/UPLOAD-DESIGN-CHANGES.md +0 -134
  147. package/dist/components/rel-upload/rel-upload-actions.ts +0 -163
  148. package/dist/components/rel-upload/rel-upload.ts +0 -968
@@ -1,1688 +0,0 @@
1
- import { LitElement, html, css, nothing } from "lit";
2
- import { customElement, property, state, query } from "lit/decorators.js";
3
- import { live } from "lit/directives/live.js";
4
- import "@reliability-design/icons/rel-icon";
5
- import "../rel-button/rel-button";
6
- import { announce } from "../../utils/announce";
7
- import { isEditableTarget } from "../../utils/shortcuts";
8
- import { parseDateInput } from "../rel-date-picker/date-parse";
9
-
10
- interface RangeDay {
11
- date: Date;
12
- day: number;
13
- isCurrentMonth: boolean;
14
- isToday: boolean;
15
- isDraftFrom: boolean;
16
- isDraftTo: boolean;
17
- isInRange: boolean;
18
- isDisabled: boolean;
19
- isWeekend: boolean;
20
- }
21
-
22
- interface QuickSelect {
23
- label: string;
24
- key: string;
25
- from: string;
26
- to: string;
27
- fullWidth?: boolean;
28
- }
29
-
30
- @customElement("rel-range-picker")
31
- export class RelRangePicker extends LitElement {
32
- @property({ type: String }) from: string = "";
33
- @property({ type: String }) to: string = "";
34
- @property({ type: String }) locale: string = "en-US";
35
- @property({ type: String, attribute: "week-start" }) weekStart: "mon" | "sun" = "sun";
36
- @property({ type: String, attribute: "min-date" }) minDate: string = "";
37
- @property({ type: String, attribute: "max-date" }) maxDate: string = "";
38
- @property({ type: Boolean, reflect: true }) disabled = false;
39
- @property({ type: Boolean, reflect: true }) open = false;
40
- @property({ type: String }) mode: "popover" | "popup" = "popover";
41
- @property({ type: String }) width: string = "";
42
- @property({ type: String, attribute: "min-width" }) minWidth: string = "";
43
- @property({ type: String, attribute: "max-width" }) maxWidth: string = "";
44
- @property({ type: String }) height: string = "";
45
- @property({ type: String, attribute: "min-height" }) minHeight: string = "";
46
- @property({ type: String, attribute: "max-height" }) maxHeight: string = "";
47
- @property({ type: String }) placeholder: string = "Select date range";
48
- @property({ type: String, attribute: "trigger-variant" }) triggerVariant: "default" | "icon" = "default";
49
- @property({ type: Boolean }) clearable = false;
50
-
51
- @state() private draftFrom: string = "";
52
- @state() private draftTo: string = "";
53
- @state() private draftActivePreset: string | null = null;
54
- @state() private viewYear: number = new Date().getFullYear();
55
- @state() private viewMonth: number = new Date().getMonth();
56
- @state() private isSelectingRange: boolean = false;
57
- @state() private hoverDate: string | null = null;
58
- /** ISO date of the cell that owns the grid's single Tab stop (roving tabindex). */
59
- @state() private focusedDate: string | null = null;
60
- /** Uncommitted typed text; null → the input shows the committed range. */
61
- @state() private inputText: string | null = null;
62
- /** Parse/range error message for the typed text (cleared on next input). */
63
- @state() private inputError: string | null = null;
64
-
65
- @query(".trigger-input") private triggerInput?: HTMLInputElement;
66
- @query(".popover") private popoverEl?: HTMLDivElement;
67
- @query(".backdrop") private backdropEl?: HTMLDivElement;
68
-
69
- static styles = css`
70
- :host {
71
- color: var(--rel-text-default);
72
- display: inline-block;
73
- font-family: var(--rel-body-md-regular-font-family);
74
- position: relative;
75
- }
76
-
77
- :host([disabled]) {
78
- opacity: 0.6;
79
- cursor: not-allowed;
80
- }
81
-
82
- :host([disabled]) .trigger-button,
83
- :host([disabled]) rel-button {
84
- pointer-events: none;
85
- }
86
-
87
- /* ── Trigger ── */
88
- .trigger-button {
89
- display: flex;
90
- align-items: center;
91
- justify-content: space-between;
92
- gap: var(--rel-spacing-xs, 8px);
93
- padding: var(--rel-spacing-sm, 12px) var(--rel-spacing-md, 16px);
94
- background: var(--rel-bg-surface);
95
- border: 1px solid var(--rel-border-default);
96
- border-radius: var(--rel-border-radius-sm, 8px);
97
- color: var(--rel-text-default);
98
- cursor: pointer;
99
- width: 100%;
100
- text-align: left;
101
- transition: border-color 0.15s ease;
102
- font-family: var(--rel-body-md-regular-font-family);
103
- font-weight: var(--rel-body-md-regular-font-weight);
104
- font-size: var(--rel-body-md-regular-font-size);
105
- line-height: var(--rel-body-md-regular-line-height);
106
- letter-spacing: var(--rel-body-md-regular-letter-spacing);
107
- }
108
-
109
- :host(:not([disabled])) .trigger-button:hover {
110
- border-color: var(--rel-border-accent);
111
- }
112
-
113
- .trigger-button:focus-within {
114
- outline: 2px solid var(--rel-border-focus);
115
- outline-offset: 2px;
116
- }
117
-
118
- .trigger-button.error {
119
- border-color: var(--rel-border-danger);
120
- }
121
-
122
- .trigger-button.error:focus-within {
123
- outline-color: var(--rel-border-danger);
124
- }
125
-
126
- /* The editable field itself — the wrapper carries the box styles. */
127
- .trigger-input {
128
- flex: 1;
129
- min-width: 0;
130
- border: none;
131
- background: transparent;
132
- padding: 0;
133
- margin: 0;
134
- outline: none;
135
- color: var(--rel-text-default);
136
- font: inherit;
137
- letter-spacing: inherit;
138
- cursor: inherit;
139
- }
140
-
141
- .trigger-input::placeholder {
142
- color: var(--rel-text-placeholder);
143
- opacity: 1;
144
- }
145
-
146
- /* Typed-entry error line (the component has no helper-text API). */
147
- .range-picker-support.error {
148
- margin-top: var(--rel-spacing-2xs);
149
- color: var(--rel-text-danger);
150
- font-family: var(--rel-body-xs-regular-font-family);
151
- font-weight: var(--rel-body-xs-regular-font-weight);
152
- font-size: var(--rel-body-xs-regular-font-size);
153
- line-height: var(--rel-body-xs-regular-line-height);
154
- letter-spacing: var(--rel-body-xs-regular-letter-spacing);
155
- }
156
-
157
- .trigger-icons {
158
- display: flex;
159
- align-items: center;
160
- gap: var(--rel-spacing-2xs);
161
- }
162
-
163
- .icon-button {
164
- background: none;
165
- border: none;
166
- padding: var(--rel-spacing-3xs);
167
- cursor: pointer;
168
- color: var(--rel-text-placeholder);
169
- display: flex;
170
- align-items: center;
171
- justify-content: center;
172
- border-radius: var(--rel-border-radius-xs);
173
- transition: all 0.15s ease;
174
- }
175
-
176
- .icon-button:hover {
177
- background: var(--rel-bg-surface-elevated);
178
- color: var(--rel-text-default);
179
- }
180
-
181
- .icon-button svg {
182
- width: 16px;
183
- height: 16px;
184
- }
185
-
186
- /* ── Popover shell ── */
187
- .popover {
188
- /* Reset native [popover] UA styles first (the shell is promoted to
189
- the top layer so transformed / overflow:hidden ancestors — e.g. a
190
- centered rel-modal panel — can't hijack or clip it). While in the
191
- top layer, JS overrides the anchored position below with inline
192
- fixed coordinates; the CSS anchoring is the no-Popover-API
193
- fallback. */
194
- margin: 0;
195
- padding: 0;
196
- width: auto;
197
- height: auto;
198
- color: inherit;
199
- position: absolute;
200
- top: calc(100% + 4px);
201
- left: 0;
202
- z-index: 2147483647;
203
- border: 1px solid var(--rel-border-default);
204
- border-radius: var(--rel-border-radius-sm, 8px);
205
- background: var(--rel-bg-neutral);
206
- box-shadow: var(--rel-shadows-shadow-200);
207
- /* Never wider or taller than the viewport (small screens) — the
208
- two-calendar layout scrolls inside the shell instead of bleeding
209
- off-screen. border-box so the caps include the 1px borders. */
210
- box-sizing: border-box;
211
- max-width: calc(100vw - 16px);
212
- max-height: calc(100vh - 16px);
213
- overflow: auto;
214
- display: none;
215
- }
216
-
217
- .popover.open { display: block; }
218
-
219
- .popover.popup {
220
- position: fixed;
221
- top: 50%;
222
- left: 50%;
223
- transform: translate(-50%, -50%);
224
- }
225
-
226
- .backdrop {
227
- position: fixed;
228
- inset: 0;
229
- /* Reset native [popover] UA styles — the backdrop is promoted to the
230
- top layer right before the panel so the panel stacks above it. */
231
- margin: 0;
232
- padding: 0;
233
- width: auto;
234
- height: auto;
235
- border: none;
236
- z-index: 2147483646;
237
- background: rgba(0,0,0,0.4);
238
- }
239
-
240
- /* ── Two-panel wrapper ── */
241
- .picker-wrapper {
242
- font-family: var(--rel-body-lg-regular-font-family);
243
- font-weight: var(--rel-body-lg-regular-font-weight);
244
- display: flex;
245
- flex-direction: row;
246
- align-items: stretch;
247
- }
248
-
249
- /* ── Left panel: presets ── */
250
- .presets {
251
- width: 280px;
252
- flex-shrink: 0;
253
- flex-grow: 0;
254
- border-right: 1px solid var(--rel-border-default);
255
- padding: var(--rel-spacing-sm);
256
- background: var(--rel-bg-surface-elevated);
257
- display: flex;
258
- flex-direction: column;
259
- gap: 0;
260
- }
261
-
262
- .presets-grid {
263
- display: grid;
264
- grid-template-columns: 1fr 1fr;
265
- gap: 6px;
266
- }
267
-
268
- .preset-item {
269
- display: flex;
270
- align-items: center;
271
- justify-content: space-between;
272
- padding: 10px var(--rel-spacing-sm);
273
- cursor: pointer;
274
- font-family: var(--rel-body-sm-medium-font-family);
275
- font-weight: var(--rel-body-sm-medium-font-weight);
276
- font-size: var(--rel-body-sm-medium-font-size);
277
- line-height: var(--rel-body-sm-medium-line-height);
278
- letter-spacing: var(--rel-body-sm-medium-letter-spacing);
279
- color: var(--rel-action-neutral-label-icons-link);
280
- background: var(--rel-bg-neutral-elevated-1);
281
- border: none;
282
- border-radius: var(--rel-border-radius-sm, 8px);
283
- width: 100%;
284
- white-space: nowrap;
285
- overflow: hidden;
286
- text-overflow: ellipsis;
287
- transition: background 0.15s ease;
288
- }
289
-
290
- .preset-item:hover:not(.active) {
291
- background: var(--rel-action-overlay-hover);
292
- }
293
-
294
- .preset-item.active {
295
- background: var(--rel-bg-neutral-inverse-2);
296
- color: var(--rel-text-inverse);
297
- font-weight: var(--rel-body-sm-semibold-font-weight);
298
- }
299
-
300
- .preset-item.full-width {
301
- grid-column: 1 / -1;
302
- }
303
-
304
- /* Single-key hint chip on each preset (T, M, W, …). */
305
- .preset-key {
306
- flex-shrink: 0;
307
- margin-left: var(--rel-spacing-2xs);
308
- border: 1px solid var(--rel-border-default);
309
- border-bottom-width: 2px;
310
- border-radius: var(--rel-border-radius-xs);
311
- background: var(--rel-bg-surface);
312
- padding: 0 var(--rel-spacing-3xs);
313
- min-width: 18px;
314
- text-align: center;
315
- font-family: var(--rel-body-xs-regular-font-family);
316
- font-weight: var(--rel-body-xs-regular-font-weight);
317
- font-size: var(--rel-body-xs-regular-font-size);
318
- line-height: var(--rel-body-xs-regular-line-height);
319
- color: var(--rel-text-label);
320
- }
321
-
322
- .preset-item.active .preset-key {
323
- display: none;
324
- }
325
-
326
- /* ── FROM/TO inputs ── */
327
- .date-inputs {
328
- display: flex;
329
- align-items: center;
330
- gap: 8px;
331
- padding: 14px 8px 4px;
332
- border-top: 1px solid var(--rel-border-default);
333
- margin-top: auto;
334
- }
335
-
336
- .date-input-group {
337
- flex: 1;
338
- min-width: 0;
339
- position: relative;
340
- }
341
-
342
- .date-input-label {
343
- position: absolute;
344
- top: -8px;
345
- left: 10px;
346
- /* Figma: the FROM/TO tag is the nested TextField's floating label (body-sm-regular) */
347
- font-family: var(--rel-body-sm-regular-font-family);
348
- font-weight: var(--rel-body-sm-regular-font-weight);
349
- font-size: var(--rel-body-sm-regular-font-size);
350
- line-height: var(--rel-body-sm-regular-line-height);
351
- letter-spacing: var(--rel-body-sm-regular-letter-spacing);
352
- color: var(--rel-text-body);
353
- background: var(--rel-bg-surface);
354
- padding: 0 3px;
355
- }
356
-
357
- .date-input-value {
358
- display: block;
359
- border: 1px solid var(--rel-border-default);
360
- border-radius: var(--rel-border-radius-sm, 8px);
361
- padding: 6px 8px;
362
- color: var(--rel-text-default);
363
- background: var(--rel-bg-surface);
364
- width: 100%;
365
- box-sizing: border-box;
366
- font-family: var(--rel-body-md-semibold-font-family);
367
- font-weight: var(--rel-body-md-semibold-font-weight);
368
- font-size: var(--rel-body-md-semibold-font-size);
369
- line-height: var(--rel-body-md-semibold-line-height);
370
- letter-spacing: var(--rel-body-md-semibold-letter-spacing);
371
- }
372
-
373
- .date-input-value.empty {
374
- color: var(--rel-text-placeholder);
375
- font-weight: var(--rel-body-md-regular-font-weight);
376
- }
377
-
378
- /* ── Right panel: calendar ── */
379
- .calendar-panel {
380
- width: 300px;
381
- flex-shrink: 0;
382
- flex-grow: 0;
383
- padding: 12px;
384
- display: flex;
385
- flex-direction: column;
386
- gap: 6px;
387
- }
388
-
389
- .calendar-header {
390
- display: flex;
391
- align-items: center;
392
- justify-content: space-between;
393
- padding: 0 2px;
394
- }
395
-
396
- .month-label {
397
- font-family: var(--rel-body-lg-semibold-font-family);
398
- font-weight: var(--rel-body-lg-semibold-font-weight);
399
- font-size: var(--rel-body-lg-regular-font-size);
400
- line-height: var(--rel-body-lg-regular-line-height);
401
- letter-spacing: var(--rel-body-lg-regular-letter-spacing);
402
- color: var(--rel-text-label);
403
- }
404
-
405
- .nav-btn {
406
- background: none;
407
- border: none;
408
- cursor: pointer;
409
- color: var(--rel-action-neutral-label-icons-ghost);
410
- padding: var(--rel-spacing-2xs);
411
- border-radius: var(--rel-border-radius-sm, 8px);
412
- display: flex;
413
- align-items: center;
414
- transition: background 0.15s ease;
415
- }
416
-
417
- .nav-btn:hover { background: var(--rel-action-overlay-hover); }
418
-
419
- /* ── Weekday header ── */
420
- .week-header {
421
- display: grid;
422
- grid-template-columns: repeat(7, 1fr);
423
- text-align: center;
424
- }
425
-
426
- .week-day {
427
- color: var(--rel-text-body);
428
- padding: 2px 0;
429
- /* Figma: sm-regular family + xs-medium weight on sm-medium metrics */
430
- font-family: var(--rel-body-sm-regular-font-family);
431
- font-weight: var(--rel-body-xs-medium-font-weight);
432
- font-size: var(--rel-body-sm-medium-font-size);
433
- line-height: var(--rel-body-sm-medium-line-height);
434
- letter-spacing: var(--rel-body-sm-medium-letter-spacing);
435
- text-align: center;
436
- }
437
-
438
- /* ── Calendar grid ── */
439
- .calendar-table {
440
- display: flex;
441
- flex-direction: column;
442
- gap: 6px;
443
- }
444
-
445
- .calendar-grid {
446
- display: grid;
447
- grid-template-columns: repeat(7, 1fr);
448
- }
449
-
450
- .calendar-week {
451
- grid-column: 1 / -1;
452
- display: grid;
453
- grid-template-columns: repeat(7, 1fr);
454
- }
455
-
456
- .day-cell {
457
- height: 36px;
458
- position: relative;
459
- display: flex;
460
- align-items: center;
461
- justify-content: center;
462
- cursor: pointer;
463
- }
464
-
465
- .day-cell:focus-visible {
466
- outline: 2px solid var(--rel-border-focus);
467
- outline-offset: -2px;
468
- z-index: 2;
469
- }
470
-
471
- .day-cell.other-month {
472
- opacity: 0.35;
473
- pointer-events: none;
474
- }
475
-
476
- .day-cell.disabled {
477
- opacity: 0.4;
478
- pointer-events: none;
479
- }
480
-
481
- .day-cell.in-range {
482
- background: var(--rel-bg-neutral-elevated-2);
483
- }
484
-
485
- .day-cell.range-start:not(.range-end) {
486
- background: linear-gradient(to right, transparent 50%, var(--rel-bg-neutral-elevated-2) 50%);
487
- }
488
-
489
- .day-cell.range-end:not(.range-start) {
490
- background: linear-gradient(to left, transparent 50%, var(--rel-bg-neutral-elevated-2) 50%);
491
- }
492
-
493
- .day-cell.range-start.range-end {
494
- background: transparent;
495
- }
496
-
497
- /* ── Day inner circle ── */
498
- .day-inner {
499
- width: 32px;
500
- height: 32px;
501
- display: flex;
502
- align-items: center;
503
- justify-content: center;
504
- border-radius: 50%;
505
- font-family: var(--rel-body-sm-medium-font-family);
506
- font-weight: var(--rel-body-sm-medium-font-weight);
507
- font-size: var(--rel-body-sm-medium-font-size);
508
- line-height: var(--rel-body-sm-medium-line-height);
509
- letter-spacing: var(--rel-body-sm-medium-letter-spacing);
510
- color: var(--rel-text-default);
511
- position: relative;
512
- z-index: 1;
513
- transition: background 0.15s ease;
514
- }
515
-
516
- .day-cell:not(.disabled):not(.other-month):not(.range-start):not(.range-end):hover .day-inner {
517
- background: var(--rel-action-overlay-hover);
518
- }
519
-
520
- /* Pressed (Figma State=Active): elevated-2 fill on the day circle */
521
- .day-cell:not(.disabled):not(.other-month):not(.range-start):not(.range-end):active .day-inner {
522
- background: var(--rel-bg-neutral-elevated-2);
523
- }
524
-
525
- /* Weekend (Figma Day of a week=Weekend): 70% text opacity unless a range endpoint */
526
- .day-cell.weekend:not(.range-start):not(.range-end) .day-inner {
527
- opacity: 0.7;
528
- }
529
-
530
- /* Today: green outline */
531
- .day-cell.today:not(.range-start):not(.range-end) .day-inner {
532
- font-weight: var(--rel-body-md-medium-font-weight);
533
- border: 2px solid var(--rel-border-brand);
534
- }
535
-
536
- /* Range endpoints: dark fill */
537
- .day-cell.range-start .day-inner,
538
- .day-cell.range-end .day-inner {
539
- background: var(--rel-action-brand-fill);
540
- color: var(--rel-action-brand-label-icons-primary);
541
- font-weight: var(--rel-body-sm-semibold-font-weight);
542
- }
543
-
544
- /* Today AND endpoint: green ring + dark fill */
545
- .day-cell.today.range-start .day-inner,
546
- .day-cell.today.range-end .day-inner {
547
- background: var(--rel-action-brand-fill);
548
- color: var(--rel-action-brand-label-icons-primary);
549
- border: 2px solid var(--rel-border-brand);
550
- }
551
-
552
- /* ── Footer ── */
553
- .calendar-footer {
554
- display: flex;
555
- align-items: center;
556
- justify-content: space-between;
557
- padding-top: 12px;
558
- border-top: 1px solid var(--rel-border-default);
559
- margin-top: auto;
560
- gap: 8px;
561
- }
562
-
563
- .footer-right {
564
- display: flex;
565
- gap: 8px;
566
- }
567
-
568
- @media (prefers-reduced-motion: reduce) {
569
- .preset-item, .nav-btn, .day-inner, .icon-button {
570
- transition: none;
571
- }
572
- }
573
- `;
574
-
575
- // ── Lifecycle ──
576
-
577
- connectedCallback() {
578
- super.connectedCallback();
579
- document.addEventListener("click", this.handleClickOutside);
580
- document.addEventListener("keydown", this.handleGlobalKeydown);
581
- }
582
-
583
- disconnectedCallback() {
584
- super.disconnectedCallback();
585
- document.removeEventListener("click", this.handleClickOutside);
586
- document.removeEventListener("keydown", this.handleGlobalKeydown);
587
- window.removeEventListener("resize", this.onReposition);
588
- window.removeEventListener("scroll", this.onReposition, true);
589
- this.hideTopLayer();
590
- }
591
-
592
- updated(changed: Map<string, unknown>) {
593
- this.style.width = this.width;
594
- this.style.minWidth = this.minWidth;
595
- this.style.maxWidth = this.maxWidth;
596
- this.style.height = this.height;
597
- this.style.minHeight = this.minHeight;
598
- this.style.maxHeight = this.maxHeight;
599
-
600
- // `open` is a public reflected property (consumers may set it directly,
601
- // not only via the trigger), so top-layer promotion syncs here rather
602
- // than inside openPopover/cancelPopover.
603
- if (changed.has("open")) {
604
- if (this.open) {
605
- this.showTopLayer();
606
- window.addEventListener("resize", this.onReposition);
607
- window.addEventListener("scroll", this.onReposition, true);
608
- } else {
609
- window.removeEventListener("resize", this.onReposition);
610
- window.removeEventListener("scroll", this.onReposition, true);
611
- this.hideTopLayer();
612
- }
613
- }
614
- }
615
-
616
- /* A transformed ancestor (e.g. rel-modal's centered panel with
617
- * translate(-50%,-50%)) becomes the containing block for position:fixed
618
- * descendants, and its overflow:hidden clips position:absolute ones —
619
- * either way the picker shell breaks inside a modal. Promoting shell
620
- * (and popup-mode backdrop) to the browser top layer sidesteps both —
621
- * same fix as rel-popover / rel-autocomplete / rel-select. `manual`
622
- * keeps outside-click and Escape handling under this component's own
623
- * control. While in the top layer the CSS anchoring (absolute, below
624
- * the trigger) is meaningless, so popover mode gets inline fixed
625
- * coordinates from updatePopoverPosition(). */
626
-
627
- private showTopLayer() {
628
- // Backdrop first — later-shown popovers stack above earlier ones.
629
- for (const el of [this.mode === "popup" ? this.backdropEl : undefined, this.popoverEl]) {
630
- if (!el || typeof el.showPopover !== "function") continue;
631
- try {
632
- if (!el.matches(":popover-open")) el.showPopover();
633
- } catch {
634
- /* older engines / detached element — CSS fallback applies */
635
- }
636
- }
637
- if (this.mode === "popover") {
638
- requestAnimationFrame(() => this.updatePopoverPosition());
639
- }
640
- }
641
-
642
- private hideTopLayer() {
643
- for (const el of [this.popoverEl, this.backdropEl]) {
644
- if (!el || typeof el.hidePopover !== "function") continue;
645
- try {
646
- if (el.matches(":popover-open")) el.hidePopover();
647
- } catch {
648
- /* already hidden or unsupported — nothing to do */
649
- }
650
- }
651
- if (this.popoverEl) {
652
- this.popoverEl.style.position = "";
653
- this.popoverEl.style.top = "";
654
- this.popoverEl.style.left = "";
655
- }
656
- }
657
-
658
- private onReposition = () => {
659
- if (this.open && this.mode === "popover") this.updatePopoverPosition();
660
- };
661
-
662
- private updatePopoverPosition = () => {
663
- const panel = this.popoverEl;
664
- if (!panel || !this.open || this.mode !== "popover") return;
665
-
666
- // Host rect anchors both trigger variants (default button and icon).
667
- const t = this.getBoundingClientRect();
668
- const c = panel.getBoundingClientRect();
669
-
670
- let top = t.bottom + 4;
671
- if (top + c.height > window.innerHeight - 8) {
672
- top = Math.max(8, t.top - c.height - 4);
673
- }
674
- let left = t.left;
675
- if (left + c.width > window.innerWidth - 8) {
676
- left = window.innerWidth - c.width - 8;
677
- }
678
- left = Math.max(8, left);
679
-
680
- // Without top-layer support a transformed ancestor may be the containing
681
- // block for position:fixed, shifting the shell away from the viewport
682
- // coordinates computed above. Apply, re-measure, and cancel the offset.
683
- panel.style.position = "fixed";
684
- panel.style.top = `${top}px`;
685
- panel.style.left = `${left}px`;
686
- const applied = panel.getBoundingClientRect();
687
- top -= applied.top - top;
688
- left -= applied.left - left;
689
- panel.style.top = `${top}px`;
690
- panel.style.left = `${left}px`;
691
- };
692
-
693
- // ── Open / close ──
694
-
695
- private handleClickOutside = (e: MouseEvent) => {
696
- if (!this.open) return;
697
- const path = e.composedPath();
698
- if (!path.includes(this)) {
699
- this.cancelPopover();
700
- }
701
- };
702
-
703
- private handleGlobalKeydown = (e: KeyboardEvent) => {
704
- if (!this.open) return;
705
-
706
- if (e.key === "Escape") {
707
- this.cancelPopover();
708
- this.triggerInput?.focus();
709
- return;
710
- }
711
-
712
- // composedPath-aware: a document-level e.target retargets to the host,
713
- // so a plain tagName check misses the typed-entry input in the shadow
714
- // root — single-key preset shortcuts must not fire while typing.
715
- if (isEditableTarget(e)) return;
716
- if (e.ctrlKey || e.metaKey || e.altKey) return;
717
-
718
- const key = e.key.toUpperCase();
719
- const keyMap: Record<string, string> = {
720
- T: "Today",
721
- M: "Tomorrow",
722
- B: "Before Today",
723
- W: "This Week",
724
- N: "Next Week",
725
- "7": "Next 7 Days",
726
- "3": "Next 30 Days",
727
- };
728
-
729
- const label = keyMap[key];
730
- if (!label) return;
731
-
732
- const qs = this.getQuickSelects().find((q) => q.label === label);
733
- if (qs) this.selectQuickSelect(qs);
734
- };
735
-
736
- private toggleOpen() {
737
- if (this.disabled) return;
738
- if (this.open) {
739
- this.cancelPopover();
740
- } else {
741
- this.openPopover();
742
- }
743
- }
744
-
745
- private openPopover() {
746
- this.draftFrom = this.from;
747
- this.draftTo = this.to;
748
- this.draftActivePreset = null;
749
- this.isSelectingRange = false;
750
- this.hoverDate = null;
751
- this.focusedDate = null;
752
-
753
- if (this.draftFrom) {
754
- const date = this.parseISODate(this.draftFrom);
755
- if (date) {
756
- this.viewYear = date.getFullYear();
757
- this.viewMonth = date.getMonth();
758
- }
759
- } else {
760
- const now = new Date();
761
- this.viewYear = now.getFullYear();
762
- this.viewMonth = now.getMonth();
763
- }
764
-
765
- this.open = true;
766
- this.dispatchEvent(
767
- new CustomEvent("rel-open-change", {
768
- detail: { open: true },
769
- bubbles: true,
770
- composed: true,
771
- })
772
- );
773
- }
774
-
775
- private cancelPopover() {
776
- if (!this.open) return;
777
- this.open = false;
778
- this.draftFrom = "";
779
- this.draftTo = "";
780
- this.draftActivePreset = null;
781
- this.isSelectingRange = false;
782
- this.hoverDate = null;
783
- this.dispatchEvent(
784
- new CustomEvent("rel-open-change", {
785
- detail: { open: false },
786
- bubbles: true,
787
- composed: true,
788
- })
789
- );
790
- }
791
-
792
- private applySelection() {
793
- // An empty draft is committable when a committed range exists — this is
794
- // how Reset propagates to the trigger (Reset → Apply clears the input).
795
- if (!this.draftFrom && !this.draftTo && !this.from && !this.to) return;
796
- this.from = this.draftFrom;
797
- this.to = this.draftTo;
798
- this.inputText = null;
799
- this.inputError = null;
800
- this.dispatchEvent(
801
- new CustomEvent("rel-change", {
802
- detail: { from: this.from, to: this.to, label: this.displayLabel },
803
- bubbles: true,
804
- composed: true,
805
- })
806
- );
807
- this.open = false;
808
- this.isSelectingRange = false;
809
- this.hoverDate = null;
810
- this.dispatchEvent(
811
- new CustomEvent("rel-open-change", {
812
- detail: { open: false },
813
- bubbles: true,
814
- composed: true,
815
- })
816
- );
817
- }
818
-
819
- private resetDraft() {
820
- if (this.draftFrom || this.draftTo) {
821
- this.draftFrom = "";
822
- this.draftTo = "";
823
- this.draftActivePreset = null;
824
- this.isSelectingRange = false;
825
- this.hoverDate = null;
826
- }
827
- }
828
-
829
- private clearRange(e: Event) {
830
- e.stopPropagation();
831
- this.from = "";
832
- this.to = "";
833
- this.draftFrom = "";
834
- this.draftTo = "";
835
- this.draftActivePreset = null;
836
- this.isSelectingRange = false;
837
- this.hoverDate = null;
838
- this.inputText = null;
839
- this.inputError = null;
840
- this.dispatchEvent(
841
- new CustomEvent("rel-change", {
842
- detail: { from: "", to: "", label: "" },
843
- bubbles: true,
844
- composed: true,
845
- })
846
- );
847
- }
848
-
849
- // ── Typed keyboard entry ──
850
-
851
- /**
852
- * Parse "date → date" text into an ISO from/to pair, or null. Each side
853
- * goes through rel-date-picker's parseDateInput, so ISO / numeric /
854
- * month-name dates and the t / t±N shortcuts all work per side.
855
- * Separators: "→", "..", spaced "-", or the word "to" ("t - t+7",
856
- * "21/7 to 28/7"). A single date yields a one-day range. Reversed input
857
- * is normalized (from ≤ to). dayFirst is hard-coded false because the
858
- * displayed format is always MM/DD/YYYY.
859
- */
860
- private parseRangeText(text: string): { from: string; to: string } | null {
861
- const parts = text
862
- .split(/\s+to\s+|\s*(?:→|\.\.)\s*|\s+-\s+/i)
863
- .map((p) => p.trim())
864
- .filter(Boolean);
865
- if (parts.length < 1 || parts.length > 2) return null;
866
-
867
- const opts = { referenceDate: new Date(), dayFirst: false, locale: this.locale };
868
- const fromDate = parseDateInput(parts[0], opts);
869
- if (!fromDate) return null;
870
- const toDate = parts.length === 2 ? parseDateInput(parts[1], opts) : fromDate;
871
- if (!toDate) return null;
872
-
873
- const [a, b] =
874
- fromDate.getTime() <= toDate.getTime() ? [fromDate, toDate] : [toDate, fromDate];
875
- return { from: this.formatISODate(a), to: this.formatISODate(b) };
876
- }
877
-
878
- /**
879
- * Parse and commit the typed text (Enter / blur). Invalid or out-of-range
880
- * text keeps the field in an error state with the text preserved for
881
- * correction; the committed range is untouched (Escape reverts the text).
882
- */
883
- private commitTypedValue() {
884
- if (this.inputText === null) return; // nothing typed since last commit
885
- const text = this.inputText.trim();
886
-
887
- if (!text) {
888
- // Field cleared by keyboard — behaves like the clear button.
889
- this.inputText = null;
890
- this.inputError = null;
891
- if (this.from || this.to) {
892
- this.from = "";
893
- this.to = "";
894
- this.draftFrom = "";
895
- this.draftTo = "";
896
- this.draftActivePreset = null;
897
- this.dispatchEvent(
898
- new CustomEvent("rel-change", {
899
- detail: { from: "", to: "", label: "" },
900
- bubbles: true,
901
- composed: true,
902
- })
903
- );
904
- }
905
- if (this.open) this.cancelPopover();
906
- return;
907
- }
908
-
909
- const range = this.parseRangeText(text);
910
- if (!range) {
911
- this.inputError = "Invalid date range";
912
- return;
913
- }
914
- const fromDate = this.parseISODate(range.from)!;
915
- const toDate = this.parseISODate(range.to)!;
916
- if (this.isDateDisabled(fromDate) || this.isDateDisabled(toDate)) {
917
- this.inputError = "Date not available";
918
- return;
919
- }
920
-
921
- this.from = range.from;
922
- this.to = range.to;
923
- this.inputText = null;
924
- this.inputError = null;
925
- this.dispatchEvent(
926
- new CustomEvent("rel-change", {
927
- detail: { from: this.from, to: this.to, label: this.displayLabel },
928
- bubbles: true,
929
- composed: true,
930
- })
931
- );
932
- if (this.open) this.cancelPopover();
933
- }
934
-
935
- private handleInputInput(e: Event) {
936
- this.inputText = (e.target as HTMLInputElement).value;
937
- if (this.inputError) this.inputError = null;
938
- }
939
-
940
- private handleInputKeydown(e: KeyboardEvent) {
941
- if (e.key === "Enter") {
942
- e.preventDefault();
943
- if (this.inputText === null) {
944
- // Nothing typed — Enter opens the panel (previous trigger behavior).
945
- if (!this.open) this.openPopover();
946
- } else {
947
- this.commitTypedValue();
948
- }
949
- return;
950
- }
951
- if (e.key === "ArrowDown") {
952
- e.preventDefault();
953
- if (!this.open) this.openPopover();
954
- return;
955
- }
956
- if (e.key === "Escape" && this.inputText !== null) {
957
- // Revert the typed text; the document listener closes the panel.
958
- this.inputText = null;
959
- this.inputError = null;
960
- }
961
- }
962
-
963
- /** Clicking anywhere on the field opens the panel (never closes). */
964
- private handleFieldClick() {
965
- if (this.open || this.disabled) return;
966
- this.openPopover();
967
- }
968
-
969
- /** The calendar icon toggles the panel (previous trigger behavior). */
970
- private handleIconClick(e: Event) {
971
- e.stopPropagation();
972
- this.toggleOpen();
973
- }
974
-
975
- /** Commit typed text when focus leaves the component entirely. */
976
- private handleInputBlur = (e: FocusEvent) => {
977
- this.dispatchEvent(new CustomEvent("rel-blur", { bubbles: true, composed: true }));
978
- const related = e.relatedTarget as Node | null;
979
- if (related && (this.renderRoot.contains(related) || this.contains(related))) {
980
- return; // focus moved into the panel/icons — their own handlers commit
981
- }
982
- this.commitTypedValue();
983
- };
984
-
985
- private getTriggerLabel(): string {
986
- const from = this.from ? this.formatDisplayDate(this.from) : null;
987
- const to = this.to ? this.formatDisplayDate(this.to) : null;
988
- if (from && to) return `${from} → ${to}`;
989
- if (from) return from;
990
- return "";
991
- }
992
-
993
- /** Formatted "MM/DD/YYYY → MM/DD/YYYY" (or single date / "") for the current committed `from`/`to`. */
994
- get displayLabel(): string {
995
- return this.getTriggerLabel();
996
- }
997
-
998
- // ── Date utilities ──
999
-
1000
- private parseISODate(iso: string): Date | null {
1001
- const m = iso.match(/^(\d{4})-(\d{2})-(\d{2})$/);
1002
- if (!m) return null;
1003
- return new Date(parseInt(m[1]), parseInt(m[2]) - 1, parseInt(m[3]));
1004
- }
1005
-
1006
- private formatISODate(date: Date): string {
1007
- const y = date.getFullYear();
1008
- const mo = String(date.getMonth() + 1).padStart(2, "0");
1009
- const d = String(date.getDate()).padStart(2, "0");
1010
- return `${y}-${mo}-${d}`;
1011
- }
1012
-
1013
- private formatDisplayDate(iso: string): string {
1014
- const date = this.parseISODate(iso);
1015
- if (!date) return "";
1016
- return new Intl.DateTimeFormat("en-US", {
1017
- month: "2-digit",
1018
- day: "2-digit",
1019
- year: "numeric",
1020
- }).format(date);
1021
- }
1022
-
1023
- private isSameDay(a: Date, b: Date): boolean {
1024
- return (
1025
- a.getFullYear() === b.getFullYear() &&
1026
- a.getMonth() === b.getMonth() &&
1027
- a.getDate() === b.getDate()
1028
- );
1029
- }
1030
-
1031
- private isDateDisabled(date: Date): boolean {
1032
- if (this.minDate) {
1033
- const min = this.parseISODate(this.minDate);
1034
- if (min && date < min) return true;
1035
- }
1036
- if (this.maxDate) {
1037
- const max = this.parseISODate(this.maxDate);
1038
- if (max && date > max) return true;
1039
- }
1040
- return false;
1041
- }
1042
-
1043
- // ── Quick selects ──
1044
-
1045
- private getQuickSelects(): QuickSelect[] {
1046
- const today = new Date();
1047
- today.setHours(0, 0, 0, 0);
1048
-
1049
- const yesterday = new Date(today);
1050
- yesterday.setDate(today.getDate() - 1);
1051
-
1052
- const tomorrow = new Date(today);
1053
- tomorrow.setDate(today.getDate() + 1);
1054
-
1055
- const dow = today.getDay(); // 0 = Sun
1056
- const thisSunday = new Date(today);
1057
- thisSunday.setDate(today.getDate() - dow);
1058
- const thisSaturday = new Date(thisSunday);
1059
- thisSaturday.setDate(thisSunday.getDate() + 6);
1060
-
1061
- const nextSunday = new Date(thisSunday);
1062
- nextSunday.setDate(thisSunday.getDate() + 7);
1063
- const nextSaturday = new Date(nextSunday);
1064
- nextSaturday.setDate(nextSunday.getDate() + 6);
1065
-
1066
- const next7To = new Date(today);
1067
- next7To.setDate(today.getDate() + 6);
1068
-
1069
- const next30To = new Date(today);
1070
- next30To.setDate(today.getDate() + 29);
1071
-
1072
- return [
1073
- { label: "Today", key: "T", from: this.formatISODate(today), to: this.formatISODate(today) },
1074
- { label: "Tomorrow", key: "M", from: this.formatISODate(tomorrow), to: this.formatISODate(tomorrow) },
1075
- { label: "Before Today", key: "B", from: "1970-01-01", to: this.formatISODate(yesterday) },
1076
- { label: "This Week", key: "W", from: this.formatISODate(thisSunday), to: this.formatISODate(thisSaturday) },
1077
- { label: "Next Week", key: "N", from: this.formatISODate(nextSunday), to: this.formatISODate(nextSaturday) },
1078
- { label: "Next 7 Days", key: "7", from: this.formatISODate(today), to: this.formatISODate(next7To) },
1079
- { label: "Next 30 Days", key: "3", from: this.formatISODate(today), to: this.formatISODate(next30To), fullWidth: true },
1080
- ];
1081
- }
1082
-
1083
- private selectQuickSelect(qs: QuickSelect) {
1084
- if (this.disabled) return;
1085
- this.draftFrom = qs.from;
1086
- this.draftTo = qs.to;
1087
- this.draftActivePreset = qs.label;
1088
- this.isSelectingRange = false;
1089
- this.hoverDate = null;
1090
-
1091
- const date = this.parseISODate(qs.from);
1092
- if (date) {
1093
- this.viewYear = date.getFullYear();
1094
- this.viewMonth = date.getMonth();
1095
- }
1096
- }
1097
-
1098
- // ── Calendar navigation ──
1099
-
1100
- private previousMonth() {
1101
- if (this.viewMonth === 0) {
1102
- this.viewMonth = 11;
1103
- this.viewYear--;
1104
- } else {
1105
- this.viewMonth--;
1106
- }
1107
- announce(`${this.getMonthName()} ${this.viewYear}`);
1108
- }
1109
-
1110
- private nextMonth() {
1111
- if (this.viewMonth === 11) {
1112
- this.viewMonth = 0;
1113
- this.viewYear++;
1114
- } else {
1115
- this.viewMonth++;
1116
- }
1117
- announce(`${this.getMonthName()} ${this.viewYear}`);
1118
- }
1119
-
1120
- private getMonthName(): string {
1121
- return new Intl.DateTimeFormat("en-US", { month: "long" }).format(
1122
- new Date(this.viewYear, this.viewMonth, 1)
1123
- );
1124
- }
1125
-
1126
- private dayLabelFormatter: Intl.DateTimeFormat | null = null;
1127
-
1128
- private formatDayLabel(day: RangeDay): string {
1129
- if (!this.dayLabelFormatter) {
1130
- this.dayLabelFormatter = new Intl.DateTimeFormat("en-US", {
1131
- weekday: "long",
1132
- month: "long",
1133
- day: "numeric",
1134
- year: "numeric",
1135
- });
1136
- }
1137
- let label = this.dayLabelFormatter.format(day.date);
1138
- if (day.isDraftFrom) label += ", range start";
1139
- if (day.isDraftTo) label += ", range end";
1140
- return label;
1141
- }
1142
-
1143
- private getWeekdayLabels(): string[] {
1144
- const formatter = new Intl.DateTimeFormat("en-US", { weekday: "short" });
1145
- const base = new Date(2024, 0, 7); // Sunday Jan 7 2024
1146
- return Array.from({ length: 7 }, (_, i) => {
1147
- const offset = this.weekStart === "mon" ? i + 1 : i;
1148
- const d = new Date(base);
1149
- d.setDate(base.getDate() + offset);
1150
- return formatter.format(d).substring(0, 2);
1151
- });
1152
- }
1153
-
1154
- // ── Calendar day computation ──
1155
-
1156
- private getCalendarDays(): RangeDay[] {
1157
- const today = new Date();
1158
- today.setHours(0, 0, 0, 0);
1159
-
1160
- const firstDay = new Date(this.viewYear, this.viewMonth, 1);
1161
- const lastDay = new Date(this.viewYear, this.viewMonth + 1, 0);
1162
-
1163
- const draftFromDate = this.draftFrom ? this.parseISODate(this.draftFrom) : null;
1164
- const draftToDate = this.draftTo ? this.parseISODate(this.draftTo) : null;
1165
-
1166
- let effectiveFrom: Date | null = draftFromDate;
1167
- let effectiveTo: Date | null = draftToDate;
1168
-
1169
- if (this.isSelectingRange && this.hoverDate && draftFromDate) {
1170
- const hDate = this.parseISODate(this.hoverDate);
1171
- if (hDate) {
1172
- if (hDate.getTime() >= draftFromDate.getTime()) {
1173
- effectiveFrom = draftFromDate;
1174
- effectiveTo = hDate;
1175
- } else {
1176
- effectiveFrom = hDate;
1177
- effectiveTo = draftFromDate;
1178
- }
1179
- }
1180
- }
1181
-
1182
- const days: RangeDay[] = [];
1183
-
1184
- let startDay = firstDay.getDay();
1185
- if (this.weekStart === "mon") {
1186
- startDay = startDay === 0 ? 6 : startDay - 1;
1187
- }
1188
- for (let i = startDay - 1; i >= 0; i--) {
1189
- const date = new Date(this.viewYear, this.viewMonth, -i);
1190
- days.push({
1191
- date,
1192
- day: date.getDate(),
1193
- isCurrentMonth: false,
1194
- isToday: false,
1195
- isDraftFrom: false,
1196
- isDraftTo: false,
1197
- isInRange: false,
1198
- isDisabled: true,
1199
- isWeekend: date.getDay() === 0 || date.getDay() === 6,
1200
- });
1201
- }
1202
-
1203
- for (let d = 1; d <= lastDay.getDate(); d++) {
1204
- const date = new Date(this.viewYear, this.viewMonth, d);
1205
- const t = date.getTime();
1206
-
1207
- const isDraftFrom = !!effectiveFrom && this.isSameDay(date, effectiveFrom);
1208
- const isDraftTo = !!effectiveTo && this.isSameDay(date, effectiveTo);
1209
- const isInRange =
1210
- !!effectiveFrom &&
1211
- !!effectiveTo &&
1212
- t > effectiveFrom.getTime() &&
1213
- t < effectiveTo.getTime();
1214
-
1215
- days.push({
1216
- date,
1217
- day: d,
1218
- isCurrentMonth: true,
1219
- isToday: this.isSameDay(date, today),
1220
- isDraftFrom,
1221
- isDraftTo,
1222
- isInRange,
1223
- isDisabled: this.isDateDisabled(date),
1224
- isWeekend: date.getDay() === 0 || date.getDay() === 6,
1225
- });
1226
- }
1227
-
1228
- const remaining = 42 - days.length;
1229
- for (let i = 1; i <= remaining; i++) {
1230
- const date = new Date(this.viewYear, this.viewMonth + 1, i);
1231
- days.push({
1232
- date,
1233
- day: date.getDate(),
1234
- isCurrentMonth: false,
1235
- isToday: false,
1236
- isDraftFrom: false,
1237
- isDraftTo: false,
1238
- isInRange: false,
1239
- isDisabled: true,
1240
- isWeekend: date.getDay() === 0 || date.getDay() === 6,
1241
- });
1242
- }
1243
-
1244
- return days;
1245
- }
1246
-
1247
- // ── Day click / hover ──
1248
-
1249
- private handleDayClick(day: RangeDay) {
1250
- if (day.isDisabled || this.disabled) return;
1251
- const iso = this.formatISODate(day.date);
1252
-
1253
- if (!this.isSelectingRange) {
1254
- this.draftFrom = iso;
1255
- this.draftTo = "";
1256
- this.draftActivePreset = null;
1257
- this.isSelectingRange = true;
1258
- this.hoverDate = null;
1259
- announce(`From date ${this.formatDisplayDate(iso)}`);
1260
- } else {
1261
- const fromDate = this.parseISODate(this.draftFrom);
1262
- if (!fromDate) {
1263
- this.draftFrom = iso;
1264
- this.draftTo = "";
1265
- announce(`From date ${this.formatDisplayDate(iso)}`);
1266
- return;
1267
- }
1268
-
1269
- if (day.date.getTime() >= fromDate.getTime()) {
1270
- this.draftTo = iso;
1271
- announce(`To date ${this.formatDisplayDate(iso)}`);
1272
- } else {
1273
- this.draftTo = this.draftFrom;
1274
- this.draftFrom = iso;
1275
- announce(`From date ${this.formatDisplayDate(iso)}`);
1276
- }
1277
-
1278
- this.isSelectingRange = false;
1279
- this.hoverDate = null;
1280
- this.draftActivePreset = null;
1281
- }
1282
- }
1283
-
1284
- private handleDayHover(day: RangeDay) {
1285
- if (!this.isSelectingRange || day.isDisabled) return;
1286
- this.hoverDate = this.formatISODate(day.date);
1287
- }
1288
-
1289
- // ── Grid keyboard navigation (APG grid pattern) ──
1290
-
1291
- /**
1292
- * The cell that carries tabindex="0". Prefers the last roved date, then the
1293
- * draft start, then today, then the first selectable day — always exactly
1294
- * one Tab stop, even after arrowing away with nothing selected.
1295
- */
1296
- private getRovingIso(days: RangeDay[]): string {
1297
- const inView = days.filter((d) => d.isCurrentMonth);
1298
- if (inView.length === 0) return "";
1299
-
1300
- const candidates = [
1301
- this.focusedDate,
1302
- this.draftFrom,
1303
- this.formatISODate(new Date()),
1304
- ];
1305
- for (const iso of candidates) {
1306
- if (iso && inView.some((d) => this.formatISODate(d.date) === iso)) {
1307
- return iso;
1308
- }
1309
- }
1310
- const firstEnabled = inView.find((d) => !d.isDisabled) ?? inView[0];
1311
- return this.formatISODate(firstEnabled.date);
1312
- }
1313
-
1314
- private handleGridKeydown = (e: KeyboardEvent) => {
1315
- const cell = (e.target as HTMLElement).closest?.(".day-cell") as
1316
- | HTMLElement
1317
- | null;
1318
- const iso = cell?.dataset.iso;
1319
- if (!iso) return;
1320
- const date = this.parseISODate(iso);
1321
- if (!date) return;
1322
-
1323
- if (e.key === "Enter" || e.key === " ") {
1324
- e.preventDefault();
1325
- const isDisabled = this.isDateDisabled(date);
1326
- if (!isDisabled) {
1327
- this.handleDayClick({
1328
- date,
1329
- day: date.getDate(),
1330
- isCurrentMonth: true,
1331
- isToday: false,
1332
- isDraftFrom: false,
1333
- isDraftTo: false,
1334
- isInRange: false,
1335
- isDisabled,
1336
- isWeekend: false,
1337
- });
1338
- }
1339
- return;
1340
- }
1341
-
1342
- const next = new Date(date);
1343
- const dow = next.getDay();
1344
- switch (e.key) {
1345
- case "ArrowLeft":
1346
- next.setDate(next.getDate() - 1);
1347
- break;
1348
- case "ArrowRight":
1349
- next.setDate(next.getDate() + 1);
1350
- break;
1351
- case "ArrowUp":
1352
- next.setDate(next.getDate() - 7);
1353
- break;
1354
- case "ArrowDown":
1355
- next.setDate(next.getDate() + 7);
1356
- break;
1357
- case "Home":
1358
- next.setDate(
1359
- next.getDate() -
1360
- (this.weekStart === "mon" ? (dow === 0 ? 6 : dow - 1) : dow)
1361
- );
1362
- break;
1363
- case "End":
1364
- next.setDate(
1365
- next.getDate() +
1366
- (this.weekStart === "mon" ? (dow === 0 ? 0 : 7 - dow) : 6 - dow)
1367
- );
1368
- break;
1369
- case "PageUp":
1370
- if (e.shiftKey) next.setFullYear(next.getFullYear() - 1);
1371
- else next.setMonth(next.getMonth() - 1);
1372
- break;
1373
- case "PageDown":
1374
- if (e.shiftKey) next.setFullYear(next.getFullYear() + 1);
1375
- else next.setMonth(next.getMonth() + 1);
1376
- break;
1377
- default:
1378
- return;
1379
- }
1380
-
1381
- e.preventDefault();
1382
- this.moveGridFocusTo(next);
1383
- };
1384
-
1385
- private async moveGridFocusTo(date: Date) {
1386
- this.focusedDate = this.formatISODate(date);
1387
-
1388
- if (
1389
- date.getMonth() !== this.viewMonth ||
1390
- date.getFullYear() !== this.viewYear
1391
- ) {
1392
- this.viewMonth = date.getMonth();
1393
- this.viewYear = date.getFullYear();
1394
- }
1395
-
1396
- // Keyboard twin of handleDayHover: keep the range preview following focus.
1397
- if (this.isSelectingRange && !this.isDateDisabled(date)) {
1398
- this.hoverDate = this.focusedDate;
1399
- }
1400
-
1401
- await this.updateComplete;
1402
- this.renderRoot
1403
- .querySelector<HTMLElement>(`.day-cell[data-iso="${this.focusedDate}"]`)
1404
- ?.focus();
1405
- }
1406
-
1407
- // ── Render ──
1408
-
1409
- render() {
1410
- const quickSelects = this.getQuickSelects();
1411
- const days = this.getCalendarDays();
1412
- const rovingIso = this.getRovingIso(days);
1413
- const weekdayLabels = this.getWeekdayLabels();
1414
- const weeks: RangeDay[][] = [];
1415
- for (let i = 0; i < days.length; i += 7) {
1416
- weeks.push(days.slice(i, i + 7));
1417
- }
1418
-
1419
- const draftFromDisplay = this.draftFrom ? this.formatDisplayDate(this.draftFrom) : "";
1420
- const draftToDisplay = this.draftTo ? this.formatDisplayDate(this.draftTo) : "";
1421
- const triggerLabel = this.getTriggerLabel();
1422
- const isDraftEmpty = !this.draftFrom && !this.draftTo;
1423
- const isPopup = this.mode === "popup";
1424
-
1425
- return html`
1426
- ${this.triggerVariant === "icon"
1427
- ? html`
1428
- <rel-button
1429
- variant="icon"
1430
- tone="secondary"
1431
- ?disabled=${this.disabled}
1432
- aria-haspopup="dialog"
1433
- aria-expanded=${this.open}
1434
- aria-label=${triggerLabel || this.placeholder}
1435
- @click=${() => this.toggleOpen()}
1436
- >
1437
- <rel-icon name="calendar-range"></rel-icon>
1438
- </rel-button>
1439
- `
1440
- : html`
1441
- <div
1442
- part="trigger"
1443
- class="trigger-button ${this.inputError ? "error" : ""}"
1444
- @click=${this.handleFieldClick}
1445
- >
1446
- <input
1447
- part="value"
1448
- class="trigger-input"
1449
- type="text"
1450
- .value=${live(this.inputText ?? triggerLabel)}
1451
- placeholder=${this.placeholder}
1452
- ?disabled=${this.disabled}
1453
- autocomplete="off"
1454
- spellcheck="false"
1455
- enterkeyhint="done"
1456
- @input=${this.handleInputInput}
1457
- @keydown=${this.handleInputKeydown}
1458
- @blur=${this.handleInputBlur}
1459
- role="combobox"
1460
- aria-label=${this.placeholder}
1461
- aria-haspopup="dialog"
1462
- aria-expanded=${this.open}
1463
- aria-controls="range-picker-panel"
1464
- aria-invalid=${this.inputError !== null}
1465
- aria-describedby=${this.inputError ? "range-picker-desc" : nothing}
1466
- />
1467
- <span class="trigger-icons">
1468
- ${this.clearable && (this.from || this.to)
1469
- ? html`
1470
- <button
1471
- class="icon-button"
1472
- type="button"
1473
- aria-label="Clear date range"
1474
- @click=${this.clearRange}
1475
- >
1476
- <svg viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
1477
- <path
1478
- d="M4 4l8 8M12 4l-8 8"
1479
- stroke="currentColor"
1480
- stroke-width="2"
1481
- stroke-linecap="round"
1482
- />
1483
- </svg>
1484
- </button>
1485
- `
1486
- : nothing}
1487
- <button
1488
- class="icon-button"
1489
- type="button"
1490
- aria-label="Open date range panel"
1491
- aria-expanded=${this.open}
1492
- ?disabled=${this.disabled}
1493
- @click=${this.handleIconClick}
1494
- >
1495
- <svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true">
1496
- <path d="M4 2h1V1h2v1h2V1h2v1h1a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2zm8 3H4v7h8V5z"/>
1497
- </svg>
1498
- </button>
1499
- </span>
1500
- </div>
1501
- ${this.inputError
1502
- ? html`<div class="range-picker-support error" id="range-picker-desc">
1503
- ${this.inputError}
1504
- </div>`
1505
- : nothing}
1506
- `}
1507
-
1508
- ${isPopup && this.open
1509
- ? html`<div part="overlay" class="backdrop" popover="manual" @click=${this.cancelPopover}></div>`
1510
- : nothing}
1511
-
1512
- <div
1513
- part="panel" class="popover ${this.open ? "open" : ""} ${isPopup ? "popup" : ""}"
1514
- id="range-picker-panel"
1515
- popover="manual"
1516
- role="dialog"
1517
- aria-label="Select date range"
1518
- >
1519
- <div class="picker-wrapper">
1520
-
1521
- <!-- ── Left: Quick select ── -->
1522
- <div part="list" class="presets">
1523
- <div class="presets-grid" role="group" aria-label="Quick date selections">
1524
- ${quickSelects.map(
1525
- (qs) => html`
1526
- <button
1527
- part="option" class="preset-item ${qs.fullWidth ? "full-width" : ""} ${this.draftActivePreset === qs.label ? "active" : ""}"
1528
- type="button"
1529
- ?disabled=${this.disabled}
1530
- aria-pressed=${this.draftActivePreset === qs.label}
1531
- @click=${() => this.selectQuickSelect(qs)}
1532
- >
1533
- <span>${qs.label}</span>
1534
- ${this.draftActivePreset !== qs.label
1535
- ? html`<kbd class="preset-key" aria-hidden="true" title="Press ${qs.key} while the panel is open">${qs.key}</kbd>`
1536
- : nothing}
1537
- ${this.draftActivePreset === qs.label
1538
- ? html`<svg width="18" height="18" viewBox="0 0 24 24" fill="none" aria-hidden="true">
1539
- <circle cx="12" cy="12" r="12" fill="var(--rel-bg-brand)"/>
1540
- <path d="M7 12.5l3.5 3.5 6.5-7" stroke="var(--rel-text-static-dark)" stroke-width="2"
1541
- stroke-linecap="round" stroke-linejoin="round"/>
1542
- </svg>`
1543
- : nothing}
1544
- </button>
1545
- `
1546
- )}
1547
- </div>
1548
-
1549
- <div class="date-inputs">
1550
- <div class="date-input-group" aria-label="From date">
1551
- <span class="date-input-label">FROM</span>
1552
- <div class="date-input-value ${draftFromDisplay ? "" : "empty"}">
1553
- ${draftFromDisplay || "MM/DD/YYYY"}
1554
- </div>
1555
- </div>
1556
- <div class="date-input-group" aria-label="To date">
1557
- <span class="date-input-label">TO</span>
1558
- <div class="date-input-value ${draftToDisplay ? "" : "empty"}">
1559
- ${draftToDisplay || "MM/DD/YYYY"}
1560
- </div>
1561
- </div>
1562
- </div>
1563
- </div>
1564
-
1565
- <!-- ── Right: Calendar panel ── -->
1566
- <div class="calendar-panel">
1567
-
1568
- <div class="calendar-header">
1569
- <button
1570
- part="action" class="nav-btn"
1571
- type="button"
1572
- aria-label="Previous month"
1573
- @click=${this.previousMonth}
1574
- >
1575
- <rel-icon name="chevron-left" size="sm"></rel-icon>
1576
- </button>
1577
- <span class="month-label">${this.getMonthName()} ${this.viewYear}</span>
1578
- <button
1579
- part="action" class="nav-btn"
1580
- type="button"
1581
- aria-label="Next month"
1582
- @click=${this.nextMonth}
1583
- >
1584
- <rel-icon name="chevron-right" size="sm"></rel-icon>
1585
- </button>
1586
- </div>
1587
-
1588
- <div class="calendar-table" role="grid" aria-label="Select date range">
1589
- <div class="week-header" role="row">
1590
- ${weekdayLabels.map(
1591
- (label) => html`
1592
- <div class="week-day" role="columnheader" aria-label="${label}">
1593
- ${label}
1594
- </div>
1595
- `
1596
- )}
1597
- </div>
1598
-
1599
- <div
1600
- part="list" class="calendar-grid"
1601
- @mouseleave=${() => { this.hoverDate = null; }}
1602
- @keydown=${this.handleGridKeydown}
1603
- >
1604
- ${weeks.map(
1605
- (week) => html`
1606
- <div class="calendar-week" role="row">
1607
- ${week.map((day) => {
1608
- const iso = this.formatISODate(day.date);
1609
- const cellClasses = [
1610
- "day-cell",
1611
- day.isInRange ? "in-range" : "",
1612
- day.isDraftFrom ? "range-start" : "",
1613
- day.isDraftTo ? "range-end" : "",
1614
- day.isToday ? "today" : "",
1615
- day.isDisabled ? "disabled" : "",
1616
- !day.isCurrentMonth ? "other-month" : "",
1617
- day.isWeekend ? "weekend" : "",
1618
- ]
1619
- .filter(Boolean)
1620
- .join(" ");
1621
-
1622
- return html`
1623
- <div
1624
- class="${cellClasses}"
1625
- role="gridcell"
1626
- tabindex="${day.isCurrentMonth && iso === rovingIso ? 0 : -1}"
1627
- data-iso="${iso}"
1628
- aria-label="${this.formatDayLabel(day)}"
1629
- aria-selected="${day.isDraftFrom || day.isDraftTo || day.isInRange}"
1630
- aria-disabled="${day.isDisabled ? "true" : nothing}"
1631
- @click=${() => this.handleDayClick(day)}
1632
- @mouseenter=${() => this.handleDayHover(day)}
1633
- >
1634
- <span class="day-inner">${day.day}</span>
1635
- </div>
1636
- `;
1637
- })}
1638
- </div>
1639
- `
1640
- )}
1641
- </div>
1642
- </div>
1643
-
1644
- <div part="footer" class="calendar-footer">
1645
- <rel-button
1646
- variant="secondary"
1647
- size="small"
1648
- border="corner-radius"
1649
- ?disabled=${isDraftEmpty}
1650
- @click=${() => this.resetDraft()}
1651
- >
1652
- Reset
1653
- </rel-button>
1654
- <div class="footer-right">
1655
- <rel-button
1656
- variant="secondary"
1657
- size="small"
1658
- border="corner-radius"
1659
- @click=${() => this.cancelPopover()}
1660
- >
1661
- Cancel
1662
- </rel-button>
1663
- <rel-button
1664
- variant="primary"
1665
- tone="default"
1666
- size="small"
1667
- border="corner-radius"
1668
- ?disabled=${isDraftEmpty && !this.from && !this.to}
1669
- @click=${() => this.applySelection()}
1670
- >
1671
- Apply
1672
- </rel-button>
1673
- </div>
1674
- </div>
1675
-
1676
- </div>
1677
- </div>
1678
- </div>
1679
- `;
1680
-
1681
- }
1682
- }
1683
-
1684
- declare global {
1685
- interface HTMLElementTagNameMap {
1686
- "rel-range-picker": RelRangePicker;
1687
- }
1688
- }