@iyulab/components 1.55.0 → 1.56.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 +17 -0
- package/dist/components/date-picker/UDatePicker.d.ts +18 -13
- package/dist/components/date-picker/UDatePicker.js +39 -34
- package/dist/index.js +2 -2
- package/dist/utilities/format.d.ts +14 -0
- package/dist/utilities/format.js +27 -1
- package/package.json +1 -1
- package/skills/iyulab-components/references/components/date-picker.md +7 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.56.0] - 2026-10-03
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **`u-date-picker mode="datetime"` takes a typed date and time.** The field is the same text box as in
|
|
8
|
+
`mode="date"`: type `2026-10-02 14:30` (or `9:05`; seconds are dropped) and press Enter or leave the
|
|
9
|
+
field. It shows `YYYY-MM-DD HH:mm` whatever the browser language (`format="locale"` writes the date
|
|
10
|
+
part in the locale's numeric order). Typing only a date keeps the time already set. An impossible time
|
|
11
|
+
(`25:00`) clears the value and reports `badInput`. The value is still a full ISO-8601 `DateTimeOffset`.
|
|
12
|
+
- **`parseDateTime`, `formatDateTimeText`** next to `parseDate`.
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
|
|
16
|
+
- **`u-date-picker mode="datetime"`: the trigger text is `YYYY-MM-DD HH:mm`** (was the locale's medium
|
|
17
|
+
date and short time, e.g. `Oct 2, 2026, 2:30 PM`), and a click keeps focus in the text box — the same
|
|
18
|
+
as `mode="date"` since 1.55.0.
|
|
19
|
+
|
|
3
20
|
## [1.55.0] - 2026-10-03
|
|
4
21
|
|
|
5
22
|
### Added
|
|
@@ -6,12 +6,13 @@ import { UPopover } from '../popover/UPopover.js';
|
|
|
6
6
|
export type DatePickerMode = 'date' | 'datetime';
|
|
7
7
|
/**
|
|
8
8
|
* A single-date(-time)-selection form control. In `mode="date"` (default) the value follows
|
|
9
|
-
* the same convention as the native `input[type=date]`: an ISO `YYYY-MM-DD` string
|
|
10
|
-
*
|
|
11
|
-
* leave the field; the calendar is a
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
9
|
+
* the same convention as the native `input[type=date]`: an ISO `YYYY-MM-DD` string. The field is a
|
|
10
|
+
* text box in both modes — type `2026-10-02`, `20261002` or `10-02` (this year), plus a time
|
|
11
|
+
* (`2026-10-02 14:30`) in `mode="datetime"`, and press Enter or leave the field; the calendar is a
|
|
12
|
+
* helper. The text shows as `YYYY-MM-DD` (`YYYY-MM-DD HH:mm`) whatever the browser language, or in
|
|
13
|
+
* the locale's numeric order with `format="locale"`. Clicking the field opens the calendar and keeps
|
|
14
|
+
* typing in the field; ArrowDown (or Alt+ArrowDown) moves into the calendar. Text that is not a date
|
|
15
|
+
* clears the value and reports `badInput`, like the native input. In
|
|
15
16
|
* `mode="datetime"` the value is a complete ISO-8601 `DateTimeOffset` string
|
|
16
17
|
* (`YYYY-MM-DDTHH:mm:ss±HH:mm`) — the component always fills in seconds and the browser's
|
|
17
18
|
* local UTC offset, so the value is unconditionally valid regardless of how coarse the time
|
|
@@ -29,7 +30,7 @@ export type DatePickerMode = 'date' | 'datetime';
|
|
|
29
30
|
* as a CSS hook for consumers who want to react to the open/closed state from outside.
|
|
30
31
|
*
|
|
31
32
|
* @csspart field - the u-field element
|
|
32
|
-
* @csspart input - the text box
|
|
33
|
+
* @csspart input - the text box
|
|
33
34
|
* @csspart container - the element wrapping the trigger area
|
|
34
35
|
* @csspart popover - the popover element showing the calendar
|
|
35
36
|
* @csspart calendar - the calendar container
|
|
@@ -66,12 +67,13 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
66
67
|
max?: string;
|
|
67
68
|
/** Whether to show the clear button */
|
|
68
69
|
clearable: boolean;
|
|
69
|
-
/** Placeholder text (shown
|
|
70
|
-
*
|
|
70
|
+
/** Placeholder text (shown when there is no value). Defaults to the pattern to type
|
|
71
|
+
* (`YYYY-MM-DD`, or `YYYY-MM-DD HH:mm` in `mode="datetime"`). */
|
|
71
72
|
placeholder?: string;
|
|
72
|
-
/** How the
|
|
73
|
-
*
|
|
74
|
-
*
|
|
73
|
+
/** How the text box writes and reads the date: `iso` (default, `YYYY-MM-DD` in every language)
|
|
74
|
+
* or `locale` (the active locale's numeric order, e.g. `10/02/2026` in `en-US`). ISO and
|
|
75
|
+
* `20261002` are read in both. The time, in `mode="datetime"`, is always `HH:mm`. The value is
|
|
76
|
+
* ISO either way. */
|
|
75
77
|
format: DateTextFormat;
|
|
76
78
|
containerEl?: HTMLElement;
|
|
77
79
|
popoverEl?: UPopover;
|
|
@@ -82,7 +84,7 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
82
84
|
/** Time-of-day for the next selection while no `value` exists yet (`mode="datetime"` only) —
|
|
83
85
|
* once `value` is set, the time input reads/writes its time portion directly instead. */
|
|
84
86
|
private pendingTime;
|
|
85
|
-
/** What the person is typing in the
|
|
87
|
+
/** What the person is typing in the text box, until it is committed; `null` shows the value. */
|
|
86
88
|
private draft;
|
|
87
89
|
/** The committed text was not a date — the value is empty and validity reports `badInput`. */
|
|
88
90
|
private badText;
|
|
@@ -107,6 +109,9 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
107
109
|
private handleDaySelect;
|
|
108
110
|
private get textInputEl();
|
|
109
111
|
private openCalendar;
|
|
112
|
+
/** The typed text as a date (ISO) and, in `mode="datetime"`, a time — or `null` when it is not one.
|
|
113
|
+
* Typing only a date in `mode="datetime"` keeps the time already set (or the pending one). */
|
|
114
|
+
private parseTyped;
|
|
110
115
|
private handleTextInput;
|
|
111
116
|
/** A click anywhere on the field (not on its clear or calendar button) opens the calendar and
|
|
112
117
|
* puts the caret in the text box — the person can pick a day or keep typing. */
|
|
@@ -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 { dateTextPattern,
|
|
7
|
+
import { dateTextPattern, formatDateText, formatDateTimeText, parseDate, parseDateTime } 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";
|
|
@@ -66,8 +66,8 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
66
66
|
};
|
|
67
67
|
this.handleTextInput = (e) => {
|
|
68
68
|
this.draft = e.target.value;
|
|
69
|
-
const typed =
|
|
70
|
-
if (typed && this.open) this.calendarEl?.showDate(typed);
|
|
69
|
+
const typed = this.parseTyped(this.draft);
|
|
70
|
+
if (typed && this.open) this.calendarEl?.showDate(typed.date);
|
|
71
71
|
};
|
|
72
72
|
this.handleContainerClick = (e) => {
|
|
73
73
|
if (e.target.closest?.("u-icon")) return;
|
|
@@ -92,9 +92,10 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
92
92
|
this.commitText = () => {
|
|
93
93
|
if (this.draft === null) return;
|
|
94
94
|
const text = this.draft;
|
|
95
|
-
const
|
|
96
|
-
this.badText = !!text.trim() &&
|
|
97
|
-
const next =
|
|
95
|
+
const typed = this.parseTyped(text);
|
|
96
|
+
this.badText = !!text.trim() && typed === null;
|
|
97
|
+
const next = typed ? buildValue(parseISODate(typed.date), this.mode, typed.time) : void 0;
|
|
98
|
+
if (typed && this.mode === "datetime") this.pendingTime = typed.time;
|
|
98
99
|
const changed = next !== this.value;
|
|
99
100
|
this.value = next;
|
|
100
101
|
this.draft = this.badText ? text : null;
|
|
@@ -148,19 +149,16 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
148
149
|
if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
|
|
149
150
|
if (changed.has("open") && this.open) {
|
|
150
151
|
const calendar = this.calendarEl;
|
|
151
|
-
const base = (this.draft !== null ?
|
|
152
|
+
const base = (this.draft !== null ? this.parseTyped(this.draft)?.date : void 0) ?? (this.value ? toISODate(splitValue(this.value).date) : toISODate(/* @__PURE__ */ new Date()));
|
|
152
153
|
calendar?.showDate(base);
|
|
153
|
-
const moveFocus = this.
|
|
154
|
+
const moveFocus = this.focusCalendarOnOpen;
|
|
154
155
|
this.focusCalendarOnOpen = false;
|
|
155
156
|
if (moveFocus) this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
|
|
156
157
|
}
|
|
157
158
|
}
|
|
158
159
|
render() {
|
|
159
|
-
const
|
|
160
|
-
|
|
161
|
-
timeStyle: "short"
|
|
162
|
-
} : void 0) : "";
|
|
163
|
-
const textEntry = this.mode === "date";
|
|
160
|
+
const datetime = this.mode === "datetime";
|
|
161
|
+
const shown = this.value ? datetime ? formatDateTimeText(`${toISODate(splitValue(this.value).date)}T${splitValue(this.value).time}`, this.format) : formatDateText(toISODate(splitValue(this.value).date), this.format) : "";
|
|
164
162
|
return html`
|
|
165
163
|
<u-field part="field"
|
|
166
164
|
?required=${this.required}
|
|
@@ -170,10 +168,10 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
170
168
|
.description=${this.description}
|
|
171
169
|
.validationMessage=${this.validationMessage}
|
|
172
170
|
>
|
|
173
|
-
|
|
171
|
+
<div class="container" part="container" @click=${this.handleContainerClick}>
|
|
174
172
|
<input class="text-input" part="input"
|
|
175
173
|
type="text"
|
|
176
|
-
inputmode
|
|
174
|
+
inputmode=${datetime ? "text" : "numeric"}
|
|
177
175
|
autocomplete="off"
|
|
178
176
|
role="combobox"
|
|
179
177
|
aria-haspopup="dialog"
|
|
@@ -182,24 +180,14 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
182
180
|
aria-label=${ifDefined(this.resolvedAriaLabel)}
|
|
183
181
|
aria-description=${ifDefined(this.resolvedAriaDescription)}
|
|
184
182
|
aria-invalid=${this.badText ? "true" : "false"}
|
|
185
|
-
placeholder=${this.placeholder ?? dateTextPattern(this.format)}
|
|
186
|
-
.value=${this.draft ??
|
|
183
|
+
placeholder=${this.placeholder ?? (datetime ? `${dateTextPattern(this.format)} HH:mm` : dateTextPattern(this.format))}
|
|
184
|
+
.value=${this.draft ?? shown}
|
|
187
185
|
?disabled=${this.effectivelyDisabled}
|
|
188
186
|
?readonly=${this.readonly}
|
|
189
187
|
@input=${this.handleTextInput}
|
|
190
188
|
@keydown=${this.handleTextKeydown}
|
|
191
189
|
@blur=${this.commitText}
|
|
192
|
-
|
|
193
|
-
tabindex=${this.effectivelyDisabled ? "-1" : "0"}
|
|
194
|
-
role="combobox"
|
|
195
|
-
aria-disabled=${ifDefined(this.effectivelyDisabled ? "true" : void 0)}
|
|
196
|
-
aria-haspopup="dialog"
|
|
197
|
-
aria-expanded=${this.open}
|
|
198
|
-
aria-label=${ifDefined(this.resolvedAriaLabel)}
|
|
199
|
-
aria-description=${ifDefined(this.resolvedAriaDescription)}
|
|
200
|
-
aria-controls=${this.calendarId}
|
|
201
|
-
>
|
|
202
|
-
<span class="text-content ${!displayText ? "placeholder" : ""}">${displayText || this.placeholder || ""}</span>`}
|
|
190
|
+
/>
|
|
203
191
|
<u-icon class="suffix-item"
|
|
204
192
|
?hidden=${!this.clearable || !this.value || this.effectivelyDisabled || this.readonly}
|
|
205
193
|
role="button"
|
|
@@ -210,7 +198,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
210
198
|
@click=${this.handleClearClick}
|
|
211
199
|
@keydown=${this.handleClearKeydown}
|
|
212
200
|
></u-icon>
|
|
213
|
-
|
|
201
|
+
<u-icon class="suffix-item calendar-button"
|
|
214
202
|
role="button"
|
|
215
203
|
tabindex="-1"
|
|
216
204
|
aria-label=${Locale.getValue("chooseDate")}
|
|
@@ -218,10 +206,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
218
206
|
lib="internal"
|
|
219
207
|
name="calendar"
|
|
220
208
|
@click=${this.handleCalendarButtonClick}
|
|
221
|
-
></u-icon
|
|
222
|
-
lib="internal"
|
|
223
|
-
name="calendar"
|
|
224
|
-
></u-icon>`}
|
|
209
|
+
></u-icon>
|
|
225
210
|
</div>
|
|
226
211
|
</u-field>
|
|
227
212
|
|
|
@@ -230,7 +215,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
230
215
|
role="dialog"
|
|
231
216
|
aria-label=${Locale.getValue("chooseDate")}
|
|
232
217
|
for=".container"
|
|
233
|
-
trigger
|
|
218
|
+
trigger="manual"
|
|
234
219
|
strategy="fixed"
|
|
235
220
|
placement="bottom-start"
|
|
236
221
|
offset="4"
|
|
@@ -308,6 +293,26 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
308
293
|
this.focusCalendarOnOpen = focusGrid;
|
|
309
294
|
if (this.containerEl) this.popoverEl?.show(this.containerEl);
|
|
310
295
|
}
|
|
296
|
+
/** The typed text as a date (ISO) and, in `mode="datetime"`, a time — or `null` when it is not one.
|
|
297
|
+
* Typing only a date in `mode="datetime"` keeps the time already set (or the pending one). */
|
|
298
|
+
parseTyped(text) {
|
|
299
|
+
if (this.mode !== "datetime") {
|
|
300
|
+
const date = parseDate(text, { format: this.format });
|
|
301
|
+
return date ? {
|
|
302
|
+
date,
|
|
303
|
+
time: this.pendingTime
|
|
304
|
+
} : null;
|
|
305
|
+
}
|
|
306
|
+
const keep = this.value ? splitValue(this.value).time : this.pendingTime;
|
|
307
|
+
const dt = parseDateTime(text, {
|
|
308
|
+
format: this.format,
|
|
309
|
+
defaultTime: keep
|
|
310
|
+
});
|
|
311
|
+
return dt ? {
|
|
312
|
+
date: dt.slice(0, 10),
|
|
313
|
+
time: dt.slice(11, 16)
|
|
314
|
+
} : null;
|
|
315
|
+
}
|
|
311
316
|
resetValue() {
|
|
312
317
|
const hadValue = !!this.value;
|
|
313
318
|
this.draft = null;
|
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 { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateText, formatNumber, parseDate, parseNumber } from "./utilities/format.js";
|
|
29
|
+
import { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateText, formatDateTimeText, formatNumber, parseDate, parseDateTime, 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, dateTextPattern, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatDateText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, 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, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, parseDateTime, parseNumber, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
|
|
@@ -81,3 +81,17 @@ export declare function parseDate(text: string, options?: {
|
|
|
81
81
|
locale?: LocaleTag;
|
|
82
82
|
referenceDate?: Date;
|
|
83
83
|
}): string | null;
|
|
84
|
+
/**
|
|
85
|
+
* Reads a date and a time of day as people type them and returns local `YYYY-MM-DDTHH:mm`, or `null`.
|
|
86
|
+
* The date part is anything {@link parseDate} reads; the time follows a space or `T` as `HH:mm`
|
|
87
|
+
* (`9:05`, `09:05`, `09:05:30` — seconds are dropped). Text with only a date takes `defaultTime`
|
|
88
|
+
* (`00:00` unless given). An hour above 23 or a minute above 59 is `null`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function parseDateTime(text: string, options?: {
|
|
91
|
+
format?: DateTextFormat;
|
|
92
|
+
locale?: LocaleTag;
|
|
93
|
+
referenceDate?: Date;
|
|
94
|
+
defaultTime?: string;
|
|
95
|
+
}): string | null;
|
|
96
|
+
/** Writes local `YYYY-MM-DDTHH:mm` (or a longer ISO date-time) as `{date} HH:mm`, the date part as {@link formatDateText} writes it. */
|
|
97
|
+
export declare function formatDateTimeText(isoLocal: string, format?: DateTextFormat, locale?: LocaleTag): string;
|
package/dist/utilities/format.js
CHANGED
|
@@ -220,5 +220,31 @@ function parseDate(text, options = {}) {
|
|
|
220
220
|
if (date.getFullYear() !== y || date.getMonth() !== mo - 1 || date.getDate() !== d) return null;
|
|
221
221
|
return `${String(y).padStart(4, "0")}-${String(mo).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
|
|
222
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Reads a date and a time of day as people type them and returns local `YYYY-MM-DDTHH:mm`, or `null`.
|
|
225
|
+
* The date part is anything {@link parseDate} reads; the time follows a space or `T` as `HH:mm`
|
|
226
|
+
* (`9:05`, `09:05`, `09:05:30` — seconds are dropped). Text with only a date takes `defaultTime`
|
|
227
|
+
* (`00:00` unless given). An hour above 23 or a minute above 59 is `null`.
|
|
228
|
+
*/
|
|
229
|
+
function parseDateTime(text, options = {}) {
|
|
230
|
+
const t = text.trim();
|
|
231
|
+
const m = /^(.*?)(?:[T\s]+(\d{1,2}):(\d{2})(?::\d{2})?)?$/.exec(t);
|
|
232
|
+
if (!m) return null;
|
|
233
|
+
const date = parseDate(m[1], options);
|
|
234
|
+
if (!date) return null;
|
|
235
|
+
if (m[2] === void 0) {
|
|
236
|
+
const fallback = options.defaultTime ?? "00:00";
|
|
237
|
+
return /^\d{2}:\d{2}$/.test(fallback) ? `${date}T${fallback}` : null;
|
|
238
|
+
}
|
|
239
|
+
const h = Number(m[2]);
|
|
240
|
+
const min = Number(m[3]);
|
|
241
|
+
if (h > 23 || min > 59) return null;
|
|
242
|
+
return `${date}T${String(h).padStart(2, "0")}:${String(min).padStart(2, "0")}`;
|
|
243
|
+
}
|
|
244
|
+
/** Writes local `YYYY-MM-DDTHH:mm` (or a longer ISO date-time) as `{date} HH:mm`, the date part as {@link formatDateText} writes it. */
|
|
245
|
+
function formatDateTimeText(isoLocal, format = "iso", locale) {
|
|
246
|
+
const m = /^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/.exec(isoLocal);
|
|
247
|
+
return m ? `${formatDateText(m[1], format, locale)} ${m[2]}` : isoLocal;
|
|
248
|
+
}
|
|
223
249
|
//#endregion
|
|
224
|
-
export { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateText, formatNumber, parseDate, parseNumber };
|
|
250
|
+
export { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateText, formatDateTimeText, formatNumber, parseDate, parseDateTime, parseNumber };
|
package/package.json
CHANGED
|
@@ -21,8 +21,10 @@ order instead (`10/02/2026` in `en-US`, `02.10.2026` in `de` — ISO is still re
|
|
|
21
21
|
field opens the calendar and keeps the caret in the text box; ArrowDown (or Alt+ArrowDown) moves
|
|
22
22
|
into the calendar. Text that is not a date clears the value and reports `badInput` (the text stays
|
|
23
23
|
so it can be fixed); a date outside `min`/`max` is kept and reported as out of range.
|
|
24
|
-
|
|
25
|
-
`
|
|
24
|
+
In `mode="datetime"` the text box takes a time after the date (`2026-10-02 14:30`, `9:05`, seconds
|
|
25
|
+
dropped) and shows `YYYY-MM-DD HH:mm`; typing only a date keeps the time already set.
|
|
26
|
+
The parser and formatter are exported as `parseDate`, `parseDateTime`, `formatDateText`,
|
|
27
|
+
`formatDateTimeText` and `dateTextPattern`.
|
|
26
28
|
|
|
27
29
|
The calendar popover has a footer with a "Today" quick-action button (selects today's date —
|
|
28
30
|
in `mode="datetime"` this also sets the time to right now — disabled when today falls outside
|
|
@@ -51,8 +53,8 @@ day preserves whatever time-of-day was already set; only the "Today" button over
|
|
|
51
53
|
| `min` | `string` | — | — | Minimum selectable date (ISO `YYYY-MM-DD`, date-only in both modes) |
|
|
52
54
|
| `max` | `string` | — | — | Maximum selectable date (ISO `YYYY-MM-DD`, date-only in both modes) |
|
|
53
55
|
| `clearable` | `boolean` | `false` | ✓ | Show clear button |
|
|
54
|
-
| `placeholder` | `string` | — | — | Placeholder text (defaults to the pattern to type
|
|
55
|
-
| `format` | `'iso' \| 'locale'` | `'iso'` | ✓ | How the
|
|
56
|
+
| `placeholder` | `string` | — | — | Placeholder text (defaults to the pattern to type, e.g. `YYYY-MM-DD` or `YYYY-MM-DD HH:mm`) |
|
|
57
|
+
| `format` | `'iso' \| 'locale'` | `'iso'` | ✓ | How the text box writes and reads the date part |
|
|
56
58
|
| `disabled` | `boolean` | `false` | ✓ | Disable |
|
|
57
59
|
| `readonly` | `boolean` | `false` | ✓ | Read-only |
|
|
58
60
|
| `required` | `boolean` | `false` | ✓ | Required |
|
|
@@ -83,7 +85,7 @@ day preserves whatever time-of-day was already set; only the "Today" button over
|
|
|
83
85
|
|------|-------------|
|
|
84
86
|
| `field` | The `u-field` element |
|
|
85
87
|
| `container` | The element wrapping the trigger area |
|
|
86
|
-
| `input` | The text box
|
|
88
|
+
| `input` | The text box |
|
|
87
89
|
| `popover` | The popover element showing the calendar |
|
|
88
90
|
| `calendar` | The calendar container |
|
|
89
91
|
| `calendar-header` | The month navigation header |
|