@reliability-design/web 1.4.6 → 1.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +211 -49
- package/dist/components/rel-accordion/README.md +132 -132
- package/dist/components/rel-alert/README.md +145 -141
- package/dist/components/rel-autocomplete/README.md +156 -61
- package/dist/components/rel-avatar/README.md +116 -130
- package/dist/components/rel-badge/README.md +98 -93
- package/dist/components/rel-breadcrumb/README.md +96 -102
- package/dist/components/rel-button/README.md +160 -130
- package/dist/components/rel-calendar/README.md +109 -109
- package/dist/components/rel-card/README.md +75 -94
- package/dist/components/rel-cardmedia/README.md +100 -127
- package/dist/components/rel-carousel/README.md +184 -166
- package/dist/components/rel-checkbox/README.md +93 -75
- package/dist/components/rel-chip/README.md +132 -121
- package/dist/components/rel-container/README.md +107 -99
- package/dist/components/rel-date-picker/README.md +200 -289
- package/dist/components/rel-divider/README.md +78 -100
- package/dist/components/rel-drawer/README.md +187 -200
- package/dist/components/rel-kbd/README.md +141 -151
- package/dist/components/rel-menu/README.md +178 -151
- package/dist/components/rel-menubar/README.md +218 -329
- package/dist/components/rel-otp/README.md +170 -440
- package/dist/components/rel-pagination/README.md +100 -424
- package/dist/components/rel-popover/README.md +203 -568
- package/dist/components/rel-progress/README.md +88 -110
- package/dist/components/rel-radio/README.md +131 -138
- package/dist/components/rel-range-picker/README.md +162 -0
- package/dist/components/rel-resizable/README.md +199 -140
- package/dist/components/rel-segmented-button/README.md +155 -141
- package/dist/components/rel-select/README.md +154 -93
- package/dist/components/rel-sheet/README.md +168 -224
- package/dist/components/rel-skeleton/README.md +103 -0
- package/dist/components/rel-slider/README.md +130 -135
- package/dist/components/rel-snackbar/README.md +162 -134
- package/dist/components/rel-stepper/README.md +158 -160
- package/dist/components/rel-switch/README.md +108 -102
- package/dist/components/rel-tab/README.md +171 -163
- package/dist/components/rel-textfield/README.md +159 -69
- package/dist/components/rel-time-picker/README.md +122 -157
- package/dist/components/rel-toast/README.md +157 -148
- package/dist/components/rel-tooltip/README.md +108 -111
- package/dist/components/rel-upload/README.md +220 -0
- package/dist/index.d.mts +1147 -340
- package/dist/index.d.ts +1147 -340
- package/dist/index.js +3451 -3163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3416 -3118
- package/dist/index.mjs.map +1 -1
- package/dist/styles/vars.css +877 -866
- package/dist/{vars-XNMTSRVN.css → vars-JHTUGNRG.css} +877 -866
- package/package.json +3 -2
- package/dist/components/rel-accordion/rel-accordion.ts +0 -336
- package/dist/components/rel-alert/rel-alert.ts +0 -305
- package/dist/components/rel-autocomplete/rel-autocomplete.ts +0 -720
- package/dist/components/rel-avatar/rel-avatar.ts +0 -142
- package/dist/components/rel-badge/rel-badge.ts +0 -175
- package/dist/components/rel-breadcrumb/rel-breadcrumb.ts +0 -106
- package/dist/components/rel-button/rel-button.ts +0 -560
- package/dist/components/rel-calendar/index.ts +0 -1
- package/dist/components/rel-calendar/rel-calendar.ts +0 -565
- package/dist/components/rel-card/rel-card.ts +0 -88
- package/dist/components/rel-cardmedia/rel-cardmedia.ts +0 -88
- package/dist/components/rel-carousel/index.ts +0 -1
- package/dist/components/rel-carousel/rel-carousel.ts +0 -723
- package/dist/components/rel-chart/README.md +0 -286
- package/dist/components/rel-chart/index.ts +0 -1
- package/dist/components/rel-chart/rel-chart.ts +0 -754
- package/dist/components/rel-checkbox/rel-checkbox.ts +0 -382
- package/dist/components/rel-chip/rel-chip.ts +0 -483
- package/dist/components/rel-container/rel-container.ts +0 -95
- package/dist/components/rel-date-picker/date-format.test.ts +0 -43
- package/dist/components/rel-date-picker/date-format.ts +0 -47
- package/dist/components/rel-date-picker/date-parse.test.ts +0 -116
- package/dist/components/rel-date-picker/date-parse.ts +0 -178
- package/dist/components/rel-date-picker/index.ts +0 -1
- package/dist/components/rel-date-picker/rel-date-picker.ts +0 -1676
- package/dist/components/rel-divider/rel-divider.ts +0 -54
- package/dist/components/rel-drawer/index.ts +0 -1
- package/dist/components/rel-drawer/rel-drawer-footer.ts +0 -27
- package/dist/components/rel-drawer/rel-drawer.ts +0 -607
- package/dist/components/rel-kbd/rel-kbd.ts +0 -188
- package/dist/components/rel-layout/rel-layout.ts +0 -49
- package/dist/components/rel-menu/rel-menu.ts +0 -541
- package/dist/components/rel-menubar/index.ts +0 -2
- package/dist/components/rel-menubar/rel-menubar-menu.css +0 -3
- package/dist/components/rel-menubar/rel-menubar-menu.ts +0 -17
- package/dist/components/rel-menubar/rel-menubar.ts +0 -777
- package/dist/components/rel-nav-menu/README.md +0 -289
- package/dist/components/rel-nav-menu/index.ts +0 -3
- package/dist/components/rel-nav-menu/rel-nav-menu-item.ts +0 -243
- package/dist/components/rel-nav-menu/rel-nav-menu-panel.ts +0 -72
- package/dist/components/rel-nav-menu/rel-nav-menu.ts +0 -270
- package/dist/components/rel-navbar/README.md +0 -126
- package/dist/components/rel-navbar/rel-navbar.ts +0 -105
- package/dist/components/rel-otp/index.ts +0 -1
- package/dist/components/rel-otp/rel-otp.ts +0 -527
- package/dist/components/rel-pagination/index.ts +0 -1
- package/dist/components/rel-pagination/rel-pagination.ts +0 -522
- package/dist/components/rel-popover/index.ts +0 -2
- package/dist/components/rel-popover/rel-popover-content.ts +0 -81
- package/dist/components/rel-popover/rel-popover.ts +0 -475
- package/dist/components/rel-progress/rel-progress.ts +0 -234
- package/dist/components/rel-radio/rel-radio.ts +0 -481
- package/dist/components/rel-range-picker/rel-range-picker.ts +0 -1688
- package/dist/components/rel-resizable/index.ts +0 -3
- package/dist/components/rel-resizable/rel-resizable-group.ts +0 -405
- package/dist/components/rel-resizable/rel-resizable-handle.ts +0 -150
- package/dist/components/rel-resizable/rel-resizable-panel.ts +0 -58
- package/dist/components/rel-segmented-button/rel-segmented-button.ts +0 -217
- package/dist/components/rel-select/rel-select.ts +0 -1416
- package/dist/components/rel-sheet/rel-sheet.ts +0 -610
- package/dist/components/rel-sidebar/README.md +0 -209
- package/dist/components/rel-sidebar/rel-sidebar.ts +0 -1191
- package/dist/components/rel-skeleton/rel-skeleton.ts +0 -143
- package/dist/components/rel-slider/rel-slider.ts +0 -673
- package/dist/components/rel-snackbar/rel-snackbar.ts +0 -329
- package/dist/components/rel-stepper/rel-stepper.ts +0 -567
- package/dist/components/rel-switch/rel-switch.ts +0 -199
- package/dist/components/rel-tab/rel-tab.ts +0 -264
- package/dist/components/rel-table/README.md +0 -178
- package/dist/components/rel-table/rel-table-body.ts +0 -22
- package/dist/components/rel-table/rel-table-caption.ts +0 -30
- package/dist/components/rel-table/rel-table-cell.ts +0 -43
- package/dist/components/rel-table/rel-table-footer.ts +0 -24
- package/dist/components/rel-table/rel-table-head.ts +0 -47
- package/dist/components/rel-table/rel-table-header.ts +0 -22
- package/dist/components/rel-table/rel-table-row.ts +0 -37
- package/dist/components/rel-table/rel-table.ts +0 -62
- package/dist/components/rel-textfield/rel-textfield.ts +0 -1054
- package/dist/components/rel-time-picker/rel-time-picker.ts +0 -1482
- package/dist/components/rel-time-picker/time-parse.test.ts +0 -67
- package/dist/components/rel-time-picker/time-parse.ts +0 -85
- package/dist/components/rel-toast/rel-toast.ts +0 -206
- package/dist/components/rel-tooltip/rel-tooltip.ts +0 -193
- package/dist/components/rel-topbar/rel-topbar-actions.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar-brand.ts +0 -54
- package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +0 -69
- package/dist/components/rel-topbar/rel-topbar-dropdown.ts +0 -31
- package/dist/components/rel-topbar/rel-topbar-item.ts +0 -324
- package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar-profile.ts +0 -243
- package/dist/components/rel-topbar/rel-topbar-utilities.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar.ts +0 -446
- package/dist/components/rel-upload/UPLOAD-DESIGN-CHANGES.md +0 -134
- package/dist/components/rel-upload/rel-upload-actions.ts +0 -163
- package/dist/components/rel-upload/rel-upload.ts +0 -968
|
@@ -1,1482 +0,0 @@
|
|
|
1
|
-
import { LitElement, html, css, nothing } from "lit";
|
|
2
|
-
import { customElement, property, state, query } from "lit/decorators.js";
|
|
3
|
-
import { live } from "lit/directives/live.js";
|
|
4
|
-
import "@reliability-design/icons/rel-icon";
|
|
5
|
-
import "../rel-button/rel-button";
|
|
6
|
-
import { parseTimeInput } from "./time-parse";
|
|
7
|
-
import { announce } from "../../utils/announce";
|
|
8
|
-
|
|
9
|
-
type TimeColumn = "hour" | "minute" | "second" | "period";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* `<rel-time-picker>` — time selection field.
|
|
13
|
-
*
|
|
14
|
-
* Follows the rel-date-picker trigger/field conventions (label, helper/error
|
|
15
|
-
* text, sizes, fullWidth, clearable) and the rel-range-picker draft model:
|
|
16
|
-
* column selections are held in draft state until Apply is clicked; Cancel,
|
|
17
|
-
* Escape, or an outside click discards the draft.
|
|
18
|
-
*
|
|
19
|
-
* The committed `value` is ALWAYS 24-hour "HH:mm" (or "HH:mm:ss" when
|
|
20
|
-
* `seconds` is enabled) regardless of the display `format`, so consumers get
|
|
21
|
-
* a consistent machine-readable string.
|
|
22
|
-
*
|
|
23
|
-
* Panel visuals follow the Figma "Time Picker" component (Reliability DS
|
|
24
|
-
* V1.0, node 8301:3771): fixed panel widths 220/250/280 by size, full-bleed
|
|
25
|
-
* columns with 1px dividers, neutral selected state, and a Now / Cancel / OK
|
|
26
|
-
* footer whose buttons are always size S.
|
|
27
|
-
*/
|
|
28
|
-
@customElement("rel-time-picker")
|
|
29
|
-
export class RelTimePicker extends LitElement {
|
|
30
|
-
/** Committed time, 24-hour "HH:mm" or "HH:mm:ss" (e.g. "09:30", "17:05:30"). */
|
|
31
|
-
@property({ type: String, reflect: true }) value: string | null = null;
|
|
32
|
-
@property({ type: String }) placeholder = "Select time";
|
|
33
|
-
@property({ type: String }) label: string | null = null;
|
|
34
|
-
@property({ type: Boolean, reflect: true }) disabled = false;
|
|
35
|
-
@property({ type: Boolean }) required = false;
|
|
36
|
-
@property({ type: Boolean, reflect: true }) readonly = false;
|
|
37
|
-
|
|
38
|
-
/** Display format of the trigger text and hour column. Value stays 24-hour. */
|
|
39
|
-
@property({ type: String }) format: "12h" | "24h" = "12h";
|
|
40
|
-
/** Shows the seconds column; committed value becomes "HH:mm:ss". */
|
|
41
|
-
@property({ type: Boolean, reflect: true }) seconds = false;
|
|
42
|
-
/** Minute granularity of the minutes column (1, 5, 10, 15, 30, …). */
|
|
43
|
-
@property({ type: Number, attribute: "minute-step" }) minuteStep = 5;
|
|
44
|
-
|
|
45
|
-
/** Earliest selectable time, "HH:mm" (inclusive). */
|
|
46
|
-
@property({ type: String, attribute: "min-time" }) minTime: string | null = null;
|
|
47
|
-
/** Latest selectable time, "HH:mm" (inclusive). */
|
|
48
|
-
@property({ type: String, attribute: "max-time" }) maxTime: string | null = null;
|
|
49
|
-
|
|
50
|
-
@property({ type: Boolean, reflect: true }) open = false;
|
|
51
|
-
@property({ type: Boolean }) clearable = false;
|
|
52
|
-
|
|
53
|
-
// ── Standardized input API (mirrors rel-textfield / rel-date-picker) ──
|
|
54
|
-
@property({ type: Boolean }) error = false;
|
|
55
|
-
/** Alias for `error` (requested-API compat); either flag applies error styling. */
|
|
56
|
-
@property({ type: Boolean }) invalid = false;
|
|
57
|
-
@property({ type: String, attribute: "error-message" }) errorMessage?: string;
|
|
58
|
-
@property({ type: String, attribute: "helper-text" }) helperText?: string;
|
|
59
|
-
@property({ type: String }) name?: string;
|
|
60
|
-
@property({ type: String }) size: "small" | "medium" | "large" = "medium";
|
|
61
|
-
@property({ type: String, reflect: true }) variant: "outlined" = "outlined";
|
|
62
|
-
@property({ type: Boolean, reflect: true }) fullWidth = false;
|
|
63
|
-
|
|
64
|
-
// Draft selection (hour is 0–23 internally; committed on OK only)
|
|
65
|
-
@state() private draftHour: number | null = null;
|
|
66
|
-
@state() private draftMinute: number | null = null;
|
|
67
|
-
@state() private draftSecond: number | null = null;
|
|
68
|
-
/** Uncommitted typed text; null → the input shows the committed value. */
|
|
69
|
-
@state() private inputText: string | null = null;
|
|
70
|
-
/** Parse/range error message for the typed text (cleared on next input). */
|
|
71
|
-
@state() private inputError: string | null = null;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Whether the next popover open should move focus into the columns.
|
|
75
|
-
* Icon-click / ArrowDown / external `open` do (previous behavior); opening
|
|
76
|
-
* by clicking into the text input must NOT, or typing would be impossible.
|
|
77
|
-
*/
|
|
78
|
-
private focusPanelOnOpen = true;
|
|
79
|
-
|
|
80
|
-
@query(".trigger-input") private triggerInput?: HTMLInputElement;
|
|
81
|
-
@query(".trigger-button") private triggerButton?: HTMLElement;
|
|
82
|
-
@query(".popover") private popoverElement?: HTMLElement;
|
|
83
|
-
@query(".columns") private columnsElement?: HTMLElement;
|
|
84
|
-
|
|
85
|
-
static styles = css`
|
|
86
|
-
:host {
|
|
87
|
-
color: var(--rel-text-default);
|
|
88
|
-
display: block;
|
|
89
|
-
font-family: var(--rel-fonts-font-family);
|
|
90
|
-
position: relative;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/* Intrinsic width by default; set fullWidth to fill the parent. */
|
|
94
|
-
:host(:not([fullwidth])) {
|
|
95
|
-
display: inline-block;
|
|
96
|
-
width: auto;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
:host([disabled]) {
|
|
100
|
-
opacity: 0.6;
|
|
101
|
-
cursor: not-allowed;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
:host([disabled]) * {
|
|
105
|
-
pointer-events: none;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
:host([readonly]) .trigger-button {
|
|
109
|
-
cursor: default;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
.time-picker-wrapper {
|
|
113
|
-
display: flex;
|
|
114
|
-
flex-direction: column;
|
|
115
|
-
gap: var(--rel-spacing-xs);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
.label {
|
|
119
|
-
color: var(--rel-text-label);
|
|
120
|
-
font-family: var(--rel-body-sm-medium-font-family);
|
|
121
|
-
font-weight: var(--rel-body-sm-medium-font-weight);
|
|
122
|
-
font-size: var(--rel-body-sm-medium-font-size);
|
|
123
|
-
line-height: var(--rel-body-sm-medium-line-height);
|
|
124
|
-
letter-spacing: var(--rel-body-sm-medium-letter-spacing);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
.required-mark {
|
|
128
|
-
color: var(--rel-text-danger);
|
|
129
|
-
margin-left: 2px;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/* Support text (helperText / errorMessage) */
|
|
133
|
-
.time-picker-support {
|
|
134
|
-
color: var(--rel-text-placeholder);
|
|
135
|
-
font-family: var(--rel-body-xs-regular-font-family);
|
|
136
|
-
font-weight: var(--rel-body-xs-regular-font-weight);
|
|
137
|
-
font-size: var(--rel-body-xs-regular-font-size);
|
|
138
|
-
line-height: var(--rel-body-xs-regular-line-height);
|
|
139
|
-
letter-spacing: var(--rel-body-xs-regular-letter-spacing);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
.time-picker-support.error {
|
|
143
|
-
color: var(--rel-text-danger);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/* Persistent live region — out of flow while empty so it adds no gap. */
|
|
147
|
-
.time-picker-support.empty {
|
|
148
|
-
position: absolute;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
.trigger-button {
|
|
152
|
-
width: 100%;
|
|
153
|
-
min-width: 160px;
|
|
154
|
-
display: flex;
|
|
155
|
-
align-items: center;
|
|
156
|
-
justify-content: space-between;
|
|
157
|
-
gap: var(--rel-spacing-xs);
|
|
158
|
-
padding: var(--rel-spacing-sm) var(--rel-spacing-md);
|
|
159
|
-
background: var(--rel-bg-surface);
|
|
160
|
-
border: 1px solid var(--rel-border-default);
|
|
161
|
-
border-radius: var(--rel-border-radius-sm);
|
|
162
|
-
color: var(--rel-text-default);
|
|
163
|
-
cursor: pointer;
|
|
164
|
-
transition: all 0.15s ease;
|
|
165
|
-
text-align: left;
|
|
166
|
-
font-family: var(--rel-body-md-regular-font-family);
|
|
167
|
-
font-weight: var(--rel-body-md-regular-font-weight);
|
|
168
|
-
font-size: var(--rel-body-md-regular-font-size);
|
|
169
|
-
line-height: var(--rel-body-md-regular-line-height);
|
|
170
|
-
letter-spacing: var(--rel-body-md-regular-letter-spacing);
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
:host(:not([disabled])) .trigger-button:hover {
|
|
174
|
-
border-color: var(--rel-border-strong);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
.trigger-button:focus-within {
|
|
178
|
-
outline: 2px solid var(--rel-border-focus);
|
|
179
|
-
outline-offset: 2px;
|
|
180
|
-
border-color: var(--rel-border-focus);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
:host([disabled]) .trigger-button {
|
|
184
|
-
cursor: not-allowed;
|
|
185
|
-
background: var(--rel-bg-surface-elevated);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/* The editable field itself — the wrapper carries the box styles. */
|
|
189
|
-
.trigger-input {
|
|
190
|
-
flex: 1;
|
|
191
|
-
min-width: 0;
|
|
192
|
-
border: none;
|
|
193
|
-
background: transparent;
|
|
194
|
-
padding: 0;
|
|
195
|
-
margin: 0;
|
|
196
|
-
outline: none;
|
|
197
|
-
color: var(--rel-text-default);
|
|
198
|
-
font: inherit;
|
|
199
|
-
letter-spacing: inherit;
|
|
200
|
-
cursor: inherit;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
.trigger-input::placeholder {
|
|
204
|
-
color: var(--rel-text-placeholder);
|
|
205
|
-
opacity: 1;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/* Error state */
|
|
209
|
-
.trigger-button.error,
|
|
210
|
-
:host(:not([disabled])) .trigger-button.error:hover {
|
|
211
|
-
border-color: var(--rel-border-danger);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
.trigger-button.error:focus-within {
|
|
215
|
-
outline-color: var(--rel-border-danger);
|
|
216
|
-
border-color: var(--rel-border-danger);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
/* Size variants (medium is the base .trigger-button style) */
|
|
220
|
-
.time-picker-wrapper.small .trigger-button {
|
|
221
|
-
padding: var(--rel-spacing-xs) var(--rel-spacing-sm);
|
|
222
|
-
font-family: var(--rel-body-sm-regular-font-family);
|
|
223
|
-
font-weight: var(--rel-body-sm-regular-font-weight);
|
|
224
|
-
font-size: var(--rel-body-sm-regular-font-size);
|
|
225
|
-
line-height: var(--rel-body-sm-regular-line-height);
|
|
226
|
-
letter-spacing: var(--rel-body-sm-regular-letter-spacing);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
.time-picker-wrapper.large .trigger-button {
|
|
230
|
-
padding: var(--rel-spacing-md) var(--rel-spacing-md);
|
|
231
|
-
font-family: var(--rel-body-lg-regular-font-family);
|
|
232
|
-
font-weight: var(--rel-body-lg-regular-font-weight);
|
|
233
|
-
font-size: var(--rel-body-lg-regular-font-size);
|
|
234
|
-
line-height: var(--rel-body-lg-regular-line-height);
|
|
235
|
-
letter-spacing: var(--rel-body-lg-regular-letter-spacing);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
.trigger-icons {
|
|
239
|
-
display: flex;
|
|
240
|
-
align-items: center;
|
|
241
|
-
gap: var(--rel-spacing-2xs);
|
|
242
|
-
color: var(--rel-text-placeholder);
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
.icon-button {
|
|
246
|
-
background: none;
|
|
247
|
-
border: none;
|
|
248
|
-
padding: var(--rel-spacing-3xs);
|
|
249
|
-
cursor: pointer;
|
|
250
|
-
color: var(--rel-text-placeholder);
|
|
251
|
-
display: flex;
|
|
252
|
-
align-items: center;
|
|
253
|
-
justify-content: center;
|
|
254
|
-
border-radius: var(--rel-border-radius-xs);
|
|
255
|
-
transition: all 0.15s ease;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
.icon-button:hover {
|
|
259
|
-
background: var(--rel-bg-surface-elevated);
|
|
260
|
-
color: var(--rel-text-default);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
.icon-button svg {
|
|
264
|
-
width: 16px;
|
|
265
|
-
height: 16px;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/* Panel (Figma "Time Picker"): fixed width per size, full-bleed content. */
|
|
269
|
-
.popover {
|
|
270
|
-
/* Reset native [popover] UA styles first (the panel is promoted to
|
|
271
|
-
the top layer so a drawer/sheet/modal ancestor — transformed,
|
|
272
|
-
overflow:hidden, or an equal-z-index sibling panel — can't clip it
|
|
273
|
-
or paint over it). While in the top layer, JS overrides the
|
|
274
|
-
anchored position below with inline fixed coordinates; the CSS
|
|
275
|
-
anchoring is the no-Popover-API fallback. */
|
|
276
|
-
margin: 0;
|
|
277
|
-
padding: 0;
|
|
278
|
-
height: auto;
|
|
279
|
-
inset: auto;
|
|
280
|
-
color: inherit;
|
|
281
|
-
position: absolute;
|
|
282
|
-
top: calc(100% + 4px);
|
|
283
|
-
left: 0;
|
|
284
|
-
z-index: 2147483647;
|
|
285
|
-
background: var(--rel-bg-surface);
|
|
286
|
-
border: 1px solid var(--rel-border-subtle);
|
|
287
|
-
border-radius: var(--rel-border-radius-sm);
|
|
288
|
-
box-shadow: var(--rel-shadows-shadow-300);
|
|
289
|
-
/* Never wider or taller than the viewport (small screens). border-box
|
|
290
|
-
so the Figma widths and viewport caps include the 1px borders. */
|
|
291
|
-
box-sizing: border-box;
|
|
292
|
-
overflow-x: hidden;
|
|
293
|
-
overflow-y: auto;
|
|
294
|
-
min-width: min(220px, calc(100vw - 16px));
|
|
295
|
-
width: 250px;
|
|
296
|
-
max-width: calc(100vw - 16px);
|
|
297
|
-
max-height: calc(100vh - 16px);
|
|
298
|
-
display: none;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
.popover.open {
|
|
302
|
-
display: block;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
/* Typed-shortcut hints ("N → Now"); each chip applies its value. */
|
|
306
|
-
.shortcut-row {
|
|
307
|
-
display: flex;
|
|
308
|
-
flex-wrap: wrap;
|
|
309
|
-
gap: var(--rel-spacing-2xs);
|
|
310
|
-
padding: var(--rel-spacing-2xs) var(--rel-spacing-xs);
|
|
311
|
-
border-bottom: 1px solid var(--rel-border-subtle);
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
.shortcut-chip {
|
|
315
|
-
display: inline-flex;
|
|
316
|
-
align-items: center;
|
|
317
|
-
gap: var(--rel-spacing-2xs);
|
|
318
|
-
border: none;
|
|
319
|
-
background: transparent;
|
|
320
|
-
border-radius: var(--rel-border-radius-xs);
|
|
321
|
-
padding: var(--rel-spacing-3xs) var(--rel-spacing-2xs);
|
|
322
|
-
cursor: pointer;
|
|
323
|
-
color: var(--rel-text-default);
|
|
324
|
-
transition: background 0.15s ease;
|
|
325
|
-
font-family: var(--rel-body-xs-regular-font-family);
|
|
326
|
-
font-weight: var(--rel-body-xs-regular-font-weight);
|
|
327
|
-
font-size: var(--rel-body-xs-regular-font-size);
|
|
328
|
-
line-height: var(--rel-body-xs-regular-line-height);
|
|
329
|
-
letter-spacing: var(--rel-body-xs-regular-letter-spacing);
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
.shortcut-chip:hover {
|
|
333
|
-
background: var(--rel-bg-neutral-elevated-1);
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
.shortcut-chip:focus-visible {
|
|
337
|
-
outline: 2px solid var(--rel-border-focus);
|
|
338
|
-
outline-offset: -2px;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
.shortcut-chip kbd {
|
|
342
|
-
border: 1px solid var(--rel-border-default);
|
|
343
|
-
border-bottom-width: 2px;
|
|
344
|
-
border-radius: var(--rel-border-radius-xs);
|
|
345
|
-
background: var(--rel-bg-surface-elevated);
|
|
346
|
-
padding: 0 var(--rel-spacing-3xs);
|
|
347
|
-
min-width: 18px;
|
|
348
|
-
text-align: center;
|
|
349
|
-
font-family: inherit;
|
|
350
|
-
font-size: inherit;
|
|
351
|
-
color: var(--rel-text-label);
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
/* Full-bleed column row with 1px dividers (Figma "Columns"). */
|
|
355
|
-
.columns {
|
|
356
|
-
display: flex;
|
|
357
|
-
align-items: stretch;
|
|
358
|
-
height: 260px;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
.column-divider {
|
|
362
|
-
flex-shrink: 0;
|
|
363
|
-
width: 1px;
|
|
364
|
-
background: var(--rel-border-subtle);
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
/* Each column scrolls independently. The 4px rail is always reserved
|
|
368
|
-
(scrollbar-gutter) so columns stay aligned whether or not they
|
|
369
|
-
overflow; the thumb only appears on overflow. */
|
|
370
|
-
.column-list {
|
|
371
|
-
flex: 1;
|
|
372
|
-
min-width: 0;
|
|
373
|
-
display: flex;
|
|
374
|
-
flex-direction: column;
|
|
375
|
-
/* Positioned so option offsetTop is list-relative — the in-column
|
|
376
|
-
scroll math depends on it (we never scrollIntoView: it scrolls every
|
|
377
|
-
ancestor, page included). */
|
|
378
|
-
position: relative;
|
|
379
|
-
overflow-y: auto;
|
|
380
|
-
padding: var(--rel-spacing-2xs);
|
|
381
|
-
scrollbar-width: thin;
|
|
382
|
-
scrollbar-color: var(--rel-border-default) transparent;
|
|
383
|
-
scrollbar-gutter: stable;
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
.column-list::-webkit-scrollbar {
|
|
387
|
-
width: 4px;
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
.column-list::-webkit-scrollbar-track {
|
|
391
|
-
background: transparent;
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
.column-list::-webkit-scrollbar-thumb {
|
|
395
|
-
background: var(--rel-border-default);
|
|
396
|
-
border-radius: var(--rel-border-radius-full-rounded);
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
/* Option cell (Figma ".Time Option"): selected uses the neutral
|
|
400
|
-
elevated-2 fill + medium weight, NOT the brand color. */
|
|
401
|
-
.option-button {
|
|
402
|
-
border: none;
|
|
403
|
-
background: transparent;
|
|
404
|
-
border-radius: var(--rel-border-radius-xs);
|
|
405
|
-
color: var(--rel-text-default);
|
|
406
|
-
cursor: pointer;
|
|
407
|
-
flex-shrink: 0;
|
|
408
|
-
height: 36px;
|
|
409
|
-
padding: 0 var(--rel-spacing-xs);
|
|
410
|
-
text-align: center;
|
|
411
|
-
transition: background 0.15s ease;
|
|
412
|
-
font-family: var(--rel-body-md-regular-font-family);
|
|
413
|
-
font-weight: var(--rel-body-md-regular-font-weight);
|
|
414
|
-
font-size: var(--rel-body-md-regular-font-size);
|
|
415
|
-
line-height: var(--rel-body-md-regular-line-height);
|
|
416
|
-
letter-spacing: var(--rel-body-md-regular-letter-spacing);
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
.option-button:hover:not(:disabled):not(.selected) {
|
|
420
|
-
background: var(--rel-bg-neutral-elevated-1);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
.option-button:focus-visible {
|
|
424
|
-
outline: 2px solid var(--rel-border-focus);
|
|
425
|
-
outline-offset: -2px;
|
|
426
|
-
z-index: 1;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
.option-button.selected {
|
|
430
|
-
background: var(--rel-bg-neutral-elevated-2);
|
|
431
|
-
color: var(--rel-text-default);
|
|
432
|
-
font-weight: var(--rel-body-md-medium-font-weight);
|
|
433
|
-
}
|
|
434
|
-
|
|
435
|
-
.option-button:disabled {
|
|
436
|
-
color: var(--rel-text-disabled);
|
|
437
|
-
cursor: not-allowed;
|
|
438
|
-
opacity: 0.5;
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
.option-button:disabled:hover {
|
|
442
|
-
background: transparent;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
/* Footer (Figma "Footer"): 8px padding + 8px extra left so the "Now"
|
|
446
|
-
link aligns with the buttons' inner padding. Buttons are always S. */
|
|
447
|
-
.time-footer {
|
|
448
|
-
display: flex;
|
|
449
|
-
align-items: center;
|
|
450
|
-
justify-content: space-between;
|
|
451
|
-
gap: var(--rel-spacing-xs);
|
|
452
|
-
padding: var(--rel-spacing-xs);
|
|
453
|
-
padding-left: calc(var(--rel-spacing-xs) * 2);
|
|
454
|
-
border-top: 1px solid var(--rel-border-subtle);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
.footer-right {
|
|
458
|
-
display: flex;
|
|
459
|
-
align-items: center;
|
|
460
|
-
gap: var(--rel-spacing-xs);
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
/* The design narrows OK below the DS small min-width (60 vs 80) so the
|
|
464
|
-
compact footer fits the 220px panel. */
|
|
465
|
-
.footer-right rel-button[variant="primary"] {
|
|
466
|
-
--rel-button-min-width: 60px;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
/* Panel size variants (Figma S/M/L): width 220/250/280, option height
|
|
470
|
-
32/36/40, body-sm/md/lg type. Medium is the base above. */
|
|
471
|
-
.time-picker-wrapper.small .popover {
|
|
472
|
-
width: 220px;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
.time-picker-wrapper.small .columns {
|
|
476
|
-
height: 232px;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
.time-picker-wrapper.small .option-button {
|
|
480
|
-
height: 32px;
|
|
481
|
-
font-family: var(--rel-body-sm-regular-font-family);
|
|
482
|
-
font-weight: var(--rel-body-sm-regular-font-weight);
|
|
483
|
-
font-size: var(--rel-body-sm-regular-font-size);
|
|
484
|
-
line-height: var(--rel-body-sm-regular-line-height);
|
|
485
|
-
letter-spacing: var(--rel-body-sm-regular-letter-spacing);
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
.time-picker-wrapper.small .option-button.selected {
|
|
489
|
-
font-weight: var(--rel-body-sm-medium-font-weight);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
.time-picker-wrapper.large .popover {
|
|
493
|
-
width: 280px;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
.time-picker-wrapper.large .columns {
|
|
497
|
-
height: 288px;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
.time-picker-wrapper.large .option-button {
|
|
501
|
-
height: 40px;
|
|
502
|
-
font-family: var(--rel-body-lg-regular-font-family);
|
|
503
|
-
font-weight: var(--rel-body-lg-regular-font-weight);
|
|
504
|
-
font-size: var(--rel-body-lg-regular-font-size);
|
|
505
|
-
line-height: var(--rel-body-lg-regular-line-height);
|
|
506
|
-
letter-spacing: var(--rel-body-lg-regular-letter-spacing);
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
.time-picker-wrapper.large .option-button.selected {
|
|
510
|
-
font-weight: var(--rel-body-lg-medium-font-weight);
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
@media (prefers-reduced-motion: reduce) {
|
|
514
|
-
.trigger-button,
|
|
515
|
-
.icon-button,
|
|
516
|
-
.option-button {
|
|
517
|
-
transition: none;
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
`;
|
|
521
|
-
|
|
522
|
-
connectedCallback() {
|
|
523
|
-
super.connectedCallback();
|
|
524
|
-
document.addEventListener("click", this.handleClickOutside);
|
|
525
|
-
document.addEventListener("keydown", this.handleEscapeKey);
|
|
526
|
-
}
|
|
527
|
-
|
|
528
|
-
disconnectedCallback() {
|
|
529
|
-
super.disconnectedCallback();
|
|
530
|
-
document.removeEventListener("click", this.handleClickOutside);
|
|
531
|
-
document.removeEventListener("keydown", this.handleEscapeKey);
|
|
532
|
-
window.removeEventListener("resize", this.onReposition);
|
|
533
|
-
window.removeEventListener("scroll", this.onReposition, true);
|
|
534
|
-
this.hideTopLayer();
|
|
535
|
-
}
|
|
536
|
-
|
|
537
|
-
private handleClickOutside = (e: MouseEvent) => {
|
|
538
|
-
if (!this.open) return;
|
|
539
|
-
const path = e.composedPath();
|
|
540
|
-
if (!path.includes(this)) {
|
|
541
|
-
// Don't refocus the field — the user clicked somewhere else on purpose.
|
|
542
|
-
this.cancelPopover(false);
|
|
543
|
-
}
|
|
544
|
-
};
|
|
545
|
-
|
|
546
|
-
private handleEscapeKey = (e: KeyboardEvent) => {
|
|
547
|
-
if (e.key === "Escape" && this.open) {
|
|
548
|
-
this.cancelPopover();
|
|
549
|
-
}
|
|
550
|
-
};
|
|
551
|
-
|
|
552
|
-
// `open` is a public reflected property (consumers may set it directly,
|
|
553
|
-
// not only via the trigger), so top-layer promotion syncs here rather
|
|
554
|
-
// than inside toggle/cancel.
|
|
555
|
-
updated(changedProperties: Map<string, any>) {
|
|
556
|
-
if (changedProperties.has("open")) {
|
|
557
|
-
if (!this.open) {
|
|
558
|
-
window.removeEventListener("resize", this.onReposition);
|
|
559
|
-
window.removeEventListener("scroll", this.onReposition, true);
|
|
560
|
-
this.hideTopLayer();
|
|
561
|
-
this.focusPanelOnOpen = true;
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
this.resetDraftFromValue();
|
|
565
|
-
this.showTopLayer();
|
|
566
|
-
window.addEventListener("resize", this.onReposition);
|
|
567
|
-
window.addEventListener("scroll", this.onReposition, true);
|
|
568
|
-
// Once the popover has rendered: center each column's selection, and —
|
|
569
|
-
// unless the open came from clicking into the text input (typing must
|
|
570
|
-
// keep working) — focus the selected hour without scrolling the page.
|
|
571
|
-
const focusPanel = this.focusPanelOnOpen;
|
|
572
|
-
this.focusPanelOnOpen = true;
|
|
573
|
-
setTimeout(() => {
|
|
574
|
-
this.scrollColumnsToSelection();
|
|
575
|
-
if (focusPanel) this.focusPanelSelection();
|
|
576
|
-
}, 0);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
/* A drawer/sheet/modal ancestor breaks the anchored panel two ways: a
|
|
581
|
-
* transform makes it the containing block for position:fixed descendants
|
|
582
|
-
* (and overflow:hidden clips absolute ones), and an equal-z-index panel
|
|
583
|
-
* later in the DOM paints over the columns. Promoting the panel to the
|
|
584
|
-
* browser top layer sidesteps both — same fix as rel-popover /
|
|
585
|
-
* rel-autocomplete / rel-select / rel-range-picker / rel-date-picker.
|
|
586
|
-
* `manual` keeps outside-click and Escape handling under this component's
|
|
587
|
-
* own control. While in the top layer the CSS anchoring is meaningless, so
|
|
588
|
-
* the panel gets inline fixed coordinates from updatePopoverPosition()
|
|
589
|
-
* (which also replaces the old .open-up CSS flip). */
|
|
590
|
-
|
|
591
|
-
private showTopLayer() {
|
|
592
|
-
const el = this.popoverElement;
|
|
593
|
-
if (el && typeof el.showPopover === "function") {
|
|
594
|
-
try {
|
|
595
|
-
if (!el.matches(":popover-open")) el.showPopover();
|
|
596
|
-
} catch {
|
|
597
|
-
/* older engines / detached element — CSS fallback applies */
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
requestAnimationFrame(() => this.updatePopoverPosition());
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
private hideTopLayer() {
|
|
604
|
-
const el = this.popoverElement;
|
|
605
|
-
if (!el) return;
|
|
606
|
-
if (typeof el.hidePopover === "function") {
|
|
607
|
-
try {
|
|
608
|
-
if (el.matches(":popover-open")) el.hidePopover();
|
|
609
|
-
} catch {
|
|
610
|
-
/* already hidden or unsupported — nothing to do */
|
|
611
|
-
}
|
|
612
|
-
}
|
|
613
|
-
el.style.position = "";
|
|
614
|
-
el.style.top = "";
|
|
615
|
-
el.style.left = "";
|
|
616
|
-
el.style.maxHeight = "";
|
|
617
|
-
}
|
|
618
|
-
|
|
619
|
-
private onReposition = () => {
|
|
620
|
-
if (this.open) this.updatePopoverPosition();
|
|
621
|
-
};
|
|
622
|
-
|
|
623
|
-
private updatePopoverPosition = () => {
|
|
624
|
-
const panel = this.popoverElement;
|
|
625
|
-
const anchor = this.triggerButton;
|
|
626
|
-
if (!panel || !anchor || !this.open) return;
|
|
627
|
-
|
|
628
|
-
const t = anchor.getBoundingClientRect();
|
|
629
|
-
// Measure the natural height, clearing any cap from a previous pass.
|
|
630
|
-
panel.style.maxHeight = "";
|
|
631
|
-
const c = panel.getBoundingClientRect();
|
|
632
|
-
|
|
633
|
-
// Below the trigger; flip above when there's no room below. Either side
|
|
634
|
-
// keeps the same 4px gap to the field (above, the panel may cover the
|
|
635
|
-
// label) and the panel shrinks to the available space — columns scroll —
|
|
636
|
-
// rather than sliding over the trigger. 8px viewport margin on every edge.
|
|
637
|
-
const spaceBelow = Math.max(0, window.innerHeight - 8 - (t.bottom + 4));
|
|
638
|
-
const spaceAbove = Math.max(0, t.top - 4 - 8);
|
|
639
|
-
let top: number;
|
|
640
|
-
if (c.height <= spaceBelow || spaceBelow >= spaceAbove) {
|
|
641
|
-
panel.style.maxHeight = `${Math.min(c.height, spaceBelow)}px`;
|
|
642
|
-
top = t.bottom + 4;
|
|
643
|
-
} else {
|
|
644
|
-
const height = Math.min(c.height, spaceAbove);
|
|
645
|
-
panel.style.maxHeight = `${height}px`;
|
|
646
|
-
top = t.top - 4 - height;
|
|
647
|
-
}
|
|
648
|
-
let left = t.left;
|
|
649
|
-
if (left + c.width > window.innerWidth - 8) {
|
|
650
|
-
left = window.innerWidth - c.width - 8;
|
|
651
|
-
}
|
|
652
|
-
left = Math.max(8, left);
|
|
653
|
-
|
|
654
|
-
// Without top-layer support a transformed ancestor may be the containing
|
|
655
|
-
// block for position:fixed, shifting the panel away from the viewport
|
|
656
|
-
// coordinates computed above. Apply, re-measure, and cancel the offset.
|
|
657
|
-
panel.style.position = "fixed";
|
|
658
|
-
panel.style.top = `${top}px`;
|
|
659
|
-
panel.style.left = `${left}px`;
|
|
660
|
-
const applied = panel.getBoundingClientRect();
|
|
661
|
-
top -= applied.top - top;
|
|
662
|
-
left -= applied.left - left;
|
|
663
|
-
panel.style.top = `${top}px`;
|
|
664
|
-
panel.style.left = `${left}px`;
|
|
665
|
-
};
|
|
666
|
-
|
|
667
|
-
/** Focus the selected (or first enabled) option in the columns. */
|
|
668
|
-
private focusPanelSelection() {
|
|
669
|
-
const target =
|
|
670
|
-
this.columnsElement?.querySelector<HTMLButtonElement>(
|
|
671
|
-
".option-button.selected:not(:disabled)"
|
|
672
|
-
) ??
|
|
673
|
-
this.columnsElement?.querySelector<HTMLButtonElement>(
|
|
674
|
-
".option-button:not(:disabled)"
|
|
675
|
-
);
|
|
676
|
-
target?.focus({ preventScroll: true });
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
// ── Parsing / formatting ──
|
|
680
|
-
|
|
681
|
-
private parseTime(
|
|
682
|
-
time: string | null
|
|
683
|
-
): { hour: number; minute: number; second: number } | null {
|
|
684
|
-
if (!time) return null;
|
|
685
|
-
const match = time.match(/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/);
|
|
686
|
-
if (!match) return null;
|
|
687
|
-
const hour = parseInt(match[1], 10);
|
|
688
|
-
const minute = parseInt(match[2], 10);
|
|
689
|
-
const second = match[3] ? parseInt(match[3], 10) : 0;
|
|
690
|
-
if (hour > 23 || minute > 59 || second > 59) return null;
|
|
691
|
-
return { hour, minute, second };
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
private formatValue(hour: number, minute: number, second = 0): string {
|
|
695
|
-
const hh = String(hour).padStart(2, "0");
|
|
696
|
-
const mm = String(minute).padStart(2, "0");
|
|
697
|
-
return this.seconds ? `${hh}:${mm}:${String(second).padStart(2, "0")}` : `${hh}:${mm}`;
|
|
698
|
-
}
|
|
699
|
-
|
|
700
|
-
private formatDisplay(hour: number, minute: number, second = 0): string {
|
|
701
|
-
const mm = String(minute).padStart(2, "0");
|
|
702
|
-
const ss = this.seconds ? `:${String(second).padStart(2, "0")}` : "";
|
|
703
|
-
if (this.format === "24h") {
|
|
704
|
-
return `${String(hour).padStart(2, "0")}:${mm}${ss}`;
|
|
705
|
-
}
|
|
706
|
-
const period = hour < 12 ? "AM" : "PM";
|
|
707
|
-
const hour12 = hour % 12 === 0 ? 12 : hour % 12;
|
|
708
|
-
return `${hour12}:${mm}${ss} ${period}`;
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
private toMinutes(hour: number, minute: number): number {
|
|
712
|
-
return hour * 60 + minute;
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
private get minuteStepSafe(): number {
|
|
716
|
-
const step = Math.floor(this.minuteStep);
|
|
717
|
-
return step >= 1 && step <= 60 ? step : 1;
|
|
718
|
-
}
|
|
719
|
-
|
|
720
|
-
private get minBoundMinutes(): number {
|
|
721
|
-
const parsed = this.parseTime(this.minTime);
|
|
722
|
-
return parsed ? this.toMinutes(parsed.hour, parsed.minute) : 0;
|
|
723
|
-
}
|
|
724
|
-
|
|
725
|
-
private get maxBoundMinutes(): number {
|
|
726
|
-
const parsed = this.parseTime(this.maxTime);
|
|
727
|
-
return parsed ? this.toMinutes(parsed.hour, parsed.minute) : 23 * 60 + 59;
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
private isTimeInRange(hour: number, minute: number): boolean {
|
|
731
|
-
const total = this.toMinutes(hour, minute);
|
|
732
|
-
return total >= this.minBoundMinutes && total <= this.maxBoundMinutes;
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
/** Minutes shown in the minutes column (respecting minuteStep). */
|
|
736
|
-
private getMinuteOptions(): number[] {
|
|
737
|
-
const minutes: number[] = [];
|
|
738
|
-
for (let m = 0; m < 60; m += this.minuteStepSafe) {
|
|
739
|
-
minutes.push(m);
|
|
740
|
-
}
|
|
741
|
-
return minutes;
|
|
742
|
-
}
|
|
743
|
-
|
|
744
|
-
/** An hour is enabled if at least one of its step minutes is in range. */
|
|
745
|
-
private isHourEnabled(hour: number): boolean {
|
|
746
|
-
return this.getMinuteOptions().some((m) => this.isTimeInRange(hour, m));
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
private isPeriodEnabled(period: "AM" | "PM"): boolean {
|
|
750
|
-
const start = period === "AM" ? 0 : 12;
|
|
751
|
-
for (let h = start; h < start + 12; h++) {
|
|
752
|
-
if (this.isHourEnabled(h)) return true;
|
|
753
|
-
}
|
|
754
|
-
return false;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
/** Hour column entries: display label + the 0–23 hour it maps to. */
|
|
758
|
-
private getHourOptions(): { label: string; hour24: number }[] {
|
|
759
|
-
if (this.format === "24h") {
|
|
760
|
-
return Array.from({ length: 24 }, (_, h) => ({
|
|
761
|
-
label: String(h).padStart(2, "0"),
|
|
762
|
-
hour24: h,
|
|
763
|
-
}));
|
|
764
|
-
}
|
|
765
|
-
// 12-hour clock, 01 … 12 as in the Figma "Hour 12" column ("12" maps to
|
|
766
|
-
// 00:xx AM / 12:xx PM).
|
|
767
|
-
const period = this.draftPeriod ?? "AM";
|
|
768
|
-
const base = period === "AM" ? 0 : 12;
|
|
769
|
-
return Array.from({ length: 12 }, (_, i) => {
|
|
770
|
-
const display = i + 1;
|
|
771
|
-
return {
|
|
772
|
-
label: String(display).padStart(2, "0"),
|
|
773
|
-
hour24: base + (display % 12),
|
|
774
|
-
};
|
|
775
|
-
});
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
/** Seconds shown in the seconds column (always step 1). */
|
|
779
|
-
private getSecondOptions(): number[] {
|
|
780
|
-
return Array.from({ length: 60 }, (_, s) => s);
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
private get draftPeriod(): "AM" | "PM" | null {
|
|
784
|
-
if (this.draftHour === null) return null;
|
|
785
|
-
return this.draftHour < 12 ? "AM" : "PM";
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
private resetDraftFromValue() {
|
|
789
|
-
const parsed = this.parseTime(this.value);
|
|
790
|
-
this.draftHour = parsed ? parsed.hour : null;
|
|
791
|
-
this.draftMinute = parsed ? parsed.minute : null;
|
|
792
|
-
this.draftSecond = parsed ? parsed.second : null;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
/** Snap the draft minute to the nearest valid step minute for the hour. */
|
|
796
|
-
private clampDraftToRange() {
|
|
797
|
-
if (this.draftHour === null || this.draftMinute === null) return;
|
|
798
|
-
if (this.isTimeInRange(this.draftHour, this.draftMinute)) return;
|
|
799
|
-
const hour = this.draftHour;
|
|
800
|
-
const valid = this.getMinuteOptions().filter((m) => this.isTimeInRange(hour, m));
|
|
801
|
-
if (valid.length === 0) {
|
|
802
|
-
this.draftMinute = null;
|
|
803
|
-
return;
|
|
804
|
-
}
|
|
805
|
-
const current = this.draftMinute;
|
|
806
|
-
this.draftMinute = valid.reduce((best, m) =>
|
|
807
|
-
Math.abs(m - current) < Math.abs(best - current) ? m : best
|
|
808
|
-
);
|
|
809
|
-
}
|
|
810
|
-
|
|
811
|
-
// ── Open / close / commit ──
|
|
812
|
-
|
|
813
|
-
private toggleTimePopover() {
|
|
814
|
-
if (this.disabled || this.readonly) return;
|
|
815
|
-
this.open = !this.open;
|
|
816
|
-
this.dispatchEvent(
|
|
817
|
-
new CustomEvent("rel-open-change", {
|
|
818
|
-
detail: { open: this.open },
|
|
819
|
-
bubbles: true,
|
|
820
|
-
composed: true,
|
|
821
|
-
})
|
|
822
|
-
);
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
/** Close discarding the draft (Cancel / Escape / outside click). */
|
|
826
|
-
private cancelPopover(refocus = true) {
|
|
827
|
-
this.open = false;
|
|
828
|
-
if (refocus) this.triggerInput?.focus();
|
|
829
|
-
this.dispatchEvent(
|
|
830
|
-
new CustomEvent("rel-open-change", {
|
|
831
|
-
detail: { open: false },
|
|
832
|
-
bubbles: true,
|
|
833
|
-
composed: true,
|
|
834
|
-
})
|
|
835
|
-
);
|
|
836
|
-
}
|
|
837
|
-
|
|
838
|
-
private applySelection() {
|
|
839
|
-
if (this.draftHour === null) return;
|
|
840
|
-
const hour = this.draftHour;
|
|
841
|
-
const minute = this.draftMinute ?? 0;
|
|
842
|
-
const second = this.draftSecond ?? 0;
|
|
843
|
-
this.commitTime(hour, minute, second);
|
|
844
|
-
announce(`${this.formatDisplay(hour, minute, second)} selected`);
|
|
845
|
-
this.cancelPopover();
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
/** Commit a time: set value, reset typed text/error, fire rel-change. */
|
|
849
|
-
private commitTime(hour: number, minute: number, second: number) {
|
|
850
|
-
const newValue = this.formatValue(hour, minute, second);
|
|
851
|
-
this.value = newValue;
|
|
852
|
-
this.inputText = null;
|
|
853
|
-
this.inputError = null;
|
|
854
|
-
this.dispatchEvent(
|
|
855
|
-
new CustomEvent("rel-change", {
|
|
856
|
-
detail: { value: newValue },
|
|
857
|
-
bubbles: true,
|
|
858
|
-
composed: true,
|
|
859
|
-
})
|
|
860
|
-
);
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
/** Set the draft to the current time, snapped to the minute step and range. */
|
|
864
|
-
private selectNow() {
|
|
865
|
-
const now = new Date();
|
|
866
|
-
const step = this.minuteStepSafe;
|
|
867
|
-
this.draftHour = now.getHours();
|
|
868
|
-
this.draftSecond = this.seconds ? now.getSeconds() : null;
|
|
869
|
-
this.draftMinute = Math.round(now.getMinutes() / step) * step;
|
|
870
|
-
if (this.draftMinute >= 60) {
|
|
871
|
-
this.draftMinute = 0;
|
|
872
|
-
this.draftHour = (this.draftHour + 1) % 24;
|
|
873
|
-
}
|
|
874
|
-
if (!this.isHourEnabled(this.draftHour)) {
|
|
875
|
-
// Current hour is outside min/max — snap to the nearest enabled hour.
|
|
876
|
-
const enabled: number[] = [];
|
|
877
|
-
for (let h = 0; h < 24; h++) if (this.isHourEnabled(h)) enabled.push(h);
|
|
878
|
-
if (enabled.length === 0) return;
|
|
879
|
-
const currentHour = this.draftHour;
|
|
880
|
-
this.draftHour = enabled.reduce((best, h) =>
|
|
881
|
-
Math.abs(h - currentHour) < Math.abs(best - currentHour) ? h : best
|
|
882
|
-
);
|
|
883
|
-
}
|
|
884
|
-
this.clampDraftToRange();
|
|
885
|
-
this.scrollColumnsToSelection();
|
|
886
|
-
}
|
|
887
|
-
|
|
888
|
-
private clearValue(e: Event) {
|
|
889
|
-
e.stopPropagation();
|
|
890
|
-
this.value = null;
|
|
891
|
-
this.draftHour = null;
|
|
892
|
-
this.draftMinute = null;
|
|
893
|
-
this.draftSecond = null;
|
|
894
|
-
this.inputText = null;
|
|
895
|
-
this.inputError = null;
|
|
896
|
-
this.dispatchEvent(
|
|
897
|
-
new CustomEvent("rel-change", {
|
|
898
|
-
detail: { value: null },
|
|
899
|
-
bubbles: true,
|
|
900
|
-
composed: true,
|
|
901
|
-
})
|
|
902
|
-
);
|
|
903
|
-
}
|
|
904
|
-
|
|
905
|
-
// ── Typed keyboard entry ──
|
|
906
|
-
|
|
907
|
-
/**
|
|
908
|
-
* Parse and commit the typed text (Enter / blur). Invalid or out-of-range
|
|
909
|
-
* text keeps the field in an error state with the text preserved for
|
|
910
|
-
* correction; the committed value is untouched (Escape reverts the text).
|
|
911
|
-
*/
|
|
912
|
-
private commitTypedValue() {
|
|
913
|
-
if (this.inputText === null) return; // nothing typed since last commit
|
|
914
|
-
const text = this.inputText.trim();
|
|
915
|
-
|
|
916
|
-
if (!text) {
|
|
917
|
-
// Field cleared by keyboard — behaves like the clear button.
|
|
918
|
-
this.inputText = null;
|
|
919
|
-
this.inputError = null;
|
|
920
|
-
if (this.value !== null) {
|
|
921
|
-
this.value = null;
|
|
922
|
-
this.dispatchEvent(
|
|
923
|
-
new CustomEvent("rel-change", {
|
|
924
|
-
detail: { value: null },
|
|
925
|
-
bubbles: true,
|
|
926
|
-
composed: true,
|
|
927
|
-
})
|
|
928
|
-
);
|
|
929
|
-
}
|
|
930
|
-
if (this.open) this.cancelPopover();
|
|
931
|
-
return;
|
|
932
|
-
}
|
|
933
|
-
|
|
934
|
-
const parsed = parseTimeInput(text);
|
|
935
|
-
if (!parsed) {
|
|
936
|
-
this.inputError = "Invalid time";
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
if (parsed.kind === "now") {
|
|
941
|
-
this.applyNowShortcut();
|
|
942
|
-
return;
|
|
943
|
-
}
|
|
944
|
-
|
|
945
|
-
if (!this.isTimeInRange(parsed.hour, parsed.minute)) {
|
|
946
|
-
this.inputError = "Time out of range";
|
|
947
|
-
return;
|
|
948
|
-
}
|
|
949
|
-
|
|
950
|
-
// Typed entry accepts exact minutes/seconds (not limited to minuteStep).
|
|
951
|
-
this.commitTime(parsed.hour, parsed.minute, this.seconds ? parsed.second : 0);
|
|
952
|
-
if (this.open) this.cancelPopover();
|
|
953
|
-
}
|
|
954
|
-
|
|
955
|
-
/** "Now", committed directly (N shortcut / popover chip), clamped to range. */
|
|
956
|
-
private applyNowShortcut() {
|
|
957
|
-
const now = new Date();
|
|
958
|
-
let hour = now.getHours();
|
|
959
|
-
let minute = now.getMinutes();
|
|
960
|
-
const total = this.toMinutes(hour, minute);
|
|
961
|
-
if (total < this.minBoundMinutes) {
|
|
962
|
-
hour = Math.floor(this.minBoundMinutes / 60);
|
|
963
|
-
minute = this.minBoundMinutes % 60;
|
|
964
|
-
} else if (total > this.maxBoundMinutes) {
|
|
965
|
-
hour = Math.floor(this.maxBoundMinutes / 60);
|
|
966
|
-
minute = this.maxBoundMinutes % 60;
|
|
967
|
-
}
|
|
968
|
-
this.commitTime(hour, minute, this.seconds ? now.getSeconds() : 0);
|
|
969
|
-
if (this.open) this.cancelPopover();
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
// ── Column selection ──
|
|
973
|
-
|
|
974
|
-
private selectHour(hour24: number) {
|
|
975
|
-
if (!this.isHourEnabled(hour24)) return;
|
|
976
|
-
this.draftHour = hour24;
|
|
977
|
-
if (this.draftMinute === null) this.draftMinute = 0;
|
|
978
|
-
this.clampDraftToRange();
|
|
979
|
-
}
|
|
980
|
-
|
|
981
|
-
private selectMinute(minute: number) {
|
|
982
|
-
if (this.draftHour === null) {
|
|
983
|
-
// Minute picked first — default the hour to the first enabled one.
|
|
984
|
-
for (let h = 0; h < 24; h++) {
|
|
985
|
-
if (this.isHourEnabled(h)) {
|
|
986
|
-
this.draftHour = h;
|
|
987
|
-
break;
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
if (this.draftHour === null) return;
|
|
991
|
-
}
|
|
992
|
-
if (!this.isTimeInRange(this.draftHour, minute)) return;
|
|
993
|
-
this.draftMinute = minute;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
private selectSecond(second: number) {
|
|
997
|
-
if (this.draftHour === null) {
|
|
998
|
-
// Second picked first — default the hour to the first enabled one.
|
|
999
|
-
for (let h = 0; h < 24; h++) {
|
|
1000
|
-
if (this.isHourEnabled(h)) {
|
|
1001
|
-
this.draftHour = h;
|
|
1002
|
-
break;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
if (this.draftHour === null) return;
|
|
1006
|
-
}
|
|
1007
|
-
if (this.draftMinute === null) this.draftMinute = 0;
|
|
1008
|
-
this.draftSecond = second;
|
|
1009
|
-
this.clampDraftToRange();
|
|
1010
|
-
}
|
|
1011
|
-
|
|
1012
|
-
private selectPeriod(period: "AM" | "PM") {
|
|
1013
|
-
if (!this.isPeriodEnabled(period)) return;
|
|
1014
|
-
const base = period === "AM" ? 0 : 12;
|
|
1015
|
-
const hour12 = this.draftHour === null ? 0 : this.draftHour % 12;
|
|
1016
|
-
this.draftHour = base + hour12;
|
|
1017
|
-
if (this.draftMinute === null) this.draftMinute = 0;
|
|
1018
|
-
if (!this.isHourEnabled(this.draftHour)) {
|
|
1019
|
-
// Same clock position is out of range in the new period — snap to the
|
|
1020
|
-
// nearest enabled hour within that period.
|
|
1021
|
-
const enabled: number[] = [];
|
|
1022
|
-
for (let h = base; h < base + 12; h++) if (this.isHourEnabled(h)) enabled.push(h);
|
|
1023
|
-
const currentHour = this.draftHour;
|
|
1024
|
-
this.draftHour = enabled.reduce((best, h) =>
|
|
1025
|
-
Math.abs(h - currentHour) < Math.abs(best - currentHour) ? h : best
|
|
1026
|
-
);
|
|
1027
|
-
}
|
|
1028
|
-
this.clampDraftToRange();
|
|
1029
|
-
this.scrollColumnsToSelection();
|
|
1030
|
-
}
|
|
1031
|
-
|
|
1032
|
-
/**
|
|
1033
|
-
* Scrolls the column's own scroll container only. scrollIntoView is off
|
|
1034
|
-
* limits here: it walks ALL scrollable ancestors, so it yanked the page
|
|
1035
|
-
* up/down whenever a column recentred (user-reported jump bug).
|
|
1036
|
-
*/
|
|
1037
|
-
private scrollOptionInColumn(btn: HTMLElement, block: "center" | "nearest") {
|
|
1038
|
-
const list = btn.parentElement;
|
|
1039
|
-
if (!list) return;
|
|
1040
|
-
const top = btn.offsetTop;
|
|
1041
|
-
const height = btn.offsetHeight;
|
|
1042
|
-
if (block === "center") {
|
|
1043
|
-
list.scrollTop = top - (list.clientHeight - height) / 2;
|
|
1044
|
-
} else if (top < list.scrollTop) {
|
|
1045
|
-
list.scrollTop = top;
|
|
1046
|
-
} else if (top + height > list.scrollTop + list.clientHeight) {
|
|
1047
|
-
list.scrollTop = top + height - list.clientHeight;
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
|
|
1051
|
-
private scrollColumnsToSelection() {
|
|
1052
|
-
this.updateComplete.then(() => {
|
|
1053
|
-
this.columnsElement
|
|
1054
|
-
?.querySelectorAll<HTMLButtonElement>(".option-button.selected")
|
|
1055
|
-
.forEach((btn) => this.scrollOptionInColumn(btn, "center"));
|
|
1056
|
-
});
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
// ── Keyboard ──
|
|
1060
|
-
|
|
1061
|
-
private handleInputInput(e: Event) {
|
|
1062
|
-
this.inputText = (e.target as HTMLInputElement).value;
|
|
1063
|
-
if (this.inputError) this.inputError = null;
|
|
1064
|
-
}
|
|
1065
|
-
|
|
1066
|
-
private handleInputKeydown(e: KeyboardEvent) {
|
|
1067
|
-
if (e.key === "Enter") {
|
|
1068
|
-
e.preventDefault();
|
|
1069
|
-
if (this.inputText === null) {
|
|
1070
|
-
// Nothing typed — Enter toggles the popover (previous trigger behavior).
|
|
1071
|
-
if (!this.open) {
|
|
1072
|
-
this.toggleTimePopover();
|
|
1073
|
-
} else {
|
|
1074
|
-
this.applySelection();
|
|
1075
|
-
}
|
|
1076
|
-
} else {
|
|
1077
|
-
this.commitTypedValue();
|
|
1078
|
-
}
|
|
1079
|
-
return;
|
|
1080
|
-
}
|
|
1081
|
-
if (e.key === "ArrowDown") {
|
|
1082
|
-
e.preventDefault();
|
|
1083
|
-
if (!this.open) {
|
|
1084
|
-
this.toggleTimePopover();
|
|
1085
|
-
} else {
|
|
1086
|
-
this.focusPanelSelection();
|
|
1087
|
-
}
|
|
1088
|
-
return;
|
|
1089
|
-
}
|
|
1090
|
-
if (e.key === "Escape" && this.inputText !== null) {
|
|
1091
|
-
// Revert the typed text; the document listener closes the popover.
|
|
1092
|
-
this.inputText = null;
|
|
1093
|
-
this.inputError = null;
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
|
|
1097
|
-
/** Clicking anywhere on the field opens the popover, keeping focus typed-in. */
|
|
1098
|
-
private handleFieldClick() {
|
|
1099
|
-
if (this.open || this.disabled || this.readonly) return;
|
|
1100
|
-
this.focusPanelOnOpen = false;
|
|
1101
|
-
this.toggleTimePopover();
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
/** The clock icon toggles the popover with the previous focus behavior. */
|
|
1105
|
-
private handleIconClick(e: Event) {
|
|
1106
|
-
e.stopPropagation();
|
|
1107
|
-
if (this.open) {
|
|
1108
|
-
this.cancelPopover();
|
|
1109
|
-
} else {
|
|
1110
|
-
this.toggleTimePopover();
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
/** Commit typed text when focus leaves the component entirely. */
|
|
1115
|
-
private handleInputBlur = (e: FocusEvent) => {
|
|
1116
|
-
this.dispatchEvent(new CustomEvent("rel-blur", { bubbles: true, composed: true }));
|
|
1117
|
-
const related = e.relatedTarget as Node | null;
|
|
1118
|
-
if (related && (this.renderRoot.contains(related) || this.contains(related))) {
|
|
1119
|
-
return; // focus moved into the panel/icons — their own handlers commit
|
|
1120
|
-
}
|
|
1121
|
-
this.commitTypedValue();
|
|
1122
|
-
};
|
|
1123
|
-
|
|
1124
|
-
/** N inside the panel (columns/footer focus) applies Now directly. */
|
|
1125
|
-
private handlePanelKeydown = (e: KeyboardEvent) => {
|
|
1126
|
-
if (
|
|
1127
|
-
(e.key === "n" || e.key === "N") &&
|
|
1128
|
-
!e.ctrlKey &&
|
|
1129
|
-
!e.metaKey &&
|
|
1130
|
-
!e.altKey
|
|
1131
|
-
) {
|
|
1132
|
-
e.preventDefault();
|
|
1133
|
-
this.applyNowShortcut();
|
|
1134
|
-
}
|
|
1135
|
-
};
|
|
1136
|
-
|
|
1137
|
-
/**
|
|
1138
|
-
* Column navigation: Up/Down move within the column (and select), Left/Right
|
|
1139
|
-
* jump between columns, Home/End go to the first/last option, Enter applies.
|
|
1140
|
-
*/
|
|
1141
|
-
private handleOptionKeydown(e: KeyboardEvent, column: TimeColumn) {
|
|
1142
|
-
const list = (e.currentTarget as HTMLElement).closest(".column-list");
|
|
1143
|
-
if (!list) return;
|
|
1144
|
-
const buttons = Array.from(
|
|
1145
|
-
list.querySelectorAll<HTMLButtonElement>(".option-button:not(:disabled)")
|
|
1146
|
-
);
|
|
1147
|
-
const index = buttons.indexOf(e.currentTarget as HTMLButtonElement);
|
|
1148
|
-
let target: HTMLButtonElement | undefined;
|
|
1149
|
-
|
|
1150
|
-
switch (e.key) {
|
|
1151
|
-
case "ArrowUp":
|
|
1152
|
-
e.preventDefault();
|
|
1153
|
-
target = buttons[Math.max(0, index - 1)];
|
|
1154
|
-
break;
|
|
1155
|
-
case "ArrowDown":
|
|
1156
|
-
e.preventDefault();
|
|
1157
|
-
target = buttons[Math.min(buttons.length - 1, index + 1)];
|
|
1158
|
-
break;
|
|
1159
|
-
case "Home":
|
|
1160
|
-
e.preventDefault();
|
|
1161
|
-
target = buttons[0];
|
|
1162
|
-
break;
|
|
1163
|
-
case "End":
|
|
1164
|
-
e.preventDefault();
|
|
1165
|
-
target = buttons[buttons.length - 1];
|
|
1166
|
-
break;
|
|
1167
|
-
case "ArrowLeft":
|
|
1168
|
-
case "ArrowRight": {
|
|
1169
|
-
e.preventDefault();
|
|
1170
|
-
this.focusAdjacentColumn(column, e.key === "ArrowRight" ? 1 : -1);
|
|
1171
|
-
return;
|
|
1172
|
-
}
|
|
1173
|
-
case "Enter":
|
|
1174
|
-
e.preventDefault();
|
|
1175
|
-
(e.currentTarget as HTMLButtonElement).click();
|
|
1176
|
-
this.applySelection();
|
|
1177
|
-
return;
|
|
1178
|
-
default:
|
|
1179
|
-
return;
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
if (target && target !== buttons[index]) {
|
|
1183
|
-
target.click();
|
|
1184
|
-
target.focus({ preventScroll: true });
|
|
1185
|
-
this.scrollOptionInColumn(target, "nearest");
|
|
1186
|
-
}
|
|
1187
|
-
}
|
|
1188
|
-
|
|
1189
|
-
private focusAdjacentColumn(from: TimeColumn, direction: 1 | -1) {
|
|
1190
|
-
const order: TimeColumn[] = ["hour", "minute"];
|
|
1191
|
-
if (this.seconds) order.push("second");
|
|
1192
|
-
if (this.format === "12h") order.push("period");
|
|
1193
|
-
const nextIndex = order.indexOf(from) + direction;
|
|
1194
|
-
if (nextIndex < 0 || nextIndex >= order.length) return;
|
|
1195
|
-
const lists = this.columnsElement?.querySelectorAll(".column-list");
|
|
1196
|
-
const list = lists?.[nextIndex];
|
|
1197
|
-
const target =
|
|
1198
|
-
list?.querySelector<HTMLButtonElement>(".option-button.selected:not(:disabled)") ??
|
|
1199
|
-
list?.querySelector<HTMLButtonElement>(".option-button:not(:disabled)");
|
|
1200
|
-
if (target) {
|
|
1201
|
-
target.focus({ preventScroll: true });
|
|
1202
|
-
this.scrollOptionInColumn(target, "nearest");
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
|
|
1206
|
-
// ── Render ──
|
|
1207
|
-
|
|
1208
|
-
render() {
|
|
1209
|
-
const isError = this.error || this.invalid || this.inputError !== null;
|
|
1210
|
-
const belowText = isError
|
|
1211
|
-
? this.errorMessage ?? this.inputError ?? this.helperText
|
|
1212
|
-
: this.helperText;
|
|
1213
|
-
const describedById = belowText ? "time-picker-desc" : undefined;
|
|
1214
|
-
const parsedValue = this.parseTime(this.value);
|
|
1215
|
-
const displayText = parsedValue
|
|
1216
|
-
? this.formatDisplay(parsedValue.hour, parsedValue.minute, parsedValue.second)
|
|
1217
|
-
: "";
|
|
1218
|
-
const hourOptions = this.getHourOptions();
|
|
1219
|
-
const minuteOptions = this.getMinuteOptions();
|
|
1220
|
-
const secondOptions = this.seconds ? this.getSecondOptions() : [];
|
|
1221
|
-
const draftPeriod = this.draftPeriod;
|
|
1222
|
-
const wrapperClasses = [
|
|
1223
|
-
"time-picker-wrapper",
|
|
1224
|
-
this.size,
|
|
1225
|
-
isError ? "error" : "",
|
|
1226
|
-
this.readonly ? "readonly" : "",
|
|
1227
|
-
]
|
|
1228
|
-
.filter(Boolean)
|
|
1229
|
-
.join(" ");
|
|
1230
|
-
|
|
1231
|
-
return html`
|
|
1232
|
-
<div part="base" class="${wrapperClasses}">
|
|
1233
|
-
${this.label
|
|
1234
|
-
? html`<label part="label" class="label" id="time-picker-label"
|
|
1235
|
-
>${this.label}${this.required
|
|
1236
|
-
? html`<span class="required-mark" aria-hidden="true">*</span>`
|
|
1237
|
-
: nothing}</label
|
|
1238
|
-
>`
|
|
1239
|
-
: nothing}
|
|
1240
|
-
|
|
1241
|
-
${this.name
|
|
1242
|
-
? html`<input type="hidden" name=${this.name} .value=${this.value ?? ""} />`
|
|
1243
|
-
: nothing}
|
|
1244
|
-
|
|
1245
|
-
<div
|
|
1246
|
-
part="trigger"
|
|
1247
|
-
class="trigger-button ${isError ? "error" : ""}"
|
|
1248
|
-
@click=${this.handleFieldClick}
|
|
1249
|
-
>
|
|
1250
|
-
<input
|
|
1251
|
-
part="value"
|
|
1252
|
-
class="trigger-input"
|
|
1253
|
-
type="text"
|
|
1254
|
-
.value=${live(this.inputText ?? displayText)}
|
|
1255
|
-
placeholder=${this.placeholder}
|
|
1256
|
-
?disabled=${this.disabled}
|
|
1257
|
-
?readonly=${this.readonly}
|
|
1258
|
-
autocomplete="off"
|
|
1259
|
-
spellcheck="false"
|
|
1260
|
-
enterkeyhint="done"
|
|
1261
|
-
@input=${this.handleInputInput}
|
|
1262
|
-
@keydown=${this.handleInputKeydown}
|
|
1263
|
-
@focus=${() =>
|
|
1264
|
-
this.dispatchEvent(
|
|
1265
|
-
new CustomEvent("rel-focus", { bubbles: true, composed: true })
|
|
1266
|
-
)}
|
|
1267
|
-
@blur=${this.handleInputBlur}
|
|
1268
|
-
role="combobox"
|
|
1269
|
-
aria-label=${this.label || "Select time"}
|
|
1270
|
-
aria-haspopup="dialog"
|
|
1271
|
-
aria-expanded=${this.open}
|
|
1272
|
-
aria-controls="time-picker-panel"
|
|
1273
|
-
aria-required=${this.required}
|
|
1274
|
-
aria-invalid=${isError}
|
|
1275
|
-
aria-describedby=${describedById ?? nothing}
|
|
1276
|
-
aria-labelledby=${this.label ? "time-picker-label" : nothing}
|
|
1277
|
-
/>
|
|
1278
|
-
<span class="trigger-icons">
|
|
1279
|
-
${this.clearable && this.value
|
|
1280
|
-
? html`
|
|
1281
|
-
<button
|
|
1282
|
-
class="icon-button"
|
|
1283
|
-
type="button"
|
|
1284
|
-
aria-label="Clear time"
|
|
1285
|
-
@click=${this.clearValue}
|
|
1286
|
-
>
|
|
1287
|
-
<svg viewBox="0 0 16 16" fill="currentColor">
|
|
1288
|
-
<path
|
|
1289
|
-
d="M4 4l8 8M12 4l-8 8"
|
|
1290
|
-
stroke="currentColor"
|
|
1291
|
-
stroke-width="2"
|
|
1292
|
-
stroke-linecap="round"
|
|
1293
|
-
/>
|
|
1294
|
-
</svg>
|
|
1295
|
-
</button>
|
|
1296
|
-
`
|
|
1297
|
-
: nothing}
|
|
1298
|
-
<button
|
|
1299
|
-
class="icon-button"
|
|
1300
|
-
type="button"
|
|
1301
|
-
aria-label="Open time panel"
|
|
1302
|
-
aria-expanded=${this.open}
|
|
1303
|
-
?disabled=${this.disabled}
|
|
1304
|
-
@click=${this.handleIconClick}
|
|
1305
|
-
>
|
|
1306
|
-
<rel-icon part="icon" name="time-filled" size="sm"></rel-icon>
|
|
1307
|
-
</button>
|
|
1308
|
-
</span>
|
|
1309
|
-
</div>
|
|
1310
|
-
|
|
1311
|
-
<div
|
|
1312
|
-
part="panel"
|
|
1313
|
-
id="time-picker-panel"
|
|
1314
|
-
class="popover ${this.open ? "open" : ""}"
|
|
1315
|
-
popover="manual"
|
|
1316
|
-
role="dialog"
|
|
1317
|
-
aria-label="Choose time"
|
|
1318
|
-
@keydown=${this.handlePanelKeydown}
|
|
1319
|
-
>
|
|
1320
|
-
<div part="shortcuts" class="shortcut-row">
|
|
1321
|
-
<button
|
|
1322
|
-
class="shortcut-chip"
|
|
1323
|
-
type="button"
|
|
1324
|
-
title="Type N in the field for the current time"
|
|
1325
|
-
@click=${() => this.applyNowShortcut()}
|
|
1326
|
-
>
|
|
1327
|
-
<kbd aria-hidden="true">N</kbd><span>Now</span>
|
|
1328
|
-
</button>
|
|
1329
|
-
</div>
|
|
1330
|
-
<div class="columns">
|
|
1331
|
-
<div class="column-list" role="listbox" aria-label="Hours">
|
|
1332
|
-
${hourOptions.map(
|
|
1333
|
-
(opt, i) => html`
|
|
1334
|
-
<button
|
|
1335
|
-
part="option"
|
|
1336
|
-
class="option-button ${this.draftHour === opt.hour24
|
|
1337
|
-
? "selected"
|
|
1338
|
-
: ""}"
|
|
1339
|
-
type="button"
|
|
1340
|
-
role="option"
|
|
1341
|
-
aria-selected=${this.draftHour === opt.hour24}
|
|
1342
|
-
?disabled=${!this.isHourEnabled(opt.hour24)}
|
|
1343
|
-
@click=${() => this.selectHour(opt.hour24)}
|
|
1344
|
-
@keydown=${(e: KeyboardEvent) => this.handleOptionKeydown(e, "hour")}
|
|
1345
|
-
tabindex=${this.draftHour === opt.hour24 ||
|
|
1346
|
-
(this.draftHour === null && i === 0)
|
|
1347
|
-
? 0
|
|
1348
|
-
: -1}
|
|
1349
|
-
>
|
|
1350
|
-
${opt.label}
|
|
1351
|
-
</button>
|
|
1352
|
-
`
|
|
1353
|
-
)}
|
|
1354
|
-
</div>
|
|
1355
|
-
|
|
1356
|
-
<div class="column-divider" aria-hidden="true"></div>
|
|
1357
|
-
|
|
1358
|
-
<div class="column-list" role="listbox" aria-label="Minutes">
|
|
1359
|
-
${minuteOptions.map(
|
|
1360
|
-
(m, i) => html`
|
|
1361
|
-
<button
|
|
1362
|
-
part="option"
|
|
1363
|
-
class="option-button ${this.draftMinute === m ? "selected" : ""}"
|
|
1364
|
-
type="button"
|
|
1365
|
-
role="option"
|
|
1366
|
-
aria-selected=${this.draftMinute === m}
|
|
1367
|
-
?disabled=${this.draftHour !== null &&
|
|
1368
|
-
!this.isTimeInRange(this.draftHour, m)}
|
|
1369
|
-
@click=${() => this.selectMinute(m)}
|
|
1370
|
-
@keydown=${(e: KeyboardEvent) =>
|
|
1371
|
-
this.handleOptionKeydown(e, "minute")}
|
|
1372
|
-
tabindex=${this.draftMinute === m ||
|
|
1373
|
-
(this.draftMinute === null && i === 0)
|
|
1374
|
-
? 0
|
|
1375
|
-
: -1}
|
|
1376
|
-
>
|
|
1377
|
-
${String(m).padStart(2, "0")}
|
|
1378
|
-
</button>
|
|
1379
|
-
`
|
|
1380
|
-
)}
|
|
1381
|
-
</div>
|
|
1382
|
-
|
|
1383
|
-
${this.seconds
|
|
1384
|
-
? html`
|
|
1385
|
-
<div class="column-divider" aria-hidden="true"></div>
|
|
1386
|
-
<div class="column-list" role="listbox" aria-label="Seconds">
|
|
1387
|
-
${secondOptions.map(
|
|
1388
|
-
(s, i) => html`
|
|
1389
|
-
<button
|
|
1390
|
-
part="option"
|
|
1391
|
-
class="option-button ${this.draftSecond === s
|
|
1392
|
-
? "selected"
|
|
1393
|
-
: ""}"
|
|
1394
|
-
type="button"
|
|
1395
|
-
role="option"
|
|
1396
|
-
aria-selected=${this.draftSecond === s}
|
|
1397
|
-
@click=${() => this.selectSecond(s)}
|
|
1398
|
-
@keydown=${(e: KeyboardEvent) =>
|
|
1399
|
-
this.handleOptionKeydown(e, "second")}
|
|
1400
|
-
tabindex=${this.draftSecond === s ||
|
|
1401
|
-
(this.draftSecond === null && i === 0)
|
|
1402
|
-
? 0
|
|
1403
|
-
: -1}
|
|
1404
|
-
>
|
|
1405
|
-
${String(s).padStart(2, "0")}
|
|
1406
|
-
</button>
|
|
1407
|
-
`
|
|
1408
|
-
)}
|
|
1409
|
-
</div>
|
|
1410
|
-
`
|
|
1411
|
-
: nothing}
|
|
1412
|
-
${this.format === "12h"
|
|
1413
|
-
? html`
|
|
1414
|
-
<div class="column-divider" aria-hidden="true"></div>
|
|
1415
|
-
<div class="column-list" role="listbox" aria-label="AM or PM">
|
|
1416
|
-
${(["AM", "PM"] as const).map(
|
|
1417
|
-
(p) => html`
|
|
1418
|
-
<button
|
|
1419
|
-
part="option"
|
|
1420
|
-
class="option-button ${draftPeriod === p ? "selected" : ""}"
|
|
1421
|
-
type="button"
|
|
1422
|
-
role="option"
|
|
1423
|
-
aria-selected=${draftPeriod === p}
|
|
1424
|
-
?disabled=${!this.isPeriodEnabled(p)}
|
|
1425
|
-
@click=${() => this.selectPeriod(p)}
|
|
1426
|
-
@keydown=${(e: KeyboardEvent) =>
|
|
1427
|
-
this.handleOptionKeydown(e, "period")}
|
|
1428
|
-
tabindex=${draftPeriod === p ||
|
|
1429
|
-
(draftPeriod === null && p === "AM")
|
|
1430
|
-
? 0
|
|
1431
|
-
: -1}
|
|
1432
|
-
>
|
|
1433
|
-
${p}
|
|
1434
|
-
</button>
|
|
1435
|
-
`
|
|
1436
|
-
)}
|
|
1437
|
-
</div>
|
|
1438
|
-
`
|
|
1439
|
-
: nothing}
|
|
1440
|
-
</div>
|
|
1441
|
-
|
|
1442
|
-
<div part="footer" class="time-footer">
|
|
1443
|
-
<rel-button variant="link" size="small" @click=${() => this.selectNow()}>
|
|
1444
|
-
Now
|
|
1445
|
-
</rel-button>
|
|
1446
|
-
<div class="footer-right">
|
|
1447
|
-
<rel-button
|
|
1448
|
-
variant="ghost"
|
|
1449
|
-
size="small"
|
|
1450
|
-
@click=${() => this.cancelPopover()}
|
|
1451
|
-
>
|
|
1452
|
-
Cancel
|
|
1453
|
-
</rel-button>
|
|
1454
|
-
<rel-button
|
|
1455
|
-
variant="primary"
|
|
1456
|
-
tone="default"
|
|
1457
|
-
size="small"
|
|
1458
|
-
?disabled=${this.draftHour === null}
|
|
1459
|
-
@click=${() => this.applySelection()}
|
|
1460
|
-
>
|
|
1461
|
-
OK
|
|
1462
|
-
</rel-button>
|
|
1463
|
-
</div>
|
|
1464
|
-
</div>
|
|
1465
|
-
</div>
|
|
1466
|
-
|
|
1467
|
-
<div
|
|
1468
|
-
part="helper"
|
|
1469
|
-
class="time-picker-support ${isError ? "error" : ""} ${belowText ? "" : "empty"}"
|
|
1470
|
-
id="time-picker-desc"
|
|
1471
|
-
aria-live="polite"
|
|
1472
|
-
>${belowText ?? nothing}</div>
|
|
1473
|
-
</div>
|
|
1474
|
-
`;
|
|
1475
|
-
}
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
declare global {
|
|
1479
|
-
interface HTMLElementTagNameMap {
|
|
1480
|
-
"rel-time-picker": RelTimePicker;
|
|
1481
|
-
}
|
|
1482
|
-
}
|