@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,1126 +0,0 @@
|
|
|
1
|
-
import { LitElement, html, css, nothing } from "lit";
|
|
2
|
-
import { customElement, property, state, query } from "lit/decorators.js";
|
|
3
|
-
import "@reliability-design/icons/rel-icon";
|
|
4
|
-
import "../rel-button/rel-button";
|
|
5
|
-
|
|
6
|
-
type TimeColumn = "hour" | "minute" | "second" | "period";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* `<rel-time-picker>` — time selection field.
|
|
10
|
-
*
|
|
11
|
-
* Follows the rel-date-picker trigger/field conventions (label, helper/error
|
|
12
|
-
* text, sizes, fullWidth, clearable) and the rel-range-picker draft model:
|
|
13
|
-
* column selections are held in draft state until Apply is clicked; Cancel,
|
|
14
|
-
* Escape, or an outside click discards the draft.
|
|
15
|
-
*
|
|
16
|
-
* The committed `value` is ALWAYS 24-hour "HH:mm" (or "HH:mm:ss" when
|
|
17
|
-
* `seconds` is enabled) regardless of the display `format`, so consumers get
|
|
18
|
-
* a consistent machine-readable string.
|
|
19
|
-
*
|
|
20
|
-
* Panel visuals follow the Figma "Time Picker" component (Reliability DS
|
|
21
|
-
* V1.0, node 8301:3771): fixed panel widths 220/250/280 by size, full-bleed
|
|
22
|
-
* columns with 1px dividers, neutral selected state, and a Now / Cancel / OK
|
|
23
|
-
* footer whose buttons are always size S.
|
|
24
|
-
*/
|
|
25
|
-
@customElement("rel-time-picker")
|
|
26
|
-
export class RelTimePicker extends LitElement {
|
|
27
|
-
/** Committed time, 24-hour "HH:mm" or "HH:mm:ss" (e.g. "09:30", "17:05:30"). */
|
|
28
|
-
@property({ type: String, reflect: true }) value: string | null = null;
|
|
29
|
-
@property({ type: String }) placeholder = "Select time";
|
|
30
|
-
@property({ type: String }) label: string | null = null;
|
|
31
|
-
@property({ type: Boolean, reflect: true }) disabled = false;
|
|
32
|
-
@property({ type: Boolean }) required = false;
|
|
33
|
-
@property({ type: Boolean, reflect: true }) readonly = false;
|
|
34
|
-
|
|
35
|
-
/** Display format of the trigger text and hour column. Value stays 24-hour. */
|
|
36
|
-
@property({ type: String }) format: "12h" | "24h" = "12h";
|
|
37
|
-
/** Shows the seconds column; committed value becomes "HH:mm:ss". */
|
|
38
|
-
@property({ type: Boolean, reflect: true }) seconds = false;
|
|
39
|
-
/** Minute granularity of the minutes column (1, 5, 10, 15, 30, …). */
|
|
40
|
-
@property({ type: Number, attribute: "minute-step" }) minuteStep = 5;
|
|
41
|
-
|
|
42
|
-
/** Earliest selectable time, "HH:mm" (inclusive). */
|
|
43
|
-
@property({ type: String, attribute: "min-time" }) minTime: string | null = null;
|
|
44
|
-
/** Latest selectable time, "HH:mm" (inclusive). */
|
|
45
|
-
@property({ type: String, attribute: "max-time" }) maxTime: string | null = null;
|
|
46
|
-
|
|
47
|
-
@property({ type: Boolean, reflect: true }) open = false;
|
|
48
|
-
@property({ type: Boolean }) clearable = false;
|
|
49
|
-
|
|
50
|
-
// ── Standardized input API (mirrors rel-textfield / rel-date-picker) ──
|
|
51
|
-
@property({ type: Boolean }) error = false;
|
|
52
|
-
/** Alias for `error` (requested-API compat); either flag applies error styling. */
|
|
53
|
-
@property({ type: Boolean }) invalid = false;
|
|
54
|
-
@property({ type: String, attribute: "error-message" }) errorMessage?: string;
|
|
55
|
-
@property({ type: String, attribute: "helper-text" }) helperText?: string;
|
|
56
|
-
@property({ type: String }) name?: string;
|
|
57
|
-
@property({ type: String }) size: "small" | "medium" | "large" = "medium";
|
|
58
|
-
@property({ type: String, reflect: true }) variant: "outlined" = "outlined";
|
|
59
|
-
@property({ type: Boolean, reflect: true }) fullWidth = false;
|
|
60
|
-
|
|
61
|
-
// Draft selection (hour is 0–23 internally; committed on OK only)
|
|
62
|
-
@state() private draftHour: number | null = null;
|
|
63
|
-
@state() private draftMinute: number | null = null;
|
|
64
|
-
@state() private draftSecond: number | null = null;
|
|
65
|
-
/** Panel opens above the field when there is no viewport space below. */
|
|
66
|
-
@state() private openUp = false;
|
|
67
|
-
|
|
68
|
-
@query(".trigger-button") private triggerButton?: HTMLButtonElement;
|
|
69
|
-
@query(".columns") private columnsElement?: HTMLElement;
|
|
70
|
-
|
|
71
|
-
static styles = css`
|
|
72
|
-
:host {
|
|
73
|
-
color: var(--rel-text-default);
|
|
74
|
-
display: block;
|
|
75
|
-
font-family: var(--rel-fonts-font-family);
|
|
76
|
-
position: relative;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/* Intrinsic width by default; set fullWidth to fill the parent. */
|
|
80
|
-
:host(:not([fullwidth])) {
|
|
81
|
-
display: inline-block;
|
|
82
|
-
width: auto;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
:host([disabled]) {
|
|
86
|
-
opacity: 0.6;
|
|
87
|
-
cursor: not-allowed;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
:host([disabled]) * {
|
|
91
|
-
pointer-events: none;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
:host([readonly]) .trigger-button {
|
|
95
|
-
cursor: default;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
.time-picker-wrapper {
|
|
99
|
-
display: flex;
|
|
100
|
-
flex-direction: column;
|
|
101
|
-
gap: var(--rel-spacing-xs);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.label {
|
|
105
|
-
color: var(--rel-text-label);
|
|
106
|
-
font-family: var(--rel-body-sm-medium-font-family);
|
|
107
|
-
font-weight: var(--rel-body-sm-medium-font-weight);
|
|
108
|
-
font-size: var(--rel-body-sm-medium-font-size);
|
|
109
|
-
line-height: var(--rel-body-sm-medium-line-height);
|
|
110
|
-
letter-spacing: var(--rel-body-sm-medium-letter-spacing);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
.required-mark {
|
|
114
|
-
color: var(--rel-text-danger);
|
|
115
|
-
margin-left: 2px;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/* Support text (helperText / errorMessage) */
|
|
119
|
-
.time-picker-support {
|
|
120
|
-
color: var(--rel-text-placeholder);
|
|
121
|
-
font-family: var(--rel-body-xs-regular-font-family);
|
|
122
|
-
font-weight: var(--rel-body-xs-regular-font-weight);
|
|
123
|
-
font-size: var(--rel-body-xs-regular-font-size);
|
|
124
|
-
line-height: var(--rel-body-xs-regular-line-height);
|
|
125
|
-
letter-spacing: var(--rel-body-xs-regular-letter-spacing);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
.time-picker-support.error {
|
|
129
|
-
color: var(--rel-text-danger);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
.trigger-button {
|
|
133
|
-
width: 100%;
|
|
134
|
-
min-width: 160px;
|
|
135
|
-
display: flex;
|
|
136
|
-
align-items: center;
|
|
137
|
-
justify-content: space-between;
|
|
138
|
-
gap: var(--rel-spacing-xs);
|
|
139
|
-
padding: var(--rel-spacing-sm) var(--rel-spacing-md);
|
|
140
|
-
background: var(--rel-bg-surface);
|
|
141
|
-
border: 1px solid var(--rel-border-default);
|
|
142
|
-
border-radius: var(--rel-border-radius-sm);
|
|
143
|
-
color: var(--rel-text-default);
|
|
144
|
-
cursor: pointer;
|
|
145
|
-
transition: all 0.15s ease;
|
|
146
|
-
text-align: left;
|
|
147
|
-
font-family: var(--rel-body-md-regular-font-family);
|
|
148
|
-
font-weight: var(--rel-body-md-regular-font-weight);
|
|
149
|
-
font-size: var(--rel-body-md-regular-font-size);
|
|
150
|
-
line-height: var(--rel-body-md-regular-line-height);
|
|
151
|
-
letter-spacing: var(--rel-body-md-regular-letter-spacing);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
.trigger-button:hover:not(:disabled) {
|
|
155
|
-
border-color: var(--rel-border-strong);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
.trigger-button:focus-visible {
|
|
159
|
-
outline: 2px solid var(--rel-border-focus);
|
|
160
|
-
outline-offset: 2px;
|
|
161
|
-
border-color: var(--rel-border-focus);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
.trigger-button:disabled {
|
|
165
|
-
cursor: not-allowed;
|
|
166
|
-
background: var(--rel-bg-surface-elevated);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/* Error state */
|
|
170
|
-
.trigger-button.error,
|
|
171
|
-
.trigger-button.error:hover:not(:disabled) {
|
|
172
|
-
border-color: var(--rel-border-danger);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
.trigger-button.error:focus-visible {
|
|
176
|
-
outline-color: var(--rel-border-danger);
|
|
177
|
-
border-color: var(--rel-border-danger);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/* Size variants (medium is the base .trigger-button style) */
|
|
181
|
-
.time-picker-wrapper.small .trigger-button {
|
|
182
|
-
padding: var(--rel-spacing-xs) var(--rel-spacing-sm);
|
|
183
|
-
font-family: var(--rel-body-sm-regular-font-family);
|
|
184
|
-
font-weight: var(--rel-body-sm-regular-font-weight);
|
|
185
|
-
font-size: var(--rel-body-sm-regular-font-size);
|
|
186
|
-
line-height: var(--rel-body-sm-regular-line-height);
|
|
187
|
-
letter-spacing: var(--rel-body-sm-regular-letter-spacing);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
.time-picker-wrapper.large .trigger-button {
|
|
191
|
-
padding: var(--rel-spacing-md) var(--rel-spacing-md);
|
|
192
|
-
font-family: var(--rel-body-lg-regular-font-family);
|
|
193
|
-
font-weight: var(--rel-body-lg-regular-font-weight);
|
|
194
|
-
font-size: var(--rel-body-lg-regular-font-size);
|
|
195
|
-
line-height: var(--rel-body-lg-regular-line-height);
|
|
196
|
-
letter-spacing: var(--rel-body-lg-regular-letter-spacing);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
.trigger-content {
|
|
200
|
-
flex: 1;
|
|
201
|
-
color: var(--rel-text-default);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
.trigger-content.placeholder {
|
|
205
|
-
color: var(--rel-text-placeholder);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
.trigger-icons {
|
|
209
|
-
display: flex;
|
|
210
|
-
align-items: center;
|
|
211
|
-
gap: var(--rel-spacing-2xs);
|
|
212
|
-
color: var(--rel-text-placeholder);
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
.icon-button {
|
|
216
|
-
background: none;
|
|
217
|
-
border: none;
|
|
218
|
-
padding: var(--rel-spacing-3xs);
|
|
219
|
-
cursor: pointer;
|
|
220
|
-
color: var(--rel-text-placeholder);
|
|
221
|
-
display: flex;
|
|
222
|
-
align-items: center;
|
|
223
|
-
justify-content: center;
|
|
224
|
-
border-radius: var(--rel-border-radius-xs);
|
|
225
|
-
transition: all 0.15s ease;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
.icon-button:hover {
|
|
229
|
-
background: var(--rel-bg-surface-elevated);
|
|
230
|
-
color: var(--rel-text-default);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
.icon-button svg {
|
|
234
|
-
width: 16px;
|
|
235
|
-
height: 16px;
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
/* Panel (Figma "Time Picker"): fixed width per size, full-bleed content. */
|
|
239
|
-
.popover {
|
|
240
|
-
position: absolute;
|
|
241
|
-
top: calc(100% + 4px);
|
|
242
|
-
left: 0;
|
|
243
|
-
z-index: 1000;
|
|
244
|
-
background: var(--rel-bg-surface);
|
|
245
|
-
border: 1px solid var(--rel-border-subtle);
|
|
246
|
-
border-radius: var(--rel-border-radius-sm);
|
|
247
|
-
box-shadow: var(--rel-shadows-shadow-300);
|
|
248
|
-
overflow: hidden;
|
|
249
|
-
min-width: 220px;
|
|
250
|
-
width: 250px;
|
|
251
|
-
display: none;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
.popover.open {
|
|
255
|
-
display: block;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
/* Flip above the field when the viewport has no room below. */
|
|
259
|
-
.popover.open-up {
|
|
260
|
-
top: auto;
|
|
261
|
-
bottom: calc(100% + 4px);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
/* Full-bleed column row with 1px dividers (Figma "Columns"). */
|
|
265
|
-
.columns {
|
|
266
|
-
display: flex;
|
|
267
|
-
align-items: stretch;
|
|
268
|
-
height: 260px;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
.column-divider {
|
|
272
|
-
flex-shrink: 0;
|
|
273
|
-
width: 1px;
|
|
274
|
-
background: var(--rel-border-subtle);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/* Each column scrolls independently. The 4px rail is always reserved
|
|
278
|
-
(scrollbar-gutter) so columns stay aligned whether or not they
|
|
279
|
-
overflow; the thumb only appears on overflow. */
|
|
280
|
-
.column-list {
|
|
281
|
-
flex: 1;
|
|
282
|
-
min-width: 0;
|
|
283
|
-
display: flex;
|
|
284
|
-
flex-direction: column;
|
|
285
|
-
/* Positioned so option offsetTop is list-relative — the in-column
|
|
286
|
-
scroll math depends on it (we never scrollIntoView: it scrolls every
|
|
287
|
-
ancestor, page included). */
|
|
288
|
-
position: relative;
|
|
289
|
-
overflow-y: auto;
|
|
290
|
-
padding: var(--rel-spacing-2xs);
|
|
291
|
-
scrollbar-width: thin;
|
|
292
|
-
scrollbar-color: var(--rel-border-default) transparent;
|
|
293
|
-
scrollbar-gutter: stable;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
.column-list::-webkit-scrollbar {
|
|
297
|
-
width: 4px;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
.column-list::-webkit-scrollbar-track {
|
|
301
|
-
background: transparent;
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
.column-list::-webkit-scrollbar-thumb {
|
|
305
|
-
background: var(--rel-border-default);
|
|
306
|
-
border-radius: var(--rel-border-radius-full-rounded);
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
/* Option cell (Figma ".Time Option"): selected uses the neutral
|
|
310
|
-
elevated-2 fill + medium weight, NOT the brand color. */
|
|
311
|
-
.option-button {
|
|
312
|
-
border: none;
|
|
313
|
-
background: transparent;
|
|
314
|
-
border-radius: var(--rel-border-radius-xs);
|
|
315
|
-
color: var(--rel-text-default);
|
|
316
|
-
cursor: pointer;
|
|
317
|
-
flex-shrink: 0;
|
|
318
|
-
height: 36px;
|
|
319
|
-
padding: 0 var(--rel-spacing-xs);
|
|
320
|
-
text-align: center;
|
|
321
|
-
transition: background 0.15s ease;
|
|
322
|
-
font-family: var(--rel-body-md-regular-font-family);
|
|
323
|
-
font-weight: var(--rel-body-md-regular-font-weight);
|
|
324
|
-
font-size: var(--rel-body-md-regular-font-size);
|
|
325
|
-
line-height: var(--rel-body-md-regular-line-height);
|
|
326
|
-
letter-spacing: var(--rel-body-md-regular-letter-spacing);
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
.option-button:hover:not(:disabled):not(.selected) {
|
|
330
|
-
background: var(--rel-bg-neutral-elevated-1);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
.option-button:focus-visible {
|
|
334
|
-
outline: 2px solid var(--rel-border-focus);
|
|
335
|
-
outline-offset: -2px;
|
|
336
|
-
z-index: 1;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
.option-button.selected {
|
|
340
|
-
background: var(--rel-bg-neutral-elevated-2);
|
|
341
|
-
color: var(--rel-text-default);
|
|
342
|
-
font-weight: var(--rel-body-md-medium-font-weight);
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
.option-button:disabled {
|
|
346
|
-
color: var(--rel-text-disabled);
|
|
347
|
-
cursor: not-allowed;
|
|
348
|
-
opacity: 0.5;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
.option-button:disabled:hover {
|
|
352
|
-
background: transparent;
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/* Footer (Figma "Footer"): 8px padding + 8px extra left so the "Now"
|
|
356
|
-
link aligns with the buttons' inner padding. Buttons are always S. */
|
|
357
|
-
.time-footer {
|
|
358
|
-
display: flex;
|
|
359
|
-
align-items: center;
|
|
360
|
-
justify-content: space-between;
|
|
361
|
-
gap: var(--rel-spacing-xs);
|
|
362
|
-
padding: var(--rel-spacing-xs);
|
|
363
|
-
padding-left: calc(var(--rel-spacing-xs) * 2);
|
|
364
|
-
border-top: 1px solid var(--rel-border-subtle);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
.footer-right {
|
|
368
|
-
display: flex;
|
|
369
|
-
align-items: center;
|
|
370
|
-
gap: var(--rel-spacing-xs);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/* The design narrows OK below the DS small min-width (60 vs 80) so the
|
|
374
|
-
compact footer fits the 220px panel. */
|
|
375
|
-
.footer-right rel-button[variant="primary"] {
|
|
376
|
-
--rel-button-min-width: 60px;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
/* Panel size variants (Figma S/M/L): width 220/250/280, option height
|
|
380
|
-
32/36/40, body-sm/md/lg type. Medium is the base above. */
|
|
381
|
-
.time-picker-wrapper.small .popover {
|
|
382
|
-
width: 220px;
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
.time-picker-wrapper.small .columns {
|
|
386
|
-
height: 232px;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
.time-picker-wrapper.small .option-button {
|
|
390
|
-
height: 32px;
|
|
391
|
-
font-family: var(--rel-body-sm-regular-font-family);
|
|
392
|
-
font-weight: var(--rel-body-sm-regular-font-weight);
|
|
393
|
-
font-size: var(--rel-body-sm-regular-font-size);
|
|
394
|
-
line-height: var(--rel-body-sm-regular-line-height);
|
|
395
|
-
letter-spacing: var(--rel-body-sm-regular-letter-spacing);
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
.time-picker-wrapper.small .option-button.selected {
|
|
399
|
-
font-weight: var(--rel-body-sm-medium-font-weight);
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
.time-picker-wrapper.large .popover {
|
|
403
|
-
width: 280px;
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
.time-picker-wrapper.large .columns {
|
|
407
|
-
height: 288px;
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
.time-picker-wrapper.large .option-button {
|
|
411
|
-
height: 40px;
|
|
412
|
-
font-family: var(--rel-body-lg-regular-font-family);
|
|
413
|
-
font-weight: var(--rel-body-lg-regular-font-weight);
|
|
414
|
-
font-size: var(--rel-body-lg-regular-font-size);
|
|
415
|
-
line-height: var(--rel-body-lg-regular-line-height);
|
|
416
|
-
letter-spacing: var(--rel-body-lg-regular-letter-spacing);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
.time-picker-wrapper.large .option-button.selected {
|
|
420
|
-
font-weight: var(--rel-body-lg-medium-font-weight);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
@media (prefers-reduced-motion: reduce) {
|
|
424
|
-
.trigger-button,
|
|
425
|
-
.icon-button,
|
|
426
|
-
.option-button {
|
|
427
|
-
transition: none;
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
`;
|
|
431
|
-
|
|
432
|
-
connectedCallback() {
|
|
433
|
-
super.connectedCallback();
|
|
434
|
-
document.addEventListener("click", this.handleClickOutside);
|
|
435
|
-
document.addEventListener("keydown", this.handleEscapeKey);
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
disconnectedCallback() {
|
|
439
|
-
super.disconnectedCallback();
|
|
440
|
-
document.removeEventListener("click", this.handleClickOutside);
|
|
441
|
-
document.removeEventListener("keydown", this.handleEscapeKey);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
private handleClickOutside = (e: MouseEvent) => {
|
|
445
|
-
if (!this.open) return;
|
|
446
|
-
const path = e.composedPath();
|
|
447
|
-
if (!path.includes(this)) {
|
|
448
|
-
this.cancelPopover();
|
|
449
|
-
}
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
private handleEscapeKey = (e: KeyboardEvent) => {
|
|
453
|
-
if (e.key === "Escape" && this.open) {
|
|
454
|
-
this.cancelPopover();
|
|
455
|
-
}
|
|
456
|
-
};
|
|
457
|
-
|
|
458
|
-
updated(changedProperties: Map<string, any>) {
|
|
459
|
-
if (changedProperties.has("open")) {
|
|
460
|
-
if (!this.open) {
|
|
461
|
-
this.openUp = false;
|
|
462
|
-
return;
|
|
463
|
-
}
|
|
464
|
-
this.resetDraftFromValue();
|
|
465
|
-
// Once the popover has rendered: flip it above the field if the
|
|
466
|
-
// viewport lacks room below, center each column's selection, and focus
|
|
467
|
-
// the selected (or first enabled) hour without scrolling the page.
|
|
468
|
-
setTimeout(() => {
|
|
469
|
-
this.updatePanelPlacement();
|
|
470
|
-
this.scrollColumnsToSelection();
|
|
471
|
-
const target =
|
|
472
|
-
this.columnsElement?.querySelector<HTMLButtonElement>(
|
|
473
|
-
".option-button.selected:not(:disabled)"
|
|
474
|
-
) ??
|
|
475
|
-
this.columnsElement?.querySelector<HTMLButtonElement>(
|
|
476
|
-
".option-button:not(:disabled)"
|
|
477
|
-
);
|
|
478
|
-
target?.focus({ preventScroll: true });
|
|
479
|
-
}, 0);
|
|
480
|
-
}
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
/** Open upward when the panel doesn't fit below but does fit above. */
|
|
484
|
-
private updatePanelPlacement() {
|
|
485
|
-
const panel = this.renderRoot.querySelector<HTMLElement>(".popover");
|
|
486
|
-
if (!panel) return;
|
|
487
|
-
const rect = this.getBoundingClientRect();
|
|
488
|
-
const panelHeight = panel.offsetHeight;
|
|
489
|
-
const spaceBelow = window.innerHeight - rect.bottom;
|
|
490
|
-
this.openUp = spaceBelow < panelHeight + 8 && rect.top > panelHeight + 8;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
// ── Parsing / formatting ──
|
|
494
|
-
|
|
495
|
-
private parseTime(
|
|
496
|
-
time: string | null
|
|
497
|
-
): { hour: number; minute: number; second: number } | null {
|
|
498
|
-
if (!time) return null;
|
|
499
|
-
const match = time.match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/);
|
|
500
|
-
if (!match) return null;
|
|
501
|
-
const hour = parseInt(match[1], 10);
|
|
502
|
-
const minute = parseInt(match[2], 10);
|
|
503
|
-
const second = match[3] ? parseInt(match[3], 10) : 0;
|
|
504
|
-
if (hour > 23 || minute > 59 || second > 59) return null;
|
|
505
|
-
return { hour, minute, second };
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
private formatValue(hour: number, minute: number, second = 0): string {
|
|
509
|
-
const hh = String(hour).padStart(2, "0");
|
|
510
|
-
const mm = String(minute).padStart(2, "0");
|
|
511
|
-
return this.seconds ? `${hh}:${mm}:${String(second).padStart(2, "0")}` : `${hh}:${mm}`;
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
private formatDisplay(hour: number, minute: number, second = 0): string {
|
|
515
|
-
const mm = String(minute).padStart(2, "0");
|
|
516
|
-
const ss = this.seconds ? `:${String(second).padStart(2, "0")}` : "";
|
|
517
|
-
if (this.format === "24h") {
|
|
518
|
-
return `${String(hour).padStart(2, "0")}:${mm}${ss}`;
|
|
519
|
-
}
|
|
520
|
-
const period = hour < 12 ? "AM" : "PM";
|
|
521
|
-
const hour12 = hour % 12 === 0 ? 12 : hour % 12;
|
|
522
|
-
return `${hour12}:${mm}${ss} ${period}`;
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
private toMinutes(hour: number, minute: number): number {
|
|
526
|
-
return hour * 60 + minute;
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
private get minuteStepSafe(): number {
|
|
530
|
-
const step = Math.floor(this.minuteStep);
|
|
531
|
-
return step >= 1 && step <= 60 ? step : 1;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
private get minBoundMinutes(): number {
|
|
535
|
-
const parsed = this.parseTime(this.minTime);
|
|
536
|
-
return parsed ? this.toMinutes(parsed.hour, parsed.minute) : 0;
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
private get maxBoundMinutes(): number {
|
|
540
|
-
const parsed = this.parseTime(this.maxTime);
|
|
541
|
-
return parsed ? this.toMinutes(parsed.hour, parsed.minute) : 23 * 60 + 59;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
private isTimeInRange(hour: number, minute: number): boolean {
|
|
545
|
-
const total = this.toMinutes(hour, minute);
|
|
546
|
-
return total >= this.minBoundMinutes && total <= this.maxBoundMinutes;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
/** Minutes shown in the minutes column (respecting minuteStep). */
|
|
550
|
-
private getMinuteOptions(): number[] {
|
|
551
|
-
const minutes: number[] = [];
|
|
552
|
-
for (let m = 0; m < 60; m += this.minuteStepSafe) {
|
|
553
|
-
minutes.push(m);
|
|
554
|
-
}
|
|
555
|
-
return minutes;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
/** An hour is enabled if at least one of its step minutes is in range. */
|
|
559
|
-
private isHourEnabled(hour: number): boolean {
|
|
560
|
-
return this.getMinuteOptions().some((m) => this.isTimeInRange(hour, m));
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
private isPeriodEnabled(period: "AM" | "PM"): boolean {
|
|
564
|
-
const start = period === "AM" ? 0 : 12;
|
|
565
|
-
for (let h = start; h < start + 12; h++) {
|
|
566
|
-
if (this.isHourEnabled(h)) return true;
|
|
567
|
-
}
|
|
568
|
-
return false;
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/** Hour column entries: display label + the 0–23 hour it maps to. */
|
|
572
|
-
private getHourOptions(): { label: string; hour24: number }[] {
|
|
573
|
-
if (this.format === "24h") {
|
|
574
|
-
return Array.from({ length: 24 }, (_, h) => ({
|
|
575
|
-
label: String(h).padStart(2, "0"),
|
|
576
|
-
hour24: h,
|
|
577
|
-
}));
|
|
578
|
-
}
|
|
579
|
-
// 12-hour clock, 01 … 12 as in the Figma "Hour 12" column ("12" maps to
|
|
580
|
-
// 00:xx AM / 12:xx PM).
|
|
581
|
-
const period = this.draftPeriod ?? "AM";
|
|
582
|
-
const base = period === "AM" ? 0 : 12;
|
|
583
|
-
return Array.from({ length: 12 }, (_, i) => {
|
|
584
|
-
const display = i + 1;
|
|
585
|
-
return {
|
|
586
|
-
label: String(display).padStart(2, "0"),
|
|
587
|
-
hour24: base + (display % 12),
|
|
588
|
-
};
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
|
|
592
|
-
/** Seconds shown in the seconds column (always step 1). */
|
|
593
|
-
private getSecondOptions(): number[] {
|
|
594
|
-
return Array.from({ length: 60 }, (_, s) => s);
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
private get draftPeriod(): "AM" | "PM" | null {
|
|
598
|
-
if (this.draftHour === null) return null;
|
|
599
|
-
return this.draftHour < 12 ? "AM" : "PM";
|
|
600
|
-
}
|
|
601
|
-
|
|
602
|
-
private resetDraftFromValue() {
|
|
603
|
-
const parsed = this.parseTime(this.value);
|
|
604
|
-
this.draftHour = parsed ? parsed.hour : null;
|
|
605
|
-
this.draftMinute = parsed ? parsed.minute : null;
|
|
606
|
-
this.draftSecond = parsed ? parsed.second : null;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
/** Snap the draft minute to the nearest valid step minute for the hour. */
|
|
610
|
-
private clampDraftToRange() {
|
|
611
|
-
if (this.draftHour === null || this.draftMinute === null) return;
|
|
612
|
-
if (this.isTimeInRange(this.draftHour, this.draftMinute)) return;
|
|
613
|
-
const hour = this.draftHour;
|
|
614
|
-
const valid = this.getMinuteOptions().filter((m) => this.isTimeInRange(hour, m));
|
|
615
|
-
if (valid.length === 0) {
|
|
616
|
-
this.draftMinute = null;
|
|
617
|
-
return;
|
|
618
|
-
}
|
|
619
|
-
const current = this.draftMinute;
|
|
620
|
-
this.draftMinute = valid.reduce((best, m) =>
|
|
621
|
-
Math.abs(m - current) < Math.abs(best - current) ? m : best
|
|
622
|
-
);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
// ── Open / close / commit ──
|
|
626
|
-
|
|
627
|
-
private toggleTimePopover() {
|
|
628
|
-
if (this.disabled || this.readonly) return;
|
|
629
|
-
this.open = !this.open;
|
|
630
|
-
this.dispatchEvent(
|
|
631
|
-
new CustomEvent("rel-open-change", {
|
|
632
|
-
detail: { open: this.open },
|
|
633
|
-
bubbles: true,
|
|
634
|
-
composed: true,
|
|
635
|
-
})
|
|
636
|
-
);
|
|
637
|
-
}
|
|
638
|
-
|
|
639
|
-
/** Close discarding the draft (Cancel / Escape / outside click). */
|
|
640
|
-
private cancelPopover() {
|
|
641
|
-
this.open = false;
|
|
642
|
-
this.triggerButton?.focus();
|
|
643
|
-
this.dispatchEvent(
|
|
644
|
-
new CustomEvent("rel-open-change", {
|
|
645
|
-
detail: { open: false },
|
|
646
|
-
bubbles: true,
|
|
647
|
-
composed: true,
|
|
648
|
-
})
|
|
649
|
-
);
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
private applySelection() {
|
|
653
|
-
if (this.draftHour === null) return;
|
|
654
|
-
const newValue = this.formatValue(
|
|
655
|
-
this.draftHour,
|
|
656
|
-
this.draftMinute ?? 0,
|
|
657
|
-
this.draftSecond ?? 0
|
|
658
|
-
);
|
|
659
|
-
this.value = newValue;
|
|
660
|
-
this.dispatchEvent(
|
|
661
|
-
new CustomEvent("rel-change", {
|
|
662
|
-
detail: { value: newValue },
|
|
663
|
-
bubbles: true,
|
|
664
|
-
composed: true,
|
|
665
|
-
})
|
|
666
|
-
);
|
|
667
|
-
this.cancelPopover();
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
/** Set the draft to the current time, snapped to the minute step and range. */
|
|
671
|
-
private selectNow() {
|
|
672
|
-
const now = new Date();
|
|
673
|
-
const step = this.minuteStepSafe;
|
|
674
|
-
this.draftHour = now.getHours();
|
|
675
|
-
this.draftSecond = this.seconds ? now.getSeconds() : null;
|
|
676
|
-
this.draftMinute = Math.round(now.getMinutes() / step) * step;
|
|
677
|
-
if (this.draftMinute >= 60) {
|
|
678
|
-
this.draftMinute = 0;
|
|
679
|
-
this.draftHour = (this.draftHour + 1) % 24;
|
|
680
|
-
}
|
|
681
|
-
if (!this.isHourEnabled(this.draftHour)) {
|
|
682
|
-
// Current hour is outside min/max — snap to the nearest enabled hour.
|
|
683
|
-
const enabled: number[] = [];
|
|
684
|
-
for (let h = 0; h < 24; h++) if (this.isHourEnabled(h)) enabled.push(h);
|
|
685
|
-
if (enabled.length === 0) return;
|
|
686
|
-
const currentHour = this.draftHour;
|
|
687
|
-
this.draftHour = enabled.reduce((best, h) =>
|
|
688
|
-
Math.abs(h - currentHour) < Math.abs(best - currentHour) ? h : best
|
|
689
|
-
);
|
|
690
|
-
}
|
|
691
|
-
this.clampDraftToRange();
|
|
692
|
-
this.scrollColumnsToSelection();
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
private clearValue(e: Event) {
|
|
696
|
-
e.stopPropagation();
|
|
697
|
-
this.value = null;
|
|
698
|
-
this.draftHour = null;
|
|
699
|
-
this.draftMinute = null;
|
|
700
|
-
this.draftSecond = null;
|
|
701
|
-
this.dispatchEvent(
|
|
702
|
-
new CustomEvent("rel-change", {
|
|
703
|
-
detail: { value: null },
|
|
704
|
-
bubbles: true,
|
|
705
|
-
composed: true,
|
|
706
|
-
})
|
|
707
|
-
);
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
// ── Column selection ──
|
|
711
|
-
|
|
712
|
-
private selectHour(hour24: number) {
|
|
713
|
-
if (!this.isHourEnabled(hour24)) return;
|
|
714
|
-
this.draftHour = hour24;
|
|
715
|
-
if (this.draftMinute === null) this.draftMinute = 0;
|
|
716
|
-
this.clampDraftToRange();
|
|
717
|
-
}
|
|
718
|
-
|
|
719
|
-
private selectMinute(minute: number) {
|
|
720
|
-
if (this.draftHour === null) {
|
|
721
|
-
// Minute picked first — default the hour to the first enabled one.
|
|
722
|
-
for (let h = 0; h < 24; h++) {
|
|
723
|
-
if (this.isHourEnabled(h)) {
|
|
724
|
-
this.draftHour = h;
|
|
725
|
-
break;
|
|
726
|
-
}
|
|
727
|
-
}
|
|
728
|
-
if (this.draftHour === null) return;
|
|
729
|
-
}
|
|
730
|
-
if (!this.isTimeInRange(this.draftHour, minute)) return;
|
|
731
|
-
this.draftMinute = minute;
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
private selectSecond(second: number) {
|
|
735
|
-
if (this.draftHour === null) {
|
|
736
|
-
// Second picked first — default the hour to the first enabled one.
|
|
737
|
-
for (let h = 0; h < 24; h++) {
|
|
738
|
-
if (this.isHourEnabled(h)) {
|
|
739
|
-
this.draftHour = h;
|
|
740
|
-
break;
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
if (this.draftHour === null) return;
|
|
744
|
-
}
|
|
745
|
-
if (this.draftMinute === null) this.draftMinute = 0;
|
|
746
|
-
this.draftSecond = second;
|
|
747
|
-
this.clampDraftToRange();
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
private selectPeriod(period: "AM" | "PM") {
|
|
751
|
-
if (!this.isPeriodEnabled(period)) return;
|
|
752
|
-
const base = period === "AM" ? 0 : 12;
|
|
753
|
-
const hour12 = this.draftHour === null ? 0 : this.draftHour % 12;
|
|
754
|
-
this.draftHour = base + hour12;
|
|
755
|
-
if (this.draftMinute === null) this.draftMinute = 0;
|
|
756
|
-
if (!this.isHourEnabled(this.draftHour)) {
|
|
757
|
-
// Same clock position is out of range in the new period — snap to the
|
|
758
|
-
// nearest enabled hour within that period.
|
|
759
|
-
const enabled: number[] = [];
|
|
760
|
-
for (let h = base; h < base + 12; h++) if (this.isHourEnabled(h)) enabled.push(h);
|
|
761
|
-
const currentHour = this.draftHour;
|
|
762
|
-
this.draftHour = enabled.reduce((best, h) =>
|
|
763
|
-
Math.abs(h - currentHour) < Math.abs(best - currentHour) ? h : best
|
|
764
|
-
);
|
|
765
|
-
}
|
|
766
|
-
this.clampDraftToRange();
|
|
767
|
-
this.scrollColumnsToSelection();
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
/**
|
|
771
|
-
* Scrolls the column's own scroll container only. scrollIntoView is off
|
|
772
|
-
* limits here: it walks ALL scrollable ancestors, so it yanked the page
|
|
773
|
-
* up/down whenever a column recentred (user-reported jump bug).
|
|
774
|
-
*/
|
|
775
|
-
private scrollOptionInColumn(btn: HTMLElement, block: "center" | "nearest") {
|
|
776
|
-
const list = btn.parentElement;
|
|
777
|
-
if (!list) return;
|
|
778
|
-
const top = btn.offsetTop;
|
|
779
|
-
const height = btn.offsetHeight;
|
|
780
|
-
if (block === "center") {
|
|
781
|
-
list.scrollTop = top - (list.clientHeight - height) / 2;
|
|
782
|
-
} else if (top < list.scrollTop) {
|
|
783
|
-
list.scrollTop = top;
|
|
784
|
-
} else if (top + height > list.scrollTop + list.clientHeight) {
|
|
785
|
-
list.scrollTop = top + height - list.clientHeight;
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
|
|
789
|
-
private scrollColumnsToSelection() {
|
|
790
|
-
this.updateComplete.then(() => {
|
|
791
|
-
this.columnsElement
|
|
792
|
-
?.querySelectorAll<HTMLButtonElement>(".option-button.selected")
|
|
793
|
-
.forEach((btn) => this.scrollOptionInColumn(btn, "center"));
|
|
794
|
-
});
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
// ── Keyboard ──
|
|
798
|
-
|
|
799
|
-
private handleTriggerKeydown(e: KeyboardEvent) {
|
|
800
|
-
if (e.key === "Enter" || e.key === " " || e.key === "ArrowDown") {
|
|
801
|
-
e.preventDefault();
|
|
802
|
-
if (!this.open) {
|
|
803
|
-
this.toggleTimePopover();
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
/**
|
|
809
|
-
* Column navigation: Up/Down move within the column (and select), Left/Right
|
|
810
|
-
* jump between columns, Home/End go to the first/last option, Enter applies.
|
|
811
|
-
*/
|
|
812
|
-
private handleOptionKeydown(e: KeyboardEvent, column: TimeColumn) {
|
|
813
|
-
const list = (e.currentTarget as HTMLElement).closest(".column-list");
|
|
814
|
-
if (!list) return;
|
|
815
|
-
const buttons = Array.from(
|
|
816
|
-
list.querySelectorAll<HTMLButtonElement>(".option-button:not(:disabled)")
|
|
817
|
-
);
|
|
818
|
-
const index = buttons.indexOf(e.currentTarget as HTMLButtonElement);
|
|
819
|
-
let target: HTMLButtonElement | undefined;
|
|
820
|
-
|
|
821
|
-
switch (e.key) {
|
|
822
|
-
case "ArrowUp":
|
|
823
|
-
e.preventDefault();
|
|
824
|
-
target = buttons[Math.max(0, index - 1)];
|
|
825
|
-
break;
|
|
826
|
-
case "ArrowDown":
|
|
827
|
-
e.preventDefault();
|
|
828
|
-
target = buttons[Math.min(buttons.length - 1, index + 1)];
|
|
829
|
-
break;
|
|
830
|
-
case "Home":
|
|
831
|
-
e.preventDefault();
|
|
832
|
-
target = buttons[0];
|
|
833
|
-
break;
|
|
834
|
-
case "End":
|
|
835
|
-
e.preventDefault();
|
|
836
|
-
target = buttons[buttons.length - 1];
|
|
837
|
-
break;
|
|
838
|
-
case "ArrowLeft":
|
|
839
|
-
case "ArrowRight": {
|
|
840
|
-
e.preventDefault();
|
|
841
|
-
this.focusAdjacentColumn(column, e.key === "ArrowRight" ? 1 : -1);
|
|
842
|
-
return;
|
|
843
|
-
}
|
|
844
|
-
case "Enter":
|
|
845
|
-
e.preventDefault();
|
|
846
|
-
(e.currentTarget as HTMLButtonElement).click();
|
|
847
|
-
this.applySelection();
|
|
848
|
-
return;
|
|
849
|
-
default:
|
|
850
|
-
return;
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
if (target && target !== buttons[index]) {
|
|
854
|
-
target.click();
|
|
855
|
-
target.focus({ preventScroll: true });
|
|
856
|
-
this.scrollOptionInColumn(target, "nearest");
|
|
857
|
-
}
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
private focusAdjacentColumn(from: TimeColumn, direction: 1 | -1) {
|
|
861
|
-
const order: TimeColumn[] = ["hour", "minute"];
|
|
862
|
-
if (this.seconds) order.push("second");
|
|
863
|
-
if (this.format === "12h") order.push("period");
|
|
864
|
-
const nextIndex = order.indexOf(from) + direction;
|
|
865
|
-
if (nextIndex < 0 || nextIndex >= order.length) return;
|
|
866
|
-
const lists = this.columnsElement?.querySelectorAll(".column-list");
|
|
867
|
-
const list = lists?.[nextIndex];
|
|
868
|
-
const target =
|
|
869
|
-
list?.querySelector<HTMLButtonElement>(".option-button.selected:not(:disabled)") ??
|
|
870
|
-
list?.querySelector<HTMLButtonElement>(".option-button:not(:disabled)");
|
|
871
|
-
if (target) {
|
|
872
|
-
target.focus({ preventScroll: true });
|
|
873
|
-
this.scrollOptionInColumn(target, "nearest");
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
// ── Render ──
|
|
878
|
-
|
|
879
|
-
render() {
|
|
880
|
-
const isError = this.error || this.invalid;
|
|
881
|
-
const belowText = isError && this.errorMessage ? this.errorMessage : this.helperText;
|
|
882
|
-
const describedById = belowText ? "time-picker-desc" : undefined;
|
|
883
|
-
const parsedValue = this.parseTime(this.value);
|
|
884
|
-
const displayText = parsedValue
|
|
885
|
-
? this.formatDisplay(parsedValue.hour, parsedValue.minute, parsedValue.second)
|
|
886
|
-
: "";
|
|
887
|
-
const hourOptions = this.getHourOptions();
|
|
888
|
-
const minuteOptions = this.getMinuteOptions();
|
|
889
|
-
const secondOptions = this.seconds ? this.getSecondOptions() : [];
|
|
890
|
-
const draftPeriod = this.draftPeriod;
|
|
891
|
-
const wrapperClasses = [
|
|
892
|
-
"time-picker-wrapper",
|
|
893
|
-
this.size,
|
|
894
|
-
isError ? "error" : "",
|
|
895
|
-
this.readonly ? "readonly" : "",
|
|
896
|
-
]
|
|
897
|
-
.filter(Boolean)
|
|
898
|
-
.join(" ");
|
|
899
|
-
|
|
900
|
-
return html`
|
|
901
|
-
<div part="base" class="${wrapperClasses}">
|
|
902
|
-
${this.label
|
|
903
|
-
? html`<label part="label" class="label" id="time-picker-label"
|
|
904
|
-
>${this.label}${this.required
|
|
905
|
-
? html`<span class="required-mark" aria-hidden="true">*</span>`
|
|
906
|
-
: nothing}</label
|
|
907
|
-
>`
|
|
908
|
-
: nothing}
|
|
909
|
-
|
|
910
|
-
${this.name
|
|
911
|
-
? html`<input type="hidden" name=${this.name} .value=${this.value ?? ""} />`
|
|
912
|
-
: nothing}
|
|
913
|
-
|
|
914
|
-
<button
|
|
915
|
-
part="trigger"
|
|
916
|
-
class="trigger-button ${isError ? "error" : ""}"
|
|
917
|
-
type="button"
|
|
918
|
-
?disabled=${this.disabled}
|
|
919
|
-
@click=${this.toggleTimePopover}
|
|
920
|
-
@keydown=${this.handleTriggerKeydown}
|
|
921
|
-
@focus=${() =>
|
|
922
|
-
this.dispatchEvent(
|
|
923
|
-
new CustomEvent("rel-focus", { bubbles: true, composed: true })
|
|
924
|
-
)}
|
|
925
|
-
@blur=${() =>
|
|
926
|
-
this.dispatchEvent(
|
|
927
|
-
new CustomEvent("rel-blur", { bubbles: true, composed: true })
|
|
928
|
-
)}
|
|
929
|
-
aria-label=${this.label || "Select time"}
|
|
930
|
-
aria-haspopup="dialog"
|
|
931
|
-
aria-expanded=${this.open}
|
|
932
|
-
aria-required=${this.required}
|
|
933
|
-
aria-invalid=${isError}
|
|
934
|
-
aria-readonly=${this.readonly}
|
|
935
|
-
aria-describedby=${describedById ?? nothing}
|
|
936
|
-
aria-labelledby=${this.label ? "time-picker-label" : nothing}
|
|
937
|
-
>
|
|
938
|
-
<span part="value" class="trigger-content ${displayText ? "" : "placeholder"}">
|
|
939
|
-
${displayText || this.placeholder}
|
|
940
|
-
</span>
|
|
941
|
-
<span class="trigger-icons">
|
|
942
|
-
${this.clearable && this.value
|
|
943
|
-
? html`
|
|
944
|
-
<button
|
|
945
|
-
class="icon-button"
|
|
946
|
-
type="button"
|
|
947
|
-
aria-label="Clear time"
|
|
948
|
-
@click=${this.clearValue}
|
|
949
|
-
>
|
|
950
|
-
<svg viewBox="0 0 16 16" fill="currentColor">
|
|
951
|
-
<path
|
|
952
|
-
d="M4 4l8 8M12 4l-8 8"
|
|
953
|
-
stroke="currentColor"
|
|
954
|
-
stroke-width="2"
|
|
955
|
-
stroke-linecap="round"
|
|
956
|
-
/>
|
|
957
|
-
</svg>
|
|
958
|
-
</button>
|
|
959
|
-
`
|
|
960
|
-
: nothing}
|
|
961
|
-
<rel-icon part="icon" name="time-filled" size="sm"></rel-icon>
|
|
962
|
-
</span>
|
|
963
|
-
</button>
|
|
964
|
-
|
|
965
|
-
<div
|
|
966
|
-
part="panel"
|
|
967
|
-
class="popover ${this.open ? "open" : ""} ${this.openUp ? "open-up" : ""}"
|
|
968
|
-
role="dialog"
|
|
969
|
-
aria-label="Choose time"
|
|
970
|
-
>
|
|
971
|
-
<div class="columns">
|
|
972
|
-
<div class="column-list" role="listbox" aria-label="Hours">
|
|
973
|
-
${hourOptions.map(
|
|
974
|
-
(opt, i) => html`
|
|
975
|
-
<button
|
|
976
|
-
part="option"
|
|
977
|
-
class="option-button ${this.draftHour === opt.hour24
|
|
978
|
-
? "selected"
|
|
979
|
-
: ""}"
|
|
980
|
-
type="button"
|
|
981
|
-
role="option"
|
|
982
|
-
aria-selected=${this.draftHour === opt.hour24}
|
|
983
|
-
?disabled=${!this.isHourEnabled(opt.hour24)}
|
|
984
|
-
@click=${() => this.selectHour(opt.hour24)}
|
|
985
|
-
@keydown=${(e: KeyboardEvent) => this.handleOptionKeydown(e, "hour")}
|
|
986
|
-
tabindex=${this.draftHour === opt.hour24 ||
|
|
987
|
-
(this.draftHour === null && i === 0)
|
|
988
|
-
? 0
|
|
989
|
-
: -1}
|
|
990
|
-
>
|
|
991
|
-
${opt.label}
|
|
992
|
-
</button>
|
|
993
|
-
`
|
|
994
|
-
)}
|
|
995
|
-
</div>
|
|
996
|
-
|
|
997
|
-
<div class="column-divider" aria-hidden="true"></div>
|
|
998
|
-
|
|
999
|
-
<div class="column-list" role="listbox" aria-label="Minutes">
|
|
1000
|
-
${minuteOptions.map(
|
|
1001
|
-
(m, i) => html`
|
|
1002
|
-
<button
|
|
1003
|
-
part="option"
|
|
1004
|
-
class="option-button ${this.draftMinute === m ? "selected" : ""}"
|
|
1005
|
-
type="button"
|
|
1006
|
-
role="option"
|
|
1007
|
-
aria-selected=${this.draftMinute === m}
|
|
1008
|
-
?disabled=${this.draftHour !== null &&
|
|
1009
|
-
!this.isTimeInRange(this.draftHour, m)}
|
|
1010
|
-
@click=${() => this.selectMinute(m)}
|
|
1011
|
-
@keydown=${(e: KeyboardEvent) =>
|
|
1012
|
-
this.handleOptionKeydown(e, "minute")}
|
|
1013
|
-
tabindex=${this.draftMinute === m ||
|
|
1014
|
-
(this.draftMinute === null && i === 0)
|
|
1015
|
-
? 0
|
|
1016
|
-
: -1}
|
|
1017
|
-
>
|
|
1018
|
-
${String(m).padStart(2, "0")}
|
|
1019
|
-
</button>
|
|
1020
|
-
`
|
|
1021
|
-
)}
|
|
1022
|
-
</div>
|
|
1023
|
-
|
|
1024
|
-
${this.seconds
|
|
1025
|
-
? html`
|
|
1026
|
-
<div class="column-divider" aria-hidden="true"></div>
|
|
1027
|
-
<div class="column-list" role="listbox" aria-label="Seconds">
|
|
1028
|
-
${secondOptions.map(
|
|
1029
|
-
(s, i) => html`
|
|
1030
|
-
<button
|
|
1031
|
-
part="option"
|
|
1032
|
-
class="option-button ${this.draftSecond === s
|
|
1033
|
-
? "selected"
|
|
1034
|
-
: ""}"
|
|
1035
|
-
type="button"
|
|
1036
|
-
role="option"
|
|
1037
|
-
aria-selected=${this.draftSecond === s}
|
|
1038
|
-
@click=${() => this.selectSecond(s)}
|
|
1039
|
-
@keydown=${(e: KeyboardEvent) =>
|
|
1040
|
-
this.handleOptionKeydown(e, "second")}
|
|
1041
|
-
tabindex=${this.draftSecond === s ||
|
|
1042
|
-
(this.draftSecond === null && i === 0)
|
|
1043
|
-
? 0
|
|
1044
|
-
: -1}
|
|
1045
|
-
>
|
|
1046
|
-
${String(s).padStart(2, "0")}
|
|
1047
|
-
</button>
|
|
1048
|
-
`
|
|
1049
|
-
)}
|
|
1050
|
-
</div>
|
|
1051
|
-
`
|
|
1052
|
-
: nothing}
|
|
1053
|
-
${this.format === "12h"
|
|
1054
|
-
? html`
|
|
1055
|
-
<div class="column-divider" aria-hidden="true"></div>
|
|
1056
|
-
<div class="column-list" role="listbox" aria-label="AM or PM">
|
|
1057
|
-
${(["AM", "PM"] as const).map(
|
|
1058
|
-
(p) => html`
|
|
1059
|
-
<button
|
|
1060
|
-
part="option"
|
|
1061
|
-
class="option-button ${draftPeriod === p ? "selected" : ""}"
|
|
1062
|
-
type="button"
|
|
1063
|
-
role="option"
|
|
1064
|
-
aria-selected=${draftPeriod === p}
|
|
1065
|
-
?disabled=${!this.isPeriodEnabled(p)}
|
|
1066
|
-
@click=${() => this.selectPeriod(p)}
|
|
1067
|
-
@keydown=${(e: KeyboardEvent) =>
|
|
1068
|
-
this.handleOptionKeydown(e, "period")}
|
|
1069
|
-
tabindex=${draftPeriod === p ||
|
|
1070
|
-
(draftPeriod === null && p === "AM")
|
|
1071
|
-
? 0
|
|
1072
|
-
: -1}
|
|
1073
|
-
>
|
|
1074
|
-
${p}
|
|
1075
|
-
</button>
|
|
1076
|
-
`
|
|
1077
|
-
)}
|
|
1078
|
-
</div>
|
|
1079
|
-
`
|
|
1080
|
-
: nothing}
|
|
1081
|
-
</div>
|
|
1082
|
-
|
|
1083
|
-
<div part="footer" class="time-footer">
|
|
1084
|
-
<rel-button variant="link" size="small" @click=${() => this.selectNow()}>
|
|
1085
|
-
Now
|
|
1086
|
-
</rel-button>
|
|
1087
|
-
<div class="footer-right">
|
|
1088
|
-
<rel-button
|
|
1089
|
-
variant="ghost"
|
|
1090
|
-
size="small"
|
|
1091
|
-
@click=${() => this.cancelPopover()}
|
|
1092
|
-
>
|
|
1093
|
-
Cancel
|
|
1094
|
-
</rel-button>
|
|
1095
|
-
<rel-button
|
|
1096
|
-
variant="primary"
|
|
1097
|
-
tone="default"
|
|
1098
|
-
size="small"
|
|
1099
|
-
?disabled=${this.draftHour === null}
|
|
1100
|
-
@click=${() => this.applySelection()}
|
|
1101
|
-
>
|
|
1102
|
-
OK
|
|
1103
|
-
</rel-button>
|
|
1104
|
-
</div>
|
|
1105
|
-
</div>
|
|
1106
|
-
</div>
|
|
1107
|
-
|
|
1108
|
-
${belowText
|
|
1109
|
-
? html`<div
|
|
1110
|
-
part="helper"
|
|
1111
|
-
class="time-picker-support ${isError ? "error" : ""}"
|
|
1112
|
-
id=${describedById}
|
|
1113
|
-
>
|
|
1114
|
-
${belowText}
|
|
1115
|
-
</div>`
|
|
1116
|
-
: nothing}
|
|
1117
|
-
</div>
|
|
1118
|
-
`;
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
|
|
1122
|
-
declare global {
|
|
1123
|
-
interface HTMLElementTagNameMap {
|
|
1124
|
-
"rel-time-picker": RelTimePicker;
|
|
1125
|
-
}
|
|
1126
|
-
}
|