@iyulab/components 1.54.0 → 1.55.0
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 +24 -0
- package/dist/components/date-picker/UDatePicker.d.ts +35 -2
- package/dist/components/date-picker/UDatePicker.js +112 -16
- package/dist/components/date-picker/UDatePicker.styles.js +19 -0
- package/dist/index.js +2 -2
- package/dist/utilities/format.d.ts +26 -0
- package/dist/utilities/format.js +89 -1
- package/package.json +1 -1
- package/skills/iyulab-components/references/components/date-picker.md +14 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.55.0] - 2026-10-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **`u-date-picker` takes a typed date.** In `mode="date"` the field is now a text box: type
|
|
8
|
+
`2026-10-02`, `2026/10/2`, `20261002` or `10-02` (this year) and press Enter or leave the field.
|
|
9
|
+
It shows the date as `YYYY-MM-DD` whatever the browser language — the native date input follows
|
|
10
|
+
the browser's UI language instead (`10/02/2026` in an English browser), which is why a picker that
|
|
11
|
+
could not be typed into was the only way to get a stable format. `format="locale"` shows and reads
|
|
12
|
+
the locale's numeric order (`10/02/2026` in `en-US`, `02.10.2026` in `de`); ISO is read either way.
|
|
13
|
+
Clicking the field opens the calendar and leaves the caret in the text box; ArrowDown or
|
|
14
|
+
Alt+ArrowDown moves into the calendar. Text that is not a date clears the value and reports
|
|
15
|
+
`badInput`, as the native date input does; a date outside `min`/`max` is kept and reported as out
|
|
16
|
+
of range. New CSS part `input`. `mode="datetime"` is unchanged.
|
|
17
|
+
- **`parseDate`, `formatDateText`, `dateTextPattern`** — the text box's reader and writer, exported
|
|
18
|
+
next to `parseNumber`: `parseDate('20261002')` is `'2026-10-02'`, `parseDate('2026-02-30')` is `null`.
|
|
19
|
+
|
|
20
|
+
### Changed
|
|
21
|
+
|
|
22
|
+
- **`u-date-picker` in `mode="date"`: the trigger text is `YYYY-MM-DD`** (was the locale's medium
|
|
23
|
+
date, e.g. `Oct 2, 2026`) so that what is shown can be typed back. Use `format="locale"` for the
|
|
24
|
+
locale's numeric order. A click no longer moves focus into the calendar — it stays in the text box
|
|
25
|
+
so the person can type; the keyboard path into the calendar is ArrowDown.
|
|
26
|
+
|
|
3
27
|
## [1.54.0] - 2026-10-02
|
|
4
28
|
|
|
5
29
|
### Added
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import { PropertyValues } from 'lit';
|
|
2
2
|
import { UFormControlElement } from '../UFormControlElement.js';
|
|
3
|
+
import { DateTextFormat } from '../../utilities/format.js';
|
|
3
4
|
import { UCalendar } from '../calendar/UCalendar.js';
|
|
4
5
|
import { UPopover } from '../popover/UPopover.js';
|
|
5
6
|
export type DatePickerMode = 'date' | 'datetime';
|
|
6
7
|
/**
|
|
7
8
|
* A single-date(-time)-selection form control. In `mode="date"` (default) the value follows
|
|
8
|
-
* the same convention as the native `input[type=date]`: an ISO `YYYY-MM-DD` string
|
|
9
|
+
* the same convention as the native `input[type=date]`: an ISO `YYYY-MM-DD` string, and the
|
|
10
|
+
* field is a text box — type `2026-10-02`, `20261002` or `10-02` (this year) and press Enter or
|
|
11
|
+
* leave the field; the calendar is a helper. The text shows as `YYYY-MM-DD` whatever the browser
|
|
12
|
+
* language, or in the locale's numeric order with `format="locale"`. Clicking the field opens the
|
|
13
|
+
* calendar and keeps typing in the field; ArrowDown (or Alt+ArrowDown) moves into the calendar.
|
|
14
|
+
* Text that is not a date clears the value and reports `badInput`, like the native input. In
|
|
9
15
|
* `mode="datetime"` the value is a complete ISO-8601 `DateTimeOffset` string
|
|
10
16
|
* (`YYYY-MM-DDTHH:mm:ss±HH:mm`) — the component always fills in seconds and the browser's
|
|
11
17
|
* local UTC offset, so the value is unconditionally valid regardless of how coarse the time
|
|
@@ -23,6 +29,7 @@ export type DatePickerMode = 'date' | 'datetime';
|
|
|
23
29
|
* as a CSS hook for consumers who want to react to the open/closed state from outside.
|
|
24
30
|
*
|
|
25
31
|
* @csspart field - the u-field element
|
|
32
|
+
* @csspart input - the text box (`mode="date"` only)
|
|
26
33
|
* @csspart container - the element wrapping the trigger area
|
|
27
34
|
* @csspart popover - the popover element showing the calendar
|
|
28
35
|
* @csspart calendar - the calendar container
|
|
@@ -59,8 +66,13 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
59
66
|
max?: string;
|
|
60
67
|
/** Whether to show the clear button */
|
|
61
68
|
clearable: boolean;
|
|
62
|
-
/** Placeholder text (shown on the trigger when there is no value)
|
|
69
|
+
/** Placeholder text (shown on the trigger when there is no value). In `mode="date"` it defaults
|
|
70
|
+
* to the pattern to type (`YYYY-MM-DD`). */
|
|
63
71
|
placeholder?: string;
|
|
72
|
+
/** How the `mode="date"` text box writes and reads a date: `iso` (default, `YYYY-MM-DD` in every
|
|
73
|
+
* language) or `locale` (the active locale's numeric order, e.g. `10/02/2026` in `en-US`). ISO
|
|
74
|
+
* and `20261002` are read in both. The value is ISO either way. */
|
|
75
|
+
format: DateTextFormat;
|
|
64
76
|
containerEl?: HTMLElement;
|
|
65
77
|
popoverEl?: UPopover;
|
|
66
78
|
calendarEl?: UCalendar;
|
|
@@ -70,6 +82,13 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
70
82
|
/** Time-of-day for the next selection while no `value` exists yet (`mode="datetime"` only) —
|
|
71
83
|
* once `value` is set, the time input reads/writes its time portion directly instead. */
|
|
72
84
|
private pendingTime;
|
|
85
|
+
/** What the person is typing in the `mode="date"` text box, until it is committed; `null` shows the value. */
|
|
86
|
+
private draft;
|
|
87
|
+
/** The committed text was not a date — the value is empty and validity reports `badInput`. */
|
|
88
|
+
private badText;
|
|
89
|
+
/** Set when the calendar opens by keyboard (or its button): focus then moves into the grid. A click
|
|
90
|
+
* in the text box opens it too, but leaves the caret where the person is typing. */
|
|
91
|
+
private focusCalendarOnOpen;
|
|
73
92
|
protected updated(changed: PropertyValues): void;
|
|
74
93
|
render(): import('lit-html').TemplateResult<1>;
|
|
75
94
|
private renderCalendar;
|
|
@@ -86,6 +105,20 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
86
105
|
* trigger — unlike selecting a day, adjusting the time doesn't conclude the interaction. */
|
|
87
106
|
private handleTimeChange;
|
|
88
107
|
private handleDaySelect;
|
|
108
|
+
private get textInputEl();
|
|
109
|
+
private openCalendar;
|
|
110
|
+
private handleTextInput;
|
|
111
|
+
/** A click anywhere on the field (not on its clear or calendar button) opens the calendar and
|
|
112
|
+
* puts the caret in the text box — the person can pick a day or keep typing. */
|
|
113
|
+
private handleContainerClick;
|
|
114
|
+
private handleCalendarButtonClick;
|
|
115
|
+
/** ArrowDown / Alt+ArrowDown opens the calendar and moves into it (the combobox convention);
|
|
116
|
+
* Enter commits what was typed. Escape is the popover layer's — it closes the calendar. */
|
|
117
|
+
private handleTextKeydown;
|
|
118
|
+
/** Turns the typed text into the value. Empty text clears it; text that is not a date also clears
|
|
119
|
+
* it and reports `badInput` (the native date input does the same); a date outside `min`/`max` is
|
|
120
|
+
* kept and reported as out of range — the person typed it, so it is not silently dropped. */
|
|
121
|
+
private commitText;
|
|
89
122
|
/** Escape inside the grid closes the calendar and returns focus to the trigger — the grid
|
|
90
123
|
* itself does not know it lives in a popover, so the picker owns this. */
|
|
91
124
|
private handleCalendarKeydown;
|
|
@@ -4,7 +4,7 @@ import { UFormControlElement } from "../UFormControlElement.js";
|
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.js";
|
|
6
6
|
import { Locale } from "../../utilities/Locale.js";
|
|
7
|
-
import { formatDate } from "../../utilities/format.js";
|
|
7
|
+
import { dateTextPattern, formatDate, formatDateText, parseDate } from "../../utilities/format.js";
|
|
8
8
|
import { isOutOfRange, parseISODate, toISODate } from "../calendar/dates.js";
|
|
9
9
|
import { UCalendar } from "../calendar/UCalendar.js";
|
|
10
10
|
import "../field/UField.js";
|
|
@@ -45,9 +45,13 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
45
45
|
super(..._args);
|
|
46
46
|
this.mode = "date";
|
|
47
47
|
this.clearable = false;
|
|
48
|
+
this.format = "iso";
|
|
48
49
|
this.calendarId = `u-date-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
|
|
49
50
|
this.open = false;
|
|
50
51
|
this.pendingTime = "00:00";
|
|
52
|
+
this.draft = null;
|
|
53
|
+
this.badText = false;
|
|
54
|
+
this.focusCalendarOnOpen = false;
|
|
51
55
|
this.handleTimeChange = (e) => {
|
|
52
56
|
const time = e.target.value || "00:00";
|
|
53
57
|
this.pendingTime = time;
|
|
@@ -60,11 +64,48 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
60
64
|
this.handleDaySelect = (e) => {
|
|
61
65
|
this.selectDay(parseISODate(e.detail.date));
|
|
62
66
|
};
|
|
67
|
+
this.handleTextInput = (e) => {
|
|
68
|
+
this.draft = e.target.value;
|
|
69
|
+
const typed = parseDate(this.draft, { format: this.format });
|
|
70
|
+
if (typed && this.open) this.calendarEl?.showDate(typed);
|
|
71
|
+
};
|
|
72
|
+
this.handleContainerClick = (e) => {
|
|
73
|
+
if (e.target.closest?.("u-icon")) return;
|
|
74
|
+
const input = this.textInputEl;
|
|
75
|
+
if (input && this.renderRoot instanceof ShadowRoot && this.renderRoot.activeElement !== input) input.focus();
|
|
76
|
+
this.openCalendar(false);
|
|
77
|
+
};
|
|
78
|
+
this.handleCalendarButtonClick = (e) => {
|
|
79
|
+
e.stopPropagation();
|
|
80
|
+
if (this.open) {
|
|
81
|
+
this.popoverEl?.hide();
|
|
82
|
+
this.textInputEl?.focus();
|
|
83
|
+
} else this.openCalendar(true);
|
|
84
|
+
};
|
|
85
|
+
this.handleTextKeydown = (e) => {
|
|
86
|
+
if (e.key === "ArrowDown") {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
this.commitText();
|
|
89
|
+
this.openCalendar(true);
|
|
90
|
+
} else if (e.key === "Enter" && !e.isComposing) this.commitText();
|
|
91
|
+
};
|
|
92
|
+
this.commitText = () => {
|
|
93
|
+
if (this.draft === null) return;
|
|
94
|
+
const text = this.draft;
|
|
95
|
+
const iso = parseDate(text, { format: this.format });
|
|
96
|
+
this.badText = !!text.trim() && iso === null;
|
|
97
|
+
const next = iso ? buildValue(parseISODate(iso), this.mode, this.pendingTime) : void 0;
|
|
98
|
+
const changed = next !== this.value;
|
|
99
|
+
this.value = next;
|
|
100
|
+
this.draft = this.badText ? text : null;
|
|
101
|
+
if (changed) this.emitChange();
|
|
102
|
+
else if (this.badText && !this.novalidate) this.validate();
|
|
103
|
+
};
|
|
63
104
|
this.handleCalendarKeydown = (e) => {
|
|
64
105
|
if (e.key !== "Escape") return;
|
|
65
106
|
e.preventDefault();
|
|
66
107
|
this.popoverEl?.hide();
|
|
67
|
-
this.containerEl?.focus();
|
|
108
|
+
(this.textInputEl ?? this.containerEl)?.focus();
|
|
68
109
|
};
|
|
69
110
|
this.handlePopoverShow = () => {
|
|
70
111
|
this.open = true;
|
|
@@ -76,7 +117,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
76
117
|
e.preventDefault();
|
|
77
118
|
e.stopPropagation();
|
|
78
119
|
this.resetValue();
|
|
79
|
-
this.containerEl?.focus();
|
|
120
|
+
(this.textInputEl ?? this.containerEl)?.focus();
|
|
80
121
|
};
|
|
81
122
|
this.handleTodayClick = () => {
|
|
82
123
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -86,7 +127,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
86
127
|
this.handleFooterResetClick = () => {
|
|
87
128
|
this.resetValue();
|
|
88
129
|
this.popoverEl?.hide();
|
|
89
|
-
this.containerEl?.focus();
|
|
130
|
+
(this.textInputEl ?? this.containerEl)?.focus();
|
|
90
131
|
};
|
|
91
132
|
this.handleClearKeydown = (e) => {
|
|
92
133
|
if (e.key !== "Enter" && e.key !== " ") return;
|
|
@@ -107,9 +148,11 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
107
148
|
if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
|
|
108
149
|
if (changed.has("open") && this.open) {
|
|
109
150
|
const calendar = this.calendarEl;
|
|
110
|
-
const base = this.value ? toISODate(splitValue(this.value).date) : toISODate(/* @__PURE__ */ new Date());
|
|
151
|
+
const base = (this.draft !== null ? parseDate(this.draft, { format: this.format }) : null) ?? (this.value ? toISODate(splitValue(this.value).date) : toISODate(/* @__PURE__ */ new Date()));
|
|
111
152
|
calendar?.showDate(base);
|
|
112
|
-
this.
|
|
153
|
+
const moveFocus = this.mode !== "date" || this.focusCalendarOnOpen;
|
|
154
|
+
this.focusCalendarOnOpen = false;
|
|
155
|
+
if (moveFocus) this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
|
|
113
156
|
}
|
|
114
157
|
}
|
|
115
158
|
render() {
|
|
@@ -117,6 +160,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
117
160
|
dateStyle: "medium",
|
|
118
161
|
timeStyle: "short"
|
|
119
162
|
} : void 0) : "";
|
|
163
|
+
const textEntry = this.mode === "date";
|
|
120
164
|
return html`
|
|
121
165
|
<u-field part="field"
|
|
122
166
|
?required=${this.required}
|
|
@@ -126,7 +170,26 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
126
170
|
.description=${this.description}
|
|
127
171
|
.validationMessage=${this.validationMessage}
|
|
128
172
|
>
|
|
129
|
-
|
|
173
|
+
${textEntry ? html`<div class="container" part="container" @click=${this.handleContainerClick}>
|
|
174
|
+
<input class="text-input" part="input"
|
|
175
|
+
type="text"
|
|
176
|
+
inputmode="numeric"
|
|
177
|
+
autocomplete="off"
|
|
178
|
+
role="combobox"
|
|
179
|
+
aria-haspopup="dialog"
|
|
180
|
+
aria-expanded=${this.open}
|
|
181
|
+
aria-controls=${this.calendarId}
|
|
182
|
+
aria-label=${ifDefined(this.resolvedAriaLabel)}
|
|
183
|
+
aria-description=${ifDefined(this.resolvedAriaDescription)}
|
|
184
|
+
aria-invalid=${this.badText ? "true" : "false"}
|
|
185
|
+
placeholder=${this.placeholder ?? dateTextPattern(this.format)}
|
|
186
|
+
.value=${this.draft ?? (this.value ? formatDateText(toISODate(splitValue(this.value).date), this.format) : "")}
|
|
187
|
+
?disabled=${this.effectivelyDisabled}
|
|
188
|
+
?readonly=${this.readonly}
|
|
189
|
+
@input=${this.handleTextInput}
|
|
190
|
+
@keydown=${this.handleTextKeydown}
|
|
191
|
+
@blur=${this.commitText}
|
|
192
|
+
/>` : html`<div class="container" part="container"
|
|
130
193
|
tabindex=${this.effectivelyDisabled ? "-1" : "0"}
|
|
131
194
|
role="combobox"
|
|
132
195
|
aria-disabled=${ifDefined(this.effectivelyDisabled ? "true" : void 0)}
|
|
@@ -136,7 +199,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
136
199
|
aria-description=${ifDefined(this.resolvedAriaDescription)}
|
|
137
200
|
aria-controls=${this.calendarId}
|
|
138
201
|
>
|
|
139
|
-
<span class="text-content ${!displayText ? "placeholder" : ""}">${displayText || this.placeholder || ""}</span
|
|
202
|
+
<span class="text-content ${!displayText ? "placeholder" : ""}">${displayText || this.placeholder || ""}</span>`}
|
|
140
203
|
<u-icon class="suffix-item"
|
|
141
204
|
?hidden=${!this.clearable || !this.value || this.effectivelyDisabled || this.readonly}
|
|
142
205
|
role="button"
|
|
@@ -147,10 +210,18 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
147
210
|
@click=${this.handleClearClick}
|
|
148
211
|
@keydown=${this.handleClearKeydown}
|
|
149
212
|
></u-icon>
|
|
150
|
-
|
|
213
|
+
${textEntry ? html`<u-icon class="suffix-item calendar-button"
|
|
214
|
+
role="button"
|
|
215
|
+
tabindex="-1"
|
|
216
|
+
aria-label=${Locale.getValue("chooseDate")}
|
|
217
|
+
?hidden=${this.effectivelyDisabled || this.readonly}
|
|
151
218
|
lib="internal"
|
|
152
219
|
name="calendar"
|
|
153
|
-
|
|
220
|
+
@click=${this.handleCalendarButtonClick}
|
|
221
|
+
></u-icon>` : html`<u-icon class="suffix-item"
|
|
222
|
+
lib="internal"
|
|
223
|
+
name="calendar"
|
|
224
|
+
></u-icon>`}
|
|
154
225
|
</div>
|
|
155
226
|
</u-field>
|
|
156
227
|
|
|
@@ -159,7 +230,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
159
230
|
role="dialog"
|
|
160
231
|
aria-label=${Locale.getValue("chooseDate")}
|
|
161
232
|
for=".container"
|
|
162
|
-
trigger
|
|
233
|
+
trigger=${textEntry ? "manual" : "click"}
|
|
163
234
|
strategy="fixed"
|
|
164
235
|
placement="bottom-start"
|
|
165
236
|
offset="4"
|
|
@@ -223,10 +294,24 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
223
294
|
if (this.mode === "datetime") this.pendingTime = time;
|
|
224
295
|
if (changed) this.emitChange();
|
|
225
296
|
this.popoverEl?.hide();
|
|
226
|
-
this.containerEl?.focus();
|
|
297
|
+
(this.textInputEl ?? this.containerEl)?.focus();
|
|
298
|
+
}
|
|
299
|
+
get textInputEl() {
|
|
300
|
+
return this.renderRoot.querySelector(".text-input");
|
|
301
|
+
}
|
|
302
|
+
openCalendar(focusGrid) {
|
|
303
|
+
if (this.effectivelyDisabled || this.readonly) return;
|
|
304
|
+
if (this.open) {
|
|
305
|
+
if (focusGrid) this.calendarEl?.focusDay();
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
this.focusCalendarOnOpen = focusGrid;
|
|
309
|
+
if (this.containerEl) this.popoverEl?.show(this.containerEl);
|
|
227
310
|
}
|
|
228
311
|
resetValue() {
|
|
229
312
|
const hadValue = !!this.value;
|
|
313
|
+
this.draft = null;
|
|
314
|
+
this.badText = false;
|
|
230
315
|
this.value = void 0;
|
|
231
316
|
if (hadValue) this.emitChange();
|
|
232
317
|
}
|
|
@@ -240,7 +325,10 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
240
325
|
setValidity() {
|
|
241
326
|
let flags = {};
|
|
242
327
|
let message = "";
|
|
243
|
-
if (this.
|
|
328
|
+
if (this.badText) {
|
|
329
|
+
flags = { badInput: true };
|
|
330
|
+
message = Locale.getValue("badInput");
|
|
331
|
+
} else if (this.required && !this.value) {
|
|
244
332
|
flags = { valueMissing: true };
|
|
245
333
|
message = Locale.getValue("valueMissing");
|
|
246
334
|
} else if (this.value && this.min && splitValue(this.value).date.getTime() < parseISODate(this.min).getTime()) {
|
|
@@ -250,10 +338,12 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
250
338
|
flags = { rangeOverflow: true };
|
|
251
339
|
message = Locale.getValue("rangeOverflow", { max: this.max });
|
|
252
340
|
}
|
|
253
|
-
this.commit(flags, message, this.containerEl ?? void 0);
|
|
341
|
+
this.commit(flags, message, this.textInputEl ?? this.containerEl ?? void 0);
|
|
254
342
|
}
|
|
255
343
|
reset() {
|
|
256
344
|
this.value = void 0;
|
|
345
|
+
this.draft = null;
|
|
346
|
+
this.badText = false;
|
|
257
347
|
this.invalid = false;
|
|
258
348
|
}
|
|
259
349
|
/** `.container`는 div라 네이티브 `disabled`가 없다 — disabled일 때 `tabindex="-1"`로만
|
|
@@ -261,10 +351,10 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
261
351
|
* 네이티브 `disabled` `<input>`에서 얻는 것과 같은 no-op을 여기서 직접 재현한다. */
|
|
262
352
|
focus(options) {
|
|
263
353
|
if (this.effectivelyDisabled) return;
|
|
264
|
-
this.containerEl?.focus(options);
|
|
354
|
+
(this.textInputEl ?? this.containerEl)?.focus(options);
|
|
265
355
|
}
|
|
266
356
|
blur() {
|
|
267
|
-
this.containerEl?.blur();
|
|
357
|
+
(this.textInputEl ?? this.containerEl)?.blur();
|
|
268
358
|
}
|
|
269
359
|
};
|
|
270
360
|
__decorate([property({
|
|
@@ -278,11 +368,17 @@ __decorate([property({
|
|
|
278
368
|
reflect: true
|
|
279
369
|
}), __decorateMetadata("design:type", Boolean)], UDatePicker.prototype, "clearable", void 0);
|
|
280
370
|
__decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDatePicker.prototype, "placeholder", void 0);
|
|
371
|
+
__decorate([property({
|
|
372
|
+
type: String,
|
|
373
|
+
reflect: true
|
|
374
|
+
}), __decorateMetadata("design:type", Object)], UDatePicker.prototype, "format", void 0);
|
|
281
375
|
__decorate([query(".container", true), __decorateMetadata("design:type", typeof HTMLElement === "undefined" ? Object : HTMLElement)], UDatePicker.prototype, "containerEl", void 0);
|
|
282
376
|
__decorate([query("u-popover", true), __decorateMetadata("design:type", typeof UPopover === "undefined" ? Object : UPopover)], UDatePicker.prototype, "popoverEl", void 0);
|
|
283
377
|
__decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDatePicker.prototype, "calendarEl", void 0);
|
|
284
378
|
__decorate([state(), __decorateMetadata("design:type", Boolean)], UDatePicker.prototype, "open", void 0);
|
|
285
379
|
__decorate([state(), __decorateMetadata("design:type", String)], UDatePicker.prototype, "pendingTime", void 0);
|
|
380
|
+
__decorate([state(), __decorateMetadata("design:type", Object)], UDatePicker.prototype, "draft", void 0);
|
|
381
|
+
__decorate([state(), __decorateMetadata("design:type", Object)], UDatePicker.prototype, "badText", void 0);
|
|
286
382
|
UDatePicker = __decorate([customElement("u-date-picker")], UDatePicker);
|
|
287
383
|
//#endregion
|
|
288
384
|
export { UDatePicker };
|
|
@@ -18,6 +18,25 @@ var styles = css`
|
|
|
18
18
|
width: var(--date-picker-popover-width);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
/* mode="date": the trigger is a text box — it takes the container's room and reads like its text. */
|
|
22
|
+
.text-input {
|
|
23
|
+
flex: 1 1 auto;
|
|
24
|
+
min-width: 0;
|
|
25
|
+
border: none;
|
|
26
|
+
outline: none;
|
|
27
|
+
padding: 0;
|
|
28
|
+
margin: 0;
|
|
29
|
+
background: transparent;
|
|
30
|
+
color: inherit;
|
|
31
|
+
font: inherit;
|
|
32
|
+
}
|
|
33
|
+
.text-input::placeholder {
|
|
34
|
+
color: var(--u-txt-color-weak, #616161);
|
|
35
|
+
}
|
|
36
|
+
.calendar-button {
|
|
37
|
+
cursor: pointer;
|
|
38
|
+
}
|
|
39
|
+
|
|
21
40
|
.calendar-time {
|
|
22
41
|
display: flex;
|
|
23
42
|
justify-content: flex-end;
|
package/dist/index.js
CHANGED
|
@@ -26,7 +26,7 @@ import { UCheckbox } from "./components/checkbox/UCheckbox.js";
|
|
|
26
26
|
import { UTag } from "./components/tag/UTag.js";
|
|
27
27
|
import { UChip } from "./components/chip/UChip.js";
|
|
28
28
|
import { UCopyButton } from "./components/copy-button/UCopyButton.js";
|
|
29
|
-
import { formatCurrency, formatDate, formatDateRange, formatNumber, parseNumber } from "./utilities/format.js";
|
|
29
|
+
import { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateText, formatNumber, parseDate, parseNumber } from "./utilities/format.js";
|
|
30
30
|
import { UField } from "./components/field/UField.js";
|
|
31
31
|
import { UPopover } from "./components/popover/UPopover.js";
|
|
32
32
|
import { UDatePicker } from "./components/date-picker/UDatePicker.js";
|
|
@@ -62,4 +62,4 @@ import { Dialog } from "./utilities/Dialog.js";
|
|
|
62
62
|
import { Theme } from "./utilities/Theme.js";
|
|
63
63
|
import { Toast } from "./utilities/Toast.js";
|
|
64
64
|
import { decodeTsv, encodeTsv } from "./utilities/tsv.js";
|
|
65
|
-
export { ALERT_STATUSES, BrowserStorage, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCopyButton, UDatePicker, UDateRangePicker, UDialog, UDivider, UDrawer, UElement, UExpander, UField, UFileInput, UFloatingElement, UForm, UFormControlElement, UIcon, UIconButton, UInput, UMenu, UMenuItem, UOption, UOverlayElement, UPanel, UPopover, UProgressBar, UProgressRing, URadio, URating, USelect, USkeleton, USlider, USpinner, USplitPanel, USwitch, UTab, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, createDevWarner, dateAttrConverter, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseNumber, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
|
|
65
|
+
export { ALERT_STATUSES, BrowserStorage, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCopyButton, UDatePicker, UDateRangePicker, UDialog, UDivider, UDrawer, UElement, UExpander, UField, UFileInput, UFloatingElement, UForm, UFormControlElement, UIcon, UIconButton, UInput, UMenu, UMenuItem, UOption, UOverlayElement, UPanel, UPopover, UProgressBar, UProgressRing, URadio, URating, USelect, USkeleton, USlider, USpinner, USplitPanel, USwitch, UTab, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, createDevWarner, dateAttrConverter, dateTextPattern, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatDateText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, parseNumber, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
|
|
@@ -55,3 +55,29 @@ export declare function formatDateRange(start: Date | string, end: Date | string
|
|
|
55
55
|
* not read. `locale` defaults to the active `Locale`.
|
|
56
56
|
*/
|
|
57
57
|
export declare function parseNumber(text: string, locale?: LocaleTag): number | null;
|
|
58
|
+
/** How a date is written in a text field: ISO `YYYY-MM-DD`, or the locale's numeric order (`10/02/2026`, `02.10.2026`). */
|
|
59
|
+
export type DateTextFormat = 'iso' | 'locale';
|
|
60
|
+
/**
|
|
61
|
+
* Writes an ISO `YYYY-MM-DD` date the way {@link parseDate} reads it back: `iso` keeps it as is;
|
|
62
|
+
* `locale` uses the locale's numeric order with two-digit month and day (`10/02/2026` in `en-US`,
|
|
63
|
+
* `02.10.2026` in `de`). A string that is not an ISO date is returned unchanged.
|
|
64
|
+
*/
|
|
65
|
+
export declare function formatDateText(iso: string, format?: DateTextFormat, locale?: LocaleTag): string;
|
|
66
|
+
/** The pattern a person should type for `format` — `YYYY-MM-DD`, or e.g. `MM/DD/YYYY` for `locale` in `en-US`. */
|
|
67
|
+
export declare function dateTextPattern(format?: DateTextFormat, locale?: LocaleTag): string;
|
|
68
|
+
/**
|
|
69
|
+
* Reads a date the way people type it into a field and returns it as ISO `YYYY-MM-DD`, or `null`
|
|
70
|
+
* when the text is not a real date (`2026-02-30` is `null`). Accepted, whatever `format` is:
|
|
71
|
+
* - `2026-10-02`, `2026/10/02`, `2026.10.02`, `2026. 10. 2.` — a four-digit first part is year-month-day;
|
|
72
|
+
* - `20261002` — eight digits are year, month, day.
|
|
73
|
+
*
|
|
74
|
+
* `format` decides the rest: with `iso`, three parts are year-month-day and two parts (`10-02`)
|
|
75
|
+
* are month-day; with `locale`, both follow the locale's numeric order (`10/02/2026` and `10/02`
|
|
76
|
+
* in `en-US`, `02.10.2026` and `2.10` in `de`). Two parts take the year of `referenceDate`
|
|
77
|
+
* (today by default). Two-digit years are not read.
|
|
78
|
+
*/
|
|
79
|
+
export declare function parseDate(text: string, options?: {
|
|
80
|
+
format?: DateTextFormat;
|
|
81
|
+
locale?: LocaleTag;
|
|
82
|
+
referenceDate?: Date;
|
|
83
|
+
}): string | null;
|
package/dist/utilities/format.js
CHANGED
|
@@ -132,5 +132,93 @@ function parseNumber(text, locale) {
|
|
|
132
132
|
const value = Number(`${negative ? "-" : ""}${digits || "0"}.${fracPart || "0"}`);
|
|
133
133
|
return Number.isFinite(value) ? value : null;
|
|
134
134
|
}
|
|
135
|
+
/** The year/month/day order and separator the locale's numeric date uses (`en-US` → month/day/year · `/`). */
|
|
136
|
+
function numericDateLayout(locale) {
|
|
137
|
+
const parts = new Intl.DateTimeFormat(locale, {
|
|
138
|
+
year: "numeric",
|
|
139
|
+
month: "2-digit",
|
|
140
|
+
day: "2-digit"
|
|
141
|
+
}).formatToParts(new Date(2026, 9, 2));
|
|
142
|
+
return {
|
|
143
|
+
order: parts.filter((p) => p.type === "year" || p.type === "month" || p.type === "day").map((p) => p.type),
|
|
144
|
+
separator: parts.find((p) => p.type === "literal")?.value ?? "-"
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Writes an ISO `YYYY-MM-DD` date the way {@link parseDate} reads it back: `iso` keeps it as is;
|
|
149
|
+
* `locale` uses the locale's numeric order with two-digit month and day (`10/02/2026` in `en-US`,
|
|
150
|
+
* `02.10.2026` in `de`). A string that is not an ISO date is returned unchanged.
|
|
151
|
+
*/
|
|
152
|
+
function formatDateText(iso, format = "iso", locale) {
|
|
153
|
+
const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
|
|
154
|
+
if (!m || format === "iso") return iso;
|
|
155
|
+
return new Intl.DateTimeFormat(locale ?? Locale.get(), {
|
|
156
|
+
year: "numeric",
|
|
157
|
+
month: "2-digit",
|
|
158
|
+
day: "2-digit"
|
|
159
|
+
}).format(new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
|
|
160
|
+
}
|
|
161
|
+
/** The pattern a person should type for `format` — `YYYY-MM-DD`, or e.g. `MM/DD/YYYY` for `locale` in `en-US`. */
|
|
162
|
+
function dateTextPattern(format = "iso", locale) {
|
|
163
|
+
if (format === "iso") return "YYYY-MM-DD";
|
|
164
|
+
const { order, separator } = numericDateLayout(locale ?? Locale.get());
|
|
165
|
+
const token = {
|
|
166
|
+
year: "YYYY",
|
|
167
|
+
month: "MM",
|
|
168
|
+
day: "DD"
|
|
169
|
+
};
|
|
170
|
+
return order.map((p) => token[p]).join(separator);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Reads a date the way people type it into a field and returns it as ISO `YYYY-MM-DD`, or `null`
|
|
174
|
+
* when the text is not a real date (`2026-02-30` is `null`). Accepted, whatever `format` is:
|
|
175
|
+
* - `2026-10-02`, `2026/10/02`, `2026.10.02`, `2026. 10. 2.` — a four-digit first part is year-month-day;
|
|
176
|
+
* - `20261002` — eight digits are year, month, day.
|
|
177
|
+
*
|
|
178
|
+
* `format` decides the rest: with `iso`, three parts are year-month-day and two parts (`10-02`)
|
|
179
|
+
* are month-day; with `locale`, both follow the locale's numeric order (`10/02/2026` and `10/02`
|
|
180
|
+
* in `en-US`, `02.10.2026` and `2.10` in `de`). Two parts take the year of `referenceDate`
|
|
181
|
+
* (today by default). Two-digit years are not read.
|
|
182
|
+
*/
|
|
183
|
+
function parseDate(text, options = {}) {
|
|
184
|
+
const t = text.trim().replace(/\.$/, "");
|
|
185
|
+
if (!t) return null;
|
|
186
|
+
let y, mo, d;
|
|
187
|
+
const compact = /^(\d{4})(\d{2})(\d{2})$/.exec(t);
|
|
188
|
+
const parts = compact ? null : t.split(/\s*[-/.]\s*|\s+/);
|
|
189
|
+
if (compact) [y, mo, d] = [
|
|
190
|
+
Number(compact[1]),
|
|
191
|
+
Number(compact[2]),
|
|
192
|
+
Number(compact[3])
|
|
193
|
+
];
|
|
194
|
+
else {
|
|
195
|
+
if (!parts || parts.some((p) => !/^\d{1,4}$/.test(p))) return null;
|
|
196
|
+
const order = options.format === "locale" ? numericDateLayout(options.locale ?? Locale.get()).order : [
|
|
197
|
+
"year",
|
|
198
|
+
"month",
|
|
199
|
+
"day"
|
|
200
|
+
];
|
|
201
|
+
let layout;
|
|
202
|
+
if (parts.length === 3) layout = parts[0].length === 4 ? [
|
|
203
|
+
"year",
|
|
204
|
+
"month",
|
|
205
|
+
"day"
|
|
206
|
+
] : order;
|
|
207
|
+
else if (parts.length === 2) layout = order.filter((p) => p !== "year");
|
|
208
|
+
else return null;
|
|
209
|
+
const read = {};
|
|
210
|
+
layout.forEach((p, i) => {
|
|
211
|
+
read[p] = parts[i];
|
|
212
|
+
});
|
|
213
|
+
if (read.year !== void 0 && read.year.length !== 4) return null;
|
|
214
|
+
if (read.month.length > 2 || read.day.length > 2) return null;
|
|
215
|
+
y = read.year !== void 0 ? Number(read.year) : (options.referenceDate ?? /* @__PURE__ */ new Date()).getFullYear();
|
|
216
|
+
mo = Number(read.month);
|
|
217
|
+
d = Number(read.day);
|
|
218
|
+
}
|
|
219
|
+
const date = new Date(y, mo - 1, d);
|
|
220
|
+
if (date.getFullYear() !== y || date.getMonth() !== mo - 1 || date.getDate() !== d) return null;
|
|
221
|
+
return `${String(y).padStart(4, "0")}-${String(mo).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
|
|
222
|
+
}
|
|
135
223
|
//#endregion
|
|
136
|
-
export { formatCurrency, formatDate, formatDateRange, formatNumber, parseNumber };
|
|
224
|
+
export { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateText, formatNumber, parseDate, parseNumber };
|
package/package.json
CHANGED
|
@@ -14,6 +14,16 @@ value is unconditionally valid regardless of how coarse the time input was). For
|
|
|
14
14
|
|
|
15
15
|
> The calendar week always starts on Sunday, regardless of locale.
|
|
16
16
|
|
|
17
|
+
**Typing a date (`mode="date"`).** The field is a text box. Type `2026-10-02`, `2026/10/2`,
|
|
18
|
+
`20261002`, or just `10-02` (this year), then press Enter or leave the field. The text shows as
|
|
19
|
+
`YYYY-MM-DD` in every browser language; `format="locale"` shows and reads the locale's numeric
|
|
20
|
+
order instead (`10/02/2026` in `en-US`, `02.10.2026` in `de` — ISO is still read). Clicking the
|
|
21
|
+
field opens the calendar and keeps the caret in the text box; ArrowDown (or Alt+ArrowDown) moves
|
|
22
|
+
into the calendar. Text that is not a date clears the value and reports `badInput` (the text stays
|
|
23
|
+
so it can be fixed); a date outside `min`/`max` is kept and reported as out of range.
|
|
24
|
+
The parser and formatter are exported as `parseDate`, `formatDateText` and `dateTextPattern`.
|
|
25
|
+
`mode="datetime"` keeps the calendar-only trigger.
|
|
26
|
+
|
|
17
27
|
The calendar popover has a footer with a "Today" quick-action button (selects today's date —
|
|
18
28
|
in `mode="datetime"` this also sets the time to right now — disabled when today falls outside
|
|
19
29
|
`min`/`max`) and, when `clearable` and a value is set, a "Clear" button next to it. Picking a
|
|
@@ -41,7 +51,8 @@ day preserves whatever time-of-day was already set; only the "Today" button over
|
|
|
41
51
|
| `min` | `string` | — | — | Minimum selectable date (ISO `YYYY-MM-DD`, date-only in both modes) |
|
|
42
52
|
| `max` | `string` | — | — | Maximum selectable date (ISO `YYYY-MM-DD`, date-only in both modes) |
|
|
43
53
|
| `clearable` | `boolean` | `false` | ✓ | Show clear button |
|
|
44
|
-
| `placeholder` | `string` | — | — | Placeholder text |
|
|
54
|
+
| `placeholder` | `string` | — | — | Placeholder text (defaults to the pattern to type in `mode="date"`, e.g. `YYYY-MM-DD`) |
|
|
55
|
+
| `format` | `'iso' \| 'locale'` | `'iso'` | ✓ | How the `mode="date"` text box writes and reads a date |
|
|
45
56
|
| `disabled` | `boolean` | `false` | ✓ | Disable |
|
|
46
57
|
| `readonly` | `boolean` | `false` | ✓ | Read-only |
|
|
47
58
|
| `required` | `boolean` | `false` | ✓ | Required |
|
|
@@ -55,7 +66,7 @@ day preserves whatever time-of-day was already set; only the "Today" button over
|
|
|
55
66
|
|
|
56
67
|
| Event | Description |
|
|
57
68
|
|-------|-------------|
|
|
58
|
-
| `change` | Fires when the user clicks a date cell, confirms via keyboard, changes the time input (`mode="datetime"`, once a date is set), or clicks the clear button. Programmatic value assignment does not fire it. |
|
|
69
|
+
| `change` | Fires when the user clicks a date cell, confirms via keyboard, commits typed text (Enter or leaving the field, when the value changes), changes the time input (`mode="datetime"`, once a date is set), or clicks the clear button. Programmatic value assignment does not fire it. |
|
|
59
70
|
|
|
60
71
|
## Methods
|
|
61
72
|
|
|
@@ -72,6 +83,7 @@ day preserves whatever time-of-day was already set; only the "Today" button over
|
|
|
72
83
|
|------|-------------|
|
|
73
84
|
| `field` | The `u-field` element |
|
|
74
85
|
| `container` | The element wrapping the trigger area |
|
|
86
|
+
| `input` | The text box (`mode="date"` only) |
|
|
75
87
|
| `popover` | The popover element showing the calendar |
|
|
76
88
|
| `calendar` | The calendar container |
|
|
77
89
|
| `calendar-header` | The month navigation header |
|