@reliability-design/web 1.4.5 → 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 -135
- 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 -103
- package/dist/components/rel-upload/README.md +220 -0
- package/dist/index.d.mts +1387 -350
- package/dist/index.d.ts +1387 -350
- package/dist/index.js +5863 -3600
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5864 -3592
- 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 +4 -3
- 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 -689
- package/dist/components/rel-avatar/rel-avatar.ts +0 -142
- package/dist/components/rel-badge/rel-badge.ts +0 -170
- 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 -519
- 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 -700
- 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 -472
- 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/index.ts +0 -1
- package/dist/components/rel-date-picker/rel-date-picker.ts +0 -1237
- 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 -604
- 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 -535
- 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 -517
- package/dist/components/rel-pagination/index.ts +0 -1
- package/dist/components/rel-pagination/rel-pagination.ts +0 -509
- 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 -444
- package/dist/components/rel-progress/rel-progress.ts +0 -225
- package/dist/components/rel-radio/rel-radio.ts +0 -305
- package/dist/components/rel-range-picker/rel-range-picker.ts +0 -1331
- 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 -213
- package/dist/components/rel-select/rel-select.ts +0 -1385
- package/dist/components/rel-sheet/rel-sheet.ts +0 -465
- package/dist/components/rel-sidebar/README.md +0 -209
- package/dist/components/rel-sidebar/rel-sidebar.ts +0 -1185
- package/dist/components/rel-skeleton/rel-skeleton.ts +0 -134
- package/dist/components/rel-slider/rel-slider.ts +0 -670
- package/dist/components/rel-snackbar/rel-snackbar.ts +0 -325
- package/dist/components/rel-stepper/rel-stepper.ts +0 -565
- package/dist/components/rel-switch/rel-switch.ts +0 -197
- 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 -866
- package/dist/components/rel-time-picker/rel-time-picker.ts +0 -1126
- package/dist/components/rel-toast/rel-toast.ts +0 -204
- package/dist/components/rel-tooltip/rel-tooltip.ts +0 -190
- 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 -943
|
@@ -1,1237 +0,0 @@
|
|
|
1
|
-
import { LitElement, html, css, nothing } from "lit";
|
|
2
|
-
import { customElement, property, state, query } from "lit/decorators.js";
|
|
3
|
-
import { formatDatePattern } from "./date-format";
|
|
4
|
-
import { getDeepActiveElement, trapTabKey } from "../../utils/focus.js";
|
|
5
|
-
|
|
6
|
-
interface CalendarDay {
|
|
7
|
-
date: Date;
|
|
8
|
-
day: number;
|
|
9
|
-
isCurrentMonth: boolean;
|
|
10
|
-
isToday: boolean;
|
|
11
|
-
isSelected: boolean;
|
|
12
|
-
isDisabled: boolean;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@customElement("rel-date-picker")
|
|
16
|
-
export class RelDatePicker extends LitElement {
|
|
17
|
-
@property({ type: String, reflect: true }) value: string | null = null;
|
|
18
|
-
@property({ type: String }) placeholder = "Select date";
|
|
19
|
-
@property({ type: String }) label: string | null = null;
|
|
20
|
-
@property({ type: Boolean, reflect: true }) disabled = false;
|
|
21
|
-
@property({ type: Boolean }) required = false;
|
|
22
|
-
@property({ type: Boolean, reflect: true }) readonly = false;
|
|
23
|
-
|
|
24
|
-
// Date bounds. minDate/maxDate are the standard names; min/max are kept as
|
|
25
|
-
// deprecated aliases (minDate/maxDate win when both are set).
|
|
26
|
-
@property({ type: String, attribute: "min-date" }) minDate: string | null = null;
|
|
27
|
-
@property({ type: String, attribute: "max-date" }) maxDate: string | null = null;
|
|
28
|
-
/** @deprecated use minDate */
|
|
29
|
-
@property({ type: String }) min: string | null = null;
|
|
30
|
-
/** @deprecated use maxDate */
|
|
31
|
-
@property({ type: String }) max: string | null = null;
|
|
32
|
-
|
|
33
|
-
@property({ type: String, attribute: "week-start" }) weekStart: "sun" | "mon" = "sun";
|
|
34
|
-
@property({ type: String }) locale = "en-US";
|
|
35
|
-
|
|
36
|
-
// ── Display formatting of the SELECTED value ──
|
|
37
|
-
// `displayFormat` is a token pattern (YYYY-MM-DD, MM/DD/YYYY, DD/MM/YYYY, …);
|
|
38
|
-
// see date-format.ts for the token table. `formatDate` is a full callback and
|
|
39
|
-
// takes precedence. When neither is set the locale long date is used, so
|
|
40
|
-
// existing consumers are unaffected. Neither affects parsing, the popup
|
|
41
|
-
// calendar, or accessibility — only the visible trigger text.
|
|
42
|
-
@property({ type: String, attribute: "display-format" }) displayFormat: string | null = null;
|
|
43
|
-
/**
|
|
44
|
-
* Full control over the selected-value display; wins over `displayFormat`.
|
|
45
|
-
* Reactive (attribute:false) so assigning it after render re-renders the
|
|
46
|
-
* trigger — frameworks set callbacks as properties post-creation.
|
|
47
|
-
*/
|
|
48
|
-
@property({ attribute: false }) formatDate?: (date: Date) => string;
|
|
49
|
-
@property({ type: Boolean, reflect: true }) open = false;
|
|
50
|
-
@property({ type: Boolean, attribute: "close-on-select" }) closeOnSelect = true;
|
|
51
|
-
@property({ type: Boolean }) clearable = false;
|
|
52
|
-
|
|
53
|
-
// ── Standardized input API (mirrors rel-textfield) ──
|
|
54
|
-
@property({ type: Boolean }) error = false;
|
|
55
|
-
@property({ type: String, attribute: "error-message" }) errorMessage?: string;
|
|
56
|
-
@property({ type: String, attribute: "helper-text" }) helperText?: string;
|
|
57
|
-
@property({ type: String }) name?: string;
|
|
58
|
-
@property({ type: String }) size: "small" | "medium" | "large" = "medium";
|
|
59
|
-
@property({ type: String, reflect: true }) variant: "outlined" = "outlined";
|
|
60
|
-
@property({ type: Boolean, reflect: true }) fullWidth = false;
|
|
61
|
-
|
|
62
|
-
// Custom disabled predicate (not settable via attribute)
|
|
63
|
-
public isDateDisabled?: (date: Date) => boolean;
|
|
64
|
-
|
|
65
|
-
// minDate/maxDate supersede the deprecated min/max aliases
|
|
66
|
-
private get minBound(): string | null {
|
|
67
|
-
return this.minDate ?? this.min;
|
|
68
|
-
}
|
|
69
|
-
private get maxBound(): string | null {
|
|
70
|
-
return this.maxDate ?? this.max;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
@state() private viewYear: number = new Date().getFullYear();
|
|
74
|
-
@state() private viewMonth: number = new Date().getMonth();
|
|
75
|
-
@state() private focusedDate: Date | null = null;
|
|
76
|
-
@state() private yearDropdownOpen = false;
|
|
77
|
-
@state() private monthDropdownOpen = false;
|
|
78
|
-
|
|
79
|
-
@query(".trigger-button") private triggerButton?: HTMLButtonElement;
|
|
80
|
-
@query(".popover") private popoverElement?: HTMLElement;
|
|
81
|
-
@query(".calendar-grid") private calendarGrid?: HTMLElement;
|
|
82
|
-
|
|
83
|
-
static styles = css`
|
|
84
|
-
:host {
|
|
85
|
-
color: var(--rel-text-default);
|
|
86
|
-
display: block;
|
|
87
|
-
font-family: var(--rel-fonts-font-family);
|
|
88
|
-
position: relative;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/* Intrinsic width by default; set fullWidth to fill the parent. */
|
|
92
|
-
:host(:not([fullwidth])) {
|
|
93
|
-
display: inline-block;
|
|
94
|
-
width: auto;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
:host([disabled]) {
|
|
98
|
-
opacity: 0.6;
|
|
99
|
-
cursor: not-allowed;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
:host([disabled]) * {
|
|
103
|
-
pointer-events: none;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
:host([readonly]) .trigger-button {
|
|
107
|
-
cursor: default;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
.date-picker-wrapper {
|
|
111
|
-
display: flex;
|
|
112
|
-
flex-direction: column;
|
|
113
|
-
gap: var(--rel-spacing-xs);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
.label {
|
|
117
|
-
color: var(--rel-text-label);
|
|
118
|
-
|
|
119
|
-
font-family: var(--rel-body-sm-medium-font-family);
|
|
120
|
-
|
|
121
|
-
font-weight: var(--rel-body-sm-medium-font-weight);
|
|
122
|
-
|
|
123
|
-
font-size: var(--rel-body-sm-medium-font-size);
|
|
124
|
-
|
|
125
|
-
line-height: var(--rel-body-sm-medium-line-height);
|
|
126
|
-
|
|
127
|
-
letter-spacing: var(--rel-body-sm-medium-letter-spacing);
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.required-mark {
|
|
132
|
-
color: var(--rel-text-danger);
|
|
133
|
-
margin-left: 2px;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/* Support text (helperText / errorMessage) */
|
|
137
|
-
.date-picker-support {
|
|
138
|
-
color: var(--rel-text-placeholder);
|
|
139
|
-
|
|
140
|
-
font-family: var(--rel-body-xs-regular-font-family);
|
|
141
|
-
|
|
142
|
-
font-weight: var(--rel-body-xs-regular-font-weight);
|
|
143
|
-
|
|
144
|
-
font-size: var(--rel-body-xs-regular-font-size);
|
|
145
|
-
|
|
146
|
-
line-height: var(--rel-body-xs-regular-line-height);
|
|
147
|
-
|
|
148
|
-
letter-spacing: var(--rel-body-xs-regular-letter-spacing);
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
.date-picker-support.error {
|
|
153
|
-
color: var(--rel-text-danger);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
.trigger-button {
|
|
157
|
-
width: 100%;
|
|
158
|
-
min-width: 200px;
|
|
159
|
-
display: flex;
|
|
160
|
-
align-items: center;
|
|
161
|
-
justify-content: space-between;
|
|
162
|
-
gap: var(--rel-spacing-xs);
|
|
163
|
-
padding: var(--rel-spacing-sm) var(--rel-spacing-md);
|
|
164
|
-
background: var(--rel-bg-surface);
|
|
165
|
-
border: 1px solid var(--rel-border-default);
|
|
166
|
-
border-radius: var(--rel-border-radius-sm);
|
|
167
|
-
color: var(--rel-text-default);
|
|
168
|
-
cursor: pointer;
|
|
169
|
-
transition: all 0.15s ease;
|
|
170
|
-
text-align: left;
|
|
171
|
-
font-family: var(--rel-body-md-regular-font-family);
|
|
172
|
-
font-weight: var(--rel-body-md-regular-font-weight);
|
|
173
|
-
font-size: var(--rel-body-md-regular-font-size);
|
|
174
|
-
line-height: var(--rel-body-md-regular-line-height);
|
|
175
|
-
letter-spacing: var(--rel-body-md-regular-letter-spacing);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
.trigger-button:hover:not(:disabled) {
|
|
179
|
-
border-color: var(--rel-border-strong);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
.trigger-button:focus-visible {
|
|
183
|
-
outline: 2px solid var(--rel-border-focus);
|
|
184
|
-
outline-offset: 2px;
|
|
185
|
-
border-color: var(--rel-border-focus);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
.trigger-button:disabled {
|
|
189
|
-
cursor: not-allowed;
|
|
190
|
-
background: var(--rel-bg-surface-elevated);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
/* Error state */
|
|
194
|
-
.trigger-button.error,
|
|
195
|
-
.trigger-button.error:hover:not(:disabled) {
|
|
196
|
-
border-color: var(--rel-border-danger);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
.trigger-button.error:focus-visible {
|
|
200
|
-
outline-color: var(--rel-border-danger);
|
|
201
|
-
border-color: var(--rel-border-danger);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/* Size variants (medium is the base .trigger-button style) */
|
|
205
|
-
.date-picker-wrapper.small .trigger-button {
|
|
206
|
-
padding: var(--rel-spacing-xs) var(--rel-spacing-sm);
|
|
207
|
-
font-family: var(--rel-body-sm-regular-font-family);
|
|
208
|
-
font-weight: var(--rel-body-sm-regular-font-weight);
|
|
209
|
-
font-size: var(--rel-body-sm-regular-font-size);
|
|
210
|
-
line-height: var(--rel-body-sm-regular-line-height);
|
|
211
|
-
letter-spacing: var(--rel-body-sm-regular-letter-spacing);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
.date-picker-wrapper.large .trigger-button {
|
|
215
|
-
padding: var(--rel-spacing-md) var(--rel-spacing-md);
|
|
216
|
-
font-family: var(--rel-body-lg-regular-font-family);
|
|
217
|
-
font-weight: var(--rel-body-lg-regular-font-weight);
|
|
218
|
-
font-size: var(--rel-body-lg-regular-font-size);
|
|
219
|
-
line-height: var(--rel-body-lg-regular-line-height);
|
|
220
|
-
letter-spacing: var(--rel-body-lg-regular-letter-spacing);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
.trigger-content {
|
|
224
|
-
flex: 1;
|
|
225
|
-
color: var(--rel-text-default);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
.trigger-content.placeholder {
|
|
229
|
-
color: var(--rel-text-placeholder);
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
.trigger-icons {
|
|
233
|
-
display: flex;
|
|
234
|
-
align-items: center;
|
|
235
|
-
gap: var(--rel-spacing-2xs);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
.icon-button {
|
|
239
|
-
background: none;
|
|
240
|
-
border: none;
|
|
241
|
-
padding: var(--rel-spacing-3xs);
|
|
242
|
-
cursor: pointer;
|
|
243
|
-
color: var(--rel-text-placeholder);
|
|
244
|
-
display: flex;
|
|
245
|
-
align-items: center;
|
|
246
|
-
justify-content: center;
|
|
247
|
-
border-radius: var(--rel-border-radius-xs);
|
|
248
|
-
transition: all 0.15s ease;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
.icon-button:hover {
|
|
252
|
-
background: var(--rel-bg-surface-elevated);
|
|
253
|
-
color: var(--rel-text-default);
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
.icon-button svg {
|
|
257
|
-
width: 16px;
|
|
258
|
-
height: 16px;
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
.popover {
|
|
262
|
-
position: absolute;
|
|
263
|
-
top: calc(100% + 4px);
|
|
264
|
-
left: 0;
|
|
265
|
-
z-index: 1000;
|
|
266
|
-
background: var(--rel-bg-surface);
|
|
267
|
-
border: 1px solid var(--rel-border-default);
|
|
268
|
-
border-radius: var(--rel-border-radius-sm);
|
|
269
|
-
box-shadow: var(--rel-shadows-shadow-300);
|
|
270
|
-
padding: var(--rel-spacing-md);
|
|
271
|
-
min-width: 280px;
|
|
272
|
-
display: none;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
.popover.open {
|
|
276
|
-
display: block;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
.calendar-header {
|
|
280
|
-
display: flex;
|
|
281
|
-
align-items: center;
|
|
282
|
-
justify-content: space-between;
|
|
283
|
-
margin-bottom: var(--rel-spacing-md);
|
|
284
|
-
gap: var(--rel-spacing-xs);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
.nav-button {
|
|
288
|
-
background: transparent;
|
|
289
|
-
border: none;
|
|
290
|
-
width: 32px;
|
|
291
|
-
height: 32px;
|
|
292
|
-
border-radius: var(--rel-border-radius-sm);
|
|
293
|
-
display: flex;
|
|
294
|
-
align-items: center;
|
|
295
|
-
justify-content: center;
|
|
296
|
-
cursor: pointer;
|
|
297
|
-
color: var(--rel-text-default);
|
|
298
|
-
transition: background-color 0.15s ease;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
.nav-button:hover {
|
|
302
|
-
background: var(--rel-bg-surface-elevated);
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
.nav-button:focus-visible {
|
|
306
|
-
outline: 2px solid var(--rel-border-focus);
|
|
307
|
-
outline-offset: 2px;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
.dropdown-container {
|
|
311
|
-
position: relative;
|
|
312
|
-
flex: 1;
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
.dropdown-trigger {
|
|
316
|
-
width: 100%;
|
|
317
|
-
padding: var(--rel-spacing-xs) var(--rel-spacing-sm);
|
|
318
|
-
background: var(--rel-bg-surface);
|
|
319
|
-
border: 1px solid var(--rel-border-default);
|
|
320
|
-
border-radius: var(--rel-border-radius-sm);
|
|
321
|
-
color: var(--rel-text-label);
|
|
322
|
-
cursor: pointer;
|
|
323
|
-
text-align: center;
|
|
324
|
-
transition: all 0.15s ease;
|
|
325
|
-
font-family: var(--rel-body-sm-medium-font-family);
|
|
326
|
-
font-weight: var(--rel-body-sm-medium-font-weight);
|
|
327
|
-
font-size: var(--rel-body-sm-medium-font-size);
|
|
328
|
-
line-height: var(--rel-body-sm-medium-line-height);
|
|
329
|
-
letter-spacing: var(--rel-body-sm-medium-letter-spacing);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
.dropdown-trigger:hover {
|
|
333
|
-
background: var(--rel-bg-surface-elevated);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
.dropdown-trigger:focus-visible {
|
|
337
|
-
outline: 2px solid var(--rel-border-focus);
|
|
338
|
-
outline-offset: 2px;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
.dropdown-menu {
|
|
342
|
-
position: absolute;
|
|
343
|
-
top: calc(100% + 4px);
|
|
344
|
-
left: 0;
|
|
345
|
-
right: 0;
|
|
346
|
-
z-index: 10;
|
|
347
|
-
background: var(--rel-bg-surface);
|
|
348
|
-
border: 1px solid var(--rel-border-default);
|
|
349
|
-
border-radius: var(--rel-border-radius-sm);
|
|
350
|
-
box-shadow: var(--rel-shadows-shadow-200);
|
|
351
|
-
max-height: 200px;
|
|
352
|
-
overflow-y: auto;
|
|
353
|
-
display: none;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
.dropdown-menu.open {
|
|
357
|
-
display: block;
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
.dropdown-item {
|
|
361
|
-
display: block;
|
|
362
|
-
width: 100%;
|
|
363
|
-
border: none;
|
|
364
|
-
background: transparent;
|
|
365
|
-
text-align: left;
|
|
366
|
-
padding: var(--rel-spacing-xs) var(--rel-spacing-sm);
|
|
367
|
-
cursor: pointer;
|
|
368
|
-
color: var(--rel-text-default);
|
|
369
|
-
transition: background-color 0.15s ease;
|
|
370
|
-
font-family: var(--rel-body-sm-regular-font-family);
|
|
371
|
-
font-weight: var(--rel-body-sm-regular-font-weight);
|
|
372
|
-
font-size: var(--rel-body-sm-regular-font-size);
|
|
373
|
-
line-height: var(--rel-body-sm-regular-line-height);
|
|
374
|
-
letter-spacing: var(--rel-body-sm-regular-letter-spacing);
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
.dropdown-item:focus-visible {
|
|
378
|
-
outline: 2px solid var(--rel-border-focus);
|
|
379
|
-
outline-offset: -2px;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
.dropdown-item:hover {
|
|
383
|
-
background: var(--rel-bg-surface-elevated);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
.dropdown-item.selected {
|
|
387
|
-
background: var(--rel-bg-info-light);
|
|
388
|
-
color: var(--rel-text-info);
|
|
389
|
-
font-weight: var(--rel-body-md-semibold-font-weight);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
.weekdays {
|
|
393
|
-
display: grid;
|
|
394
|
-
grid-template-columns: repeat(7, 1fr);
|
|
395
|
-
gap: var(--rel-spacing-3xs);
|
|
396
|
-
margin-bottom: var(--rel-spacing-xs);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
.weekday {
|
|
400
|
-
text-align: center;
|
|
401
|
-
color: var(--rel-text-placeholder);
|
|
402
|
-
padding: var(--rel-spacing-xs);
|
|
403
|
-
text-transform: uppercase;
|
|
404
|
-
font-family: var(--rel-body-xs-semibold-font-family);
|
|
405
|
-
font-weight: var(--rel-body-xs-semibold-font-weight);
|
|
406
|
-
font-size: var(--rel-body-xs-semibold-font-size);
|
|
407
|
-
line-height: var(--rel-body-xs-semibold-line-height);
|
|
408
|
-
letter-spacing: var(--rel-body-xs-semibold-letter-spacing);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
.calendar-grid {
|
|
412
|
-
display: grid;
|
|
413
|
-
grid-template-columns: repeat(7, 1fr);
|
|
414
|
-
gap: var(--rel-spacing-3xs);
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
.day-button {
|
|
418
|
-
aspect-ratio: 1;
|
|
419
|
-
border: none;
|
|
420
|
-
background: transparent;
|
|
421
|
-
border-radius: var(--rel-border-radius-sm);
|
|
422
|
-
color: var(--rel-text-default);
|
|
423
|
-
cursor: pointer;
|
|
424
|
-
position: relative;
|
|
425
|
-
transition: all 0.15s ease;
|
|
426
|
-
font-family: var(--rel-body-sm-medium-font-family);
|
|
427
|
-
font-weight: var(--rel-body-sm-medium-font-weight);
|
|
428
|
-
font-size: var(--rel-body-sm-medium-font-size);
|
|
429
|
-
line-height: var(--rel-body-sm-medium-line-height);
|
|
430
|
-
letter-spacing: var(--rel-body-sm-medium-letter-spacing);
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
.day-button:hover:not(:disabled):not(.selected) {
|
|
434
|
-
background: var(--rel-bg-surface-elevated);
|
|
435
|
-
}
|
|
436
|
-
|
|
437
|
-
.day-button:focus-visible {
|
|
438
|
-
outline: 2px solid var(--rel-border-focus);
|
|
439
|
-
outline-offset: -2px;
|
|
440
|
-
z-index: 1;
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
.day-button.today:not(.selected) {
|
|
444
|
-
border: 2px solid var(--rel-border-brand);
|
|
445
|
-
}
|
|
446
|
-
|
|
447
|
-
.day-button.selected {
|
|
448
|
-
background: var(--rel-action-brand-fill);
|
|
449
|
-
color: var(--rel-action-brand-label-icons-primary);
|
|
450
|
-
font-weight: var(--rel-body-md-semibold-font-weight);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
.day-button.other-month {
|
|
454
|
-
color: var(--rel-text-placeholder);
|
|
455
|
-
opacity: 0.5;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
.day-button:disabled {
|
|
459
|
-
color: var(--rel-text-disabled);
|
|
460
|
-
cursor: not-allowed;
|
|
461
|
-
opacity: 0.5;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
.day-button:disabled:hover {
|
|
465
|
-
background: transparent;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
@media (prefers-reduced-motion: reduce) {
|
|
469
|
-
.trigger-button,
|
|
470
|
-
.icon-button,
|
|
471
|
-
.nav-button,
|
|
472
|
-
.dropdown-trigger,
|
|
473
|
-
.dropdown-item,
|
|
474
|
-
.day-button {
|
|
475
|
-
transition: none;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
`;
|
|
479
|
-
|
|
480
|
-
connectedCallback() {
|
|
481
|
-
super.connectedCallback();
|
|
482
|
-
if (this.value) {
|
|
483
|
-
const date = this.parseISODate(this.value);
|
|
484
|
-
if (date) {
|
|
485
|
-
this.viewYear = date.getFullYear();
|
|
486
|
-
this.viewMonth = date.getMonth();
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
// Click outside handler
|
|
491
|
-
document.addEventListener("click", this.handleClickOutside);
|
|
492
|
-
document.addEventListener("keydown", this.handleEscapeKey);
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
disconnectedCallback() {
|
|
496
|
-
super.disconnectedCallback();
|
|
497
|
-
document.removeEventListener("click", this.handleClickOutside);
|
|
498
|
-
document.removeEventListener("keydown", this.handleEscapeKey);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
private handleClickOutside = (e: MouseEvent) => {
|
|
502
|
-
if (!this.open) return;
|
|
503
|
-
|
|
504
|
-
const path = e.composedPath();
|
|
505
|
-
if (!path.includes(this)) {
|
|
506
|
-
this.closeCalendarPopover();
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
|
|
510
|
-
private handleEscapeKey = (e: KeyboardEvent) => {
|
|
511
|
-
if (!this.open) return;
|
|
512
|
-
if (e.key === "Escape") {
|
|
513
|
-
this.closeCalendarPopover();
|
|
514
|
-
return;
|
|
515
|
-
}
|
|
516
|
-
// The popover announces itself as a dialog — keep Tab inside it.
|
|
517
|
-
if (e.key === "Tab") {
|
|
518
|
-
const popover = this.renderRoot.querySelector<HTMLElement>(".popover");
|
|
519
|
-
if (popover) trapTabKey(e, popover);
|
|
520
|
-
}
|
|
521
|
-
};
|
|
522
|
-
|
|
523
|
-
updated(changedProperties: Map<string, any>) {
|
|
524
|
-
if (changedProperties.has("value") && this.value) {
|
|
525
|
-
const date = this.parseISODate(this.value);
|
|
526
|
-
if (date) {
|
|
527
|
-
this.viewYear = date.getFullYear();
|
|
528
|
-
this.viewMonth = date.getMonth();
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
if (changedProperties.has("open") && this.open) {
|
|
533
|
-
// Focus the roving cell (selected day, else today, else first
|
|
534
|
-
// selectable) when opening — not blindly the first of the month.
|
|
535
|
-
setTimeout(() => {
|
|
536
|
-
const target =
|
|
537
|
-
this.calendarGrid?.querySelector<HTMLButtonElement>(
|
|
538
|
-
'.day-button[tabindex="0"]:not(:disabled)'
|
|
539
|
-
) ??
|
|
540
|
-
this.calendarGrid?.querySelector<HTMLButtonElement>(
|
|
541
|
-
".day-button:not(:disabled)"
|
|
542
|
-
);
|
|
543
|
-
target?.focus();
|
|
544
|
-
}, 100);
|
|
545
|
-
}
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
private parseISODate(iso: string): Date | null {
|
|
549
|
-
const match = iso.match(/^(\d{4})-(\d{2})-(\d{2})$/);
|
|
550
|
-
if (!match) return null;
|
|
551
|
-
const [, year, month, day] = match;
|
|
552
|
-
return new Date(parseInt(year), parseInt(month) - 1, parseInt(day));
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
private formatISODate(date: Date): string {
|
|
556
|
-
const year = date.getFullYear();
|
|
557
|
-
const month = String(date.getMonth() + 1).padStart(2, "0");
|
|
558
|
-
const day = String(date.getDate()).padStart(2, "0");
|
|
559
|
-
return `${year}-${month}-${day}`;
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
private formatDisplayDate(iso: string): string {
|
|
563
|
-
const date = this.parseISODate(iso);
|
|
564
|
-
if (!date) return iso;
|
|
565
|
-
|
|
566
|
-
// 1) explicit callback wins (fall back on error so a bad callback can't
|
|
567
|
-
// blank the field)
|
|
568
|
-
if (typeof this.formatDate === "function") {
|
|
569
|
-
try {
|
|
570
|
-
const out = this.formatDate(date);
|
|
571
|
-
if (typeof out === "string") return out;
|
|
572
|
-
} catch {
|
|
573
|
-
/* fall through to the default */
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
// 2) token pattern (e.g. "YYYY-MM-DD")
|
|
577
|
-
if (this.displayFormat) {
|
|
578
|
-
return formatDatePattern(date, this.displayFormat, this.locale);
|
|
579
|
-
}
|
|
580
|
-
// 3) backward-compatible locale long date
|
|
581
|
-
return new Intl.DateTimeFormat(this.locale, {
|
|
582
|
-
year: "numeric",
|
|
583
|
-
month: "long",
|
|
584
|
-
day: "numeric",
|
|
585
|
-
}).format(date);
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
private isSameDay(date1: Date, date2: Date): boolean {
|
|
589
|
-
return (
|
|
590
|
-
date1.getFullYear() === date2.getFullYear() &&
|
|
591
|
-
date1.getMonth() === date2.getMonth() &&
|
|
592
|
-
date1.getDate() === date2.getDate()
|
|
593
|
-
);
|
|
594
|
-
}
|
|
595
|
-
|
|
596
|
-
private isDateDisabledInternal(date: Date): boolean {
|
|
597
|
-
if (this.disabled) return true;
|
|
598
|
-
|
|
599
|
-
if (this.minBound) {
|
|
600
|
-
const minDate = this.parseISODate(this.minBound);
|
|
601
|
-
if (minDate && date < minDate) return true;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
if (this.maxBound) {
|
|
605
|
-
const maxDate = this.parseISODate(this.maxBound);
|
|
606
|
-
if (maxDate && date > maxDate) return true;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
if (this.isDateDisabled && this.isDateDisabled(date)) {
|
|
610
|
-
return true;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
return false;
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
private getCalendarDays(): CalendarDay[] {
|
|
617
|
-
const days: CalendarDay[] = [];
|
|
618
|
-
const firstDayOfMonth = new Date(this.viewYear, this.viewMonth, 1);
|
|
619
|
-
const lastDayOfMonth = new Date(this.viewYear, this.viewMonth + 1, 0);
|
|
620
|
-
const today = new Date();
|
|
621
|
-
const selectedDate = this.value ? this.parseISODate(this.value) : null;
|
|
622
|
-
|
|
623
|
-
let startDay = firstDayOfMonth.getDay();
|
|
624
|
-
if (this.weekStart === "mon") {
|
|
625
|
-
startDay = startDay === 0 ? 6 : startDay - 1;
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
// Leading days from previous month
|
|
629
|
-
for (let i = startDay - 1; i >= 0; i--) {
|
|
630
|
-
const date = new Date(this.viewYear, this.viewMonth, -i);
|
|
631
|
-
days.push({
|
|
632
|
-
date,
|
|
633
|
-
day: date.getDate(),
|
|
634
|
-
isCurrentMonth: false,
|
|
635
|
-
isToday: this.isSameDay(date, today),
|
|
636
|
-
isSelected: selectedDate ? this.isSameDay(date, selectedDate) : false,
|
|
637
|
-
isDisabled: true, // Leading days not selectable
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
// Current month days
|
|
642
|
-
for (let day = 1; day <= lastDayOfMonth.getDate(); day++) {
|
|
643
|
-
const date = new Date(this.viewYear, this.viewMonth, day);
|
|
644
|
-
days.push({
|
|
645
|
-
date,
|
|
646
|
-
day,
|
|
647
|
-
isCurrentMonth: true,
|
|
648
|
-
isToday: this.isSameDay(date, today),
|
|
649
|
-
isSelected: selectedDate ? this.isSameDay(date, selectedDate) : false,
|
|
650
|
-
isDisabled: this.isDateDisabledInternal(date),
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
|
|
654
|
-
// Trailing days from next month
|
|
655
|
-
const remainingCells = 42 - days.length; // 6 weeks max
|
|
656
|
-
for (let i = 1; i <= remainingCells; i++) {
|
|
657
|
-
const date = new Date(this.viewYear, this.viewMonth + 1, i);
|
|
658
|
-
days.push({
|
|
659
|
-
date,
|
|
660
|
-
day: date.getDate(),
|
|
661
|
-
isCurrentMonth: false,
|
|
662
|
-
isToday: this.isSameDay(date, today),
|
|
663
|
-
isSelected: selectedDate ? this.isSameDay(date, selectedDate) : false,
|
|
664
|
-
isDisabled: true, // Trailing days not selectable
|
|
665
|
-
});
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
return days;
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
private getWeekdayLabels(): string[] {
|
|
672
|
-
const formatter = new Intl.DateTimeFormat(this.locale, { weekday: "short" });
|
|
673
|
-
const days = [];
|
|
674
|
-
const baseDate = new Date(2024, 0, 7); // Sunday, Jan 7, 2024
|
|
675
|
-
|
|
676
|
-
for (let i = 0; i < 7; i++) {
|
|
677
|
-
const offset = this.weekStart === "mon" ? i + 1 : i;
|
|
678
|
-
const date = new Date(baseDate);
|
|
679
|
-
date.setDate(baseDate.getDate() + offset);
|
|
680
|
-
days.push(formatter.format(date).substring(0, 2));
|
|
681
|
-
}
|
|
682
|
-
|
|
683
|
-
return days;
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
private getMonthName(): string {
|
|
687
|
-
const formatter = new Intl.DateTimeFormat(this.locale, { month: "long" });
|
|
688
|
-
return formatter.format(new Date(this.viewYear, this.viewMonth, 1));
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
private getMonthsList(): { value: number; label: string }[] {
|
|
692
|
-
const months = [];
|
|
693
|
-
for (let i = 0; i < 12; i++) {
|
|
694
|
-
const formatter = new Intl.DateTimeFormat(this.locale, { month: "long" });
|
|
695
|
-
const label = formatter.format(new Date(2024, i, 1));
|
|
696
|
-
months.push({ value: i, label });
|
|
697
|
-
}
|
|
698
|
-
return months;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
private getYearsList(): number[] {
|
|
702
|
-
const currentYear = new Date().getFullYear();
|
|
703
|
-
let startYear = currentYear - 100;
|
|
704
|
-
let endYear = currentYear + 10;
|
|
705
|
-
|
|
706
|
-
if (this.minBound) {
|
|
707
|
-
const minDate = this.parseISODate(this.minBound);
|
|
708
|
-
if (minDate) startYear = Math.max(startYear, minDate.getFullYear() - 5);
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
if (this.maxBound) {
|
|
712
|
-
const maxDate = this.parseISODate(this.maxBound);
|
|
713
|
-
if (maxDate) endYear = Math.min(endYear, maxDate.getFullYear() + 5);
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
const years = [];
|
|
717
|
-
for (let y = startYear; y <= endYear; y++) {
|
|
718
|
-
years.push(y);
|
|
719
|
-
}
|
|
720
|
-
return years.reverse(); // Most recent first
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
private toggleCalendarPopover() {
|
|
724
|
-
if (this.disabled || this.readonly) return;
|
|
725
|
-
this.open = !this.open;
|
|
726
|
-
this.dispatchEvent(
|
|
727
|
-
new CustomEvent("rel-open-change", {
|
|
728
|
-
detail: { open: this.open },
|
|
729
|
-
bubbles: true,
|
|
730
|
-
composed: true,
|
|
731
|
-
})
|
|
732
|
-
);
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
private closeCalendarPopover() {
|
|
736
|
-
this.open = false;
|
|
737
|
-
this.monthDropdownOpen = false;
|
|
738
|
-
this.yearDropdownOpen = false;
|
|
739
|
-
this.triggerButton?.focus();
|
|
740
|
-
this.dispatchEvent(
|
|
741
|
-
new CustomEvent("rel-open-change", {
|
|
742
|
-
detail: { open: false },
|
|
743
|
-
bubbles: true,
|
|
744
|
-
composed: true,
|
|
745
|
-
})
|
|
746
|
-
);
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
private previousMonth() {
|
|
750
|
-
if (this.viewMonth === 0) {
|
|
751
|
-
this.viewMonth = 11;
|
|
752
|
-
this.viewYear--;
|
|
753
|
-
} else {
|
|
754
|
-
this.viewMonth--;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
private nextMonth() {
|
|
759
|
-
if (this.viewMonth === 11) {
|
|
760
|
-
this.viewMonth = 0;
|
|
761
|
-
this.viewYear++;
|
|
762
|
-
} else {
|
|
763
|
-
this.viewMonth++;
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
private selectDay(day: CalendarDay) {
|
|
768
|
-
if (day.isDisabled || this.disabled || this.readonly) return;
|
|
769
|
-
|
|
770
|
-
const newValue = this.formatISODate(day.date);
|
|
771
|
-
this.value = newValue;
|
|
772
|
-
|
|
773
|
-
this.dispatchEvent(
|
|
774
|
-
new CustomEvent("rel-change", {
|
|
775
|
-
detail: {
|
|
776
|
-
value: newValue,
|
|
777
|
-
date: new Date(day.date),
|
|
778
|
-
},
|
|
779
|
-
bubbles: true,
|
|
780
|
-
composed: true,
|
|
781
|
-
})
|
|
782
|
-
);
|
|
783
|
-
|
|
784
|
-
if (this.closeOnSelect) {
|
|
785
|
-
this.closeCalendarPopover();
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
private clearValue(e: Event) {
|
|
790
|
-
e.stopPropagation();
|
|
791
|
-
this.value = null;
|
|
792
|
-
|
|
793
|
-
this.dispatchEvent(
|
|
794
|
-
new CustomEvent("rel-change", {
|
|
795
|
-
detail: {
|
|
796
|
-
value: null,
|
|
797
|
-
date: null,
|
|
798
|
-
},
|
|
799
|
-
bubbles: true,
|
|
800
|
-
composed: true,
|
|
801
|
-
})
|
|
802
|
-
);
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
private handleTriggerKeydown(e: KeyboardEvent) {
|
|
806
|
-
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
807
|
-
e.preventDefault();
|
|
808
|
-
if (!this.open) {
|
|
809
|
-
this.toggleCalendarPopover();
|
|
810
|
-
}
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
private handleDayKeydown(e: KeyboardEvent, day: CalendarDay, index: number) {
|
|
815
|
-
const days = this.getCalendarDays();
|
|
816
|
-
let targetIndex = index;
|
|
817
|
-
|
|
818
|
-
switch (e.key) {
|
|
819
|
-
case "ArrowLeft":
|
|
820
|
-
e.preventDefault();
|
|
821
|
-
targetIndex = index - 1;
|
|
822
|
-
break;
|
|
823
|
-
case "ArrowRight":
|
|
824
|
-
e.preventDefault();
|
|
825
|
-
targetIndex = index + 1;
|
|
826
|
-
break;
|
|
827
|
-
case "ArrowUp":
|
|
828
|
-
e.preventDefault();
|
|
829
|
-
targetIndex = index - 7;
|
|
830
|
-
break;
|
|
831
|
-
case "ArrowDown":
|
|
832
|
-
e.preventDefault();
|
|
833
|
-
targetIndex = index + 7;
|
|
834
|
-
break;
|
|
835
|
-
case "Home":
|
|
836
|
-
e.preventDefault();
|
|
837
|
-
targetIndex = index - (index % 7);
|
|
838
|
-
break;
|
|
839
|
-
case "End":
|
|
840
|
-
e.preventDefault();
|
|
841
|
-
targetIndex = index - (index % 7) + 6;
|
|
842
|
-
break;
|
|
843
|
-
case "PageUp":
|
|
844
|
-
e.preventDefault();
|
|
845
|
-
if (e.shiftKey) {
|
|
846
|
-
this.viewYear--;
|
|
847
|
-
} else {
|
|
848
|
-
this.previousMonth();
|
|
849
|
-
}
|
|
850
|
-
return;
|
|
851
|
-
case "PageDown":
|
|
852
|
-
e.preventDefault();
|
|
853
|
-
if (e.shiftKey) {
|
|
854
|
-
this.viewYear++;
|
|
855
|
-
} else {
|
|
856
|
-
this.nextMonth();
|
|
857
|
-
}
|
|
858
|
-
return;
|
|
859
|
-
case "Enter":
|
|
860
|
-
case " ":
|
|
861
|
-
e.preventDefault();
|
|
862
|
-
this.selectDay(day);
|
|
863
|
-
return;
|
|
864
|
-
default:
|
|
865
|
-
return;
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
if (targetIndex >= 0 && targetIndex < days.length) {
|
|
869
|
-
const targetDay = days[targetIndex];
|
|
870
|
-
if (!targetDay.isCurrentMonth) {
|
|
871
|
-
if (targetIndex < index) {
|
|
872
|
-
this.previousMonth();
|
|
873
|
-
} else {
|
|
874
|
-
this.nextMonth();
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
this.requestUpdate();
|
|
878
|
-
this.updateComplete.then(() => {
|
|
879
|
-
const buttons = this.calendarGrid?.querySelectorAll<HTMLButtonElement>(".day-button");
|
|
880
|
-
if (buttons && buttons[targetIndex]) {
|
|
881
|
-
buttons[targetIndex].focus();
|
|
882
|
-
}
|
|
883
|
-
});
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
private toggleMonthDropdown(e: Event) {
|
|
888
|
-
e.stopPropagation();
|
|
889
|
-
this.monthDropdownOpen = !this.monthDropdownOpen;
|
|
890
|
-
this.yearDropdownOpen = false;
|
|
891
|
-
if (this.monthDropdownOpen) this.focusOpenDropdownSelection();
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
private toggleYearDropdown(e: Event) {
|
|
895
|
-
e.stopPropagation();
|
|
896
|
-
this.yearDropdownOpen = !this.yearDropdownOpen;
|
|
897
|
-
this.monthDropdownOpen = false;
|
|
898
|
-
if (this.yearDropdownOpen) this.focusOpenDropdownSelection();
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
private handleDropdownTriggerKeydown(e: KeyboardEvent, kind: "month" | "year") {
|
|
902
|
-
if (e.key !== "ArrowDown") return;
|
|
903
|
-
e.preventDefault();
|
|
904
|
-
e.stopPropagation();
|
|
905
|
-
this.monthDropdownOpen = kind === "month";
|
|
906
|
-
this.yearDropdownOpen = kind === "year";
|
|
907
|
-
this.focusOpenDropdownSelection();
|
|
908
|
-
}
|
|
909
|
-
|
|
910
|
-
private async focusOpenDropdownSelection() {
|
|
911
|
-
await this.updateComplete;
|
|
912
|
-
const menu = this.renderRoot.querySelector<HTMLElement>(".dropdown-menu.open");
|
|
913
|
-
if (!menu) return;
|
|
914
|
-
const target =
|
|
915
|
-
menu.querySelector<HTMLElement>(".dropdown-item.selected") ??
|
|
916
|
-
menu.querySelector<HTMLElement>(".dropdown-item");
|
|
917
|
-
target?.focus();
|
|
918
|
-
target?.scrollIntoView({ block: "nearest" });
|
|
919
|
-
}
|
|
920
|
-
|
|
921
|
-
private handleDropdownKeydown = (e: KeyboardEvent) => {
|
|
922
|
-
const menu = e.currentTarget as HTMLElement;
|
|
923
|
-
const items = Array.from(
|
|
924
|
-
menu.querySelectorAll<HTMLElement>(".dropdown-item")
|
|
925
|
-
);
|
|
926
|
-
if (items.length === 0) return;
|
|
927
|
-
|
|
928
|
-
if (e.key === "Escape") {
|
|
929
|
-
// Close only the dropdown, not the whole calendar popover behind it.
|
|
930
|
-
e.preventDefault();
|
|
931
|
-
e.stopPropagation();
|
|
932
|
-
const trigger = menu
|
|
933
|
-
.closest(".dropdown-container")
|
|
934
|
-
?.querySelector<HTMLElement>(".dropdown-trigger");
|
|
935
|
-
this.monthDropdownOpen = false;
|
|
936
|
-
this.yearDropdownOpen = false;
|
|
937
|
-
trigger?.focus();
|
|
938
|
-
return;
|
|
939
|
-
}
|
|
940
|
-
|
|
941
|
-
if (e.key === "Tab") {
|
|
942
|
-
this.monthDropdownOpen = false;
|
|
943
|
-
this.yearDropdownOpen = false;
|
|
944
|
-
return;
|
|
945
|
-
}
|
|
946
|
-
|
|
947
|
-
const idx = items.indexOf(getDeepActiveElement() as HTMLElement);
|
|
948
|
-
let target: number;
|
|
949
|
-
switch (e.key) {
|
|
950
|
-
case "ArrowDown":
|
|
951
|
-
target = Math.min(items.length - 1, idx + 1);
|
|
952
|
-
break;
|
|
953
|
-
case "ArrowUp":
|
|
954
|
-
target = Math.max(0, idx - 1);
|
|
955
|
-
break;
|
|
956
|
-
case "Home":
|
|
957
|
-
target = 0;
|
|
958
|
-
break;
|
|
959
|
-
case "End":
|
|
960
|
-
target = items.length - 1;
|
|
961
|
-
break;
|
|
962
|
-
default:
|
|
963
|
-
return;
|
|
964
|
-
}
|
|
965
|
-
e.preventDefault();
|
|
966
|
-
e.stopPropagation();
|
|
967
|
-
items[target]?.focus();
|
|
968
|
-
items[target]?.scrollIntoView({ block: "nearest" });
|
|
969
|
-
};
|
|
970
|
-
|
|
971
|
-
private selectMonth(month: number, e: Event) {
|
|
972
|
-
e.stopPropagation();
|
|
973
|
-
const trigger = (e.target as HTMLElement)
|
|
974
|
-
.closest(".dropdown-container")
|
|
975
|
-
?.querySelector<HTMLElement>(".dropdown-trigger");
|
|
976
|
-
this.viewMonth = month;
|
|
977
|
-
this.monthDropdownOpen = false;
|
|
978
|
-
// The focused item just went display:none — keep keyboard users anchored.
|
|
979
|
-
this.updateComplete.then(() => trigger?.focus());
|
|
980
|
-
}
|
|
981
|
-
|
|
982
|
-
private selectYear(year: number, e: Event) {
|
|
983
|
-
e.stopPropagation();
|
|
984
|
-
const trigger = (e.target as HTMLElement)
|
|
985
|
-
.closest(".dropdown-container")
|
|
986
|
-
?.querySelector<HTMLElement>(".dropdown-trigger");
|
|
987
|
-
this.viewYear = year;
|
|
988
|
-
this.yearDropdownOpen = false;
|
|
989
|
-
this.updateComplete.then(() => trigger?.focus());
|
|
990
|
-
}
|
|
991
|
-
|
|
992
|
-
/**
|
|
993
|
-
* Index of the single grid cell carrying tabindex="0". The old expression
|
|
994
|
-
* (`isSelected || (index === 0 && !value)`) left the grid with ZERO tab
|
|
995
|
-
* stops once the user arrowed around without a selection.
|
|
996
|
-
*/
|
|
997
|
-
private getRovingIndex(days: CalendarDay[]): number {
|
|
998
|
-
const candidates = [
|
|
999
|
-
this.focusedDate
|
|
1000
|
-
? days.findIndex(
|
|
1001
|
-
(d) => d.isCurrentMonth && this.isSameDay(d.date, this.focusedDate!)
|
|
1002
|
-
)
|
|
1003
|
-
: -1,
|
|
1004
|
-
days.findIndex((d) => d.isSelected),
|
|
1005
|
-
days.findIndex((d) => d.isCurrentMonth && d.isToday),
|
|
1006
|
-
days.findIndex((d) => d.isCurrentMonth && !d.isDisabled),
|
|
1007
|
-
];
|
|
1008
|
-
const found = candidates.find((i) => i >= 0);
|
|
1009
|
-
return found ?? 0;
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
render() {
|
|
1013
|
-
const days = this.getCalendarDays();
|
|
1014
|
-
const weekdayLabels = this.getWeekdayLabels();
|
|
1015
|
-
const months = this.getMonthsList();
|
|
1016
|
-
const years = this.getYearsList();
|
|
1017
|
-
const rovingIndex = this.getRovingIndex(days);
|
|
1018
|
-
|
|
1019
|
-
const isError = this.error;
|
|
1020
|
-
const belowText = isError && this.errorMessage ? this.errorMessage : this.helperText;
|
|
1021
|
-
const describedById = belowText ? "date-picker-desc" : undefined;
|
|
1022
|
-
const wrapperClasses = [
|
|
1023
|
-
"date-picker-wrapper",
|
|
1024
|
-
this.size,
|
|
1025
|
-
isError ? "error" : "",
|
|
1026
|
-
this.readonly ? "readonly" : "",
|
|
1027
|
-
]
|
|
1028
|
-
.filter(Boolean)
|
|
1029
|
-
.join(" ");
|
|
1030
|
-
|
|
1031
|
-
return html`
|
|
1032
|
-
<div part="base" class="${wrapperClasses}">
|
|
1033
|
-
${this.label
|
|
1034
|
-
? html`<label part="label" class="label" id="date-picker-label"
|
|
1035
|
-
>${this.label}${this.required
|
|
1036
|
-
? html`<span class="required-mark" aria-hidden="true">*</span>`
|
|
1037
|
-
: nothing}</label
|
|
1038
|
-
>`
|
|
1039
|
-
: nothing}
|
|
1040
|
-
|
|
1041
|
-
${this.name
|
|
1042
|
-
? html`<input type="hidden" name=${this.name} .value=${this.value ?? ""} />`
|
|
1043
|
-
: nothing}
|
|
1044
|
-
|
|
1045
|
-
<button
|
|
1046
|
-
class="trigger-button ${isError ? "error" : ""}"
|
|
1047
|
-
type="button"
|
|
1048
|
-
?disabled=${this.disabled}
|
|
1049
|
-
@click=${this.toggleCalendarPopover}
|
|
1050
|
-
@keydown=${this.handleTriggerKeydown}
|
|
1051
|
-
aria-label=${this.label || "Select date"}
|
|
1052
|
-
aria-haspopup="dialog"
|
|
1053
|
-
aria-expanded=${this.open}
|
|
1054
|
-
aria-required=${this.required}
|
|
1055
|
-
aria-invalid=${isError}
|
|
1056
|
-
aria-readonly=${this.readonly}
|
|
1057
|
-
aria-describedby=${describedById ?? nothing}
|
|
1058
|
-
aria-labelledby=${this.label ? "date-picker-label" : nothing}
|
|
1059
|
-
>
|
|
1060
|
-
<span class="trigger-content ${this.value ? "" : "placeholder"}">
|
|
1061
|
-
${this.value ? this.formatDisplayDate(this.value) : this.placeholder}
|
|
1062
|
-
</span>
|
|
1063
|
-
<span class="trigger-icons">
|
|
1064
|
-
${this.clearable && this.value
|
|
1065
|
-
? html`
|
|
1066
|
-
<button
|
|
1067
|
-
class="icon-button"
|
|
1068
|
-
type="button"
|
|
1069
|
-
aria-label="Clear date"
|
|
1070
|
-
@click=${this.clearValue}
|
|
1071
|
-
>
|
|
1072
|
-
<svg viewBox="0 0 16 16" fill="currentColor">
|
|
1073
|
-
<path
|
|
1074
|
-
d="M4 4l8 8M12 4l-8 8"
|
|
1075
|
-
stroke="currentColor"
|
|
1076
|
-
stroke-width="2"
|
|
1077
|
-
stroke-linecap="round"
|
|
1078
|
-
/>
|
|
1079
|
-
</svg>
|
|
1080
|
-
</button>
|
|
1081
|
-
`
|
|
1082
|
-
: nothing}
|
|
1083
|
-
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
1084
|
-
<path
|
|
1085
|
-
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"
|
|
1086
|
-
/>
|
|
1087
|
-
</svg>
|
|
1088
|
-
</span>
|
|
1089
|
-
</button>
|
|
1090
|
-
|
|
1091
|
-
<div class="popover ${this.open ? "open" : ""}" role="dialog" aria-label="Choose date">
|
|
1092
|
-
<div class="calendar-header">
|
|
1093
|
-
<button
|
|
1094
|
-
class="nav-button"
|
|
1095
|
-
@click=${this.previousMonth}
|
|
1096
|
-
aria-label="Previous month"
|
|
1097
|
-
type="button"
|
|
1098
|
-
>
|
|
1099
|
-
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
1100
|
-
<path
|
|
1101
|
-
d="M10 12L6 8L10 4"
|
|
1102
|
-
stroke="currentColor"
|
|
1103
|
-
stroke-width="2"
|
|
1104
|
-
fill="none"
|
|
1105
|
-
stroke-linecap="round"
|
|
1106
|
-
stroke-linejoin="round"
|
|
1107
|
-
/>
|
|
1108
|
-
</svg>
|
|
1109
|
-
</button>
|
|
1110
|
-
|
|
1111
|
-
<div class="dropdown-container">
|
|
1112
|
-
<button
|
|
1113
|
-
class="dropdown-trigger"
|
|
1114
|
-
type="button"
|
|
1115
|
-
@click=${this.toggleMonthDropdown}
|
|
1116
|
-
@keydown=${(e: KeyboardEvent) => this.handleDropdownTriggerKeydown(e, "month")}
|
|
1117
|
-
aria-label="Select month"
|
|
1118
|
-
aria-haspopup="listbox"
|
|
1119
|
-
aria-expanded=${this.monthDropdownOpen}
|
|
1120
|
-
>
|
|
1121
|
-
${this.getMonthName()}
|
|
1122
|
-
</button>
|
|
1123
|
-
<div
|
|
1124
|
-
class="dropdown-menu ${this.monthDropdownOpen ? "open" : ""}"
|
|
1125
|
-
role="listbox"
|
|
1126
|
-
aria-label="Month"
|
|
1127
|
-
@keydown=${this.handleDropdownKeydown}
|
|
1128
|
-
>
|
|
1129
|
-
${months.map(
|
|
1130
|
-
(m) => html`
|
|
1131
|
-
<button
|
|
1132
|
-
class="dropdown-item ${m.value === this.viewMonth ? "selected" : ""}"
|
|
1133
|
-
type="button"
|
|
1134
|
-
tabindex="-1"
|
|
1135
|
-
@click=${(e: Event) => this.selectMonth(m.value, e)}
|
|
1136
|
-
role="option"
|
|
1137
|
-
aria-selected=${m.value === this.viewMonth}
|
|
1138
|
-
>
|
|
1139
|
-
${m.label}
|
|
1140
|
-
</button>
|
|
1141
|
-
`
|
|
1142
|
-
)}
|
|
1143
|
-
</div>
|
|
1144
|
-
</div>
|
|
1145
|
-
|
|
1146
|
-
<div class="dropdown-container">
|
|
1147
|
-
<button
|
|
1148
|
-
class="dropdown-trigger"
|
|
1149
|
-
type="button"
|
|
1150
|
-
@click=${this.toggleYearDropdown}
|
|
1151
|
-
@keydown=${(e: KeyboardEvent) => this.handleDropdownTriggerKeydown(e, "year")}
|
|
1152
|
-
aria-label="Select year"
|
|
1153
|
-
aria-haspopup="listbox"
|
|
1154
|
-
aria-expanded=${this.yearDropdownOpen}
|
|
1155
|
-
>
|
|
1156
|
-
${this.viewYear}
|
|
1157
|
-
</button>
|
|
1158
|
-
<div
|
|
1159
|
-
class="dropdown-menu ${this.yearDropdownOpen ? "open" : ""}"
|
|
1160
|
-
role="listbox"
|
|
1161
|
-
aria-label="Year"
|
|
1162
|
-
@keydown=${this.handleDropdownKeydown}
|
|
1163
|
-
>
|
|
1164
|
-
${years.map(
|
|
1165
|
-
(y) => html`
|
|
1166
|
-
<button
|
|
1167
|
-
class="dropdown-item ${y === this.viewYear ? "selected" : ""}"
|
|
1168
|
-
type="button"
|
|
1169
|
-
tabindex="-1"
|
|
1170
|
-
@click=${(e: Event) => this.selectYear(y, e)}
|
|
1171
|
-
role="option"
|
|
1172
|
-
aria-selected=${y === this.viewYear}
|
|
1173
|
-
>
|
|
1174
|
-
${y}
|
|
1175
|
-
</button>
|
|
1176
|
-
`
|
|
1177
|
-
)}
|
|
1178
|
-
</div>
|
|
1179
|
-
</div>
|
|
1180
|
-
|
|
1181
|
-
<button
|
|
1182
|
-
class="nav-button"
|
|
1183
|
-
@click=${this.nextMonth}
|
|
1184
|
-
aria-label="Next month"
|
|
1185
|
-
type="button"
|
|
1186
|
-
>
|
|
1187
|
-
<svg width="16" height="16" viewBox="0 0 16 16" fill="currentColor">
|
|
1188
|
-
<path
|
|
1189
|
-
d="M6 4L10 8L6 12"
|
|
1190
|
-
stroke="currentColor"
|
|
1191
|
-
stroke-width="2"
|
|
1192
|
-
fill="none"
|
|
1193
|
-
stroke-linecap="round"
|
|
1194
|
-
stroke-linejoin="round"
|
|
1195
|
-
/>
|
|
1196
|
-
</svg>
|
|
1197
|
-
</button>
|
|
1198
|
-
</div>
|
|
1199
|
-
|
|
1200
|
-
<div class="weekdays">
|
|
1201
|
-
${weekdayLabels.map(
|
|
1202
|
-
(label) => html` <div class="weekday" aria-label="${label}">${label}</div> `
|
|
1203
|
-
)}
|
|
1204
|
-
</div>
|
|
1205
|
-
|
|
1206
|
-
<div class="calendar-grid" role="grid">
|
|
1207
|
-
${days.map(
|
|
1208
|
-
(day, index) => html`
|
|
1209
|
-
<button
|
|
1210
|
-
class="day-button ${day.isSelected ? "selected" : ""} ${day.isToday
|
|
1211
|
-
? "today"
|
|
1212
|
-
: ""} ${!day.isCurrentMonth ? "other-month" : ""}"
|
|
1213
|
-
role="gridcell"
|
|
1214
|
-
type="button"
|
|
1215
|
-
aria-label="${this.formatISODate(day.date)}"
|
|
1216
|
-
aria-selected="${day.isSelected}"
|
|
1217
|
-
?disabled=${day.isDisabled}
|
|
1218
|
-
@click=${() => this.selectDay(day)}
|
|
1219
|
-
@keydown=${(e: KeyboardEvent) => this.handleDayKeydown(e, day, index)}
|
|
1220
|
-
tabindex="${index === rovingIndex ? 0 : -1}"
|
|
1221
|
-
>
|
|
1222
|
-
${day.day}
|
|
1223
|
-
</button>
|
|
1224
|
-
`
|
|
1225
|
-
)}
|
|
1226
|
-
</div>
|
|
1227
|
-
</div>
|
|
1228
|
-
|
|
1229
|
-
${belowText
|
|
1230
|
-
? html`<div class="date-picker-support ${isError ? "error" : ""}" id=${describedById}>
|
|
1231
|
-
${belowText}
|
|
1232
|
-
</div>`
|
|
1233
|
-
: nothing}
|
|
1234
|
-
</div>
|
|
1235
|
-
`;
|
|
1236
|
-
}
|
|
1237
|
-
}
|