@iyulab/components 1.52.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.
Files changed (106) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/README.md +54 -1
  3. package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/decorate.js +1 -1
  4. package/dist/_virtual/{_@oxc-project_runtime@0.151.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/decorateMetadata.js +1 -1
  5. package/dist/_virtual/_glob-assets_raw/player-pause-fill.svg.a756c400.js +4 -0
  6. package/dist/_virtual/_glob-assets_raw/player-play-fill.svg.768b6efc.js +4 -0
  7. package/dist/assets/locales/ar.json.js +27 -1
  8. package/dist/assets/locales/de.json.js +27 -1
  9. package/dist/assets/locales/en.json.js +27 -1
  10. package/dist/assets/locales/es.json.js +27 -1
  11. package/dist/assets/locales/fr.json.js +27 -1
  12. package/dist/assets/locales/id.json.js +27 -1
  13. package/dist/assets/locales/ja.json.js +27 -1
  14. package/dist/assets/locales/ko.json.js +27 -1
  15. package/dist/assets/locales/pt-BR.json.js +27 -1
  16. package/dist/assets/locales/ru.json.js +27 -1
  17. package/dist/assets/locales/th.json.js +27 -1
  18. package/dist/assets/locales/vi.json.js +27 -1
  19. package/dist/assets/locales/zh-CN.json.js +27 -1
  20. package/dist/assets/locales/zh-TW.json.js +27 -1
  21. package/dist/components/UFloatingElement.js +2 -2
  22. package/dist/components/UFormControlElement.js +2 -2
  23. package/dist/components/UOverlayElement.js +2 -2
  24. package/dist/components/alert/UAlert.js +2 -2
  25. package/dist/components/avatar/UAvatar.js +2 -2
  26. package/dist/components/badge/UBadge.js +2 -2
  27. package/dist/components/breadcrumb/UBreadcrumb.js +1 -1
  28. package/dist/components/breadcrumb-item/UBreadcrumbItem.js +2 -2
  29. package/dist/components/button/UButton.js +2 -2
  30. package/dist/components/button-group/UButtonGroup.js +2 -2
  31. package/dist/components/calendar/UCalendar.d.ts +101 -0
  32. package/dist/components/calendar/UCalendar.js +223 -0
  33. package/dist/components/calendar/UCalendar.styles.d.ts +1 -0
  34. package/dist/components/calendar/UCalendar.styles.js +137 -0
  35. package/dist/components/calendar/dates.d.ts +13 -0
  36. package/dist/components/calendar/dates.js +37 -0
  37. package/dist/components/calendar/picker.styles.d.ts +5 -0
  38. package/dist/components/calendar/picker.styles.js +78 -0
  39. package/dist/components/card/UCard.js +2 -2
  40. package/dist/components/carousel/UCarousel.d.ts +17 -0
  41. package/dist/components/carousel/UCarousel.js +53 -12
  42. package/dist/components/carousel/UCarousel.styles.js +20 -0
  43. package/dist/components/checkbox/UCheckbox.js +2 -2
  44. package/dist/components/chip/UChip.js +2 -2
  45. package/dist/components/copy-button/UCopyButton.js +2 -2
  46. package/dist/components/date-picker/UDatePicker.d.ts +8 -13
  47. package/dist/components/date-picker/UDatePicker.js +36 -165
  48. package/dist/components/date-picker/UDatePicker.styles.js +0 -135
  49. package/dist/components/date-range-picker/UDateRangePicker.d.ts +113 -0
  50. package/dist/components/date-range-picker/UDateRangePicker.js +276 -0
  51. package/dist/components/date-range-picker/UDateRangePicker.styles.d.ts +1 -0
  52. package/dist/components/date-range-picker/UDateRangePicker.styles.js +83 -0
  53. package/dist/components/date-range-picker/presets.d.ts +32 -0
  54. package/dist/components/date-range-picker/presets.js +78 -0
  55. package/dist/components/dialog/UDialog.js +2 -2
  56. package/dist/components/divider/UDivider.js +2 -2
  57. package/dist/components/drawer/UDrawer.js +2 -2
  58. package/dist/components/expander/UExpander.js +2 -2
  59. package/dist/components/field/UField.js +2 -2
  60. package/dist/components/file-input/UFileInput.js +2 -2
  61. package/dist/components/form/UForm.js +2 -2
  62. package/dist/components/icon/UIcon.js +2 -2
  63. package/dist/components/icon-button/UIconButton.js +2 -2
  64. package/dist/components/input/UInput.d.ts +31 -3
  65. package/dist/components/input/UInput.js +131 -24
  66. package/dist/components/menu/UMenu.js +2 -2
  67. package/dist/components/menu-item/UMenuItem.js +2 -2
  68. package/dist/components/option/UOption.js +2 -2
  69. package/dist/components/panel/UPanel.js +2 -2
  70. package/dist/components/popover/UPopover.js +2 -2
  71. package/dist/components/progress-bar/UProgressBar.js +2 -2
  72. package/dist/components/progress-ring/UProgressRing.js +2 -2
  73. package/dist/components/radio/URadio.js +2 -2
  74. package/dist/components/rating/URating.js +2 -2
  75. package/dist/components/select/USelect.js +2 -2
  76. package/dist/components/skeleton/USkeleton.js +2 -2
  77. package/dist/components/slider/USlider.js +2 -2
  78. package/dist/components/spinner/USpinner.js +2 -2
  79. package/dist/components/split-panel/USplitPanel.js +2 -2
  80. package/dist/components/switch/USwitch.js +2 -2
  81. package/dist/components/tab/UTab.js +2 -2
  82. package/dist/components/tab-panel/UTabPanel.js +2 -2
  83. package/dist/components/tag/UTag.js +2 -2
  84. package/dist/components/text/UText.js +2 -2
  85. package/dist/components/textarea/UTextarea.js +2 -2
  86. package/dist/components/tooltip/UTooltip.js +2 -2
  87. package/dist/components/tree/UTree.js +2 -2
  88. package/dist/components/tree-item/UTreeItem.js +2 -2
  89. package/dist/index.d.ts +1 -0
  90. package/dist/index.js +3 -2
  91. package/dist/plugins/vite-plugin-react-wrapper.d.ts +7 -0
  92. package/dist/plugins/vite-plugin-react-wrapper.js +11 -1
  93. package/dist/react/UDateRangePicker.d.ts +13 -0
  94. package/dist/react/UDateRangePicker.js +12 -0
  95. package/dist/react/index.d.ts +1 -0
  96. package/dist/react/index.js +1 -0
  97. package/dist/utilities/Locale.d.ts +1 -1
  98. package/dist/utilities/format.d.ts +27 -0
  99. package/dist/utilities/format.js +71 -1
  100. package/dist/utilities/icons.js +4 -0
  101. package/package.json +3 -3
  102. package/skills/iyulab-components/SKILL.md +1 -0
  103. package/skills/iyulab-components/references/components/carousel.md +6 -0
  104. package/skills/iyulab-components/references/components/date-picker.md +2 -0
  105. package/skills/iyulab-components/references/components/date-range-picker.md +147 -0
  106. package/skills/iyulab-components/references/components/input.md +14 -4
@@ -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 };
@@ -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 {};