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