material-inspired-component-library 8.1.0 → 9.0.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 +106 -18
- package/components/README.md +1 -1
- package/components/accordion/README.md +6 -6
- package/components/alert/README.md +10 -10
- package/components/alert/index.scss +27 -52
- package/components/appbar/README.md +19 -6
- package/components/appbar/index.scss +40 -44
- package/components/badge/README.md +12 -10
- package/components/badge/index.scss +21 -25
- package/components/bottomsheet/README.md +26 -1
- package/components/bottomsheet/index.scss +58 -44
- package/components/button/README.md +70 -10
- package/components/button/_shared.scss +210 -0
- package/components/button/index.scss +75 -389
- package/components/card/README.md +97 -85
- package/components/card/index.scss +46 -65
- package/components/checkbox/README.md +25 -14
- package/{tools/shapes/check.mjs → components/checkbox/_label.scss} +37 -42
- package/components/checkbox/index.scss +66 -66
- package/components/chip/README.md +186 -0
- package/components/chip/index.scss +285 -0
- package/components/datepicker/README.md +79 -0
- package/components/datepicker/index.scss +346 -315
- package/components/dialog/README.md +20 -10
- package/components/dialog/index.scss +55 -66
- package/components/divider/README.md +16 -15
- package/components/divider/index.scss +9 -25
- package/components/iconbutton/README.md +63 -12
- package/components/iconbutton/index.scss +142 -303
- package/components/list/README.md +89 -156
- package/components/list/index.scss +34 -36
- package/components/menu/README.md +81 -155
- package/components/menu/index.scss +52 -58
- package/components/navigationbar/README.md +108 -0
- package/components/navigationbar/index.scss +185 -0
- package/components/navigationrail/README.md +62 -37
- package/components/navigationrail/_navitem.scss +96 -0
- package/components/navigationrail/index.scss +78 -132
- package/components/progressindicator/README.md +83 -47
- package/components/progressindicator/index.scss +622 -172
- package/components/radio/README.md +11 -9
- package/components/radio/index.scss +36 -33
- package/components/select/README.md +12 -7
- package/components/select/index.scss +26 -34
- package/components/shapes/README.md +3 -3
- package/components/shapes/index.scss +0 -1
- package/components/sidesheet/README.md +21 -9
- package/components/sidesheet/index.scss +38 -46
- package/components/slider/README.md +21 -0
- package/components/slider/index.scss +108 -139
- package/components/snackbar/README.md +32 -35
- package/components/snackbar/index.scss +10 -22
- package/components/stepper/README.md +14 -7
- package/components/stepper/index.scss +58 -39
- package/components/switch/README.md +22 -15
- package/components/switch/index.scss +68 -60
- package/components/textfield/README.md +48 -5
- package/components/textfield/index.scss +192 -248
- package/components/timepicker/README.md +53 -23
- package/components/timepicker/index.scss +110 -128
- package/dist/alert.css +1 -1
- package/dist/alert.js +1 -1
- package/dist/appbar.css +1 -1
- package/dist/appbar.js +1 -1
- package/dist/badge.css +1 -1
- package/dist/badge.js +1 -1
- package/dist/base.css +1 -0
- package/dist/base.js +1 -0
- package/dist/bottomsheet.css +1 -1
- package/dist/bottomsheet.js +1 -1
- package/dist/button.css +1 -1
- package/dist/button.js +1 -1
- package/dist/card.css +1 -1
- package/dist/card.js +1 -1
- package/dist/checkbox.css +1 -1
- package/dist/checkbox.js +1 -1
- package/dist/chip.css +1 -0
- package/dist/chip.js +1 -0
- package/dist/components/button/index.d.ts +1 -1
- package/dist/components/iconbutton/index.d.ts +2 -7
- package/dist/components/slider/index.d.ts +1 -1
- package/dist/components/textfield/index.d.ts +2 -2
- package/dist/datepicker.css +1 -1
- package/dist/datepicker.js +1 -1
- package/dist/dialog.css +1 -1
- package/dist/dialog.js +1 -1
- package/dist/divider.css +1 -1
- package/dist/divider.js +1 -1
- package/dist/field.css +1 -0
- package/dist/field.js +1 -0
- package/dist/foundations/form/index.js +1 -1
- package/dist/foundations/runtime.d.ts +15 -0
- package/dist/foundations/runtime.js +1 -0
- package/dist/iconbutton.css +1 -1
- package/dist/iconbutton.js +1 -1
- package/dist/layout.css +1 -1
- package/dist/layout.js +1 -1
- package/dist/list.css +1 -1
- package/dist/list.js +1 -1
- package/dist/menu.css +1 -1
- package/dist/menu.js +1 -1
- package/dist/micl.css +1 -1
- package/dist/micl.d.ts +14 -5
- package/dist/micl.js +1 -1
- package/dist/navigationbar.css +1 -0
- package/dist/navigationbar.js +1 -0
- package/dist/navigationrail.css +1 -1
- package/dist/navigationrail.js +1 -1
- package/dist/progressindicator.css +1 -1
- package/dist/progressindicator.js +1 -1
- package/dist/radio.css +1 -1
- package/dist/radio.js +1 -1
- package/dist/scrollbar.js +1 -1
- package/dist/select.css +1 -1
- package/dist/select.js +1 -1
- package/dist/shapes.css +1 -1
- package/dist/shapes.js +1 -1
- package/dist/sidesheet.css +1 -1
- package/dist/sidesheet.js +1 -1
- package/dist/slider.css +1 -1
- package/dist/slider.js +1 -1
- package/dist/snackbar.css +1 -1
- package/dist/snackbar.js +1 -1
- package/dist/stepper.css +1 -1
- package/dist/stepper.js +1 -1
- package/dist/switch.css +1 -1
- package/dist/switch.js +1 -1
- package/dist/textfield.css +1 -1
- package/dist/textfield.js +1 -1
- package/dist/timepicker.css +1 -1
- package/dist/timepicker.js +1 -1
- package/foundations/_index.scss +35 -0
- package/foundations/{index.scss → base/index.scss} +21 -56
- package/foundations/field/index.scss +37 -0
- package/foundations/layout/index.scss +64 -65
- package/package.json +23 -9
- package/styles/statelayer.scss +20 -5
- package/styles.scss +5 -2
- package/.claude/settings.local.json +0 -14
- package/.editorconfig +0 -12
- package/.gitattributes +0 -9
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -35
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/CLAUDE.md +0 -53
- package/CODE_OF_CONDUCT.md +0 -128
- package/components/bottomsheet/index.ts +0 -153
- package/components/button/index.ts +0 -79
- package/components/checkbox/index.ts +0 -148
- package/components/datepicker/index.ts +0 -693
- package/components/iconbutton/index.ts +0 -77
- package/components/list/index.ts +0 -138
- package/components/menu/index.ts +0 -145
- package/components/navigationrail/index.ts +0 -87
- package/components/progressindicator/index.ts +0 -77
- package/components/slider/index.ts +0 -149
- package/components/snackbar/index.ts +0 -118
- package/components/stepper/index.ts +0 -248
- package/components/textfield/index.ts +0 -188
- package/components/timepicker/index.ts +0 -413
- package/dist/components/progressindicator/index.d.ts +0 -6
- package/dist/foundations.css +0 -1
- package/dist/foundations.js +0 -1
- package/docs/accordion.html +0 -344
- package/docs/alert.html +0 -177
- package/docs/bottomsheet.html +0 -240
- package/docs/button.html +0 -290
- package/docs/card-awards.webp +0 -0
- package/docs/card-cabinet.webp +0 -0
- package/docs/card-city.webp +0 -0
- package/docs/card-fingerprint.webp +0 -0
- package/docs/card-holiday.webp +0 -0
- package/docs/card-names.webp +0 -0
- package/docs/card.html +0 -159
- package/docs/checkbox.html +0 -147
- package/docs/datepicker.html +0 -274
- package/docs/dialog.html +0 -195
- package/docs/divider.html +0 -139
- package/docs/docs.css +0 -26
- package/docs/docs.js +0 -139
- package/docs/iconbutton.html +0 -329
- package/docs/index.html +0 -431
- package/docs/list.html +0 -310
- package/docs/menu.html +0 -574
- package/docs/micl.css +0 -1
- package/docs/micl.js +0 -1
- package/docs/navigationrail.html +0 -138
- package/docs/progressindicator.html +0 -288
- package/docs/radio.html +0 -123
- package/docs/select.html +0 -337
- package/docs/shapes.css +0 -1
- package/docs/shapes.html +0 -159
- package/docs/shapes.js +0 -1
- package/docs/sidesheet.html +0 -149
- package/docs/slider.html +0 -141
- package/docs/snackbar.html +0 -102
- package/docs/stepper.html +0 -319
- package/docs/switch.html +0 -196
- package/docs/textfield.html +0 -208
- package/docs/themes/airblue/dark-hc.css +0 -51
- package/docs/themes/airblue/dark-mc.css +0 -51
- package/docs/themes/airblue/dark.css +0 -51
- package/docs/themes/airblue/light-hc.css +0 -51
- package/docs/themes/airblue/light-mc.css +0 -51
- package/docs/themes/airblue/light.css +0 -51
- package/docs/themes/airblue/theme.css +0 -306
- package/docs/themes/barnred/dark-hc.css +0 -51
- package/docs/themes/barnred/dark-mc.css +0 -51
- package/docs/themes/barnred/dark.css +0 -51
- package/docs/themes/barnred/light-hc.css +0 -51
- package/docs/themes/barnred/light-mc.css +0 -51
- package/docs/themes/barnred/light.css +0 -51
- package/docs/themes/barnred/theme.css +0 -306
- package/docs/themes/citrine/dark-hc.css +0 -51
- package/docs/themes/citrine/dark-mc.css +0 -51
- package/docs/themes/citrine/dark.css +0 -51
- package/docs/themes/citrine/light-hc.css +0 -51
- package/docs/themes/citrine/light-mc.css +0 -51
- package/docs/themes/citrine/light.css +0 -51
- package/docs/themes/citrine/theme.css +0 -306
- package/docs/themes/gray/dark-hc.css +0 -51
- package/docs/themes/gray/dark-mc.css +0 -51
- package/docs/themes/gray/dark.css +0 -51
- package/docs/themes/gray/light-hc.css +0 -51
- package/docs/themes/gray/light-mc.css +0 -51
- package/docs/themes/gray/light.css +0 -51
- package/docs/themes/gray/theme.css +0 -306
- package/docs/themes/greenery/dark-hc.css +0 -51
- package/docs/themes/greenery/dark-mc.css +0 -51
- package/docs/themes/greenery/dark.css +0 -51
- package/docs/themes/greenery/light-hc.css +0 -51
- package/docs/themes/greenery/light-mc.css +0 -51
- package/docs/themes/greenery/light.css +0 -51
- package/docs/themes/greenery/theme.css +0 -306
- package/docs/themes/hermana/dark-hc.css +0 -51
- package/docs/themes/hermana/dark-mc.css +0 -51
- package/docs/themes/hermana/dark.css +0 -51
- package/docs/themes/hermana/light-hc.css +0 -51
- package/docs/themes/hermana/light-mc.css +0 -51
- package/docs/themes/hermana/light.css +0 -51
- package/docs/themes/hermana/theme.css +0 -306
- package/docs/themes/illuminating/dark-hc.css +0 -51
- package/docs/themes/illuminating/dark-mc.css +0 -51
- package/docs/themes/illuminating/dark.css +0 -51
- package/docs/themes/illuminating/light-hc.css +0 -51
- package/docs/themes/illuminating/light-mc.css +0 -51
- package/docs/themes/illuminating/light.css +0 -51
- package/docs/themes/illuminating/theme.css +0 -306
- package/docs/themes/magenta/dark-hc.css +0 -51
- package/docs/themes/magenta/dark-mc.css +0 -51
- package/docs/themes/magenta/dark.css +0 -51
- package/docs/themes/magenta/light-hc.css +0 -51
- package/docs/themes/magenta/light-mc.css +0 -51
- package/docs/themes/magenta/light.css +0 -51
- package/docs/themes/magenta/theme.css +0 -306
- package/docs/themes/mocha/dark-hc.css +0 -51
- package/docs/themes/mocha/dark-mc.css +0 -51
- package/docs/themes/mocha/dark.css +0 -51
- package/docs/themes/mocha/light-hc.css +0 -51
- package/docs/themes/mocha/light-mc.css +0 -51
- package/docs/themes/mocha/light.css +0 -51
- package/docs/themes/mocha/theme.css +0 -306
- package/docs/themes/olivegreen/dark-hc.css +0 -51
- package/docs/themes/olivegreen/dark-mc.css +0 -51
- package/docs/themes/olivegreen/dark.css +0 -51
- package/docs/themes/olivegreen/light-hc.css +0 -51
- package/docs/themes/olivegreen/light-mc.css +0 -51
- package/docs/themes/olivegreen/light.css +0 -51
- package/docs/themes/olivegreen/theme.css +0 -306
- package/docs/themes/peri/dark-hc.css +0 -51
- package/docs/themes/peri/dark-mc.css +0 -51
- package/docs/themes/peri/dark.css +0 -51
- package/docs/themes/peri/light-hc.css +0 -51
- package/docs/themes/peri/light-mc.css +0 -51
- package/docs/themes/peri/light.css +0 -51
- package/docs/themes/peri/theme.css +0 -306
- package/docs/timepicker.html +0 -160
- package/foundations/form/index.ts +0 -174
- package/foundations/layout/README.md +0 -127
- package/intl.d.ts +0 -9
- package/micl.ts +0 -221
- package/styles/README.md +0 -196
- package/tools/shapes/generate.mjs +0 -828
- package/tsconfig.json +0 -116
- package/webpack.config.js +0 -104
|
@@ -1,693 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright © 2025 Hermana AS
|
|
3
|
-
//
|
|
4
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
-
// in the Software without restriction, including without limitation the rights
|
|
7
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
-
// furnished to do so, subject to the following conditions:
|
|
10
|
-
//
|
|
11
|
-
// The above copyright notice and this permission notice shall be included in all
|
|
12
|
-
// copies or substantial portions of the Software.
|
|
13
|
-
//
|
|
14
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
-
// SOFTWARE.
|
|
21
|
-
|
|
22
|
-
export const datepickerSelector = 'dialog.micl-dialog.micl-datepicker';
|
|
23
|
-
|
|
24
|
-
type ValueElement = HTMLInputElement | HTMLButtonElement;
|
|
25
|
-
|
|
26
|
-
interface DatePickerState {
|
|
27
|
-
invoker : ValueElement | null;
|
|
28
|
-
selected: Date;
|
|
29
|
-
viewDate: Date; // the month/year currently being viewed
|
|
30
|
-
min : Date;
|
|
31
|
-
max : Date;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const stateMap = new WeakMap<HTMLDialogElement, DatePickerState>();
|
|
35
|
-
const locale = new Intl.DateTimeFormat().resolvedOptions().locale;
|
|
36
|
-
|
|
37
|
-
const formatters = {
|
|
38
|
-
input: new Intl.DateTimeFormat(locale, {
|
|
39
|
-
year : 'numeric',
|
|
40
|
-
month: '2-digit',
|
|
41
|
-
day : '2-digit'
|
|
42
|
-
}),
|
|
43
|
-
header: new Intl.DateTimeFormat(locale, { weekday: 'short', day: 'numeric', month: 'short' }),
|
|
44
|
-
monthLong: new Intl.DateTimeFormat(undefined, { month: 'long' }),
|
|
45
|
-
monthShort: new Intl.DateTimeFormat(locale, { month: 'short' }),
|
|
46
|
-
weekdayNarrow: new Intl.DateTimeFormat(locale, { weekday: 'narrow' }),
|
|
47
|
-
weekdayLong: new Intl.DateTimeFormat(locale, { weekday: 'long' })
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const toLocalMidnight = (date: Date): Date =>
|
|
51
|
-
{
|
|
52
|
-
const d = new Date(date);
|
|
53
|
-
d.setHours(0, 0, 0, 0);
|
|
54
|
-
return d;
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const formatToInputDateValue = (d: Date): string =>
|
|
58
|
-
{
|
|
59
|
-
const month = (d.getMonth() + 1).toString().padStart(2, '0');
|
|
60
|
-
const day = d.getDate().toString().padStart(2, '0');
|
|
61
|
-
return `${d.getFullYear()}-${month}-${day}`;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const getDateFormat = (): string =>
|
|
65
|
-
{
|
|
66
|
-
return formatters.input.formatToParts(new Date(2025, 0, 15)).map(part =>
|
|
67
|
-
{
|
|
68
|
-
switch (part.type) {
|
|
69
|
-
case 'day' : return 'DD';
|
|
70
|
-
case 'month' : return 'MM';
|
|
71
|
-
case 'year' : return 'YYYY';
|
|
72
|
-
case 'literal': return part.value;
|
|
73
|
-
default: return '';
|
|
74
|
-
}
|
|
75
|
-
}).join('').trim();
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
const getFirstDayOfWeek = (): number =>
|
|
79
|
-
{
|
|
80
|
-
try {
|
|
81
|
-
const info = (new Intl.Locale(locale) as any).getWeekInfo?.();
|
|
82
|
-
if (info) {
|
|
83
|
-
return info.firstDay === 7 ? 0 : info.firstDay;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
catch {}
|
|
87
|
-
|
|
88
|
-
return /US|CA|MX/i.test(locale) ? 0 : 1; // Sunday for USA, Mexico and Canada, Monday as default
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const firstDayOfWeek = getFirstDayOfWeek();
|
|
92
|
-
const isValidDate = (date: Date): boolean => !isNaN(date.getTime());
|
|
93
|
-
|
|
94
|
-
const setText = (parent: Element | null, text: string): void =>
|
|
95
|
-
{
|
|
96
|
-
if (!parent) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if (parent.firstElementChild) {
|
|
100
|
-
let node = parent.firstChild;
|
|
101
|
-
while (node) {
|
|
102
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
103
|
-
node.nodeValue = text;
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
node = node.nextSibling;
|
|
107
|
-
}
|
|
108
|
-
parent.appendChild(document.createTextNode(text));
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
parent.textContent = text;
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const getCalendarDays = (
|
|
116
|
-
year : number,
|
|
117
|
-
month: number
|
|
118
|
-
): Array<{ date: Date, val: string, isCurrentMonth: boolean }> => {
|
|
119
|
-
|
|
120
|
-
const firstOfMonth = new Date(year, month, 1);
|
|
121
|
-
const dayOfWeek = firstOfMonth.getDay();
|
|
122
|
-
const offset = (dayOfWeek - firstDayOfWeek + 7) % 7;
|
|
123
|
-
|
|
124
|
-
const startDate = new Date(year, month, 1 - offset);
|
|
125
|
-
|
|
126
|
-
return Array.from({ length: 42 }, (_, i) => {
|
|
127
|
-
const current = new Date(startDate);
|
|
128
|
-
current.setDate(startDate.getDate() + i);
|
|
129
|
-
return {
|
|
130
|
-
date : current,
|
|
131
|
-
val : formatToInputDateValue(current),
|
|
132
|
-
isCurrentMonth: current.getMonth() === month
|
|
133
|
-
};
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const renderCalendarHeader = (): DocumentFragment =>
|
|
138
|
-
{
|
|
139
|
-
const tempDate = new Date();
|
|
140
|
-
const startOffset = tempDate.getDay() - firstDayOfWeek;
|
|
141
|
-
tempDate.setDate(tempDate.getDate() - startOffset);
|
|
142
|
-
|
|
143
|
-
const fragment = document.createDocumentFragment();
|
|
144
|
-
|
|
145
|
-
for (let i = 0; i < 7; i++) {
|
|
146
|
-
const span = document.createElement('span');
|
|
147
|
-
span.style.gridArea = `1 / ${i + 1}`;
|
|
148
|
-
span.textContent = formatters.weekdayNarrow.format(tempDate);
|
|
149
|
-
span.title = formatters.weekdayLong.format(tempDate);
|
|
150
|
-
fragment.appendChild(span);
|
|
151
|
-
tempDate.setDate(tempDate.getDate() + 1);
|
|
152
|
-
}
|
|
153
|
-
return fragment;
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const populateContainerWithDays = (
|
|
157
|
-
container: HTMLElement,
|
|
158
|
-
days : Array<{ date: Date, val: string, isCurrentMonth: boolean }>,
|
|
159
|
-
state : DatePickerState,
|
|
160
|
-
isEmpty : boolean = false
|
|
161
|
-
): void => {
|
|
162
|
-
if (isEmpty) {
|
|
163
|
-
const fragment = renderCalendarHeader();
|
|
164
|
-
|
|
165
|
-
days.forEach((_, index) => {
|
|
166
|
-
const time = document.createElement('time');
|
|
167
|
-
const row = Math.floor(index / 7) + 2;
|
|
168
|
-
const col = (index % 7) + 1;
|
|
169
|
-
time.style.gridArea = `${row} / ${col}`;
|
|
170
|
-
fragment.appendChild(time);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
container.appendChild(fragment);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const today = toLocalMidnight(new Date());
|
|
177
|
-
container.querySelectorAll('time').forEach((el, index) =>
|
|
178
|
-
{
|
|
179
|
-
const day = days[index];
|
|
180
|
-
el.dateTime = day.val;
|
|
181
|
-
el.textContent = day.date.getDate().toString();
|
|
182
|
-
|
|
183
|
-
const isSelected = day.date.getTime() === state.selected.getTime();
|
|
184
|
-
const isToday = day.date.getTime() === today.getTime();
|
|
185
|
-
|
|
186
|
-
el.className = '';
|
|
187
|
-
if (!day.isCurrentMonth) el.classList.add('micl-datepicker__outside');
|
|
188
|
-
if (isSelected) el.classList.add('micl-datepicker__selected');
|
|
189
|
-
if (isToday) el.classList.add('micl-datepicker__today');
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
const renderCalendar = (
|
|
194
|
-
dialog: HTMLDialogElement,
|
|
195
|
-
state : DatePickerState,
|
|
196
|
-
amount: number = 0
|
|
197
|
-
): void => {
|
|
198
|
-
|
|
199
|
-
const content = dialog.querySelector<HTMLElement>('.micl-dialog__content');
|
|
200
|
-
const calendars = content?.querySelector<HTMLElement>('.micl-datepicker__calendars');
|
|
201
|
-
if (!calendars) {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
const startClass = 'micl-startleft';
|
|
206
|
-
const endClass = 'micl-startright';
|
|
207
|
-
const moveLeftClass = 'micl-moveleft';
|
|
208
|
-
const moveRightClass = 'micl-moveright';
|
|
209
|
-
|
|
210
|
-
calendars.classList.remove(moveLeftClass, moveRightClass, startClass, endClass);
|
|
211
|
-
void calendars.offsetWidth;
|
|
212
|
-
|
|
213
|
-
if (amount !== 0) {
|
|
214
|
-
const oldCalendar = calendars.querySelector<HTMLElement>('.micl-datepicker__calendar');
|
|
215
|
-
if (!oldCalendar) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const newCalendar = document.createElement('div');
|
|
220
|
-
const newCalendarInner = document.createElement('div');
|
|
221
|
-
newCalendar.classList.add('micl-datepicker__calendar');
|
|
222
|
-
newCalendarInner.classList.add('micl-datepicker__calendar-inner');
|
|
223
|
-
|
|
224
|
-
const days = getCalendarDays(state.viewDate.getFullYear(), state.viewDate.getMonth());
|
|
225
|
-
populateContainerWithDays(newCalendarInner, days, state, true);
|
|
226
|
-
|
|
227
|
-
const isNextMonth = amount > 0;
|
|
228
|
-
const startPositionClass = isNextMonth ? startClass : endClass;
|
|
229
|
-
const endTransformClass = isNextMonth ? moveLeftClass : moveRightClass;
|
|
230
|
-
|
|
231
|
-
newCalendar.appendChild(newCalendarInner);
|
|
232
|
-
if (isNextMonth) {
|
|
233
|
-
calendars.appendChild(newCalendar);
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
calendars.prepend(newCalendar);
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
calendars.classList.add('micl-no-transition', startPositionClass);
|
|
240
|
-
void calendars.offsetWidth;
|
|
241
|
-
|
|
242
|
-
requestAnimationFrame(() => {
|
|
243
|
-
calendars.classList.remove('micl-no-transition', startPositionClass);
|
|
244
|
-
calendars.classList.add(endTransformClass);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
const onTransitionEnd = () =>
|
|
248
|
-
{
|
|
249
|
-
calendars.removeEventListener('transitionend', onTransitionEnd);
|
|
250
|
-
|
|
251
|
-
setTimeout(() =>
|
|
252
|
-
{
|
|
253
|
-
calendars.classList.remove(endTransformClass);
|
|
254
|
-
if (oldCalendar.parentElement === calendars) {
|
|
255
|
-
oldCalendar.remove();
|
|
256
|
-
}
|
|
257
|
-
calendars.classList.add('micl-no-transition', startClass);
|
|
258
|
-
void calendars.offsetWidth;
|
|
259
|
-
|
|
260
|
-
calendars.classList.remove('micl-no-transition', startClass);
|
|
261
|
-
}, 0);
|
|
262
|
-
};
|
|
263
|
-
calendars.addEventListener('transitionend', onTransitionEnd);
|
|
264
|
-
}
|
|
265
|
-
else {
|
|
266
|
-
let calendar = calendars.querySelector<HTMLElement>('.micl-datepicker__calendar');
|
|
267
|
-
if (!calendar) {
|
|
268
|
-
calendar = document.createElement('div');
|
|
269
|
-
calendar.classList.add('micl-datepicker__calendar');
|
|
270
|
-
calendar = calendars.appendChild(calendar);
|
|
271
|
-
}
|
|
272
|
-
let inner = calendar.querySelector<HTMLElement>('.micl-datepicker__calendar-inner');
|
|
273
|
-
if (!inner) {
|
|
274
|
-
inner = document.createElement('div');
|
|
275
|
-
inner.classList.add('micl-datepicker__calendar-inner');
|
|
276
|
-
calendar.appendChild(inner);
|
|
277
|
-
}
|
|
278
|
-
const days = getCalendarDays(state.viewDate.getFullYear(), state.viewDate.getMonth());
|
|
279
|
-
populateContainerWithDays(inner, days, state, inner.querySelectorAll('time').length === 0);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const input = content?.querySelector<HTMLInputElement>('.micl-datepicker__input input');
|
|
283
|
-
if (input) {
|
|
284
|
-
input.value = formatters.input.format(state.selected);
|
|
285
|
-
if (input.value) {
|
|
286
|
-
input.dataset.miclvalue = '1';
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
delete input.dataset.miclvalue;
|
|
290
|
-
}
|
|
291
|
-
if (!input.dataset.micldateformat) {
|
|
292
|
-
input.dataset.micldateformat = getDateFormat();
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
setText(dialog.querySelector('h1, h2, h3, h4, h5, h6, .micl-heading'), formatters.header.format(state.selected));
|
|
297
|
-
setText(dialog.querySelector('.micl-datepicker__month'), formatters.monthShort.format(state.viewDate));
|
|
298
|
-
setText(
|
|
299
|
-
dialog.querySelector('.micl-datepicker__year'),
|
|
300
|
-
state.viewDate.toLocaleDateString(locale, dialog.classList.contains('micl-dialog--docked') ?
|
|
301
|
-
{ year: 'numeric' } : { month: 'long', year: 'numeric' })
|
|
302
|
-
);
|
|
303
|
-
|
|
304
|
-
const monthInput = dialog.querySelector<HTMLInputElement>(`.micl-datepicker__months input[value="${state.viewDate.getMonth()}"]`);
|
|
305
|
-
if (monthInput) monthInput.checked = true;
|
|
306
|
-
|
|
307
|
-
const yearInput = dialog.querySelector<HTMLInputElement>(`.micl-datepicker__years input[value="${state.viewDate.getFullYear()}"]`);
|
|
308
|
-
if (yearInput) yearInput.checked = true;
|
|
309
|
-
};
|
|
310
|
-
|
|
311
|
-
const initPeriodPickers = (dialog: HTMLDialogElement, min: Date, max: Date): void =>
|
|
312
|
-
{
|
|
313
|
-
const minYear = min.getFullYear();
|
|
314
|
-
const maxYear = max.getFullYear();
|
|
315
|
-
|
|
316
|
-
['months', 'years'].forEach(period =>
|
|
317
|
-
{
|
|
318
|
-
const container = dialog.querySelector(`.micl-datepicker__${period}`);
|
|
319
|
-
if (!container) {
|
|
320
|
-
return;
|
|
321
|
-
}
|
|
322
|
-
container.innerHTML = '';
|
|
323
|
-
const frag = document.createDocumentFragment();
|
|
324
|
-
|
|
325
|
-
const maxMonth = max.getMonth();
|
|
326
|
-
|
|
327
|
-
if (period === 'months') {
|
|
328
|
-
const months: number[] = [];
|
|
329
|
-
|
|
330
|
-
let current = new Date(min.getFullYear(), min.getMonth(), 1);
|
|
331
|
-
while (
|
|
332
|
-
current <= max
|
|
333
|
-
|| (current.getMonth() === maxMonth && current.getFullYear() === maxYear)
|
|
334
|
-
) {
|
|
335
|
-
months.push(current.getMonth());
|
|
336
|
-
current.setMonth(current.getMonth() + 1);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
[...new Set(months.sort((a, b) => a - b))].forEach(m => {
|
|
340
|
-
const label = document.createElement('label');
|
|
341
|
-
label.innerHTML = `<span class="material-symbols-outlined">check</span><input type="radio" name="miclmonth" value="${m}"> ${formatters.monthLong.format(new Date(2000, m, 1))}`;
|
|
342
|
-
frag.appendChild(label);
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
for (let y = minYear; y <= maxYear; y++) {
|
|
347
|
-
const label = document.createElement('label');
|
|
348
|
-
label.innerHTML = `<input type="radio" name="miclyear" value="${y}"> ${y}`;
|
|
349
|
-
frag.appendChild(label);
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
const inner = document.createElement('div');
|
|
354
|
-
inner.classList.add(`micl-datepicker__${period}-inner`);
|
|
355
|
-
container.appendChild(inner).appendChild(frag);
|
|
356
|
-
});
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
const toggleView = (dialog: HTMLDialogElement, view: 'calendars' | 'months' | 'years' | 'input'): void =>
|
|
360
|
-
{
|
|
361
|
-
if (view === 'months' || view === 'years') {
|
|
362
|
-
if (!dialog.querySelector(`.micl-datepicker__${view}.micl-datepicker__view-hidden`)) {
|
|
363
|
-
view = 'calendars';
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
['calendars', 'input', 'month-selector', 'year-selector'].forEach(name =>
|
|
368
|
-
{
|
|
369
|
-
let doHide = view === 'input';
|
|
370
|
-
if (name === 'calendars' || name === 'input') {
|
|
371
|
-
doHide = view !== name;
|
|
372
|
-
}
|
|
373
|
-
dialog.querySelector(`.micl-datepicker__${name}`)?.classList.toggle(
|
|
374
|
-
'micl-datepicker__view-hidden',
|
|
375
|
-
doHide
|
|
376
|
-
);
|
|
377
|
-
});
|
|
378
|
-
|
|
379
|
-
const content = dialog.querySelector<HTMLElement>('.micl-dialog__content');
|
|
380
|
-
if (!content) {
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
const contentHeight = parseInt(window.getComputedStyle(content).getPropertyValue('max-block-size'), 10);
|
|
384
|
-
|
|
385
|
-
['.micl-datepicker__months', '.micl-datepicker__years'].forEach(selector =>
|
|
386
|
-
{
|
|
387
|
-
const period = content.querySelector<HTMLElement>(selector);
|
|
388
|
-
if (!period) {
|
|
389
|
-
return;
|
|
390
|
-
}
|
|
391
|
-
const selected = period.querySelector<HTMLInputElement>('input:checked');
|
|
392
|
-
const height = 48;
|
|
393
|
-
let doHide: boolean | null = false;
|
|
394
|
-
|
|
395
|
-
if (selected && (selector.substring(18) === view)) {
|
|
396
|
-
const property = window.getComputedStyle(period).getPropertyValue('transition-duration');
|
|
397
|
-
const duration = parseFloat(property) * (property.includes('ms') ? 1 : 1000);
|
|
398
|
-
const maxScrollDistance = period.scrollHeight - contentHeight;
|
|
399
|
-
const centerTop = (contentHeight - height) / 2;
|
|
400
|
-
|
|
401
|
-
if (selected.offsetTop > centerTop) {
|
|
402
|
-
let scrollDistance = selected.offsetTop - centerTop - (height / 2);
|
|
403
|
-
if (scrollDistance > maxScrollDistance) {
|
|
404
|
-
scrollDistance = maxScrollDistance;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
const startTime = performance.now();
|
|
408
|
-
const animateScroll = (currentTime: number) => {
|
|
409
|
-
const progress = Math.min((currentTime - startTime) / duration, 1);
|
|
410
|
-
content.scrollTop = scrollDistance * progress;
|
|
411
|
-
if (progress < 1) {
|
|
412
|
-
requestAnimationFrame(animateScroll);
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
period.classList.remove('micl-datepicker__view-hidden');
|
|
416
|
-
requestAnimationFrame(animateScroll);
|
|
417
|
-
doHide = null;
|
|
418
|
-
|
|
419
|
-
period.addEventListener('transitionend', function handler(event)
|
|
420
|
-
{
|
|
421
|
-
if (event.propertyName === 'height' || event.propertyName === 'block-size') {
|
|
422
|
-
content.scrollTop = scrollDistance;
|
|
423
|
-
period.removeEventListener('transitionend', handler);
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
429
|
-
doHide = true;
|
|
430
|
-
}
|
|
431
|
-
if (doHide !== null) {
|
|
432
|
-
period.classList.toggle('micl-datepicker__view-hidden', doHide);
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
const changePeriod = (dialog: HTMLDialogElement, amount: number, unit: 'month' | 'year'): void =>
|
|
438
|
-
{
|
|
439
|
-
const state = stateMap.get(dialog);
|
|
440
|
-
if (!state) {
|
|
441
|
-
return;
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
const newDate = new Date(state.viewDate);
|
|
445
|
-
if (unit === 'month') {
|
|
446
|
-
newDate.setMonth(newDate.getMonth() + amount);
|
|
447
|
-
}
|
|
448
|
-
else {
|
|
449
|
-
newDate.setFullYear(newDate.getFullYear() + amount);
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
const belowMin = state.min && newDate < state.min;
|
|
453
|
-
const aboveMax = state.max && newDate > state.max;
|
|
454
|
-
|
|
455
|
-
if (belowMin || aboveMax) {
|
|
456
|
-
dialog.querySelector('.micl-datepicker__calendars')?.animate([
|
|
457
|
-
{ transform: 'translateX(0)' },
|
|
458
|
-
{ transform: `translateX(${belowMin ? 8 : -8}px)` },
|
|
459
|
-
{ transform: 'translateX(0)' }
|
|
460
|
-
], { duration: 500, easing: 'ease-in-out' });
|
|
461
|
-
return;
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
state.viewDate = newDate;
|
|
465
|
-
renderCalendar(dialog, state, unit === 'month' ? amount : 0);
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
const selectDate = (dialog: HTMLDialogElement, dateStr: string, isLocaleFormatted = false): void =>
|
|
469
|
-
{
|
|
470
|
-
const state = stateMap.get(dialog);
|
|
471
|
-
if (!state) {
|
|
472
|
-
return;
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
let parts: number[] = [];
|
|
476
|
-
if (isLocaleFormatted) {
|
|
477
|
-
const dateformat = getDateFormat();
|
|
478
|
-
if (dateStr.length === dateformat.length) {
|
|
479
|
-
let d = '';
|
|
480
|
-
let m = '';
|
|
481
|
-
let y = '';
|
|
482
|
-
for (let i = 0; i < dateformat.length; i++) {
|
|
483
|
-
switch (dateformat[i]) {
|
|
484
|
-
case 'D': d += dateStr[i]; break;
|
|
485
|
-
case 'M': m += dateStr[i]; break;
|
|
486
|
-
case 'Y': y += dateStr[i]; break;
|
|
487
|
-
default:
|
|
488
|
-
}
|
|
489
|
-
}
|
|
490
|
-
parts = [parseInt(y, 10), parseInt(m, 10) - 1, parseInt(d, 10)];
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
else {
|
|
494
|
-
parts = dateStr.split('-').map(Number);
|
|
495
|
-
parts[1]--;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
if (parts.length === 3) {
|
|
499
|
-
state.selected = new Date(parts[0], parts[1], parts[2]);
|
|
500
|
-
state.viewDate = new Date(state.selected);
|
|
501
|
-
|
|
502
|
-
renderCalendar(dialog, state);
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
|
|
506
|
-
export default (() =>
|
|
507
|
-
{
|
|
508
|
-
return {
|
|
509
|
-
keydown: (event: Event): void =>
|
|
510
|
-
{
|
|
511
|
-
if (
|
|
512
|
-
!(event instanceof KeyboardEvent)
|
|
513
|
-
|| !(event.target instanceof Element)
|
|
514
|
-
) {
|
|
515
|
-
return;
|
|
516
|
-
}
|
|
517
|
-
const dialog = event.target.closest(datepickerSelector) as HTMLDialogElement;
|
|
518
|
-
if (!dialog) {
|
|
519
|
-
return;
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
switch (event.key) {
|
|
523
|
-
case 'Enter':
|
|
524
|
-
case ' ':
|
|
525
|
-
if (event.target instanceof HTMLInputElement && event.target.type === 'date') {
|
|
526
|
-
event.preventDefault();
|
|
527
|
-
}
|
|
528
|
-
break;
|
|
529
|
-
case 'M':
|
|
530
|
-
toggleView(dialog, 'months');
|
|
531
|
-
break;
|
|
532
|
-
case 'Y':
|
|
533
|
-
toggleView(dialog, 'years');
|
|
534
|
-
break;
|
|
535
|
-
case 'PageUp':
|
|
536
|
-
case 'PageDown':
|
|
537
|
-
changePeriod(dialog, event.key === 'PageUp' ? 1 : -1, event.shiftKey ? 'year' : 'month');
|
|
538
|
-
break;
|
|
539
|
-
default:
|
|
540
|
-
}
|
|
541
|
-
},
|
|
542
|
-
|
|
543
|
-
initialize: (dialog: HTMLDialogElement): void =>
|
|
544
|
-
{
|
|
545
|
-
if (dialog.dataset.miclinitialized) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
const form = dialog.querySelector('form');
|
|
550
|
-
const content = dialog.querySelector('.micl-dialog__content');
|
|
551
|
-
if (!form || !content) {
|
|
552
|
-
return;
|
|
553
|
-
}
|
|
554
|
-
dialog.dataset.miclinitialized = '1';
|
|
555
|
-
|
|
556
|
-
dialog.addEventListener('click', event =>
|
|
557
|
-
{
|
|
558
|
-
const target = event.target as HTMLElement;
|
|
559
|
-
const btn = target.closest('button');
|
|
560
|
-
|
|
561
|
-
if (btn) {
|
|
562
|
-
const forMonth = btn.parentElement?.classList.contains('micl-datepicker__month-selector');
|
|
563
|
-
const isNext = btn.classList.contains('micl-datepicker__next');
|
|
564
|
-
const isPrev = btn.classList.contains('micl-datepicker__previous');
|
|
565
|
-
|
|
566
|
-
if (isNext || isPrev) {
|
|
567
|
-
changePeriod(dialog, isNext ? 1 : -1, forMonth ? 'month' : 'year');
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
if (target.closest('.micl-datepicker__month')) toggleView(dialog, 'months');
|
|
573
|
-
if (target.closest('.micl-datepicker__year')) toggleView(dialog, 'years');
|
|
574
|
-
|
|
575
|
-
const mode = target.closest('.micl-datepicker__inputmode') as HTMLElement;
|
|
576
|
-
if (mode) {
|
|
577
|
-
toggleView(dialog, !dialog.querySelector(
|
|
578
|
-
'.micl-datepicker__input.micl-datepicker__view-hidden'
|
|
579
|
-
) ? 'calendars' : 'input');
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
const time = target.closest('time');
|
|
583
|
-
if (time && time.dateTime) {
|
|
584
|
-
selectDate(dialog, time.dateTime);
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
if (
|
|
588
|
-
target instanceof HTMLInputElement
|
|
589
|
-
&& (target.name === 'miclmonth' || target.name === 'miclyear')
|
|
590
|
-
) {
|
|
591
|
-
const state = stateMap.get(dialog);
|
|
592
|
-
if (state) {
|
|
593
|
-
const value = parseInt(target.value, 10);
|
|
594
|
-
if (target.name === 'miclmonth') {
|
|
595
|
-
state.viewDate.setMonth(value);
|
|
596
|
-
}
|
|
597
|
-
else {
|
|
598
|
-
state.viewDate.setFullYear(value);
|
|
599
|
-
}
|
|
600
|
-
if (state.viewDate < state.min) {
|
|
601
|
-
state.viewDate = state.min;
|
|
602
|
-
}
|
|
603
|
-
else if (state.viewDate > state.max) {
|
|
604
|
-
state.viewDate = state.max;
|
|
605
|
-
}
|
|
606
|
-
renderCalendar(dialog, state);
|
|
607
|
-
toggleView(dialog, 'calendars');
|
|
608
|
-
}
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
dialog.addEventListener('beforetoggle', (event: any): void =>
|
|
613
|
-
{
|
|
614
|
-
if (event.newState !== 'open') {
|
|
615
|
-
return;
|
|
616
|
-
}
|
|
617
|
-
const isInvoker = (e: Element | null): e is ValueElement => e instanceof HTMLInputElement || e instanceof HTMLButtonElement;
|
|
618
|
-
|
|
619
|
-
let invoker = document.activeElement;
|
|
620
|
-
if (
|
|
621
|
-
!isInvoker(invoker)
|
|
622
|
-
|| (!invoker.dataset.datepicker && !invoker.popoverTargetElement && !(invoker as any).commandForElement)
|
|
623
|
-
) {
|
|
624
|
-
invoker = document.querySelector(
|
|
625
|
-
`[data-datepicker="${dialog.id}"],[popovertarget="${dialog.id}"],[commandfor="${dialog.id}"]`
|
|
626
|
-
);
|
|
627
|
-
}
|
|
628
|
-
if (!isInvoker(invoker)) {
|
|
629
|
-
return;
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
let initialDate = new Date();
|
|
633
|
-
let min = new Date(1900, 0, 1);
|
|
634
|
-
let max = new Date(2099, 11, 31);
|
|
635
|
-
|
|
636
|
-
if (invoker instanceof HTMLInputElement) {
|
|
637
|
-
if (invoker.type === 'date' && invoker.valueAsDate) {
|
|
638
|
-
initialDate = invoker.valueAsDate;
|
|
639
|
-
}
|
|
640
|
-
else if (invoker.value) {
|
|
641
|
-
initialDate = new Date(invoker.value);
|
|
642
|
-
}
|
|
643
|
-
if (invoker.min) min = new Date(invoker.min);
|
|
644
|
-
if (invoker.max) max = new Date(invoker.max);
|
|
645
|
-
}
|
|
646
|
-
else {
|
|
647
|
-
const parsed = new Date(invoker.value || invoker.textContent);
|
|
648
|
-
if (isValidDate(parsed)) {
|
|
649
|
-
initialDate = parsed;
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
|
-
if (!isValidDate(initialDate)) initialDate = new Date();
|
|
653
|
-
initialDate = toLocalMidnight(initialDate);
|
|
654
|
-
|
|
655
|
-
const state: DatePickerState = {
|
|
656
|
-
invoker,
|
|
657
|
-
selected: initialDate,
|
|
658
|
-
viewDate: new Date(initialDate),
|
|
659
|
-
min,
|
|
660
|
-
max
|
|
661
|
-
};
|
|
662
|
-
stateMap.set(dialog, state);
|
|
663
|
-
|
|
664
|
-
initPeriodPickers(dialog, min, max);
|
|
665
|
-
toggleView(dialog, 'calendars');
|
|
666
|
-
renderCalendar(dialog, state);
|
|
667
|
-
|
|
668
|
-
dialog.querySelector('.micl-datepicker__input input')?.addEventListener('blur', e =>
|
|
669
|
-
{
|
|
670
|
-
const element = e.target as HTMLInputElement;
|
|
671
|
-
selectDate(dialog, element.value, true);
|
|
672
|
-
}, { once: true });
|
|
673
|
-
});
|
|
674
|
-
|
|
675
|
-
dialog.addEventListener('close', (): void =>
|
|
676
|
-
{
|
|
677
|
-
const state = stateMap.get(dialog);
|
|
678
|
-
if (!state?.invoker || dialog.returnValue === '') {
|
|
679
|
-
return;
|
|
680
|
-
}
|
|
681
|
-
state.invoker.value = formatToInputDateValue(state.selected);
|
|
682
|
-
|
|
683
|
-
if (state.invoker instanceof HTMLInputElement) {
|
|
684
|
-
state.invoker.dispatchEvent(new Event('change', { bubbles: true }));
|
|
685
|
-
state.invoker.dispatchEvent(new Event('input', { bubbles: true }));
|
|
686
|
-
}
|
|
687
|
-
else {
|
|
688
|
-
state.invoker.textContent = state.selected.toLocaleDateString();
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
}
|
|
692
|
-
};
|
|
693
|
-
})();
|