@iyulab/components 1.53.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 +74 -0
- package/README.md +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/decorate.js +1 -1
- package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/decorateMetadata.js +1 -1
- package/dist/assets/locales/ar.json.js +23 -1
- package/dist/assets/locales/de.json.js +23 -1
- package/dist/assets/locales/en.json.js +23 -1
- package/dist/assets/locales/es.json.js +23 -1
- package/dist/assets/locales/fr.json.js +23 -1
- package/dist/assets/locales/id.json.js +23 -1
- package/dist/assets/locales/ja.json.js +23 -1
- package/dist/assets/locales/ko.json.js +23 -1
- package/dist/assets/locales/pt-BR.json.js +23 -1
- package/dist/assets/locales/ru.json.js +23 -1
- package/dist/assets/locales/th.json.js +23 -1
- package/dist/assets/locales/vi.json.js +23 -1
- package/dist/assets/locales/zh-CN.json.js +23 -1
- package/dist/assets/locales/zh-TW.json.js +23 -1
- package/dist/components/UFloatingElement.js +2 -2
- package/dist/components/UFormControlElement.js +2 -2
- package/dist/components/UOverlayElement.js +2 -2
- package/dist/components/alert/UAlert.js +2 -2
- package/dist/components/avatar/UAvatar.js +2 -2
- package/dist/components/badge/UBadge.js +2 -2
- package/dist/components/breadcrumb/UBreadcrumb.js +1 -1
- package/dist/components/breadcrumb-item/UBreadcrumbItem.js +2 -2
- package/dist/components/button/UButton.js +2 -2
- package/dist/components/button-group/UButtonGroup.js +2 -2
- package/dist/components/calendar/UCalendar.d.ts +101 -0
- package/dist/components/calendar/UCalendar.js +223 -0
- package/dist/components/calendar/UCalendar.styles.d.ts +1 -0
- package/dist/components/calendar/UCalendar.styles.js +137 -0
- package/dist/components/calendar/dates.d.ts +13 -0
- package/dist/components/calendar/dates.js +37 -0
- package/dist/components/calendar/picker.styles.d.ts +5 -0
- package/dist/components/calendar/picker.styles.js +78 -0
- package/dist/components/card/UCard.js +2 -2
- package/dist/components/carousel/UCarousel.js +2 -2
- package/dist/components/checkbox/UCheckbox.js +2 -2
- package/dist/components/chip/UChip.js +2 -2
- package/dist/components/copy-button/UCopyButton.js +2 -2
- package/dist/components/date-picker/UDatePicker.d.ts +43 -15
- package/dist/components/date-picker/UDatePicker.js +142 -175
- package/dist/components/date-picker/UDatePicker.styles.js +13 -129
- package/dist/components/date-range-picker/UDateRangePicker.d.ts +113 -0
- package/dist/components/date-range-picker/UDateRangePicker.js +276 -0
- package/dist/components/date-range-picker/UDateRangePicker.styles.d.ts +1 -0
- package/dist/components/date-range-picker/UDateRangePicker.styles.js +83 -0
- package/dist/components/date-range-picker/presets.d.ts +32 -0
- package/dist/components/date-range-picker/presets.js +78 -0
- package/dist/components/dialog/UDialog.js +2 -2
- package/dist/components/divider/UDivider.js +2 -2
- package/dist/components/drawer/UDrawer.js +2 -2
- package/dist/components/expander/UExpander.js +2 -2
- package/dist/components/field/UField.js +2 -2
- package/dist/components/file-input/UFileInput.js +2 -2
- package/dist/components/form/UForm.js +2 -2
- package/dist/components/icon/UIcon.js +2 -2
- package/dist/components/icon-button/UIconButton.js +2 -2
- package/dist/components/input/UInput.d.ts +31 -3
- package/dist/components/input/UInput.js +131 -24
- package/dist/components/menu/UMenu.js +2 -2
- package/dist/components/menu-item/UMenuItem.js +2 -2
- package/dist/components/option/UOption.js +2 -2
- package/dist/components/panel/UPanel.js +2 -2
- package/dist/components/popover/UPopover.js +2 -2
- package/dist/components/progress-bar/UProgressBar.js +2 -2
- package/dist/components/progress-ring/UProgressRing.js +2 -2
- package/dist/components/radio/URadio.js +2 -2
- package/dist/components/rating/URating.js +2 -2
- package/dist/components/select/USelect.js +2 -2
- package/dist/components/skeleton/USkeleton.js +2 -2
- package/dist/components/slider/USlider.js +2 -2
- package/dist/components/spinner/USpinner.js +2 -2
- package/dist/components/split-panel/USplitPanel.js +2 -2
- package/dist/components/switch/USwitch.js +2 -2
- package/dist/components/tab/UTab.js +2 -2
- package/dist/components/tab-panel/UTabPanel.js +2 -2
- package/dist/components/tag/UTag.js +2 -2
- package/dist/components/text/UText.js +2 -2
- package/dist/components/textarea/UTextarea.js +2 -2
- package/dist/components/tooltip/UTooltip.js +2 -2
- package/dist/components/tree/UTree.js +2 -2
- package/dist/components/tree-item/UTreeItem.js +2 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -2
- package/dist/plugins/vite-plugin-react-wrapper.d.ts +7 -0
- package/dist/plugins/vite-plugin-react-wrapper.js +11 -1
- package/dist/react/UDateRangePicker.d.ts +13 -0
- package/dist/react/UDateRangePicker.js +12 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/utilities/Locale.d.ts +1 -1
- package/dist/utilities/format.d.ts +53 -0
- package/dist/utilities/format.js +159 -1
- package/package.json +1 -1
- package/skills/iyulab-components/SKILL.md +1 -0
- package/skills/iyulab-components/references/components/date-picker.md +16 -2
- package/skills/iyulab-components/references/components/date-range-picker.md +147 -0
- package/skills/iyulab-components/references/components/input.md +14 -4
|
@@ -1,40 +1,20 @@
|
|
|
1
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
1
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
2
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
3
3
|
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 "
|
|
7
|
+
import { dateTextPattern, formatDate, formatDateText, parseDate } from "../../utilities/format.js";
|
|
8
|
+
import { isOutOfRange, parseISODate, toISODate } from "../calendar/dates.js";
|
|
9
|
+
import { UCalendar } from "../calendar/UCalendar.js";
|
|
8
10
|
import "../field/UField.js";
|
|
9
11
|
import { UPopover } from "../popover/UPopover.js";
|
|
10
|
-
import {
|
|
11
|
-
import { styles } from "./UDatePicker.styles.js";
|
|
12
|
+
import { styles } from "../calendar/picker.styles.js";
|
|
13
|
+
import { styles as styles$1 } from "./UDatePicker.styles.js";
|
|
12
14
|
import { html } from "lit";
|
|
13
15
|
import { customElement, property, query, state } from "lit/decorators.js";
|
|
14
16
|
import { ifDefined } from "lit/directives/if-defined.js";
|
|
15
17
|
//#region src/components/date-picker/UDatePicker.ts
|
|
16
|
-
function parseISODate(iso) {
|
|
17
|
-
const [y, m, d] = iso.split("-").map(Number);
|
|
18
|
-
return new Date(y, m - 1, d);
|
|
19
|
-
}
|
|
20
|
-
function toISODate(date) {
|
|
21
|
-
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
22
|
-
}
|
|
23
|
-
function isSameDay(a, b) {
|
|
24
|
-
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
25
|
-
}
|
|
26
|
-
function startOfMonth(date) {
|
|
27
|
-
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
28
|
-
}
|
|
29
|
-
function addMonths(date, delta) {
|
|
30
|
-
return new Date(date.getFullYear(), date.getMonth() + delta, 1);
|
|
31
|
-
}
|
|
32
|
-
function addDays(date, delta) {
|
|
33
|
-
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + delta);
|
|
34
|
-
}
|
|
35
|
-
function daysInMonth(date) {
|
|
36
|
-
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
37
|
-
}
|
|
38
18
|
/** `±HH:mm` for the browser's local timezone at `date` (DST-aware — recomputed per date,
|
|
39
19
|
* not cached — `getTimezoneOffset()`'s sign is the inverse of the ISO-8601 offset sign). */
|
|
40
20
|
function getLocalOffset(date) {
|
|
@@ -60,38 +40,18 @@ function splitValue(value) {
|
|
|
60
40
|
time: match ? match[1] : "00:00"
|
|
61
41
|
};
|
|
62
42
|
}
|
|
63
|
-
/** Cells to render for the calendar grid — leading `null`s pad the previous month's weekday offset. */
|
|
64
|
-
function buildMonthGrid(viewDate) {
|
|
65
|
-
const startOffset = startOfMonth(viewDate).getDay();
|
|
66
|
-
const total = daysInMonth(viewDate);
|
|
67
|
-
const cells = [];
|
|
68
|
-
for (let i = 0; i < startOffset; i++) cells.push(null);
|
|
69
|
-
for (let d = 1; d <= total; d++) cells.push(new Date(viewDate.getFullYear(), viewDate.getMonth(), d));
|
|
70
|
-
return cells;
|
|
71
|
-
}
|
|
72
|
-
/** Splits the flat cell list into 7-day weeks — the `role="row"` grouping the APG grid pattern expects. */
|
|
73
|
-
function chunkWeeks(cells) {
|
|
74
|
-
const weeks = [];
|
|
75
|
-
for (let i = 0; i < cells.length; i += 7) weeks.push(cells.slice(i, i + 7));
|
|
76
|
-
return weeks;
|
|
77
|
-
}
|
|
78
|
-
/** 2023-01-01 was a Sunday — a fixed reference date that always yields Sun..Sat order regardless of today. */
|
|
79
|
-
function getWeekdayLabels(locale) {
|
|
80
|
-
const formatter = new Intl.DateTimeFormat(locale ?? Locale.get(), { weekday: "narrow" });
|
|
81
|
-
const sunday = new Date(2023, 0, 1);
|
|
82
|
-
return Array.from({ length: 7 }, (_, i) => formatter.format(addDays(sunday, i)));
|
|
83
|
-
}
|
|
84
43
|
var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
85
44
|
constructor(..._args) {
|
|
86
45
|
super(..._args);
|
|
87
46
|
this.mode = "date";
|
|
88
47
|
this.clearable = false;
|
|
48
|
+
this.format = "iso";
|
|
89
49
|
this.calendarId = `u-date-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
|
|
90
50
|
this.open = false;
|
|
91
|
-
this.viewDate = startOfMonth(/* @__PURE__ */ new Date());
|
|
92
|
-
this.focusedDate = /* @__PURE__ */ new Date();
|
|
93
51
|
this.pendingTime = "00:00";
|
|
94
|
-
this.
|
|
52
|
+
this.draft = null;
|
|
53
|
+
this.badText = false;
|
|
54
|
+
this.focusCalendarOnOpen = false;
|
|
95
55
|
this.handleTimeChange = (e) => {
|
|
96
56
|
const time = e.target.value || "00:00";
|
|
97
57
|
this.pendingTime = time;
|
|
@@ -101,51 +61,54 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
101
61
|
this.value = iso;
|
|
102
62
|
if (changed) this.emitChange();
|
|
103
63
|
};
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
64
|
+
this.handleDaySelect = (e) => {
|
|
65
|
+
this.selectDay(parseISODate(e.detail.date));
|
|
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
|
+
};
|
|
104
|
+
this.handleCalendarKeydown = (e) => {
|
|
105
|
+
if (e.key !== "Escape") return;
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
this.popoverEl?.hide();
|
|
108
|
+
(this.textInputEl ?? this.containerEl)?.focus();
|
|
142
109
|
};
|
|
143
110
|
this.handlePopoverShow = () => {
|
|
144
111
|
this.open = true;
|
|
145
|
-
this.grabFocusOnUpdate = true;
|
|
146
|
-
const base = this.value ? splitValue(this.value).date : /* @__PURE__ */ new Date();
|
|
147
|
-
this.viewDate = startOfMonth(base);
|
|
148
|
-
this.focusedDate = base;
|
|
149
112
|
};
|
|
150
113
|
this.handlePopoverHide = () => {
|
|
151
114
|
this.open = false;
|
|
@@ -154,7 +117,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
154
117
|
e.preventDefault();
|
|
155
118
|
e.stopPropagation();
|
|
156
119
|
this.resetValue();
|
|
157
|
-
this.containerEl?.focus();
|
|
120
|
+
(this.textInputEl ?? this.containerEl)?.focus();
|
|
158
121
|
};
|
|
159
122
|
this.handleTodayClick = () => {
|
|
160
123
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -164,7 +127,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
164
127
|
this.handleFooterResetClick = () => {
|
|
165
128
|
this.resetValue();
|
|
166
129
|
this.popoverEl?.hide();
|
|
167
|
-
this.containerEl?.focus();
|
|
130
|
+
(this.textInputEl ?? this.containerEl)?.focus();
|
|
168
131
|
};
|
|
169
132
|
this.handleClearKeydown = (e) => {
|
|
170
133
|
if (e.key !== "Enter" && e.key !== " ") return;
|
|
@@ -173,15 +136,23 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
173
136
|
};
|
|
174
137
|
}
|
|
175
138
|
static {
|
|
176
|
-
this.styles = [
|
|
139
|
+
this.styles = [
|
|
140
|
+
super.styles,
|
|
141
|
+
styles,
|
|
142
|
+
styles$1
|
|
143
|
+
];
|
|
177
144
|
}
|
|
178
145
|
updated(changed) {
|
|
179
146
|
super.updated(changed);
|
|
180
147
|
if (changed.has("value")) this.internals?.setFormValue(this.value ?? "");
|
|
181
148
|
if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
|
|
182
|
-
if (changed.has("open") && this.open
|
|
183
|
-
|
|
184
|
-
this.
|
|
149
|
+
if (changed.has("open") && this.open) {
|
|
150
|
+
const calendar = this.calendarEl;
|
|
151
|
+
const base = (this.draft !== null ? parseDate(this.draft, { format: this.format }) : null) ?? (this.value ? toISODate(splitValue(this.value).date) : toISODate(/* @__PURE__ */ new Date()));
|
|
152
|
+
calendar?.showDate(base);
|
|
153
|
+
const moveFocus = this.mode !== "date" || this.focusCalendarOnOpen;
|
|
154
|
+
this.focusCalendarOnOpen = false;
|
|
155
|
+
if (moveFocus) this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
|
|
185
156
|
}
|
|
186
157
|
}
|
|
187
158
|
render() {
|
|
@@ -189,6 +160,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
189
160
|
dateStyle: "medium",
|
|
190
161
|
timeStyle: "short"
|
|
191
162
|
} : void 0) : "";
|
|
163
|
+
const textEntry = this.mode === "date";
|
|
192
164
|
return html`
|
|
193
165
|
<u-field part="field"
|
|
194
166
|
?required=${this.required}
|
|
@@ -198,7 +170,26 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
198
170
|
.description=${this.description}
|
|
199
171
|
.validationMessage=${this.validationMessage}
|
|
200
172
|
>
|
|
201
|
-
|
|
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"
|
|
202
193
|
tabindex=${this.effectivelyDisabled ? "-1" : "0"}
|
|
203
194
|
role="combobox"
|
|
204
195
|
aria-disabled=${ifDefined(this.effectivelyDisabled ? "true" : void 0)}
|
|
@@ -208,7 +199,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
208
199
|
aria-description=${ifDefined(this.resolvedAriaDescription)}
|
|
209
200
|
aria-controls=${this.calendarId}
|
|
210
201
|
>
|
|
211
|
-
<span class="text-content ${!displayText ? "placeholder" : ""}">${displayText || this.placeholder || ""}</span
|
|
202
|
+
<span class="text-content ${!displayText ? "placeholder" : ""}">${displayText || this.placeholder || ""}</span>`}
|
|
212
203
|
<u-icon class="suffix-item"
|
|
213
204
|
?hidden=${!this.clearable || !this.value || this.effectivelyDisabled || this.readonly}
|
|
214
205
|
role="button"
|
|
@@ -219,10 +210,18 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
219
210
|
@click=${this.handleClearClick}
|
|
220
211
|
@keydown=${this.handleClearKeydown}
|
|
221
212
|
></u-icon>
|
|
222
|
-
|
|
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}
|
|
223
218
|
lib="internal"
|
|
224
219
|
name="calendar"
|
|
225
|
-
|
|
220
|
+
@click=${this.handleCalendarButtonClick}
|
|
221
|
+
></u-icon>` : html`<u-icon class="suffix-item"
|
|
222
|
+
lib="internal"
|
|
223
|
+
name="calendar"
|
|
224
|
+
></u-icon>`}
|
|
226
225
|
</div>
|
|
227
226
|
</u-field>
|
|
228
227
|
|
|
@@ -231,7 +230,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
231
230
|
role="dialog"
|
|
232
231
|
aria-label=${Locale.getValue("chooseDate")}
|
|
233
232
|
for=".container"
|
|
234
|
-
trigger
|
|
233
|
+
trigger=${textEntry ? "manual" : "click"}
|
|
235
234
|
strategy="fixed"
|
|
236
235
|
placement="bottom-start"
|
|
237
236
|
offset="4"
|
|
@@ -243,29 +242,16 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
243
242
|
`;
|
|
244
243
|
}
|
|
245
244
|
renderCalendar() {
|
|
246
|
-
const cells = buildMonthGrid(this.viewDate);
|
|
247
|
-
const monthLabel = formatDate(this.viewDate, {
|
|
248
|
-
year: "numeric",
|
|
249
|
-
month: "long"
|
|
250
|
-
});
|
|
251
|
-
const weekdayLabels = getWeekdayLabels();
|
|
252
245
|
return html`
|
|
253
246
|
<div class="calendar" part="calendar">
|
|
254
|
-
<
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
<div class="calendar-grid" part="calendar-grid" role="grid">
|
|
263
|
-
${chunkWeeks(cells).map((week) => html`
|
|
264
|
-
<div class="calendar-week" part="calendar-week" role="row">
|
|
265
|
-
${week.map((date) => date ? this.renderDay(date) : html`<span class="day-empty" role="gridcell" aria-hidden="true"></span>`)}
|
|
266
|
-
</div>
|
|
267
|
-
`)}
|
|
268
|
-
</div>
|
|
247
|
+
<u-calendar
|
|
248
|
+
exportparts="calendar-header, calendar-title, calendar-weekdays, calendar-grid, calendar-week, day"
|
|
249
|
+
.value=${this.value ? toISODate(splitValue(this.value).date) : void 0}
|
|
250
|
+
.min=${this.min}
|
|
251
|
+
.max=${this.max}
|
|
252
|
+
@day-select=${this.handleDaySelect}
|
|
253
|
+
@keydown=${this.handleCalendarKeydown}
|
|
254
|
+
></u-calendar>
|
|
269
255
|
${this.renderTimeRow()}
|
|
270
256
|
${this.renderFooter()}
|
|
271
257
|
</div>
|
|
@@ -285,7 +271,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
285
271
|
`;
|
|
286
272
|
}
|
|
287
273
|
renderFooter() {
|
|
288
|
-
const todayDisabled =
|
|
274
|
+
const todayDisabled = isOutOfRange(/* @__PURE__ */ new Date(), this.min, this.max);
|
|
289
275
|
return html`
|
|
290
276
|
<div class="calendar-footer" part="calendar-footer">
|
|
291
277
|
<u-button variant="ghost" size="sm" ?disabled=${todayDisabled} @click=${this.handleTodayClick}>${Locale.getValue("today")}</u-button>
|
|
@@ -295,42 +281,12 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
295
281
|
</div>
|
|
296
282
|
`;
|
|
297
283
|
}
|
|
298
|
-
renderDay(date) {
|
|
299
|
-
const selected = this.value ? isSameDay(date, splitValue(this.value).date) : false;
|
|
300
|
-
const focused = isSameDay(date, this.focusedDate);
|
|
301
|
-
const today = isSameDay(date, /* @__PURE__ */ new Date());
|
|
302
|
-
const outOfRange = this.isOutOfRange(date);
|
|
303
|
-
return html`
|
|
304
|
-
<button type="button" class="day" part="day"
|
|
305
|
-
role="gridcell"
|
|
306
|
-
data-iso=${toISODate(date)}
|
|
307
|
-
tabindex=${focused ? 0 : -1}
|
|
308
|
-
aria-selected=${selected}
|
|
309
|
-
aria-disabled=${outOfRange}
|
|
310
|
-
?data-today=${today}
|
|
311
|
-
@click=${() => this.selectDay(date)}
|
|
312
|
-
@keydown=${(e) => this.handleDayKeydown(e, date)}
|
|
313
|
-
@focus=${() => {
|
|
314
|
-
this.focusedDate = date;
|
|
315
|
-
}}
|
|
316
|
-
>${date.getDate()}</button>
|
|
317
|
-
`;
|
|
318
|
-
}
|
|
319
|
-
isOutOfRange(date) {
|
|
320
|
-
if (this.min && date.getTime() < parseISODate(this.min).getTime()) return true;
|
|
321
|
-
if (this.max && date.getTime() > parseISODate(this.max).getTime()) return true;
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
focusDayButton(date) {
|
|
325
|
-
const iso = toISODate(date);
|
|
326
|
-
this.renderRoot.querySelector(`button.day[data-iso="${iso}"]`)?.focus();
|
|
327
|
-
}
|
|
328
284
|
/** `timeOverride` lets a caller force the time-of-day (the "today" quick action wants
|
|
329
285
|
* "right now", overriding whatever time was previously set) — a plain day-cell click omits
|
|
330
286
|
* it, which preserves the existing time-of-day (or `pendingTime`) so switching the date
|
|
331
287
|
* alone doesn't clobber a time the user already picked. */
|
|
332
288
|
selectDay(date, timeOverride) {
|
|
333
|
-
if (
|
|
289
|
+
if (isOutOfRange(date, this.min, this.max)) return;
|
|
334
290
|
const time = timeOverride ?? (this.value ? splitValue(this.value).time : this.pendingTime);
|
|
335
291
|
const iso = buildValue(date, this.mode, time);
|
|
336
292
|
const changed = iso !== this.value;
|
|
@@ -338,23 +294,24 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
338
294
|
if (this.mode === "datetime") this.pendingTime = time;
|
|
339
295
|
if (changed) this.emitChange();
|
|
340
296
|
this.popoverEl?.hide();
|
|
341
|
-
this.containerEl?.focus();
|
|
297
|
+
(this.textInputEl ?? this.containerEl)?.focus();
|
|
342
298
|
}
|
|
343
|
-
|
|
344
|
-
this.
|
|
345
|
-
const next = addMonths(this.viewDate, delta);
|
|
346
|
-
this.viewDate = next;
|
|
347
|
-
const clampedDay = Math.min(this.focusedDate.getDate(), daysInMonth(next));
|
|
348
|
-
this.focusedDate = new Date(next.getFullYear(), next.getMonth(), clampedDay);
|
|
299
|
+
get textInputEl() {
|
|
300
|
+
return this.renderRoot.querySelector(".text-input");
|
|
349
301
|
}
|
|
350
|
-
|
|
351
|
-
this.
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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);
|
|
355
310
|
}
|
|
356
311
|
resetValue() {
|
|
357
312
|
const hadValue = !!this.value;
|
|
313
|
+
this.draft = null;
|
|
314
|
+
this.badText = false;
|
|
358
315
|
this.value = void 0;
|
|
359
316
|
if (hadValue) this.emitChange();
|
|
360
317
|
}
|
|
@@ -368,7 +325,10 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
368
325
|
setValidity() {
|
|
369
326
|
let flags = {};
|
|
370
327
|
let message = "";
|
|
371
|
-
if (this.
|
|
328
|
+
if (this.badText) {
|
|
329
|
+
flags = { badInput: true };
|
|
330
|
+
message = Locale.getValue("badInput");
|
|
331
|
+
} else if (this.required && !this.value) {
|
|
372
332
|
flags = { valueMissing: true };
|
|
373
333
|
message = Locale.getValue("valueMissing");
|
|
374
334
|
} else if (this.value && this.min && splitValue(this.value).date.getTime() < parseISODate(this.min).getTime()) {
|
|
@@ -378,10 +338,12 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
378
338
|
flags = { rangeOverflow: true };
|
|
379
339
|
message = Locale.getValue("rangeOverflow", { max: this.max });
|
|
380
340
|
}
|
|
381
|
-
this.commit(flags, message, this.containerEl ?? void 0);
|
|
341
|
+
this.commit(flags, message, this.textInputEl ?? this.containerEl ?? void 0);
|
|
382
342
|
}
|
|
383
343
|
reset() {
|
|
384
344
|
this.value = void 0;
|
|
345
|
+
this.draft = null;
|
|
346
|
+
this.badText = false;
|
|
385
347
|
this.invalid = false;
|
|
386
348
|
}
|
|
387
349
|
/** `.container`는 div라 네이티브 `disabled`가 없다 — disabled일 때 `tabindex="-1"`로만
|
|
@@ -389,10 +351,10 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
389
351
|
* 네이티브 `disabled` `<input>`에서 얻는 것과 같은 no-op을 여기서 직접 재현한다. */
|
|
390
352
|
focus(options) {
|
|
391
353
|
if (this.effectivelyDisabled) return;
|
|
392
|
-
this.containerEl?.focus(options);
|
|
354
|
+
(this.textInputEl ?? this.containerEl)?.focus(options);
|
|
393
355
|
}
|
|
394
356
|
blur() {
|
|
395
|
-
this.containerEl?.blur();
|
|
357
|
+
(this.textInputEl ?? this.containerEl)?.blur();
|
|
396
358
|
}
|
|
397
359
|
};
|
|
398
360
|
__decorate([property({
|
|
@@ -406,12 +368,17 @@ __decorate([property({
|
|
|
406
368
|
reflect: true
|
|
407
369
|
}), __decorateMetadata("design:type", Boolean)], UDatePicker.prototype, "clearable", void 0);
|
|
408
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);
|
|
409
375
|
__decorate([query(".container", true), __decorateMetadata("design:type", typeof HTMLElement === "undefined" ? Object : HTMLElement)], UDatePicker.prototype, "containerEl", void 0);
|
|
410
376
|
__decorate([query("u-popover", true), __decorateMetadata("design:type", typeof UPopover === "undefined" ? Object : UPopover)], UDatePicker.prototype, "popoverEl", void 0);
|
|
377
|
+
__decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDatePicker.prototype, "calendarEl", void 0);
|
|
411
378
|
__decorate([state(), __decorateMetadata("design:type", Boolean)], UDatePicker.prototype, "open", void 0);
|
|
412
|
-
__decorate([state(), __decorateMetadata("design:type", typeof Date === "undefined" ? Object : Date)], UDatePicker.prototype, "viewDate", void 0);
|
|
413
|
-
__decorate([state(), __decorateMetadata("design:type", typeof Date === "undefined" ? Object : Date)], UDatePicker.prototype, "focusedDate", void 0);
|
|
414
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);
|
|
415
382
|
UDatePicker = __decorate([customElement("u-date-picker")], UDatePicker);
|
|
416
383
|
//#endregion
|
|
417
384
|
export { UDatePicker };
|
|
@@ -14,133 +14,27 @@ var styles = css`
|
|
|
14
14
|
font-family: var(--u-font-base);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
.container {
|
|
18
|
-
display: flex;
|
|
19
|
-
flex-direction: row;
|
|
20
|
-
align-items: center;
|
|
21
|
-
gap: 0.4em;
|
|
22
|
-
padding: 0.3em 0.6em;
|
|
23
|
-
border: 1px solid var(--u-input-border-color, #E0E0E0);
|
|
24
|
-
border-radius: 0.25em;
|
|
25
|
-
background-color: var(--u-input-bg-color, #FFFFFF);
|
|
26
|
-
cursor: pointer;
|
|
27
|
-
transition: border-color var(--u-duration-normal, 220ms) var(--u-ease-standard, cubic-bezier(0.2, 0, 0, 1)),
|
|
28
|
-
box-shadow var(--u-duration-normal, 220ms) var(--u-ease-standard, cubic-bezier(0.2, 0, 0, 1));
|
|
29
|
-
}
|
|
30
|
-
:host([readonly]) .container,
|
|
31
|
-
:host(:disabled) .container {
|
|
32
|
-
cursor: not-allowed;
|
|
33
|
-
border-color: var(--u-border-color-weak, #EEEEEE);
|
|
34
|
-
background-color: var(--u-bg-color-disabled, #FAFAFA);
|
|
35
|
-
}
|
|
36
|
-
:host(:not([readonly]):not(:disabled)) .container:hover {
|
|
37
|
-
box-shadow: 0 0 0 1px var(--u-input-border-color-hover, #BDBDBD);
|
|
38
|
-
}
|
|
39
|
-
:host(:not([readonly]):not(:disabled)) .container:focus-within {
|
|
40
|
-
box-shadow: 0 0 0 1px var(--u-input-border-color-focus, #1565C0);
|
|
41
|
-
}
|
|
42
|
-
:host([invalid]:not([readonly]):not(:disabled)) .container {
|
|
43
|
-
box-shadow: 0 0 0 1px var(--u-input-border-color-invalid, #C62828);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.text-content {
|
|
47
|
-
flex: 1 0 auto;
|
|
48
|
-
min-width: 0;
|
|
49
|
-
font-size: 1em;
|
|
50
|
-
line-height: 1.5;
|
|
51
|
-
overflow: hidden;
|
|
52
|
-
text-overflow: ellipsis;
|
|
53
|
-
white-space: nowrap;
|
|
54
|
-
}
|
|
55
|
-
.text-content.placeholder {
|
|
56
|
-
color: var(--u-txt-color-weak, #616161);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
.suffix-item {
|
|
60
|
-
color: var(--u-icon-color, #616161);
|
|
61
|
-
font-size: 1em;
|
|
62
|
-
transition: color var(--u-duration-normal, 220ms) var(--u-ease-standard, cubic-bezier(0.2, 0, 0, 1));
|
|
63
|
-
}
|
|
64
|
-
.suffix-item:hover {
|
|
65
|
-
color: var(--u-icon-color-hover, #1565C0);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
17
|
u-popover {
|
|
69
18
|
width: var(--date-picker-popover-width);
|
|
70
|
-
padding: 8px;
|
|
71
|
-
border: 1px solid var(--u-border-color, #E0E0E0);
|
|
72
|
-
border-radius: var(--u-radius-lg, 6px);
|
|
73
|
-
background-color: var(--u-panel-bg-color, #FFFFFF);
|
|
74
|
-
box-shadow: var(--u-shadow-lg, 0 4px 12px rgba(0, 0, 0, 0.16), 0 2px 4px rgba(0, 0, 0, 0.06));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.calendar-header {
|
|
78
|
-
display: flex;
|
|
79
|
-
flex-direction: row;
|
|
80
|
-
align-items: center;
|
|
81
|
-
justify-content: space-between;
|
|
82
|
-
padding: 0 4px 8px;
|
|
83
|
-
}
|
|
84
|
-
.calendar-title {
|
|
85
|
-
font-size: var(--u-text-label-size, 13px);
|
|
86
|
-
font-weight: var(--u-text-label-weight, 600);
|
|
87
19
|
}
|
|
88
20
|
|
|
89
|
-
.
|
|
90
|
-
.
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
.calendar-weekdays {
|
|
95
|
-
padding-bottom: 4px;
|
|
96
|
-
}
|
|
97
|
-
/* role="row" wrapper for APG grid semantics — display:contents keeps it out of the
|
|
98
|
-
CSS grid track so its day cells still lay out as direct grid items. */
|
|
99
|
-
.calendar-week {
|
|
100
|
-
display: contents;
|
|
101
|
-
}
|
|
102
|
-
.weekday {
|
|
103
|
-
display: flex;
|
|
104
|
-
align-items: center;
|
|
105
|
-
justify-content: center;
|
|
106
|
-
font-size: var(--u-text-caption-size, 12px);
|
|
107
|
-
color: var(--u-txt-color-weak, #616161);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
.day,
|
|
111
|
-
.day-empty {
|
|
112
|
-
aspect-ratio: 1;
|
|
113
|
-
}
|
|
114
|
-
.day {
|
|
115
|
-
display: flex;
|
|
116
|
-
align-items: center;
|
|
117
|
-
justify-content: center;
|
|
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;
|
|
118
25
|
border: none;
|
|
119
|
-
border-radius: var(--u-radius-circle, 50%);
|
|
120
|
-
background: transparent;
|
|
121
|
-
color: var(--u-txt-color, #212121);
|
|
122
|
-
font-size: 1em;
|
|
123
|
-
font-family: inherit;
|
|
124
|
-
cursor: pointer;
|
|
125
|
-
}
|
|
126
|
-
.day:hover:not([aria-disabled="true"]) {
|
|
127
|
-
background-color: var(--u-bg-color-hover, #F5F5F5);
|
|
128
|
-
}
|
|
129
|
-
.day:focus-visible {
|
|
130
26
|
outline: none;
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
27
|
+
padding: 0;
|
|
28
|
+
margin: 0;
|
|
29
|
+
background: transparent;
|
|
30
|
+
color: inherit;
|
|
31
|
+
font: inherit;
|
|
136
32
|
}
|
|
137
|
-
.
|
|
138
|
-
|
|
139
|
-
color: var(--u-primary-txt-color, #FFFFFF);
|
|
33
|
+
.text-input::placeholder {
|
|
34
|
+
color: var(--u-txt-color-weak, #616161);
|
|
140
35
|
}
|
|
141
|
-
.
|
|
142
|
-
|
|
143
|
-
cursor: not-allowed;
|
|
36
|
+
.calendar-button {
|
|
37
|
+
cursor: pointer;
|
|
144
38
|
}
|
|
145
39
|
|
|
146
40
|
.calendar-time {
|
|
@@ -161,16 +55,6 @@ var styles = css`
|
|
|
161
55
|
outline: none;
|
|
162
56
|
box-shadow: 0 0 0 1px var(--u-input-border-color-focus, #1565C0);
|
|
163
57
|
}
|
|
164
|
-
|
|
165
|
-
.calendar-footer {
|
|
166
|
-
display: flex;
|
|
167
|
-
justify-content: space-between;
|
|
168
|
-
align-items: center;
|
|
169
|
-
gap: 8px;
|
|
170
|
-
padding-top: 8px;
|
|
171
|
-
margin-top: 4px;
|
|
172
|
-
border-top: 1px solid var(--u-border-color-weak, #EEEEEE);
|
|
173
|
-
}
|
|
174
58
|
`;
|
|
175
59
|
//#endregion
|
|
176
60
|
export { styles };
|