@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
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { PropertyValues } from 'lit';
|
|
2
|
+
import { UFormControlElement } from '../UFormControlElement.js';
|
|
3
|
+
import { UCalendar } from '../calendar/UCalendar.js';
|
|
4
|
+
import { UPopover } from '../popover/UPopover.js';
|
|
5
|
+
import { DateRangePresetOption } from './presets.js';
|
|
6
|
+
export type { DateRangePreset, DateRangePresetName, DateRangePresetOption } from './presets.js';
|
|
7
|
+
/**
|
|
8
|
+
* A date-range form control — one field for a period such as "orders placed between".
|
|
9
|
+
*
|
|
10
|
+
* The value is an ISO 8601 time interval of two calendar days, `YYYY-MM-DD/YYYY-MM-DD`, start
|
|
11
|
+
* first: one string, so it works as an attribute and submits with a form as a single field.
|
|
12
|
+
* `start` and `end` read the two halves. The picker never holds a reversed range — choosing the
|
|
13
|
+
* earlier day second makes it the start, and a reversed value set from code is put in order.
|
|
14
|
+
*
|
|
15
|
+
* The calendar shows two months. The first day chosen is an anchor and the range previews up to
|
|
16
|
+
* the day under the pointer or keyboard focus; the second day completes the range, fires
|
|
17
|
+
* `change` and closes the calendar. Escape while an anchor is set drops it; Escape again closes.
|
|
18
|
+
*
|
|
19
|
+
* `presets` adds a list of quick ranges beside the calendar — built-in names (`today`, `yesterday`,
|
|
20
|
+
* `last7Days`, `last30Days`, `thisWeek`, `lastWeek`, `thisMonth`, `lastMonth`, `thisYear`, which
|
|
21
|
+
* can be written as a space-separated attribute) and app-defined `{ label, range }` objects, in the
|
|
22
|
+
* order given. Picking one sets the range at once, fires `change` and closes the calendar. A preset
|
|
23
|
+
* whose range reaches outside `min`/`max` is disabled; the one equal to the current range is
|
|
24
|
+
* marked `aria-pressed="true"`. Relative ranges are computed when drawn.
|
|
25
|
+
*
|
|
26
|
+
* The calendar week starts on Sunday regardless of locale (same as `u-date-picker`); `thisWeek` and
|
|
27
|
+
* `lastWeek` follow it.
|
|
28
|
+
*
|
|
29
|
+
* Exposes a `:state(open)` custom state while the calendar is showing.
|
|
30
|
+
*
|
|
31
|
+
* @csspart field - the u-field element
|
|
32
|
+
* @csspart container - the element wrapping the trigger area
|
|
33
|
+
* @csspart popover - the popover element showing the calendar
|
|
34
|
+
* @csspart calendar - the calendar container
|
|
35
|
+
* @csspart calendar-month - one month block
|
|
36
|
+
* @csspart calendar-header - a month navigation header
|
|
37
|
+
* @csspart calendar-title - a "Month Year" title
|
|
38
|
+
* @csspart calendar-weekdays - a weekday header row
|
|
39
|
+
* @csspart calendar-grid - a date grid
|
|
40
|
+
* @csspart calendar-week - one week row inside a date grid
|
|
41
|
+
* @csspart day - a date cell button
|
|
42
|
+
* @csspart calendar-footer - the row holding the "clear" quick action
|
|
43
|
+
* @csspart presets - the list of quick ranges beside the calendar
|
|
44
|
+
* @csspart preset - one quick-range button
|
|
45
|
+
*
|
|
46
|
+
* @cssprop --u-date-range-picker-display - host `display` (default: inline-block). Set `block` to
|
|
47
|
+
* fill the container width in forms and grid cells.
|
|
48
|
+
* @cssprop --u-date-range-picker-width - host `width` (default: auto). Set `100%` where `block`
|
|
49
|
+
* alone does not stretch the host (e.g. inside a flex container).
|
|
50
|
+
*
|
|
51
|
+
* @event change - fires when the user completes a range or clears it. Programmatic value
|
|
52
|
+
* assignment does not fire it (same contract as native form controls).
|
|
53
|
+
*/
|
|
54
|
+
export declare class UDateRangePicker extends UFormControlElement<string> {
|
|
55
|
+
static styles: import('lit').CSSResultGroup[];
|
|
56
|
+
/** Earliest selectable day (ISO `YYYY-MM-DD`), inclusive. */
|
|
57
|
+
min?: string;
|
|
58
|
+
/** Latest selectable day (ISO `YYYY-MM-DD`), inclusive. */
|
|
59
|
+
max?: string;
|
|
60
|
+
/** Whether to show the clear button */
|
|
61
|
+
clearable: boolean;
|
|
62
|
+
/** Placeholder text (shown on the trigger when there is no value) */
|
|
63
|
+
placeholder?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Quick ranges listed beside the calendar, in display order — built-in names and app-defined
|
|
66
|
+
* `{ label, range }` presets. As an attribute: space-separated built-in names
|
|
67
|
+
* (`presets="today last7Days thisMonth"`). Empty (default) shows no list.
|
|
68
|
+
*/
|
|
69
|
+
presets: DateRangePresetOption[];
|
|
70
|
+
/** First day of the range (ISO), or `undefined` when there is no complete range. */
|
|
71
|
+
get start(): string | undefined;
|
|
72
|
+
/** Last day of the range (ISO), or `undefined` when there is no complete range. */
|
|
73
|
+
get end(): string | undefined;
|
|
74
|
+
containerEl?: HTMLElement;
|
|
75
|
+
popoverEl?: UPopover;
|
|
76
|
+
calendarEl?: UCalendar;
|
|
77
|
+
private readonly calendarId;
|
|
78
|
+
private open;
|
|
79
|
+
protected willUpdate(changed: PropertyValues): void;
|
|
80
|
+
protected shouldValidate(changed: PropertyValues): boolean;
|
|
81
|
+
protected updated(changed: PropertyValues): void;
|
|
82
|
+
render(): import('lit-html').TemplateResult<1>;
|
|
83
|
+
private renderCalendar;
|
|
84
|
+
private renderPresets;
|
|
85
|
+
/** A preset that reaches outside `min`/`max` is not offered — its label would promise more
|
|
86
|
+
* than the picker may hold. */
|
|
87
|
+
private outOfBounds;
|
|
88
|
+
private handleRangeSelect;
|
|
89
|
+
/** A user-chosen range (calendar or preset): set it, announce it, close the calendar. */
|
|
90
|
+
private commitRange;
|
|
91
|
+
/** Escape that reaches the picker closes the calendar — the calendar keeps the first Escape
|
|
92
|
+
* for itself while a range is half picked. */
|
|
93
|
+
private handleCalendarKeydown;
|
|
94
|
+
private handlePopoverShow;
|
|
95
|
+
private handlePopoverHide;
|
|
96
|
+
private handleClearClick;
|
|
97
|
+
private handleFooterResetClick;
|
|
98
|
+
private resetValue;
|
|
99
|
+
/** The clear icon is a display element — relay Enter/Space to its click handler
|
|
100
|
+
* (same pattern as `u-date-picker`, `u-input`, `u-select`). */
|
|
101
|
+
private handleClearKeydown;
|
|
102
|
+
private emitChange;
|
|
103
|
+
protected setValidity(): void;
|
|
104
|
+
reset(): void;
|
|
105
|
+
/** `.container` is a div — no native `disabled`, so a disabled picker ignores `focus()` here. */
|
|
106
|
+
focus(options?: FocusOptions): void;
|
|
107
|
+
blur(): void;
|
|
108
|
+
}
|
|
109
|
+
declare global {
|
|
110
|
+
interface HTMLElementTagNameMap {
|
|
111
|
+
'u-date-range-picker': UDateRangePicker;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
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
|
+
import { UFormControlElement } from "../UFormControlElement.js";
|
|
4
|
+
import "../button/UButton.js";
|
|
5
|
+
import { devWarnOnce } from "../../utilities/devWarning.js";
|
|
6
|
+
import "../icon/UIcon.js";
|
|
7
|
+
import { Locale } from "../../utilities/Locale.js";
|
|
8
|
+
import { formatDateRange } from "../../utilities/format.js";
|
|
9
|
+
import { parseISODate } from "../calendar/dates.js";
|
|
10
|
+
import { UCalendar } from "../calendar/UCalendar.js";
|
|
11
|
+
import "../field/UField.js";
|
|
12
|
+
import { UPopover } from "../popover/UPopover.js";
|
|
13
|
+
import { styles } from "../calendar/picker.styles.js";
|
|
14
|
+
import { resolvePresets } from "./presets.js";
|
|
15
|
+
import { styles as styles$1 } from "./UDateRangePicker.styles.js";
|
|
16
|
+
import { html } from "lit";
|
|
17
|
+
import { customElement, property, query, state } from "lit/decorators.js";
|
|
18
|
+
import { ifDefined } from "lit/directives/if-defined.js";
|
|
19
|
+
//#region src/components/date-range-picker/UDateRangePicker.ts
|
|
20
|
+
var ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
|
|
21
|
+
/** Splits `"start/end"` into its two ISO dates — `undefined` unless both halves are ISO dates. */
|
|
22
|
+
function parseInterval(value) {
|
|
23
|
+
if (!value) return void 0;
|
|
24
|
+
const [start, end, ...rest] = value.split("/");
|
|
25
|
+
if (rest.length || !ISO_DATE.test(start ?? "") || !ISO_DATE.test(end ?? "")) return void 0;
|
|
26
|
+
return {
|
|
27
|
+
start,
|
|
28
|
+
end
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
32
|
+
constructor(..._args) {
|
|
33
|
+
super(..._args);
|
|
34
|
+
this.clearable = false;
|
|
35
|
+
this.presets = [];
|
|
36
|
+
this.calendarId = `u-date-range-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
|
|
37
|
+
this.open = false;
|
|
38
|
+
this.handleRangeSelect = (e) => {
|
|
39
|
+
this.commitRange(e.detail.start, e.detail.end);
|
|
40
|
+
};
|
|
41
|
+
this.handleCalendarKeydown = (e) => {
|
|
42
|
+
if (e.key !== "Escape") return;
|
|
43
|
+
e.preventDefault();
|
|
44
|
+
this.popoverEl?.hide();
|
|
45
|
+
this.containerEl?.focus();
|
|
46
|
+
};
|
|
47
|
+
this.handlePopoverShow = () => {
|
|
48
|
+
this.open = true;
|
|
49
|
+
};
|
|
50
|
+
this.handlePopoverHide = () => {
|
|
51
|
+
this.open = false;
|
|
52
|
+
};
|
|
53
|
+
this.handleClearClick = (e) => {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
e.stopPropagation();
|
|
56
|
+
this.resetValue();
|
|
57
|
+
this.containerEl?.focus();
|
|
58
|
+
};
|
|
59
|
+
this.handleFooterResetClick = () => {
|
|
60
|
+
this.resetValue();
|
|
61
|
+
this.popoverEl?.hide();
|
|
62
|
+
this.containerEl?.focus();
|
|
63
|
+
};
|
|
64
|
+
this.handleClearKeydown = (e) => {
|
|
65
|
+
if (e.key !== "Enter" && e.key !== " ") return;
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
this.handleClearClick(e);
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
static {
|
|
71
|
+
this.styles = [
|
|
72
|
+
super.styles,
|
|
73
|
+
styles,
|
|
74
|
+
styles$1
|
|
75
|
+
];
|
|
76
|
+
}
|
|
77
|
+
/** First day of the range (ISO), or `undefined` when there is no complete range. */
|
|
78
|
+
get start() {
|
|
79
|
+
return parseInterval(this.value)?.start;
|
|
80
|
+
}
|
|
81
|
+
/** Last day of the range (ISO), or `undefined` when there is no complete range. */
|
|
82
|
+
get end() {
|
|
83
|
+
return parseInterval(this.value)?.end;
|
|
84
|
+
}
|
|
85
|
+
willUpdate(changed) {
|
|
86
|
+
super.willUpdate(changed);
|
|
87
|
+
if (changed.has("value")) {
|
|
88
|
+
const range = parseInterval(this.value);
|
|
89
|
+
if (range && range.start > range.end) this.value = `${range.end}/${range.start}`;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
shouldValidate(changed) {
|
|
93
|
+
return super.shouldValidate(changed) || changed.has("min") || changed.has("max");
|
|
94
|
+
}
|
|
95
|
+
updated(changed) {
|
|
96
|
+
super.updated(changed);
|
|
97
|
+
if (changed.has("value")) this.internals?.setFormValue(this.value ?? "");
|
|
98
|
+
if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
|
|
99
|
+
if (changed.has("open") && this.open) {
|
|
100
|
+
const calendar = this.calendarEl;
|
|
101
|
+
calendar?.showDate(this.start ?? /* @__PURE__ */ new Date());
|
|
102
|
+
this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
render() {
|
|
106
|
+
const range = parseInterval(this.value);
|
|
107
|
+
const displayText = range ? formatDateRange(range.start, range.end) : this.value ?? "";
|
|
108
|
+
return html`
|
|
109
|
+
<u-field part="field"
|
|
110
|
+
?required=${this.required}
|
|
111
|
+
?disabled=${this.effectivelyDisabled}
|
|
112
|
+
?invalid=${this.invalid}
|
|
113
|
+
.label=${this.label}
|
|
114
|
+
.description=${this.description}
|
|
115
|
+
.validationMessage=${this.validationMessage}
|
|
116
|
+
>
|
|
117
|
+
<div class="container" part="container"
|
|
118
|
+
tabindex=${this.effectivelyDisabled ? "-1" : "0"}
|
|
119
|
+
role="combobox"
|
|
120
|
+
aria-disabled=${ifDefined(this.effectivelyDisabled ? "true" : void 0)}
|
|
121
|
+
aria-haspopup="dialog"
|
|
122
|
+
aria-expanded=${this.open}
|
|
123
|
+
aria-label=${ifDefined(this.resolvedAriaLabel)}
|
|
124
|
+
aria-description=${ifDefined(this.resolvedAriaDescription)}
|
|
125
|
+
aria-controls=${this.calendarId}
|
|
126
|
+
>
|
|
127
|
+
<span class="text-content ${!displayText ? "placeholder" : ""}">${displayText || this.placeholder || ""}</span>
|
|
128
|
+
<u-icon class="suffix-item"
|
|
129
|
+
?hidden=${!this.clearable || !this.value || this.effectivelyDisabled || this.readonly}
|
|
130
|
+
role="button"
|
|
131
|
+
tabindex="0"
|
|
132
|
+
aria-label=${Locale.getValue("clear")}
|
|
133
|
+
lib="internal"
|
|
134
|
+
name="x"
|
|
135
|
+
@click=${this.handleClearClick}
|
|
136
|
+
@keydown=${this.handleClearKeydown}
|
|
137
|
+
></u-icon>
|
|
138
|
+
<u-icon class="suffix-item"
|
|
139
|
+
lib="internal"
|
|
140
|
+
name="calendar"
|
|
141
|
+
></u-icon>
|
|
142
|
+
</div>
|
|
143
|
+
</u-field>
|
|
144
|
+
|
|
145
|
+
<u-popover part="popover"
|
|
146
|
+
id=${this.calendarId}
|
|
147
|
+
role="dialog"
|
|
148
|
+
aria-label=${Locale.getValue("chooseDateRange")}
|
|
149
|
+
for=".container"
|
|
150
|
+
trigger="click"
|
|
151
|
+
strategy="fixed"
|
|
152
|
+
placement="bottom-start"
|
|
153
|
+
offset="4"
|
|
154
|
+
shift
|
|
155
|
+
@show=${this.handlePopoverShow}
|
|
156
|
+
@hide=${this.handlePopoverHide}
|
|
157
|
+
>
|
|
158
|
+
${this.open ? this.renderCalendar() : ""}
|
|
159
|
+
</u-popover>
|
|
160
|
+
`;
|
|
161
|
+
}
|
|
162
|
+
renderCalendar() {
|
|
163
|
+
const presets = resolvePresets(this.presets, /* @__PURE__ */ new Date(), (name) => devWarnOnce(`date-range-preset:${name}`, `u-date-range-picker: unknown preset "${name}" — it is not listed.`));
|
|
164
|
+
return html`
|
|
165
|
+
<div class="body">
|
|
166
|
+
${presets.length ? this.renderPresets(presets) : ""}
|
|
167
|
+
<div class="calendar" part="calendar">
|
|
168
|
+
<u-calendar
|
|
169
|
+
exportparts="calendar-month, calendar-header, calendar-title, calendar-weekdays, calendar-grid, calendar-week, day"
|
|
170
|
+
selection="range"
|
|
171
|
+
visible-months="2"
|
|
172
|
+
.start=${this.start}
|
|
173
|
+
.end=${this.end}
|
|
174
|
+
.min=${this.min}
|
|
175
|
+
.max=${this.max}
|
|
176
|
+
@range-select=${this.handleRangeSelect}
|
|
177
|
+
@keydown=${this.handleCalendarKeydown}
|
|
178
|
+
></u-calendar>
|
|
179
|
+
${this.clearable && this.value ? html`
|
|
180
|
+
<div class="calendar-footer" part="calendar-footer">
|
|
181
|
+
<u-button variant="ghost" size="sm" @click=${this.handleFooterResetClick}>${Locale.getValue("clear")}</u-button>
|
|
182
|
+
</div>
|
|
183
|
+
` : ""}
|
|
184
|
+
</div>
|
|
185
|
+
</div>
|
|
186
|
+
`;
|
|
187
|
+
}
|
|
188
|
+
renderPresets(presets) {
|
|
189
|
+
return html`
|
|
190
|
+
<div class="presets" part="presets" role="group" aria-label=${Locale.getValue("quickRanges")}>
|
|
191
|
+
${presets.map((p) => html`
|
|
192
|
+
<button type="button" class="preset" part="preset"
|
|
193
|
+
aria-pressed=${`${p.start}/${p.end}` === this.value}
|
|
194
|
+
?disabled=${this.outOfBounds(p)}
|
|
195
|
+
@click=${() => this.commitRange(p.start, p.end)}
|
|
196
|
+
>${p.label}</button>
|
|
197
|
+
`)}
|
|
198
|
+
</div>
|
|
199
|
+
`;
|
|
200
|
+
}
|
|
201
|
+
/** A preset that reaches outside `min`/`max` is not offered — its label would promise more
|
|
202
|
+
* than the picker may hold. */
|
|
203
|
+
outOfBounds(p) {
|
|
204
|
+
return !!this.min && p.start < this.min || !!this.max && p.end > this.max;
|
|
205
|
+
}
|
|
206
|
+
/** A user-chosen range (calendar or preset): set it, announce it, close the calendar. */
|
|
207
|
+
commitRange(start, end) {
|
|
208
|
+
const next = `${start}/${end}`;
|
|
209
|
+
const changed = next !== this.value;
|
|
210
|
+
this.value = next;
|
|
211
|
+
if (changed) this.emitChange();
|
|
212
|
+
this.popoverEl?.hide();
|
|
213
|
+
this.containerEl?.focus();
|
|
214
|
+
}
|
|
215
|
+
resetValue() {
|
|
216
|
+
const hadValue = !!this.value;
|
|
217
|
+
this.value = void 0;
|
|
218
|
+
if (hadValue) this.emitChange();
|
|
219
|
+
}
|
|
220
|
+
emitChange() {
|
|
221
|
+
if (!this.novalidate) this.validate();
|
|
222
|
+
this.dispatchEvent(new Event("change", {
|
|
223
|
+
bubbles: true,
|
|
224
|
+
composed: true
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
setValidity() {
|
|
228
|
+
let flags = {};
|
|
229
|
+
let message = "";
|
|
230
|
+
const range = parseInterval(this.value);
|
|
231
|
+
if (this.required && !this.value) {
|
|
232
|
+
flags = { valueMissing: true };
|
|
233
|
+
message = Locale.getValue("valueMissing");
|
|
234
|
+
} else if (this.value && !range) {
|
|
235
|
+
flags = { badInput: true };
|
|
236
|
+
message = Locale.getValue("badInput");
|
|
237
|
+
} else if (range && this.min && parseISODate(range.start) < parseISODate(this.min)) {
|
|
238
|
+
flags = { rangeUnderflow: true };
|
|
239
|
+
message = Locale.getValue("rangeUnderflow", { min: this.min });
|
|
240
|
+
} else if (range && this.max && parseISODate(range.end) > parseISODate(this.max)) {
|
|
241
|
+
flags = { rangeOverflow: true };
|
|
242
|
+
message = Locale.getValue("rangeOverflow", { max: this.max });
|
|
243
|
+
}
|
|
244
|
+
this.commit(flags, message, this.containerEl ?? void 0);
|
|
245
|
+
}
|
|
246
|
+
reset() {
|
|
247
|
+
this.value = void 0;
|
|
248
|
+
this.invalid = false;
|
|
249
|
+
}
|
|
250
|
+
/** `.container` is a div — no native `disabled`, so a disabled picker ignores `focus()` here. */
|
|
251
|
+
focus(options) {
|
|
252
|
+
if (this.effectivelyDisabled) return;
|
|
253
|
+
this.containerEl?.focus(options);
|
|
254
|
+
}
|
|
255
|
+
blur() {
|
|
256
|
+
this.containerEl?.blur();
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
__decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDateRangePicker.prototype, "min", void 0);
|
|
260
|
+
__decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDateRangePicker.prototype, "max", void 0);
|
|
261
|
+
__decorate([property({
|
|
262
|
+
type: Boolean,
|
|
263
|
+
reflect: true
|
|
264
|
+
}), __decorateMetadata("design:type", Boolean)], UDateRangePicker.prototype, "clearable", void 0);
|
|
265
|
+
__decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDateRangePicker.prototype, "placeholder", void 0);
|
|
266
|
+
__decorate([property({
|
|
267
|
+
attribute: "presets",
|
|
268
|
+
converter: { fromAttribute: (v) => (v ?? "").split(/\s+/).filter(Boolean) }
|
|
269
|
+
}), __decorateMetadata("design:type", Array)], UDateRangePicker.prototype, "presets", void 0);
|
|
270
|
+
__decorate([query(".container", true), __decorateMetadata("design:type", typeof HTMLElement === "undefined" ? Object : HTMLElement)], UDateRangePicker.prototype, "containerEl", void 0);
|
|
271
|
+
__decorate([query("u-popover", true), __decorateMetadata("design:type", typeof UPopover === "undefined" ? Object : UPopover)], UDateRangePicker.prototype, "popoverEl", void 0);
|
|
272
|
+
__decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDateRangePicker.prototype, "calendarEl", void 0);
|
|
273
|
+
__decorate([state(), __decorateMetadata("design:type", Boolean)], UDateRangePicker.prototype, "open", void 0);
|
|
274
|
+
UDateRangePicker = __decorate([customElement("u-date-range-picker")], UDateRangePicker);
|
|
275
|
+
//#endregion
|
|
276
|
+
export { UDateRangePicker };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const styles: import('lit').CSSResult;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
//#region src/components/date-range-picker/UDateRangePicker.styles.ts
|
|
3
|
+
var styles = css`
|
|
4
|
+
:host {
|
|
5
|
+
position: relative;
|
|
6
|
+
display: var(--u-date-range-picker-display, inline-block);
|
|
7
|
+
width: var(--u-date-range-picker-width, auto);
|
|
8
|
+
color: var(--u-txt-color, #212121);
|
|
9
|
+
font-size: inherit;
|
|
10
|
+
font-family: var(--u-font-base);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* 두 달이 나란히 들어가는 폭을 내용에서 얻는다(달마다 칸 7 × 32px 이상). 화면이 그보다 좁으면
|
|
14
|
+
팝오버가 뷰포트 안에 머물고, 달력이 둘째 달을 아래로 내린다. */
|
|
15
|
+
u-popover {
|
|
16
|
+
width: max-content;
|
|
17
|
+
max-width: calc(100vw - 16px);
|
|
18
|
+
}
|
|
19
|
+
/* 빠른 선택 목록은 달력 왼쪽 세로 줄 — 자리가 모자라면(좁은 화면) 달력 위로 올라가 가로로 흐른다. */
|
|
20
|
+
.body {
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: row;
|
|
23
|
+
flex-wrap: wrap;
|
|
24
|
+
gap: 8px;
|
|
25
|
+
}
|
|
26
|
+
.presets {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-direction: column;
|
|
29
|
+
align-items: stretch;
|
|
30
|
+
gap: 2px;
|
|
31
|
+
padding-inline-end: 8px;
|
|
32
|
+
border-inline-end: 1px solid var(--u-border-color-weak, #EEEEEE);
|
|
33
|
+
}
|
|
34
|
+
.preset {
|
|
35
|
+
display: flex;
|
|
36
|
+
align-items: center;
|
|
37
|
+
min-height: 28px;
|
|
38
|
+
padding: 0 10px;
|
|
39
|
+
border: none;
|
|
40
|
+
border-radius: var(--u-radius-md, 4px);
|
|
41
|
+
background: transparent;
|
|
42
|
+
color: var(--u-txt-color, #212121);
|
|
43
|
+
font: inherit;
|
|
44
|
+
font-size: var(--u-text-label-size, 13px);
|
|
45
|
+
text-align: start;
|
|
46
|
+
white-space: nowrap;
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
}
|
|
49
|
+
.preset:hover:not(:disabled) {
|
|
50
|
+
background-color: var(--u-bg-color-hover, #F5F5F5);
|
|
51
|
+
}
|
|
52
|
+
.preset:focus-visible {
|
|
53
|
+
outline: none;
|
|
54
|
+
box-shadow: 0 0 0 2px var(--u-input-border-color-focus, #1565C0);
|
|
55
|
+
}
|
|
56
|
+
/* 지금 범위와 같은 프리셋 — 달력의 띠와 같은 색 축으로 «지금 이것» 을 보인다. */
|
|
57
|
+
.preset[aria-pressed="true"] {
|
|
58
|
+
background-color: var(--u-primary-bg-color, #E3F2FD);
|
|
59
|
+
color: var(--u-primary-color-strong, #1565C0);
|
|
60
|
+
font-weight: var(--u-text-label-weight, 600);
|
|
61
|
+
}
|
|
62
|
+
.preset:disabled {
|
|
63
|
+
color: var(--u-txt-color-disabled, #BDBDBD);
|
|
64
|
+
cursor: not-allowed;
|
|
65
|
+
}
|
|
66
|
+
.calendar {
|
|
67
|
+
flex: 1 1 auto;
|
|
68
|
+
min-width: 0;
|
|
69
|
+
}
|
|
70
|
+
@media (max-width: 560px) {
|
|
71
|
+
.presets {
|
|
72
|
+
flex-direction: row;
|
|
73
|
+
flex-wrap: wrap;
|
|
74
|
+
flex-basis: 100%;
|
|
75
|
+
padding-inline-end: 0;
|
|
76
|
+
padding-block-end: 8px;
|
|
77
|
+
border-inline-end: none;
|
|
78
|
+
border-block-end: 1px solid var(--u-border-color-weak, #EEEEEE);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
//#endregion
|
|
83
|
+
export { styles };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { LocaleMessageKey } from '../../utilities/Locale.js';
|
|
2
|
+
/** A built-in quick range, named so it can be listed in the `presets` attribute. */
|
|
3
|
+
export type DateRangePresetName = 'today' | 'yesterday' | 'last7Days' | 'last30Days' | 'thisWeek' | 'lastWeek' | 'thisMonth' | 'lastMonth' | 'thisYear';
|
|
4
|
+
/**
|
|
5
|
+
* A quick range the app defines — a fiscal quarter, "since the last release". `range` runs when
|
|
6
|
+
* the preset is drawn and when it is picked, so a relative range stays current. It returns the
|
|
7
|
+
* two ends as `Date`s (local calendar days) or ISO `YYYY-MM-DD` strings, in either order.
|
|
8
|
+
*/
|
|
9
|
+
export interface DateRangePreset {
|
|
10
|
+
label: string;
|
|
11
|
+
range: () => [Date | string, Date | string];
|
|
12
|
+
}
|
|
13
|
+
/** What the `presets` property takes — built-in names and app-defined presets, in display order. */
|
|
14
|
+
export type DateRangePresetOption = DateRangePresetName | DateRangePreset;
|
|
15
|
+
/** A preset ready to draw: its label and its two ISO ends, earliest first. */
|
|
16
|
+
export interface ResolvedPreset {
|
|
17
|
+
label: string;
|
|
18
|
+
start: string;
|
|
19
|
+
end: string;
|
|
20
|
+
}
|
|
21
|
+
type Builtin = {
|
|
22
|
+
key: LocaleMessageKey;
|
|
23
|
+
range: (today: Date) => [Date, Date];
|
|
24
|
+
};
|
|
25
|
+
/** Built-in ranges as pure functions of "today" (a local calendar day). Both ends are inclusive. */
|
|
26
|
+
export declare const BUILTIN_PRESETS: Record<DateRangePresetName, Builtin>;
|
|
27
|
+
/**
|
|
28
|
+
* Resolves the `presets` list against `today` — labels through the active locale, ends as ISO
|
|
29
|
+
* days earliest first. An unknown name is skipped and reported through `onUnknown`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolvePresets(options: readonly DateRangePresetOption[], today: Date, onUnknown?: (name: string) => void): ResolvedPreset[];
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Locale } from "../../utilities/Locale.js";
|
|
2
|
+
import { addDays, addMonths, daysInMonth, parseISODate, toISODate } from "../calendar/dates.js";
|
|
3
|
+
//#region src/components/date-range-picker/presets.ts
|
|
4
|
+
var startOfWeek = (d) => addDays(d, -d.getDay());
|
|
5
|
+
var endOfMonth = (d) => new Date(d.getFullYear(), d.getMonth(), daysInMonth(d));
|
|
6
|
+
/** Built-in ranges as pure functions of "today" (a local calendar day). Both ends are inclusive. */
|
|
7
|
+
var BUILTIN_PRESETS = {
|
|
8
|
+
today: {
|
|
9
|
+
key: "today",
|
|
10
|
+
range: (t) => [t, t]
|
|
11
|
+
},
|
|
12
|
+
yesterday: {
|
|
13
|
+
key: "yesterday",
|
|
14
|
+
range: (t) => [addDays(t, -1), addDays(t, -1)]
|
|
15
|
+
},
|
|
16
|
+
last7Days: {
|
|
17
|
+
key: "last7Days",
|
|
18
|
+
range: (t) => [addDays(t, -6), t]
|
|
19
|
+
},
|
|
20
|
+
last30Days: {
|
|
21
|
+
key: "last30Days",
|
|
22
|
+
range: (t) => [addDays(t, -29), t]
|
|
23
|
+
},
|
|
24
|
+
thisWeek: {
|
|
25
|
+
key: "thisWeek",
|
|
26
|
+
range: (t) => [startOfWeek(t), addDays(startOfWeek(t), 6)]
|
|
27
|
+
},
|
|
28
|
+
lastWeek: {
|
|
29
|
+
key: "lastWeek",
|
|
30
|
+
range: (t) => [addDays(startOfWeek(t), -7), addDays(startOfWeek(t), -1)]
|
|
31
|
+
},
|
|
32
|
+
thisMonth: {
|
|
33
|
+
key: "thisMonth",
|
|
34
|
+
range: (t) => [addMonths(t, 0), endOfMonth(t)]
|
|
35
|
+
},
|
|
36
|
+
lastMonth: {
|
|
37
|
+
key: "lastMonth",
|
|
38
|
+
range: (t) => [addMonths(t, -1), endOfMonth(addMonths(t, -1))]
|
|
39
|
+
},
|
|
40
|
+
thisYear: {
|
|
41
|
+
key: "thisYear",
|
|
42
|
+
range: (t) => [new Date(t.getFullYear(), 0, 1), new Date(t.getFullYear(), 11, 31)]
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var toISO = (v) => typeof v === "string" ? toISODate(parseISODate(v)) : toISODate(v);
|
|
46
|
+
/**
|
|
47
|
+
* Resolves the `presets` list against `today` — labels through the active locale, ends as ISO
|
|
48
|
+
* days earliest first. An unknown name is skipped and reported through `onUnknown`.
|
|
49
|
+
*/
|
|
50
|
+
function resolvePresets(options, today, onUnknown) {
|
|
51
|
+
const out = [];
|
|
52
|
+
for (const option of options) if (typeof option === "string") {
|
|
53
|
+
const builtin = BUILTIN_PRESETS[option];
|
|
54
|
+
if (!builtin) {
|
|
55
|
+
onUnknown?.(option);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const [a, b] = builtin.range(today);
|
|
59
|
+
out.push(ordered(Locale.getValue(builtin.key), toISODate(a), toISODate(b)));
|
|
60
|
+
} else {
|
|
61
|
+
const [a, b] = option.range();
|
|
62
|
+
out.push(ordered(option.label, toISO(a), toISO(b)));
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
function ordered(label, a, b) {
|
|
67
|
+
return a <= b ? {
|
|
68
|
+
label,
|
|
69
|
+
start: a,
|
|
70
|
+
end: b
|
|
71
|
+
} : {
|
|
72
|
+
label,
|
|
73
|
+
start: b,
|
|
74
|
+
end: a
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
export { BUILTIN_PRESETS, resolvePresets };
|
|
@@ -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 { UOverlayElement } from "../UOverlayElement.js";
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.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 { styles } from "./UDivider.styles.js";
|
|
5
5
|
import { html } from "lit";
|
|
6
6
|
import { customElement, property } from "lit/decorators.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 { UOverlayElement } from "../UOverlayElement.js";
|
|
4
4
|
import "../button/UButton.js";
|
|
5
5
|
import "../icon/UIcon.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 "../icon/UIcon.js";
|
|
5
5
|
import { styles } from "./UExpander.styles.js";
|
|
6
6
|
import { html } from "lit";
|
|
@@ -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 { devWarnOnce } from "../../utilities/devWarning.js";
|
|
5
5
|
import { styles } from "./UField.styles.js";
|
|
6
6
|
import { html, nothing } from "lit";
|
|
@@ -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 { UFormControlElement } from "../UFormControlElement.js";
|
|
5
5
|
import { arrayAttrConverter } from "../../utilities/converters.js";
|
|
6
6
|
import { styles } from "./UForm.styles.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 { IconRegistry, getDefaultBaseUrl } from "../../utilities/icons.js";
|
|
5
5
|
import { devWarnOnce } from "../../utilities/devWarning.js";
|
|
6
6
|
import { styles } from "./UIcon.styles.js";
|