@sebgroup/green-core 1.15.0 → 1.16.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/README.md +101 -7
- package/chunks/chunk.274BU2AI.js +244 -0
- package/chunks/chunk.2LQSDOD4.js +29 -0
- package/chunks/chunk.2ND5EWHE.js +65 -0
- package/chunks/chunk.2OOTOCUG.js +420 -0
- package/chunks/chunk.2WO4NHJ2.js +34 -0
- package/chunks/chunk.2Y3BHFKO.js +154 -0
- package/chunks/chunk.375BWME4.js +29 -0
- package/chunks/chunk.3SEVAGLE.js +96 -0
- package/chunks/chunk.522C22QY.js +460 -0
- package/chunks/chunk.5VURDMKE.js +75 -0
- package/chunks/chunk.6NM7ENKA.js +31 -0
- package/chunks/chunk.6UA66KQU.js +153 -0
- package/chunks/chunk.7P5N6NZL.js +560 -0
- package/chunks/chunk.7TCXY7BP.js +0 -0
- package/chunks/chunk.D7H7CUS4.js +55 -0
- package/chunks/chunk.DFYMYEGD.js +78 -0
- package/chunks/chunk.HS7ICQNA.js +0 -0
- package/chunks/chunk.IYCENQZG.js +28 -0
- package/chunks/chunk.J2A6J77W.js +81 -0
- package/chunks/chunk.KC32OWZE.js +274 -0
- package/chunks/chunk.KV4SDMFS.js +101 -0
- package/chunks/chunk.LUHCF4BJ.js +64 -0
- package/chunks/chunk.MAD5DQMN.js +161 -0
- package/chunks/chunk.MI4A2C2A.js +0 -0
- package/chunks/chunk.NOYHINYP.js +467 -0
- package/chunks/chunk.Q2T57HE7.js +0 -0
- package/chunks/chunk.QONSFT2N.js +4653 -0
- package/chunks/chunk.TMBQL2RO.js +0 -0
- package/chunks/chunk.TN6ZYAH3.js +74 -0
- package/chunks/chunk.TSDZQZBY.js +0 -0
- package/chunks/chunk.TX64TTBN.js +0 -0
- package/chunks/chunk.UF6IEONX.js +0 -0
- package/chunks/chunk.VOYMQ322.js +61 -0
- package/chunks/chunk.VYK7D6QO.js +64 -0
- package/chunks/chunk.WDZ2JTCP.js +360 -0
- package/chunks/chunk.WJDR7FTS.js +193 -0
- package/chunks/chunk.WM7HBMMV.js +54 -0
- package/chunks/chunk.XHTJVQUJ.js +140 -0
- package/chunks/chunk.XI4H54TV.js +39 -0
- package/chunks/chunk.XU4HZLJL.js +0 -0
- package/chunks/chunk.YIQIH4RW.js +139 -0
- package/chunks/chunk.YJHAKLGR.js +54 -0
- package/chunks/chunk.YO24ZYAD.js +0 -0
- package/chunks/chunk.ZTE73BY2.js +655 -0
- package/components/badge/badge.js +245 -0
- package/components/button/button.d.ts +5 -5
- package/components/button/button.js +18 -0
- package/components/button/button.trans.styles.d.ts +2 -0
- package/components/button/index.d.ts +1 -0
- package/components/button/index.js +18 -0
- package/components/checkbox/checkbox.js +219 -0
- package/components/context-menu/context-menu.d.ts +2 -1
- package/components/context-menu/context-menu.js +22 -0
- package/components/context-menu/index.d.ts +3 -0
- package/components/context-menu/index.js +29 -0
- package/components/datepicker/date-part-spinner.js +10 -0
- package/components/datepicker/datepicker.d.ts +3 -2
- package/components/datepicker/datepicker.js +29 -0
- package/components/datepicker/index.d.ts +1 -0
- package/components/datepicker/index.js +29 -0
- package/components/dropdown/dropdown.d.ts +2 -2
- package/components/dropdown/dropdown.js +22 -0
- package/components/dropdown/index.d.ts +3 -0
- package/components/dropdown/index.js +30 -0
- package/components/form-control.js +12 -0
- package/components/grid/grid.d.ts +2 -2
- package/components/grid/grid.js +11 -0
- package/components/grid/grid.style.css.js +7 -0
- package/components/grid/index.d.ts +1 -0
- package/components/grid/index.js +11 -0
- package/components/grouped-list/grouped-list.js +14 -0
- package/components/grouped-list/index.d.ts +2 -0
- package/components/grouped-list/index.js +17 -0
- package/components/grouped-list/list-item.js +10 -0
- package/components/icon/icon.d.ts +2 -2
- package/components/icon/icon.js +10 -0
- package/components/icon/index.d.ts +1 -0
- package/components/icon/index.js +10 -0
- package/components/index.d.ts +4 -3
- package/components/index.js +81 -0
- package/components/input/input.js +682 -0
- package/components/radio/radio-group.js +9 -0
- package/components/radio/radio.js +240 -0
- package/components/segmented-control/index.d.ts +1 -0
- package/components/segmented-control/index.js +15 -0
- package/components/segmented-control/segment/index.d.ts +1 -0
- package/components/segmented-control/segment/index.js +13 -0
- package/components/segmented-control/segment/segment.js +12 -0
- package/components/segmented-control/segmented-control.d.ts +1 -1
- package/components/segmented-control/segmented-control.js +15 -0
- package/components/switch/switch.js +164 -0
- package/components/theme/index.d.ts +1 -0
- package/components/theme/index.js +11 -0
- package/components/theme/theme.js +11 -0
- package/components/tooltip/tooltip.js +252 -0
- package/index.js +72 -4278
- package/localization.js +40 -44
- package/package.json +7 -16
- package/primitives/calendar/calendar.js +13 -0
- package/primitives/calendar/functions.js +7 -0
- package/primitives/calendar/index.d.ts +1 -0
- package/primitives/calendar/index.js +14 -0
- package/primitives/listbox/index.d.ts +0 -1
- package/primitives/listbox/index.js +17 -0
- package/primitives/listbox/listbox.d.ts +2 -1
- package/primitives/listbox/listbox.js +16 -0
- package/primitives/listbox/option.js +14 -0
- package/primitives/menu/index.d.ts +1 -0
- package/primitives/menu/index.js +15 -0
- package/primitives/menu/menu-heading.js +11 -0
- package/primitives/menu/menu-item.d.ts +1 -2
- package/primitives/menu/menu-item.js +12 -0
- package/primitives/menu/menu.d.ts +2 -1
- package/primitives/menu/menu.js +14 -0
- package/primitives/popover/index.js +14 -0
- package/primitives/popover/popover.js +13 -0
- package/primitives/ripple/index.d.ts +1 -0
- package/primitives/ripple/index.js +11 -0
- package/primitives/ripple/ripple.d.ts +1 -1
- package/primitives/ripple/ripple.js +10 -0
- package/scoping.d.ts +1 -0
- package/scoping.js +18 -0
- package/transitional-styles.js +6 -4275
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
import {
|
|
2
|
+
GdsFormControlElement
|
|
3
|
+
} from "./chunk.YIQIH4RW.js";
|
|
4
|
+
import {
|
|
5
|
+
TransitionalStyles
|
|
6
|
+
} from "./chunk.QONSFT2N.js";
|
|
7
|
+
import {
|
|
8
|
+
watch
|
|
9
|
+
} from "./chunk.2WO4NHJ2.js";
|
|
10
|
+
import {
|
|
11
|
+
gdsCustomElement,
|
|
12
|
+
html
|
|
13
|
+
} from "./chunk.VOYMQ322.js";
|
|
14
|
+
import {
|
|
15
|
+
__decorateClass,
|
|
16
|
+
__privateAdd,
|
|
17
|
+
__privateGet,
|
|
18
|
+
__privateMethod,
|
|
19
|
+
__privateSet
|
|
20
|
+
} from "./chunk.5VURDMKE.js";
|
|
21
|
+
|
|
22
|
+
// libs/core/src/components/datepicker/datepicker.ts
|
|
23
|
+
import { property, query, queryAll, queryAsync, state } from "lit/decorators.js";
|
|
24
|
+
import { join } from "lit/directives/join.js";
|
|
25
|
+
import { when } from "lit/directives/when.js";
|
|
26
|
+
import { until } from "lit/directives/until.js";
|
|
27
|
+
import { map } from "lit/directives/map.js";
|
|
28
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
29
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
30
|
+
import { nothing } from "lit";
|
|
31
|
+
import { msg } from "@lit/localize";
|
|
32
|
+
|
|
33
|
+
// libs/core/src/components/datepicker/datepicker.styles.ts
|
|
34
|
+
import { css } from "lit";
|
|
35
|
+
var styles = css`
|
|
36
|
+
@layer base, reset, transitional-styles;
|
|
37
|
+
@layer base {
|
|
38
|
+
label {
|
|
39
|
+
display: block;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
`;
|
|
43
|
+
|
|
44
|
+
// libs/core/src/components/datepicker/datepicker.ts
|
|
45
|
+
var dateConverter = {
|
|
46
|
+
fromAttribute(value) {
|
|
47
|
+
return new Date(value);
|
|
48
|
+
},
|
|
49
|
+
toAttribute(value) {
|
|
50
|
+
return value.toISOString();
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var dateArrayConverter = {
|
|
54
|
+
fromAttribute(value) {
|
|
55
|
+
return value.split(",").map((d) => new Date(d.trim()));
|
|
56
|
+
},
|
|
57
|
+
toAttribute(value) {
|
|
58
|
+
return JSON.stringify(value.map((d) => d.toISOString()));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
var _valueOnOpen, _renderBackToValidRangeButton, renderBackToValidRangeButton_fn, _focusDate, focusDate_fn, _getSpinnerLabel, getSpinnerLabel_fn, _getMinSpinnerValue, getMinSpinnerValue_fn, _getMaxSpinnerValue, getMaxSpinnerValue_fn, _dispatchChangeEvent, dispatchChangeEvent_fn, _dispatchInputEvent, dispatchInputEvent_fn, _handleFieldFocusOut, _handleSpinnerFocus, _handleClipboardCopy, _handleClipboardPaste, _handleFieldClick, _handleCalendarChange, _handleMonthChange, _handleYearChange, _handleIncrementFocusedMonth, _handleDecrementFocusedMonth, _handleCalendarFocusChange, _handlePopoverStateChange, _handleSpinnerKeydown, _parseDateFormat, parseDateFormat_fn, _handleSpinnerChange, _spinnerState, _years, years_get, _isValueOutsideRange, isValueOutsideRange_get;
|
|
62
|
+
var GdsDatepicker = class extends GdsFormControlElement {
|
|
63
|
+
constructor() {
|
|
64
|
+
super(...arguments);
|
|
65
|
+
__privateAdd(this, _renderBackToValidRangeButton);
|
|
66
|
+
__privateAdd(this, _focusDate);
|
|
67
|
+
__privateAdd(this, _getSpinnerLabel);
|
|
68
|
+
__privateAdd(this, _getMinSpinnerValue);
|
|
69
|
+
__privateAdd(this, _getMaxSpinnerValue);
|
|
70
|
+
__privateAdd(this, _dispatchChangeEvent);
|
|
71
|
+
__privateAdd(this, _dispatchInputEvent);
|
|
72
|
+
/**
|
|
73
|
+
* Takes a dateformat string from the dateformat attribute and turnes it to a DateFormatLayout object used in rendering the template.
|
|
74
|
+
*/
|
|
75
|
+
__privateAdd(this, _parseDateFormat);
|
|
76
|
+
/**
|
|
77
|
+
* Returns a year iterator between the min and max dates for use in the year dropdown.
|
|
78
|
+
*/
|
|
79
|
+
__privateAdd(this, _years);
|
|
80
|
+
__privateAdd(this, _isValueOutsideRange);
|
|
81
|
+
this.min = new Date((/* @__PURE__ */ new Date()).getFullYear() - 10, 0, 1);
|
|
82
|
+
this.max = new Date((/* @__PURE__ */ new Date()).getFullYear() + 10, 0, 1);
|
|
83
|
+
this.open = false;
|
|
84
|
+
this.label = "";
|
|
85
|
+
this.showWeekNumbers = false;
|
|
86
|
+
this.size = "medium";
|
|
87
|
+
this.hideLabel = false;
|
|
88
|
+
this.disabledWeekends = false;
|
|
89
|
+
this._focusedMonth = (/* @__PURE__ */ new Date()).getMonth();
|
|
90
|
+
this._focusedYear = (/* @__PURE__ */ new Date()).getFullYear();
|
|
91
|
+
this._dateFormatLayout = __privateMethod(this, _parseDateFormat, parseDateFormat_fn).call(this, "y-m-d");
|
|
92
|
+
__privateAdd(this, _valueOnOpen, void 0);
|
|
93
|
+
__privateAdd(this, _handleFieldFocusOut, (e) => {
|
|
94
|
+
this._elTrigger.then((_) => {
|
|
95
|
+
var _a, _b;
|
|
96
|
+
const parent = (_a = e.relatedTarget) == null ? void 0 : _a.parentElement;
|
|
97
|
+
if (parent === e.target)
|
|
98
|
+
return;
|
|
99
|
+
(_b = document.getSelection()) == null ? void 0 : _b.removeAllRanges();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
__privateAdd(this, _handleSpinnerFocus, (e) => {
|
|
103
|
+
this._elTrigger.then((field) => {
|
|
104
|
+
var _a, _b;
|
|
105
|
+
(_a = document.getSelection()) == null ? void 0 : _a.removeAllRanges();
|
|
106
|
+
const range = new Range();
|
|
107
|
+
range.setStart(field.firstChild, 0);
|
|
108
|
+
range.setEnd(field.lastChild, 4);
|
|
109
|
+
(_b = document.getSelection()) == null ? void 0 : _b.addRange(range);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
__privateAdd(this, _handleClipboardCopy, (e) => {
|
|
113
|
+
this._elTrigger.then((field) => {
|
|
114
|
+
var _a;
|
|
115
|
+
if (e.currentTarget !== field)
|
|
116
|
+
return;
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
(_a = e.clipboardData) == null ? void 0 : _a.setData("text/plain", this.displayValue);
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
__privateAdd(this, _handleClipboardPaste, (e) => {
|
|
122
|
+
this._elTrigger.then((field) => {
|
|
123
|
+
var _a;
|
|
124
|
+
if (e.currentTarget !== field)
|
|
125
|
+
return;
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
const pasted = (_a = e.clipboardData) == null ? void 0 : _a.getData("text/plain");
|
|
128
|
+
if (!pasted)
|
|
129
|
+
return;
|
|
130
|
+
const pastedDate = new Date(pasted);
|
|
131
|
+
if (pastedDate.toString() === "Invalid Date")
|
|
132
|
+
return;
|
|
133
|
+
this.value = pastedDate;
|
|
134
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
__privateAdd(this, _handleFieldClick, (e) => {
|
|
138
|
+
var _a;
|
|
139
|
+
(_a = this._elSpinners[0]) == null ? void 0 : _a.focus();
|
|
140
|
+
});
|
|
141
|
+
__privateAdd(this, _handleCalendarChange, (e) => {
|
|
142
|
+
e.stopPropagation();
|
|
143
|
+
this.value = e.detail;
|
|
144
|
+
this.open = false;
|
|
145
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
146
|
+
});
|
|
147
|
+
__privateAdd(this, _handleMonthChange, (e) => {
|
|
148
|
+
var _a;
|
|
149
|
+
e.stopPropagation();
|
|
150
|
+
this._focusedMonth = (_a = e.target) == null ? void 0 : _a.value;
|
|
151
|
+
});
|
|
152
|
+
__privateAdd(this, _handleYearChange, (e) => {
|
|
153
|
+
var _a;
|
|
154
|
+
e.stopPropagation();
|
|
155
|
+
this._focusedYear = (_a = e.target) == null ? void 0 : _a.value;
|
|
156
|
+
});
|
|
157
|
+
__privateAdd(this, _handleIncrementFocusedMonth, (_e) => {
|
|
158
|
+
this._focusedMonth++;
|
|
159
|
+
if (this._focusedMonth > 11) {
|
|
160
|
+
this._focusedMonth = 0;
|
|
161
|
+
this._focusedYear++;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
__privateAdd(this, _handleDecrementFocusedMonth, (_e) => {
|
|
165
|
+
this._focusedMonth--;
|
|
166
|
+
if (this._focusedMonth < 0) {
|
|
167
|
+
this._focusedMonth = 11;
|
|
168
|
+
this._focusedYear--;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
__privateAdd(this, _handleCalendarFocusChange, async () => {
|
|
172
|
+
this._focusedMonth = (await this._elCalendar).focusedMonth;
|
|
173
|
+
this._focusedYear = (await this._elCalendar).focusedYear;
|
|
174
|
+
this.value = (await this._elCalendar).focusedDate;
|
|
175
|
+
this.requestUpdate();
|
|
176
|
+
__privateMethod(this, _dispatchInputEvent, dispatchInputEvent_fn).call(this);
|
|
177
|
+
});
|
|
178
|
+
__privateAdd(this, _handlePopoverStateChange, async (e) => {
|
|
179
|
+
if (e.target !== e.currentTarget)
|
|
180
|
+
return;
|
|
181
|
+
this.open = e.detail.open;
|
|
182
|
+
if (e.detail.reason === "close") {
|
|
183
|
+
this.value = (await this._elCalendar).value;
|
|
184
|
+
if (this.value) {
|
|
185
|
+
this._focusedMonth = this.value.getMonth();
|
|
186
|
+
this._focusedYear = this.value.getFullYear();
|
|
187
|
+
}
|
|
188
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
189
|
+
}
|
|
190
|
+
if (e.detail.reason === "cancel") {
|
|
191
|
+
this.value = __privateGet(this, _valueOnOpen);
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
__privateAdd(this, _handleSpinnerKeydown, (e) => {
|
|
195
|
+
const index = Array.from(this._elSpinners).findIndex(
|
|
196
|
+
(spinner) => spinner === e.target
|
|
197
|
+
);
|
|
198
|
+
if (e.key === "ArrowRight") {
|
|
199
|
+
const next = this._elSpinners[index + 1];
|
|
200
|
+
if (next)
|
|
201
|
+
next.focus();
|
|
202
|
+
}
|
|
203
|
+
if (e.key === "ArrowLeft") {
|
|
204
|
+
const prev = this._elSpinners[index - 1];
|
|
205
|
+
if (prev)
|
|
206
|
+
prev.focus();
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
__privateAdd(this, _handleSpinnerChange, (val, name) => {
|
|
210
|
+
__privateGet(this, _spinnerState)[name] = val;
|
|
211
|
+
const newDate = /* @__PURE__ */ new Date();
|
|
212
|
+
newDate.setFullYear(parseInt(__privateGet(this, _spinnerState).year));
|
|
213
|
+
newDate.setMonth(parseInt(__privateGet(this, _spinnerState).month) - 1);
|
|
214
|
+
newDate.setDate(parseInt(__privateGet(this, _spinnerState).day));
|
|
215
|
+
if (newDate.toString() === "Invalid Date")
|
|
216
|
+
return;
|
|
217
|
+
this.value = newDate;
|
|
218
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
219
|
+
});
|
|
220
|
+
/**
|
|
221
|
+
* The spinner state keeps track of the spinner values regardless of wheter a complete date has been enter yet.
|
|
222
|
+
*/
|
|
223
|
+
__privateAdd(this, _spinnerState, {
|
|
224
|
+
year: "yyyy",
|
|
225
|
+
month: "mm",
|
|
226
|
+
day: "dd"
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
get type() {
|
|
230
|
+
return "gds-datepicker";
|
|
231
|
+
}
|
|
232
|
+
get dateformat() {
|
|
233
|
+
return this._dateFormatLayout.layout.map((f) => f.token).join(this._dateFormatLayout.delimiter);
|
|
234
|
+
}
|
|
235
|
+
set dateformat(dateformat) {
|
|
236
|
+
this._dateFormatLayout = __privateMethod(this, _parseDateFormat, parseDateFormat_fn).call(this, dateformat);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get the currently focused date in the calendar popover. If no date is focused, or the calendar popover
|
|
240
|
+
* is closed, the value will be undefined.
|
|
241
|
+
*/
|
|
242
|
+
async getFocusedDate() {
|
|
243
|
+
if (this.open)
|
|
244
|
+
return this._elCalendar.then((el) => el.focusedDate);
|
|
245
|
+
else
|
|
246
|
+
return void 0;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Get a string representation of the currently displayed value in the input field. The formatting will match the dateformat attribute.
|
|
250
|
+
*/
|
|
251
|
+
get displayValue() {
|
|
252
|
+
return this._elInput.innerText.replace(/\s+/g, "");
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* A reference to a date cell element (<td>) inside the shadow root of the calendar primitive.
|
|
256
|
+
* Inteded for use in integration tests.
|
|
257
|
+
*/
|
|
258
|
+
async test_getDateCell(dayNumber) {
|
|
259
|
+
return this._elCalendar.then((el) => el.getDateCell(dayNumber));
|
|
260
|
+
}
|
|
261
|
+
connectedCallback() {
|
|
262
|
+
super.connectedCallback();
|
|
263
|
+
TransitionalStyles.instance.apply(this, "gds-datepicker");
|
|
264
|
+
}
|
|
265
|
+
render() {
|
|
266
|
+
return html`${this._tStyles}
|
|
267
|
+
${when(
|
|
268
|
+
this.label && !this.hideLabel,
|
|
269
|
+
() => html`<label for="spinner-0" id="label">${this.label}</label>`
|
|
270
|
+
)}
|
|
271
|
+
|
|
272
|
+
<div class="form-info"><slot name="sub-label"></slot></div>
|
|
273
|
+
|
|
274
|
+
<div
|
|
275
|
+
class=${classMap({ field: true, small: this.size === "small" })}
|
|
276
|
+
id="trigger"
|
|
277
|
+
@click=${__privateGet(this, _handleFieldClick)}
|
|
278
|
+
@copy=${__privateGet(this, _handleClipboardCopy)}
|
|
279
|
+
@paste=${__privateGet(this, _handleClipboardPaste)}
|
|
280
|
+
>
|
|
281
|
+
<div
|
|
282
|
+
class=${classMap({ input: true, "is-placeholder": !this.value })}
|
|
283
|
+
@focusout=${__privateGet(this, _handleFieldFocusOut)}
|
|
284
|
+
>
|
|
285
|
+
${join(
|
|
286
|
+
map(
|
|
287
|
+
this._dateFormatLayout.layout,
|
|
288
|
+
(f, i) => html`<gds-date-part-spinner
|
|
289
|
+
id="spinner-${i}"
|
|
290
|
+
.length=${f.token === "y" ? 4 : 2}
|
|
291
|
+
.value=${__privateGet(this, _spinnerState)[f.name]}
|
|
292
|
+
aria-valuemin=${__privateMethod(this, _getMinSpinnerValue, getMinSpinnerValue_fn).call(this, f.name)}
|
|
293
|
+
aria-valuemax=${__privateMethod(this, _getMaxSpinnerValue, getMaxSpinnerValue_fn).call(this, f.name)}
|
|
294
|
+
aria-label=${__privateMethod(this, _getSpinnerLabel, getSpinnerLabel_fn).call(this, f.name)}
|
|
295
|
+
aria-describedby="label"
|
|
296
|
+
@keydown=${__privateGet(this, _handleSpinnerKeydown)}
|
|
297
|
+
@change=${(e) => __privateGet(this, _handleSpinnerChange).call(this, e.detail.value, f.name)}
|
|
298
|
+
@focus=${__privateGet(this, _handleSpinnerFocus)}
|
|
299
|
+
@touchend=${(e) => {
|
|
300
|
+
this.open = true;
|
|
301
|
+
e.preventDefault();
|
|
302
|
+
}}
|
|
303
|
+
></gds-date-part-spinner>`
|
|
304
|
+
),
|
|
305
|
+
html`<span>${this._dateFormatLayout.delimiter}</span>`
|
|
306
|
+
)}
|
|
307
|
+
</div>
|
|
308
|
+
<button
|
|
309
|
+
id="calendar-button"
|
|
310
|
+
aria-label="${msg("Open calendar modal")}"
|
|
311
|
+
aria-haspopup="menu"
|
|
312
|
+
aria-expanded=${this.open}
|
|
313
|
+
aria-controls="calendar-popover"
|
|
314
|
+
aria-describedby="label"
|
|
315
|
+
@click=${() => this.open = !this.open}
|
|
316
|
+
>
|
|
317
|
+
<svg viewBox="0 0 24 24" inert>
|
|
318
|
+
<rect x="3" y="4" width="18" height="18" rx="2" ry="2" />
|
|
319
|
+
<line x1="16" y1="2" x2="16" y2="6" />
|
|
320
|
+
<line x1="8" y1="2" x2="8" y2="6" />
|
|
321
|
+
<line x1="3" y1="10" x2="21" y2="10" />
|
|
322
|
+
</svg>
|
|
323
|
+
</button>
|
|
324
|
+
</div>
|
|
325
|
+
|
|
326
|
+
<div class="form-info"><slot name="message"></slot></div>
|
|
327
|
+
|
|
328
|
+
<gds-popover
|
|
329
|
+
.triggerRef=${this._elTrigger}
|
|
330
|
+
.open=${this.open}
|
|
331
|
+
@gds-ui-state=${__privateGet(this, _handlePopoverStateChange)}
|
|
332
|
+
label=${this.label}
|
|
333
|
+
id="calendar-popover"
|
|
334
|
+
.placement=${"bottom-end"}
|
|
335
|
+
.calcMinWidth=${() => this.showWeekNumbers ? "350px" : "305px"}
|
|
336
|
+
@focusin=${async (e) => {
|
|
337
|
+
var _a;
|
|
338
|
+
const isPopover = ((_a = e.target) == null ? void 0 : _a.id) === "calendar-popover";
|
|
339
|
+
if (!isPopover)
|
|
340
|
+
return;
|
|
341
|
+
this._elCalendar.then((cal) => cal.focus());
|
|
342
|
+
}}
|
|
343
|
+
>
|
|
344
|
+
<div class="header">
|
|
345
|
+
<button
|
|
346
|
+
@click=${__privateGet(this, _handleDecrementFocusedMonth)}
|
|
347
|
+
aria-label=${msg("Previous month")}
|
|
348
|
+
>
|
|
349
|
+
<i class="icon prev"></i>
|
|
350
|
+
</button>
|
|
351
|
+
<gds-dropdown
|
|
352
|
+
.value=${this._focusedMonth.toString()}
|
|
353
|
+
@change=${__privateGet(this, _handleMonthChange)}
|
|
354
|
+
.maxHeight=${300}
|
|
355
|
+
label="${msg("Month")}"
|
|
356
|
+
style="width:120px"
|
|
357
|
+
size="small"
|
|
358
|
+
hide-label
|
|
359
|
+
>
|
|
360
|
+
<gds-option value="0">${msg("January")}</gds-option>
|
|
361
|
+
<gds-option value="1">${msg("February")}</gds-option>
|
|
362
|
+
<gds-option value="2">${msg("March")}</gds-option>
|
|
363
|
+
<gds-option value="3">${msg("April")}</gds-option>
|
|
364
|
+
<gds-option value="4">${msg("May")}</gds-option>
|
|
365
|
+
<gds-option value="5">${msg("June")}</gds-option>
|
|
366
|
+
<gds-option value="6">${msg("July")}</gds-option>
|
|
367
|
+
<gds-option value="7">${msg("August")}</gds-option>
|
|
368
|
+
<gds-option value="8">${msg("September")}</gds-option>
|
|
369
|
+
<gds-option value="9">${msg("October")}</gds-option>
|
|
370
|
+
<gds-option value="10">${msg("November")}</gds-option>
|
|
371
|
+
<gds-option value="11">${msg("December")}</gds-option>
|
|
372
|
+
</gds-dropdown>
|
|
373
|
+
<gds-dropdown
|
|
374
|
+
.value=${this._focusedYear.toString()}
|
|
375
|
+
@change=${__privateGet(this, _handleYearChange)}
|
|
376
|
+
.maxHeight=${300}
|
|
377
|
+
label="${msg("Year")}"
|
|
378
|
+
size="small"
|
|
379
|
+
hide-label
|
|
380
|
+
>
|
|
381
|
+
${repeat(
|
|
382
|
+
__privateGet(this, _years, years_get),
|
|
383
|
+
(year) => year,
|
|
384
|
+
(year) => html`<gds-option value=${year}>${year}</gds-option>`
|
|
385
|
+
)}
|
|
386
|
+
</gds-dropdown>
|
|
387
|
+
<button
|
|
388
|
+
@click=${__privateGet(this, _handleIncrementFocusedMonth)}
|
|
389
|
+
aria-label=${msg("Next month")}
|
|
390
|
+
>
|
|
391
|
+
<i class="icon next"></i>
|
|
392
|
+
</button>
|
|
393
|
+
</div>
|
|
394
|
+
|
|
395
|
+
<gds-calendar
|
|
396
|
+
id="calendar"
|
|
397
|
+
@change=${__privateGet(this, _handleCalendarChange)}
|
|
398
|
+
@gds-date-focused=${__privateGet(this, _handleCalendarFocusChange)}
|
|
399
|
+
.focusedMonth=${this._focusedMonth}
|
|
400
|
+
.focusedYear=${this._focusedYear}
|
|
401
|
+
.value=${this.value}
|
|
402
|
+
.min=${this.min}
|
|
403
|
+
.max=${this.max}
|
|
404
|
+
.showWeekNumbers=${this.showWeekNumbers}
|
|
405
|
+
.disabledWeekends=${this.disabledWeekends}
|
|
406
|
+
.disabledDates=${this.disabledDates}
|
|
407
|
+
></gds-calendar>
|
|
408
|
+
|
|
409
|
+
<div class="footer">
|
|
410
|
+
<button
|
|
411
|
+
class="tertiary clear"
|
|
412
|
+
@click=${() => {
|
|
413
|
+
this.value = void 0;
|
|
414
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
415
|
+
}}
|
|
416
|
+
>
|
|
417
|
+
${msg("Clear")}
|
|
418
|
+
</button>
|
|
419
|
+
${until(__privateMethod(this, _renderBackToValidRangeButton, renderBackToValidRangeButton_fn).call(this), nothing)}
|
|
420
|
+
<button
|
|
421
|
+
class="tertiary today"
|
|
422
|
+
@click=${() => {
|
|
423
|
+
this.value = /* @__PURE__ */ new Date();
|
|
424
|
+
__privateMethod(this, _dispatchChangeEvent, dispatchChangeEvent_fn).call(this);
|
|
425
|
+
}}
|
|
426
|
+
>
|
|
427
|
+
${msg("Today")}
|
|
428
|
+
</button>
|
|
429
|
+
</div>
|
|
430
|
+
</gds-popover> `;
|
|
431
|
+
}
|
|
432
|
+
_handleValueChange() {
|
|
433
|
+
if (!this.value) {
|
|
434
|
+
__privateSet(this, _spinnerState, {
|
|
435
|
+
year: "yyyy",
|
|
436
|
+
month: "mm",
|
|
437
|
+
day: "dd"
|
|
438
|
+
});
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
const date = this.value;
|
|
442
|
+
this._focusedMonth = date.getMonth();
|
|
443
|
+
this._focusedYear = date.getFullYear();
|
|
444
|
+
const year = date.getFullYear().toString();
|
|
445
|
+
const month = (date.getMonth() + 1).toString().padStart(2, "0");
|
|
446
|
+
const day = date.getDate().toString().padStart(2, "0");
|
|
447
|
+
__privateSet(this, _spinnerState, { year, month, day });
|
|
448
|
+
}
|
|
449
|
+
_handleOpenChange() {
|
|
450
|
+
if (this.open) {
|
|
451
|
+
__privateSet(this, _valueOnOpen, this.value);
|
|
452
|
+
this._elCalendar.then((el) => el.focus());
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
_valueOnOpen = new WeakMap();
|
|
457
|
+
_renderBackToValidRangeButton = new WeakSet();
|
|
458
|
+
renderBackToValidRangeButton_fn = async function() {
|
|
459
|
+
const focusedDate = await this.getFocusedDate();
|
|
460
|
+
let buttonTxt = "";
|
|
461
|
+
let buttonAction;
|
|
462
|
+
if (focusedDate && focusedDate > this.max) {
|
|
463
|
+
buttonTxt = msg("Last available date");
|
|
464
|
+
buttonAction = () => __privateMethod(this, _focusDate, focusDate_fn).call(this, this.max);
|
|
465
|
+
} else if (focusedDate && focusedDate < this.min) {
|
|
466
|
+
buttonTxt = msg("First available date");
|
|
467
|
+
buttonAction = () => __privateMethod(this, _focusDate, focusDate_fn).call(this, this.min);
|
|
468
|
+
}
|
|
469
|
+
return html`${when(
|
|
470
|
+
buttonTxt.length > 0,
|
|
471
|
+
() => html`<button class="tertiary back-to-range" @click=${buttonAction}>
|
|
472
|
+
${buttonTxt}
|
|
473
|
+
</button>`,
|
|
474
|
+
() => nothing
|
|
475
|
+
)}`;
|
|
476
|
+
};
|
|
477
|
+
_focusDate = new WeakSet();
|
|
478
|
+
focusDate_fn = function(d) {
|
|
479
|
+
const firstValidDate = new Date(d);
|
|
480
|
+
this._elCalendar.then((el) => el.focusedDate = firstValidDate).then(__privateGet(this, _handleCalendarFocusChange));
|
|
481
|
+
};
|
|
482
|
+
_getSpinnerLabel = new WeakSet();
|
|
483
|
+
getSpinnerLabel_fn = function(name) {
|
|
484
|
+
const labels = {
|
|
485
|
+
year: msg("Year"),
|
|
486
|
+
month: msg("Month"),
|
|
487
|
+
day: msg("Day")
|
|
488
|
+
};
|
|
489
|
+
return labels[name];
|
|
490
|
+
};
|
|
491
|
+
_getMinSpinnerValue = new WeakSet();
|
|
492
|
+
getMinSpinnerValue_fn = function(name) {
|
|
493
|
+
const min = {
|
|
494
|
+
year: 1900,
|
|
495
|
+
month: 1,
|
|
496
|
+
day: 1
|
|
497
|
+
};
|
|
498
|
+
return min[name];
|
|
499
|
+
};
|
|
500
|
+
_getMaxSpinnerValue = new WeakSet();
|
|
501
|
+
getMaxSpinnerValue_fn = function(name) {
|
|
502
|
+
const max = {
|
|
503
|
+
year: 9999,
|
|
504
|
+
month: 12,
|
|
505
|
+
day: 31
|
|
506
|
+
};
|
|
507
|
+
return max[name];
|
|
508
|
+
};
|
|
509
|
+
_dispatchChangeEvent = new WeakSet();
|
|
510
|
+
dispatchChangeEvent_fn = function() {
|
|
511
|
+
this.dispatchEvent(
|
|
512
|
+
new CustomEvent("change", {
|
|
513
|
+
detail: { value: this.value }
|
|
514
|
+
})
|
|
515
|
+
);
|
|
516
|
+
};
|
|
517
|
+
_dispatchInputEvent = new WeakSet();
|
|
518
|
+
dispatchInputEvent_fn = function() {
|
|
519
|
+
this.dispatchEvent(
|
|
520
|
+
new CustomEvent("input", {
|
|
521
|
+
detail: { value: this.value }
|
|
522
|
+
})
|
|
523
|
+
);
|
|
524
|
+
};
|
|
525
|
+
_handleFieldFocusOut = new WeakMap();
|
|
526
|
+
_handleSpinnerFocus = new WeakMap();
|
|
527
|
+
_handleClipboardCopy = new WeakMap();
|
|
528
|
+
_handleClipboardPaste = new WeakMap();
|
|
529
|
+
_handleFieldClick = new WeakMap();
|
|
530
|
+
_handleCalendarChange = new WeakMap();
|
|
531
|
+
_handleMonthChange = new WeakMap();
|
|
532
|
+
_handleYearChange = new WeakMap();
|
|
533
|
+
_handleIncrementFocusedMonth = new WeakMap();
|
|
534
|
+
_handleDecrementFocusedMonth = new WeakMap();
|
|
535
|
+
_handleCalendarFocusChange = new WeakMap();
|
|
536
|
+
_handlePopoverStateChange = new WeakMap();
|
|
537
|
+
_handleSpinnerKeydown = new WeakMap();
|
|
538
|
+
_parseDateFormat = new WeakSet();
|
|
539
|
+
parseDateFormat_fn = function(dateformat) {
|
|
540
|
+
const delimiter = dateformat.replace(/[a-z0-9]/gi, "")[0];
|
|
541
|
+
const format = dateformat.split(delimiter);
|
|
542
|
+
const year = format.findIndex((f) => f === "y");
|
|
543
|
+
const month = format.findIndex((f) => f === "m");
|
|
544
|
+
const day = format.findIndex((f) => f === "d");
|
|
545
|
+
if (year === -1 || month === -1 || day === -1)
|
|
546
|
+
throw new Error("Invalid date format for <gds-datepicker>");
|
|
547
|
+
const ordered = [year, month, day].sort((a, b) => a - b);
|
|
548
|
+
const orderedFormat = ordered.map((i) => format[i]).map((f) => ({
|
|
549
|
+
token: f,
|
|
550
|
+
name: f === "y" ? "year" : f === "m" ? "month" : "day"
|
|
551
|
+
}));
|
|
552
|
+
return { delimiter, layout: orderedFormat };
|
|
553
|
+
};
|
|
554
|
+
_handleSpinnerChange = new WeakMap();
|
|
555
|
+
_spinnerState = new WeakMap();
|
|
556
|
+
_years = new WeakSet();
|
|
557
|
+
years_get = function() {
|
|
558
|
+
var _a;
|
|
559
|
+
const minYear = this.min.getFullYear();
|
|
560
|
+
const maxYear = this.max.getFullYear();
|
|
561
|
+
const isOutsideRange = __privateGet(this, _isValueOutsideRange, isValueOutsideRange_get);
|
|
562
|
+
const valueYear = (_a = this.value) == null ? void 0 : _a.getFullYear();
|
|
563
|
+
return {
|
|
564
|
+
*[Symbol.iterator]() {
|
|
565
|
+
if (isOutsideRange)
|
|
566
|
+
yield valueYear;
|
|
567
|
+
for (let i = minYear; i <= maxYear; i++)
|
|
568
|
+
yield i;
|
|
569
|
+
}
|
|
570
|
+
};
|
|
571
|
+
};
|
|
572
|
+
_isValueOutsideRange = new WeakSet();
|
|
573
|
+
isValueOutsideRange_get = function() {
|
|
574
|
+
if (!this.value)
|
|
575
|
+
return false;
|
|
576
|
+
return this.value.getFullYear() < this.min.getFullYear() || this.value.getFullYear() > this.max.getFullYear();
|
|
577
|
+
};
|
|
578
|
+
GdsDatepicker.styles = [styles];
|
|
579
|
+
GdsDatepicker.shadowRootOptions = {
|
|
580
|
+
mode: "open",
|
|
581
|
+
delegatesFocus: true
|
|
582
|
+
};
|
|
583
|
+
__decorateClass([
|
|
584
|
+
property({ converter: dateConverter })
|
|
585
|
+
], GdsDatepicker.prototype, "value", 2);
|
|
586
|
+
__decorateClass([
|
|
587
|
+
property({ converter: dateConverter })
|
|
588
|
+
], GdsDatepicker.prototype, "min", 2);
|
|
589
|
+
__decorateClass([
|
|
590
|
+
property({ converter: dateConverter })
|
|
591
|
+
], GdsDatepicker.prototype, "max", 2);
|
|
592
|
+
__decorateClass([
|
|
593
|
+
property({ type: Boolean })
|
|
594
|
+
], GdsDatepicker.prototype, "open", 2);
|
|
595
|
+
__decorateClass([
|
|
596
|
+
property()
|
|
597
|
+
], GdsDatepicker.prototype, "label", 2);
|
|
598
|
+
__decorateClass([
|
|
599
|
+
property({ type: Boolean, attribute: "show-week-numbers" })
|
|
600
|
+
], GdsDatepicker.prototype, "showWeekNumbers", 2);
|
|
601
|
+
__decorateClass([
|
|
602
|
+
property()
|
|
603
|
+
], GdsDatepicker.prototype, "size", 2);
|
|
604
|
+
__decorateClass([
|
|
605
|
+
property({ type: Boolean, attribute: "hide-label" })
|
|
606
|
+
], GdsDatepicker.prototype, "hideLabel", 2);
|
|
607
|
+
__decorateClass([
|
|
608
|
+
property()
|
|
609
|
+
], GdsDatepicker.prototype, "dateformat", 1);
|
|
610
|
+
__decorateClass([
|
|
611
|
+
property({ type: Boolean, attribute: "disabled-weekends" })
|
|
612
|
+
], GdsDatepicker.prototype, "disabledWeekends", 2);
|
|
613
|
+
__decorateClass([
|
|
614
|
+
property({ converter: dateArrayConverter, attribute: "disabled-dates" })
|
|
615
|
+
], GdsDatepicker.prototype, "disabledDates", 2);
|
|
616
|
+
__decorateClass([
|
|
617
|
+
queryAsync("#calendar-button")
|
|
618
|
+
], GdsDatepicker.prototype, "test_calendarButton", 2);
|
|
619
|
+
__decorateClass([
|
|
620
|
+
state()
|
|
621
|
+
], GdsDatepicker.prototype, "_focusedMonth", 2);
|
|
622
|
+
__decorateClass([
|
|
623
|
+
state()
|
|
624
|
+
], GdsDatepicker.prototype, "_focusedYear", 2);
|
|
625
|
+
__decorateClass([
|
|
626
|
+
state()
|
|
627
|
+
], GdsDatepicker.prototype, "_dateFormatLayout", 2);
|
|
628
|
+
__decorateClass([
|
|
629
|
+
queryAsync("#calendar")
|
|
630
|
+
], GdsDatepicker.prototype, "_elCalendar", 2);
|
|
631
|
+
__decorateClass([
|
|
632
|
+
queryAsync("#trigger")
|
|
633
|
+
], GdsDatepicker.prototype, "_elTrigger", 2);
|
|
634
|
+
__decorateClass([
|
|
635
|
+
queryAll("[role=spinbutton]")
|
|
636
|
+
], GdsDatepicker.prototype, "_elSpinners", 2);
|
|
637
|
+
__decorateClass([
|
|
638
|
+
query(".input")
|
|
639
|
+
], GdsDatepicker.prototype, "_elInput", 2);
|
|
640
|
+
__decorateClass([
|
|
641
|
+
state()
|
|
642
|
+
], GdsDatepicker.prototype, "_tStyles", 2);
|
|
643
|
+
__decorateClass([
|
|
644
|
+
watch("value")
|
|
645
|
+
], GdsDatepicker.prototype, "_handleValueChange", 1);
|
|
646
|
+
__decorateClass([
|
|
647
|
+
watch("open")
|
|
648
|
+
], GdsDatepicker.prototype, "_handleOpenChange", 1);
|
|
649
|
+
GdsDatepicker = __decorateClass([
|
|
650
|
+
gdsCustomElement("gds-datepicker")
|
|
651
|
+
], GdsDatepicker);
|
|
652
|
+
|
|
653
|
+
export {
|
|
654
|
+
GdsDatepicker
|
|
655
|
+
};
|