@iyulab/components 1.53.0 → 1.54.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 +50 -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 +8 -13
- package/dist/components/date-picker/UDatePicker.js +36 -165
- package/dist/components/date-picker/UDatePicker.styles.js +0 -135
- 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 +27 -0
- package/dist/utilities/format.js +71 -1
- package/package.json +1 -1
- package/skills/iyulab-components/SKILL.md +1 -0
- package/skills/iyulab-components/references/components/date-picker.md +2 -0
- package/skills/iyulab-components/references/components/date-range-picker.md +147 -0
- package/skills/iyulab-components/references/components/input.md +14 -4
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
//#region src/components/calendar/dates.ts
|
|
2
|
+
/** ISO `YYYY-MM-DD` → 로컬 자정 `Date`. */
|
|
3
|
+
function parseISODate(iso) {
|
|
4
|
+
const [y, m, d] = iso.split("-").map(Number);
|
|
5
|
+
return new Date(y, m - 1, d);
|
|
6
|
+
}
|
|
7
|
+
/** 로컬 `Date` → ISO `YYYY-MM-DD`. */
|
|
8
|
+
function toISODate(date) {
|
|
9
|
+
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}`;
|
|
10
|
+
}
|
|
11
|
+
function isSameDay(a, b) {
|
|
12
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
13
|
+
}
|
|
14
|
+
function startOfMonth(date) {
|
|
15
|
+
return new Date(date.getFullYear(), date.getMonth(), 1);
|
|
16
|
+
}
|
|
17
|
+
function addMonths(date, delta) {
|
|
18
|
+
return new Date(date.getFullYear(), date.getMonth() + delta, 1);
|
|
19
|
+
}
|
|
20
|
+
function addDays(date, delta) {
|
|
21
|
+
return new Date(date.getFullYear(), date.getMonth(), date.getDate() + delta);
|
|
22
|
+
}
|
|
23
|
+
function daysInMonth(date) {
|
|
24
|
+
return new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
|
|
25
|
+
}
|
|
26
|
+
/** 두 날의 달 차이(`b` 가 `a` 보다 몇 달 뒤인가). 일자는 무시한다. */
|
|
27
|
+
function monthDiff(a, b) {
|
|
28
|
+
return (b.getFullYear() - a.getFullYear()) * 12 + (b.getMonth() - a.getMonth());
|
|
29
|
+
}
|
|
30
|
+
/** `min`/`max`(ISO 날짜, 둘 다 선택)를 벗어나는가 — 경계일은 포함이다. */
|
|
31
|
+
function isOutOfRange(date, min, max) {
|
|
32
|
+
if (min && date.getTime() < parseISODate(min).getTime()) return true;
|
|
33
|
+
if (max && date.getTime() > parseISODate(max).getTime()) return true;
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
//#endregion
|
|
37
|
+
export { addDays, addMonths, daysInMonth, isOutOfRange, isSameDay, monthDiff, parseISODate, startOfMonth, toISODate };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
//#region src/components/calendar/picker.styles.ts
|
|
3
|
+
/**
|
|
4
|
+
* 날짜 피커들(`u-date-picker` · `u-date-range-picker`)이 함께 쓰는 트리거·팝오버·하단 줄 규칙.
|
|
5
|
+
* 호스트의 `display`/`width` 와 팝오버 폭은 피커마다 다르므로 각 피커의 시트가 갖는다.
|
|
6
|
+
*/
|
|
7
|
+
var styles = css`
|
|
8
|
+
.container {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: row;
|
|
11
|
+
align-items: center;
|
|
12
|
+
gap: 0.4em;
|
|
13
|
+
padding: 0.3em 0.6em;
|
|
14
|
+
border: 1px solid var(--u-input-border-color, #E0E0E0);
|
|
15
|
+
border-radius: 0.25em;
|
|
16
|
+
background-color: var(--u-input-bg-color, #FFFFFF);
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
transition: border-color var(--u-duration-normal, 220ms) var(--u-ease-standard, cubic-bezier(0.2, 0, 0, 1)),
|
|
19
|
+
box-shadow var(--u-duration-normal, 220ms) var(--u-ease-standard, cubic-bezier(0.2, 0, 0, 1));
|
|
20
|
+
}
|
|
21
|
+
:host([readonly]) .container,
|
|
22
|
+
:host(:disabled) .container {
|
|
23
|
+
cursor: not-allowed;
|
|
24
|
+
border-color: var(--u-border-color-weak, #EEEEEE);
|
|
25
|
+
background-color: var(--u-bg-color-disabled, #FAFAFA);
|
|
26
|
+
}
|
|
27
|
+
:host(:not([readonly]):not(:disabled)) .container:hover {
|
|
28
|
+
box-shadow: 0 0 0 1px var(--u-input-border-color-hover, #BDBDBD);
|
|
29
|
+
}
|
|
30
|
+
:host(:not([readonly]):not(:disabled)) .container:focus-within {
|
|
31
|
+
box-shadow: 0 0 0 1px var(--u-input-border-color-focus, #1565C0);
|
|
32
|
+
}
|
|
33
|
+
:host([invalid]:not([readonly]):not(:disabled)) .container {
|
|
34
|
+
box-shadow: 0 0 0 1px var(--u-input-border-color-invalid, #C62828);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
.text-content {
|
|
38
|
+
flex: 1 0 auto;
|
|
39
|
+
min-width: 0;
|
|
40
|
+
font-size: 1em;
|
|
41
|
+
line-height: 1.5;
|
|
42
|
+
overflow: hidden;
|
|
43
|
+
text-overflow: ellipsis;
|
|
44
|
+
white-space: nowrap;
|
|
45
|
+
}
|
|
46
|
+
.text-content.placeholder {
|
|
47
|
+
color: var(--u-txt-color-weak, #616161);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.suffix-item {
|
|
51
|
+
color: var(--u-icon-color, #616161);
|
|
52
|
+
font-size: 1em;
|
|
53
|
+
transition: color var(--u-duration-normal, 220ms) var(--u-ease-standard, cubic-bezier(0.2, 0, 0, 1));
|
|
54
|
+
}
|
|
55
|
+
.suffix-item:hover {
|
|
56
|
+
color: var(--u-icon-color-hover, #1565C0);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
u-popover {
|
|
60
|
+
padding: 8px;
|
|
61
|
+
border: 1px solid var(--u-border-color, #E0E0E0);
|
|
62
|
+
border-radius: var(--u-radius-lg, 6px);
|
|
63
|
+
background-color: var(--u-panel-bg-color, #FFFFFF);
|
|
64
|
+
box-shadow: var(--u-shadow-lg, 0 4px 12px rgba(0, 0, 0, 0.16), 0 2px 4px rgba(0, 0, 0, 0.06));
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
.calendar-footer {
|
|
68
|
+
display: flex;
|
|
69
|
+
justify-content: space-between;
|
|
70
|
+
align-items: center;
|
|
71
|
+
gap: 8px;
|
|
72
|
+
padding-top: 8px;
|
|
73
|
+
margin-top: 4px;
|
|
74
|
+
border-top: 1px solid var(--u-border-color-weak, #EEEEEE);
|
|
75
|
+
}
|
|
76
|
+
`;
|
|
77
|
+
//#endregion
|
|
78
|
+
export { styles };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
4
|
import { styles } from "./UCard.styles.js";
|
|
5
5
|
import { html } from "lit";
|
|
6
6
|
import { customElement, property } from "lit/decorators.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.js";
|
|
6
6
|
import { Locale } from "../../utilities/Locale.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
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 "../icon/UIcon.js";
|
|
5
5
|
import { Locale } from "../../utilities/Locale.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.js";
|
|
6
6
|
import { Locale } from "../../utilities/Locale.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UElement } from "../UElement.js";
|
|
2
|
-
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.
|
|
3
|
-
import __decorate from "../../_virtual/_@oxc-project_runtime@0.
|
|
2
|
+
import __decorateMetadata from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorateMetadata.js";
|
|
3
|
+
import __decorate from "../../_virtual/_@oxc-project_runtime@0.152.0/helpers/esm/decorate.js";
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.js";
|
|
6
6
|
import { Locale } from "../../utilities/Locale.js";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropertyValues } from 'lit';
|
|
2
2
|
import { UFormControlElement } from '../UFormControlElement.js';
|
|
3
|
+
import { UCalendar } from '../calendar/UCalendar.js';
|
|
3
4
|
import { UPopover } from '../popover/UPopover.js';
|
|
4
5
|
export type DatePickerMode = 'date' | 'datetime';
|
|
5
6
|
/**
|
|
@@ -62,23 +63,18 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
62
63
|
placeholder?: string;
|
|
63
64
|
containerEl?: HTMLElement;
|
|
64
65
|
popoverEl?: UPopover;
|
|
66
|
+
calendarEl?: UCalendar;
|
|
65
67
|
/** Unique id wiring the combobox's `aria-controls` to the calendar dialog — mirrors USelect's `listboxId`. */
|
|
66
68
|
private readonly calendarId;
|
|
67
69
|
private open;
|
|
68
|
-
private viewDate;
|
|
69
|
-
private focusedDate;
|
|
70
70
|
/** Time-of-day for the next selection while no `value` exists yet (`mode="datetime"` only) —
|
|
71
71
|
* once `value` is set, the time input reads/writes its time portion directly instead. */
|
|
72
72
|
private pendingTime;
|
|
73
|
-
private grabFocusOnUpdate;
|
|
74
73
|
protected updated(changed: PropertyValues): void;
|
|
75
74
|
render(): import('lit-html').TemplateResult<1>;
|
|
76
75
|
private renderCalendar;
|
|
77
76
|
private renderTimeRow;
|
|
78
77
|
private renderFooter;
|
|
79
|
-
private renderDay;
|
|
80
|
-
private isOutOfRange;
|
|
81
|
-
private focusDayButton;
|
|
82
78
|
/** `timeOverride` lets a caller force the time-of-day (the "today" quick action wants
|
|
83
79
|
* "right now", overriding whatever time was previously set) — a plain day-cell click omits
|
|
84
80
|
* it, which preserves the existing time-of-day (or `pendingTime`) so switching the date
|
|
@@ -89,16 +85,15 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
89
85
|
* `pendingTime` for whenever a day gets picked. Doesn't close the popover or refocus the
|
|
90
86
|
* trigger — unlike selecting a day, adjusting the time doesn't conclude the interaction. */
|
|
91
87
|
private handleTimeChange;
|
|
92
|
-
private
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
private
|
|
96
|
-
private moveFocus;
|
|
88
|
+
private handleDaySelect;
|
|
89
|
+
/** Escape inside the grid closes the calendar and returns focus to the trigger — the grid
|
|
90
|
+
* itself does not know it lives in a popover, so the picker owns this. */
|
|
91
|
+
private handleCalendarKeydown;
|
|
97
92
|
private handlePopoverShow;
|
|
98
93
|
private handlePopoverHide;
|
|
99
94
|
private handleClearClick;
|
|
100
|
-
/** "오늘" 퀵액션 — `today`
|
|
101
|
-
* `
|
|
95
|
+
/** "오늘" 퀵액션 — 달력이 이미 `data-today` 로 표시 중인 날을 실제로 선택하는 것뿐이라
|
|
96
|
+
* `selectDay`를 그대로 탄다
|
|
102
97
|
* (범위 밖이면 `selectDay`가 조용히 no-op — 클릭 불가 상태인 day 셀과 동일 규약).
|
|
103
98
|
* datetime 모드에서는 "지금"을 통째로 채우는 것이 소비자 요청의 본질
|
|
104
99
|
* 이라 시간까지 `now`로 덮어쓴다 — 평범한 day 셀 클릭과 달리 기존 시각을 보존하지 않는다. */
|
|
@@ -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 { formatDate } 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,27 +40,6 @@ 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);
|
|
@@ -88,10 +47,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
88
47
|
this.clearable = false;
|
|
89
48
|
this.calendarId = `u-date-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
|
|
90
49
|
this.open = false;
|
|
91
|
-
this.viewDate = startOfMonth(/* @__PURE__ */ new Date());
|
|
92
|
-
this.focusedDate = /* @__PURE__ */ new Date();
|
|
93
50
|
this.pendingTime = "00:00";
|
|
94
|
-
this.grabFocusOnUpdate = false;
|
|
95
51
|
this.handleTimeChange = (e) => {
|
|
96
52
|
const time = e.target.value || "00:00";
|
|
97
53
|
this.pendingTime = time;
|
|
@@ -101,51 +57,17 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
101
57
|
this.value = iso;
|
|
102
58
|
if (changed) this.emitChange();
|
|
103
59
|
};
|
|
104
|
-
this.
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
case "ArrowLeft":
|
|
113
|
-
e.preventDefault();
|
|
114
|
-
this.moveFocus(date, -1);
|
|
115
|
-
break;
|
|
116
|
-
case "ArrowDown":
|
|
117
|
-
e.preventDefault();
|
|
118
|
-
this.moveFocus(date, 7);
|
|
119
|
-
break;
|
|
120
|
-
case "ArrowUp":
|
|
121
|
-
e.preventDefault();
|
|
122
|
-
this.moveFocus(date, -7);
|
|
123
|
-
break;
|
|
124
|
-
case "Home":
|
|
125
|
-
e.preventDefault();
|
|
126
|
-
this.moveFocus(date, -date.getDay());
|
|
127
|
-
break;
|
|
128
|
-
case "End":
|
|
129
|
-
e.preventDefault();
|
|
130
|
-
this.moveFocus(date, 6 - date.getDay());
|
|
131
|
-
break;
|
|
132
|
-
case "Enter":
|
|
133
|
-
case " ":
|
|
134
|
-
e.preventDefault();
|
|
135
|
-
this.selectDay(date);
|
|
136
|
-
break;
|
|
137
|
-
case "Escape":
|
|
138
|
-
e.preventDefault();
|
|
139
|
-
this.popoverEl?.hide();
|
|
140
|
-
this.containerEl?.focus();
|
|
141
|
-
}
|
|
60
|
+
this.handleDaySelect = (e) => {
|
|
61
|
+
this.selectDay(parseISODate(e.detail.date));
|
|
62
|
+
};
|
|
63
|
+
this.handleCalendarKeydown = (e) => {
|
|
64
|
+
if (e.key !== "Escape") return;
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
this.popoverEl?.hide();
|
|
67
|
+
this.containerEl?.focus();
|
|
142
68
|
};
|
|
143
69
|
this.handlePopoverShow = () => {
|
|
144
70
|
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
71
|
};
|
|
150
72
|
this.handlePopoverHide = () => {
|
|
151
73
|
this.open = false;
|
|
@@ -173,15 +95,21 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
173
95
|
};
|
|
174
96
|
}
|
|
175
97
|
static {
|
|
176
|
-
this.styles = [
|
|
98
|
+
this.styles = [
|
|
99
|
+
super.styles,
|
|
100
|
+
styles,
|
|
101
|
+
styles$1
|
|
102
|
+
];
|
|
177
103
|
}
|
|
178
104
|
updated(changed) {
|
|
179
105
|
super.updated(changed);
|
|
180
106
|
if (changed.has("value")) this.internals?.setFormValue(this.value ?? "");
|
|
181
107
|
if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
|
|
182
|
-
if (changed.has("open") && this.open
|
|
183
|
-
|
|
184
|
-
this.
|
|
108
|
+
if (changed.has("open") && this.open) {
|
|
109
|
+
const calendar = this.calendarEl;
|
|
110
|
+
const base = this.value ? toISODate(splitValue(this.value).date) : toISODate(/* @__PURE__ */ new Date());
|
|
111
|
+
calendar?.showDate(base);
|
|
112
|
+
this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
|
|
185
113
|
}
|
|
186
114
|
}
|
|
187
115
|
render() {
|
|
@@ -243,29 +171,16 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
243
171
|
`;
|
|
244
172
|
}
|
|
245
173
|
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
174
|
return html`
|
|
253
175
|
<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>
|
|
176
|
+
<u-calendar
|
|
177
|
+
exportparts="calendar-header, calendar-title, calendar-weekdays, calendar-grid, calendar-week, day"
|
|
178
|
+
.value=${this.value ? toISODate(splitValue(this.value).date) : void 0}
|
|
179
|
+
.min=${this.min}
|
|
180
|
+
.max=${this.max}
|
|
181
|
+
@day-select=${this.handleDaySelect}
|
|
182
|
+
@keydown=${this.handleCalendarKeydown}
|
|
183
|
+
></u-calendar>
|
|
269
184
|
${this.renderTimeRow()}
|
|
270
185
|
${this.renderFooter()}
|
|
271
186
|
</div>
|
|
@@ -285,7 +200,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
285
200
|
`;
|
|
286
201
|
}
|
|
287
202
|
renderFooter() {
|
|
288
|
-
const todayDisabled =
|
|
203
|
+
const todayDisabled = isOutOfRange(/* @__PURE__ */ new Date(), this.min, this.max);
|
|
289
204
|
return html`
|
|
290
205
|
<div class="calendar-footer" part="calendar-footer">
|
|
291
206
|
<u-button variant="ghost" size="sm" ?disabled=${todayDisabled} @click=${this.handleTodayClick}>${Locale.getValue("today")}</u-button>
|
|
@@ -295,42 +210,12 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
295
210
|
</div>
|
|
296
211
|
`;
|
|
297
212
|
}
|
|
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
213
|
/** `timeOverride` lets a caller force the time-of-day (the "today" quick action wants
|
|
329
214
|
* "right now", overriding whatever time was previously set) — a plain day-cell click omits
|
|
330
215
|
* it, which preserves the existing time-of-day (or `pendingTime`) so switching the date
|
|
331
216
|
* alone doesn't clobber a time the user already picked. */
|
|
332
217
|
selectDay(date, timeOverride) {
|
|
333
|
-
if (
|
|
218
|
+
if (isOutOfRange(date, this.min, this.max)) return;
|
|
334
219
|
const time = timeOverride ?? (this.value ? splitValue(this.value).time : this.pendingTime);
|
|
335
220
|
const iso = buildValue(date, this.mode, time);
|
|
336
221
|
const changed = iso !== this.value;
|
|
@@ -340,19 +225,6 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
340
225
|
this.popoverEl?.hide();
|
|
341
226
|
this.containerEl?.focus();
|
|
342
227
|
}
|
|
343
|
-
navigateMonth(delta) {
|
|
344
|
-
this.grabFocusOnUpdate = false;
|
|
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);
|
|
349
|
-
}
|
|
350
|
-
moveFocus(from, deltaDays) {
|
|
351
|
-
this.grabFocusOnUpdate = true;
|
|
352
|
-
const next = addDays(from, deltaDays);
|
|
353
|
-
if (next.getMonth() !== this.viewDate.getMonth() || next.getFullYear() !== this.viewDate.getFullYear()) this.viewDate = startOfMonth(next);
|
|
354
|
-
this.focusedDate = next;
|
|
355
|
-
}
|
|
356
228
|
resetValue() {
|
|
357
229
|
const hadValue = !!this.value;
|
|
358
230
|
this.value = void 0;
|
|
@@ -408,9 +280,8 @@ __decorate([property({
|
|
|
408
280
|
__decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDatePicker.prototype, "placeholder", void 0);
|
|
409
281
|
__decorate([query(".container", true), __decorateMetadata("design:type", typeof HTMLElement === "undefined" ? Object : HTMLElement)], UDatePicker.prototype, "containerEl", void 0);
|
|
410
282
|
__decorate([query("u-popover", true), __decorateMetadata("design:type", typeof UPopover === "undefined" ? Object : UPopover)], UDatePicker.prototype, "popoverEl", void 0);
|
|
283
|
+
__decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDatePicker.prototype, "calendarEl", void 0);
|
|
411
284
|
__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
285
|
__decorate([state(), __decorateMetadata("design:type", String)], UDatePicker.prototype, "pendingTime", void 0);
|
|
415
286
|
UDatePicker = __decorate([customElement("u-date-picker")], UDatePicker);
|
|
416
287
|
//#endregion
|
|
@@ -14,133 +14,8 @@ 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
|
-
}
|
|
88
|
-
|
|
89
|
-
.calendar-weekdays,
|
|
90
|
-
.calendar-grid {
|
|
91
|
-
display: grid;
|
|
92
|
-
grid-template-columns: repeat(7, 1fr);
|
|
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;
|
|
118
|
-
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
|
-
outline: none;
|
|
131
|
-
box-shadow: 0 0 0 2px var(--u-input-border-color-focus, #1565C0);
|
|
132
|
-
}
|
|
133
|
-
.day[data-today] {
|
|
134
|
-
font-weight: 700;
|
|
135
|
-
color: var(--u-primary-color, #1976D2);
|
|
136
|
-
}
|
|
137
|
-
.day[aria-selected="true"] {
|
|
138
|
-
background-color: var(--u-primary-color, #1976D2);
|
|
139
|
-
color: var(--u-primary-txt-color, #FFFFFF);
|
|
140
|
-
}
|
|
141
|
-
.day[aria-disabled="true"] {
|
|
142
|
-
color: var(--u-txt-color-disabled, #BDBDBD);
|
|
143
|
-
cursor: not-allowed;
|
|
144
19
|
}
|
|
145
20
|
|
|
146
21
|
.calendar-time {
|
|
@@ -161,16 +36,6 @@ var styles = css`
|
|
|
161
36
|
outline: none;
|
|
162
37
|
box-shadow: 0 0 0 1px var(--u-input-border-color-focus, #1565C0);
|
|
163
38
|
}
|
|
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
39
|
`;
|
|
175
40
|
//#endregion
|
|
176
41
|
export { styles };
|