@idds/js 1.0.36 → 1.0.37
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/dist/index.iife.js +305 -238
- package/dist/index.js +363 -286
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -120,10 +120,19 @@ var InaUI = (() => {
|
|
|
120
120
|
// src/js/components/stateful/datepicker.js
|
|
121
121
|
function initDatepicker() {
|
|
122
122
|
document.querySelectorAll(".ina-date-picker").forEach((datepicker) => {
|
|
123
|
+
const trigger = datepicker.querySelector(".ina-date-picker__trigger");
|
|
124
|
+
const triggerText = trigger.querySelector(".ina-date-picker__trigger-text");
|
|
125
|
+
const panel = datepicker.querySelector(".ina-date-picker__panel");
|
|
126
|
+
let panelContent = panel.querySelector(".ina-date-picker__panel-content");
|
|
127
|
+
if (!panelContent) {
|
|
128
|
+
panelContent = document.createElement("div");
|
|
129
|
+
panelContent.className = "ina-date-picker__panel-content";
|
|
130
|
+
panel.appendChild(panelContent);
|
|
131
|
+
}
|
|
123
132
|
let currentDate = /* @__PURE__ */ new Date();
|
|
124
|
-
let selectedDateTarget = null;
|
|
125
133
|
let selectedDate = null;
|
|
126
|
-
|
|
134
|
+
let isOpen = false;
|
|
135
|
+
const MONTHS_ID = [
|
|
127
136
|
"Januari",
|
|
128
137
|
"Februari",
|
|
129
138
|
"Maret",
|
|
@@ -137,267 +146,325 @@ var InaUI = (() => {
|
|
|
137
146
|
"November",
|
|
138
147
|
"Desember"
|
|
139
148
|
];
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
"
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
"
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
)
|
|
171
|
-
|
|
172
|
-
"
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
149
|
+
const MONTHS_SHORT_ID = [
|
|
150
|
+
"Jan",
|
|
151
|
+
"Feb",
|
|
152
|
+
"Mar",
|
|
153
|
+
"Apr",
|
|
154
|
+
"Mei",
|
|
155
|
+
"Jun",
|
|
156
|
+
"Jul",
|
|
157
|
+
"Agu",
|
|
158
|
+
"Sep",
|
|
159
|
+
"Okt",
|
|
160
|
+
"Nov",
|
|
161
|
+
"Des"
|
|
162
|
+
];
|
|
163
|
+
const DAYS_SHORT = ["Min", "Sen", "Sel", "Rab", "Kam", "Jum", "Sab"];
|
|
164
|
+
function formatDate(date) {
|
|
165
|
+
const day = date.getDate().toString().padStart(2, "0");
|
|
166
|
+
const monthIndex = date.getMonth();
|
|
167
|
+
const year = date.getFullYear();
|
|
168
|
+
return `${day} ${MONTHS_SHORT_ID[monthIndex]} ${year}`;
|
|
169
|
+
}
|
|
170
|
+
function createIcon(name, size = 16) {
|
|
171
|
+
if (name === "chevron-left") {
|
|
172
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-chevron-left"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M15 6l-6 6l6 6" /></svg>`;
|
|
173
|
+
}
|
|
174
|
+
if (name === "chevron-right") {
|
|
175
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-chevron-right"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M9 6l6 6l-6 6" /></svg>`;
|
|
176
|
+
}
|
|
177
|
+
return "";
|
|
178
|
+
}
|
|
179
|
+
function createMonthPicker(initialMonth, onChange) {
|
|
180
|
+
const container = document.createElement("div");
|
|
181
|
+
container.className = "ina-month-picker";
|
|
182
|
+
let currentMonthIdx = initialMonth;
|
|
183
|
+
let isPickerOpen = false;
|
|
184
|
+
const pickerTrigger = document.createElement("button");
|
|
185
|
+
pickerTrigger.type = "button";
|
|
186
|
+
pickerTrigger.className = "ina-month-picker__trigger ina-month-picker__trigger--size-sm";
|
|
187
|
+
const updateTriggerText = () => {
|
|
188
|
+
pickerTrigger.innerHTML = `
|
|
189
|
+
<span class="ina-month-picker__trigger-text">${MONTHS_SHORT_ID[currentMonthIdx]}</span>
|
|
190
|
+
`;
|
|
191
|
+
};
|
|
192
|
+
updateTriggerText();
|
|
193
|
+
pickerTrigger.addEventListener("click", (e) => {
|
|
194
|
+
e.stopPropagation();
|
|
195
|
+
togglePicker(!isPickerOpen);
|
|
196
|
+
});
|
|
197
|
+
const pickerPanel = document.createElement("div");
|
|
198
|
+
pickerPanel.className = "ina-month-picker__panel";
|
|
199
|
+
const grid = document.createElement("div");
|
|
200
|
+
grid.className = "ina-month-picker__grid";
|
|
201
|
+
MONTHS_SHORT_ID.forEach((m, idx) => {
|
|
202
|
+
const btn = document.createElement("button");
|
|
203
|
+
btn.type = "button";
|
|
204
|
+
btn.className = "ina-month-picker__month-option";
|
|
205
|
+
if (idx === currentMonthIdx)
|
|
206
|
+
btn.classList.add("ina-month-picker__month-option--selected");
|
|
207
|
+
btn.textContent = m;
|
|
208
|
+
btn.addEventListener("click", (e) => {
|
|
209
|
+
e.stopPropagation();
|
|
210
|
+
currentMonthIdx = idx;
|
|
211
|
+
updateTriggerText();
|
|
212
|
+
grid.querySelectorAll(".ina-month-picker__month-option").forEach((b, i) => {
|
|
213
|
+
if (i === idx)
|
|
214
|
+
b.classList.add("ina-month-picker__month-option--selected");
|
|
215
|
+
else
|
|
216
|
+
b.classList.remove("ina-month-picker__month-option--selected");
|
|
217
|
+
});
|
|
218
|
+
togglePicker(false);
|
|
219
|
+
onChange(idx);
|
|
220
|
+
});
|
|
221
|
+
grid.appendChild(btn);
|
|
222
|
+
});
|
|
223
|
+
pickerPanel.appendChild(grid);
|
|
224
|
+
container.appendChild(pickerTrigger);
|
|
225
|
+
container.appendChild(pickerPanel);
|
|
226
|
+
function togglePicker(show) {
|
|
227
|
+
isPickerOpen = show;
|
|
228
|
+
if (show) {
|
|
229
|
+
pickerPanel.classList.add("ina-month-picker__panel--open");
|
|
230
|
+
pickerTrigger.setAttribute("aria-expanded", "true");
|
|
231
|
+
} else {
|
|
232
|
+
pickerPanel.classList.remove("ina-month-picker__panel--open");
|
|
233
|
+
pickerTrigger.setAttribute("aria-expanded", "false");
|
|
199
234
|
}
|
|
200
|
-
datepickerYearContent.appendChild(yearEl);
|
|
201
235
|
}
|
|
236
|
+
document.addEventListener("click", (e) => {
|
|
237
|
+
if (!container.contains(e.target)) togglePicker(false);
|
|
238
|
+
});
|
|
239
|
+
return {
|
|
240
|
+
element: container,
|
|
241
|
+
setMonth: (m) => {
|
|
242
|
+
currentMonthIdx = m;
|
|
243
|
+
updateTriggerText();
|
|
244
|
+
grid.querySelectorAll(".ina-month-picker__month-option").forEach((b, i) => {
|
|
245
|
+
if (i === m)
|
|
246
|
+
b.classList.add("ina-month-picker__month-option--selected");
|
|
247
|
+
else
|
|
248
|
+
b.classList.remove("ina-month-picker__month-option--selected");
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
};
|
|
202
252
|
}
|
|
203
|
-
function
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
253
|
+
function createYearPicker(initialYear, onChange) {
|
|
254
|
+
const container = document.createElement("div");
|
|
255
|
+
container.className = "ina-year-picker";
|
|
256
|
+
let currentYearVal = initialYear;
|
|
257
|
+
let isPickerOpen = false;
|
|
258
|
+
let decadeStart = Math.floor(initialYear / 20) * 20;
|
|
259
|
+
const pickerTrigger = document.createElement("button");
|
|
260
|
+
pickerTrigger.type = "button";
|
|
261
|
+
pickerTrigger.className = "ina-year-picker__trigger ina-year-picker__trigger--size-sm";
|
|
262
|
+
const updateTriggerText = () => {
|
|
263
|
+
pickerTrigger.innerHTML = `
|
|
264
|
+
<span class="ina-year-picker__trigger-text">${currentYearVal}</span>
|
|
265
|
+
`;
|
|
266
|
+
};
|
|
267
|
+
updateTriggerText();
|
|
268
|
+
pickerTrigger.addEventListener("click", (e) => {
|
|
269
|
+
e.stopPropagation();
|
|
270
|
+
togglePicker(!isPickerOpen);
|
|
271
|
+
});
|
|
272
|
+
const pickerPanel = document.createElement("div");
|
|
273
|
+
pickerPanel.className = "ina-year-picker__panel";
|
|
274
|
+
const header = document.createElement("div");
|
|
275
|
+
header.className = "ina-year-picker__header";
|
|
276
|
+
const prevBtn = document.createElement("button");
|
|
277
|
+
prevBtn.type = "button";
|
|
278
|
+
prevBtn.className = "ina-year-picker__nav-button";
|
|
279
|
+
prevBtn.innerHTML = createIcon("chevron-left");
|
|
280
|
+
prevBtn.onclick = (e) => {
|
|
281
|
+
e.stopPropagation();
|
|
282
|
+
decadeStart -= 20;
|
|
283
|
+
renderGrid();
|
|
284
|
+
};
|
|
285
|
+
const nextBtn = document.createElement("button");
|
|
286
|
+
nextBtn.type = "button";
|
|
287
|
+
nextBtn.className = "ina-year-picker__nav-button";
|
|
288
|
+
nextBtn.innerHTML = createIcon("chevron-right");
|
|
289
|
+
nextBtn.onclick = (e) => {
|
|
290
|
+
e.stopPropagation();
|
|
291
|
+
decadeStart += 20;
|
|
292
|
+
renderGrid();
|
|
293
|
+
};
|
|
294
|
+
const rangeText = document.createElement("span");
|
|
295
|
+
rangeText.className = "ina-year-picker__decade-range";
|
|
296
|
+
header.append(prevBtn, rangeText, nextBtn);
|
|
297
|
+
const grid = document.createElement("div");
|
|
298
|
+
grid.className = "ina-year-picker__grid";
|
|
299
|
+
function renderGrid() {
|
|
300
|
+
grid.innerHTML = "";
|
|
301
|
+
rangeText.textContent = `${decadeStart} - ${decadeStart + 19}`;
|
|
302
|
+
for (let y = decadeStart; y < decadeStart + 20; y++) {
|
|
303
|
+
const btn = document.createElement("button");
|
|
304
|
+
btn.type = "button";
|
|
305
|
+
btn.className = "ina-year-picker__year-option";
|
|
306
|
+
if (y === currentYearVal)
|
|
307
|
+
btn.classList.add("ina-year-picker__year-option--selected");
|
|
308
|
+
btn.textContent = y;
|
|
309
|
+
btn.addEventListener("click", (e) => {
|
|
310
|
+
e.stopPropagation();
|
|
311
|
+
currentYearVal = y;
|
|
312
|
+
updateTriggerText();
|
|
313
|
+
togglePicker(false);
|
|
314
|
+
onChange(y);
|
|
315
|
+
});
|
|
316
|
+
grid.appendChild(btn);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
pickerPanel.append(header, grid);
|
|
320
|
+
container.append(pickerTrigger, pickerPanel);
|
|
321
|
+
function togglePicker(show) {
|
|
322
|
+
isPickerOpen = show;
|
|
323
|
+
if (show) {
|
|
324
|
+
decadeStart = Math.floor(currentYearVal / 20) * 20;
|
|
325
|
+
renderGrid();
|
|
326
|
+
pickerPanel.classList.add("ina-year-picker__panel--open");
|
|
327
|
+
pickerTrigger.setAttribute("aria-expanded", "true");
|
|
328
|
+
} else {
|
|
329
|
+
pickerPanel.classList.remove("ina-year-picker__panel--open");
|
|
330
|
+
pickerTrigger.setAttribute("aria-expanded", "false");
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
document.addEventListener("click", (e) => {
|
|
334
|
+
if (!container.contains(e.target)) togglePicker(false);
|
|
335
|
+
});
|
|
336
|
+
return {
|
|
337
|
+
element: container,
|
|
338
|
+
setYear: (y) => {
|
|
339
|
+
currentYearVal = y;
|
|
340
|
+
updateTriggerText();
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
function renderCalendar() {
|
|
345
|
+
panelContent.innerHTML = "";
|
|
346
|
+
const year = currentDate.getFullYear();
|
|
347
|
+
const month = currentDate.getMonth();
|
|
348
|
+
const calendarContainer = document.createElement("div");
|
|
349
|
+
calendarContainer.className = "ina-date-picker__calendar-container";
|
|
350
|
+
const header = document.createElement("div");
|
|
351
|
+
header.className = "ina-date-picker__calendar-header";
|
|
352
|
+
const prevBtn = document.createElement("button");
|
|
353
|
+
prevBtn.className = "ina-date-picker__nav-button";
|
|
354
|
+
prevBtn.type = "button";
|
|
355
|
+
prevBtn.innerHTML = createIcon("chevron-left", 20);
|
|
356
|
+
prevBtn.addEventListener("click", (e) => {
|
|
357
|
+
e.stopPropagation();
|
|
358
|
+
currentDate.setMonth(month - 1);
|
|
359
|
+
renderCalendar();
|
|
360
|
+
});
|
|
361
|
+
const nextBtn = document.createElement("button");
|
|
362
|
+
nextBtn.className = "ina-date-picker__nav-button";
|
|
363
|
+
nextBtn.type = "button";
|
|
364
|
+
nextBtn.innerHTML = createIcon("chevron-right", 20);
|
|
365
|
+
nextBtn.addEventListener("click", (e) => {
|
|
366
|
+
e.stopPropagation();
|
|
367
|
+
currentDate.setMonth(month + 1);
|
|
368
|
+
renderCalendar();
|
|
369
|
+
});
|
|
370
|
+
const controls = document.createElement("div");
|
|
371
|
+
controls.className = "ina-date-picker__header-controls";
|
|
372
|
+
const monthContainer = document.createElement("div");
|
|
373
|
+
monthContainer.className = "ina-date-picker__dropdown-container";
|
|
374
|
+
const monthPicker = createMonthPicker(month, (newMonth) => {
|
|
375
|
+
currentDate.setMonth(newMonth);
|
|
376
|
+
renderCalendar();
|
|
377
|
+
});
|
|
378
|
+
monthContainer.appendChild(monthPicker.element);
|
|
379
|
+
const yearContainer = document.createElement("div");
|
|
380
|
+
yearContainer.className = "ina-date-picker__dropdown-container";
|
|
381
|
+
const yearPicker = createYearPicker(year, (newYear) => {
|
|
382
|
+
currentDate.setFullYear(newYear);
|
|
383
|
+
renderCalendar();
|
|
384
|
+
});
|
|
385
|
+
yearContainer.appendChild(yearPicker.element);
|
|
386
|
+
controls.append(monthContainer, yearContainer);
|
|
387
|
+
header.append(prevBtn, controls, nextBtn);
|
|
388
|
+
const grid = document.createElement("div");
|
|
389
|
+
grid.className = "ina-date-picker__calendar-grid";
|
|
390
|
+
DAYS_SHORT.forEach((day) => {
|
|
391
|
+
const dh = document.createElement("div");
|
|
392
|
+
dh.className = "ina-date-picker__day-header";
|
|
393
|
+
dh.textContent = day;
|
|
394
|
+
grid.appendChild(dh);
|
|
215
395
|
});
|
|
216
396
|
const firstDayOfMonth = new Date(year, month, 1).getDay();
|
|
217
397
|
const daysInMonth = new Date(year, month + 1, 0).getDate();
|
|
218
398
|
const daysInPrevMonth = new Date(year, month, 0).getDate();
|
|
219
|
-
for (let i =
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
399
|
+
for (let i = firstDayOfMonth - 1; i >= 0; i--) {
|
|
400
|
+
const dayBtn = document.createElement("button");
|
|
401
|
+
dayBtn.type = "button";
|
|
402
|
+
dayBtn.className = "ina-date-picker__day ina-date-picker__day--other-month ina-date-picker__day--disabled";
|
|
403
|
+
dayBtn.textContent = daysInPrevMonth - i;
|
|
404
|
+
grid.appendChild(dayBtn);
|
|
225
405
|
}
|
|
226
406
|
const today = /* @__PURE__ */ new Date();
|
|
227
407
|
for (let i = 1; i <= daysInMonth; i++) {
|
|
228
|
-
const
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
dayEl.appendChild(marker);
|
|
237
|
-
dayEl.classList.add("today");
|
|
408
|
+
const dayBtn = document.createElement("button");
|
|
409
|
+
dayBtn.type = "button";
|
|
410
|
+
dayBtn.className = "ina-date-picker__day";
|
|
411
|
+
dayBtn.textContent = i;
|
|
412
|
+
let isSelected = false;
|
|
413
|
+
if (selectedDate && selectedDate.getDate() === i && selectedDate.getMonth() === month && selectedDate.getFullYear() === year) {
|
|
414
|
+
dayBtn.classList.add("ina-date-picker__day--selected");
|
|
415
|
+
isSelected = true;
|
|
238
416
|
}
|
|
239
|
-
if (
|
|
240
|
-
|
|
417
|
+
if (today.getDate() === i && today.getMonth() === month && today.getFullYear() === year) {
|
|
418
|
+
dayBtn.classList.add("ina-date-picker__day--today");
|
|
241
419
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const totalCells = 42;
|
|
245
|
-
const cellsRendered = firstDayOfMonth + daysInMonth;
|
|
246
|
-
const remainingCells = totalCells - cellsRendered;
|
|
247
|
-
for (let i = 1; i <= remainingCells; i++) {
|
|
248
|
-
const dayEl = document.createElement("button");
|
|
249
|
-
dayEl.className = "ina-date-picker__calendar-day outside-month";
|
|
250
|
-
dayEl.textContent = i;
|
|
251
|
-
dayEl.disabled = true;
|
|
252
|
-
datepickerContent.appendChild(dayEl);
|
|
253
|
-
}
|
|
254
|
-
datepickerMonthPopover.innerHTML = "";
|
|
255
|
-
MONTHS.forEach((monthName, index) => {
|
|
256
|
-
const monthEl = document.createElement("button");
|
|
257
|
-
monthEl.className = "ina-date-picker__month-item";
|
|
258
|
-
monthEl.textContent = monthName.substring(0, 3);
|
|
259
|
-
monthEl.dataset.month = index;
|
|
260
|
-
if (index === month) {
|
|
261
|
-
monthEl.classList.add("selected");
|
|
262
|
-
}
|
|
263
|
-
datepickerMonthPopover.appendChild(monthEl);
|
|
264
|
-
});
|
|
265
|
-
datepickerYearContent.innerHTML = "";
|
|
266
|
-
const startYear = Math.floor(year / 10) * 10;
|
|
267
|
-
const endYear = startYear + 19;
|
|
268
|
-
datepickerYearCurrent.textContent = `${startYear} - ${endYear}`;
|
|
269
|
-
for (let y = startYear; y <= endYear; y++) {
|
|
270
|
-
const yearEl = document.createElement("button");
|
|
271
|
-
yearEl.className = "ina-date-picker__year-item";
|
|
272
|
-
yearEl.textContent = y;
|
|
273
|
-
yearEl.dataset.year = y;
|
|
274
|
-
if (y === year) {
|
|
275
|
-
yearEl.classList.add("selected");
|
|
420
|
+
if (!isSelected) {
|
|
421
|
+
dayBtn.classList.add("ina-date-picker__day--hover");
|
|
276
422
|
}
|
|
277
|
-
|
|
423
|
+
dayBtn.addEventListener("click", (e) => {
|
|
424
|
+
e.stopPropagation();
|
|
425
|
+
selectedDate = new Date(year, month, i);
|
|
426
|
+
triggerText.textContent = formatDate(selectedDate);
|
|
427
|
+
triggerText.classList.add("ina-date-picker__trigger-text--value");
|
|
428
|
+
triggerText.classList.remove(
|
|
429
|
+
"ina-date-picker__trigger-text--placeholder"
|
|
430
|
+
);
|
|
431
|
+
datepicker.dispatchEvent(
|
|
432
|
+
new CustomEvent("date:changed", { detail: { selectedDate } })
|
|
433
|
+
);
|
|
434
|
+
toggle(false);
|
|
435
|
+
});
|
|
436
|
+
grid.appendChild(dayBtn);
|
|
278
437
|
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
438
|
+
const currentCells = grid.children.length - 7;
|
|
439
|
+
const remaining = 42 - currentCells;
|
|
440
|
+
for (let i = 1; i <= remaining; i++) {
|
|
441
|
+
const dayBtn = document.createElement("button");
|
|
442
|
+
dayBtn.type = "button";
|
|
443
|
+
dayBtn.className = "ina-date-picker__day ina-date-picker__day--other-month ina-date-picker__day--disabled";
|
|
444
|
+
dayBtn.textContent = i;
|
|
445
|
+
grid.appendChild(dayBtn);
|
|
286
446
|
}
|
|
447
|
+
calendarContainer.append(header, grid);
|
|
448
|
+
panelContent.appendChild(calendarContainer);
|
|
287
449
|
}
|
|
288
|
-
function
|
|
289
|
-
|
|
290
|
-
|
|
450
|
+
function toggle(show) {
|
|
451
|
+
isOpen = show;
|
|
452
|
+
if (show) {
|
|
453
|
+
panel.classList.add("ina-date-picker__panel--open");
|
|
454
|
+
renderCalendar();
|
|
291
455
|
} else {
|
|
292
|
-
|
|
456
|
+
panel.classList.remove("ina-date-picker__panel--open");
|
|
293
457
|
}
|
|
294
458
|
}
|
|
295
|
-
|
|
296
|
-
if (datepickerYearPopover.style.display === "none" || datepickerYearPopover.style.display === "") {
|
|
297
|
-
datepickerYearPopover.style.display = "block";
|
|
298
|
-
} else {
|
|
299
|
-
datepickerYearPopover.style.display = "none";
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
datepickerTrigger.addEventListener("click", (e) => {
|
|
459
|
+
trigger.addEventListener("click", (e) => {
|
|
303
460
|
e.stopPropagation();
|
|
304
|
-
|
|
305
|
-
});
|
|
306
|
-
prevMonthButton.addEventListener("click", () => {
|
|
307
|
-
currentDate.setMonth(currentDate.getMonth() - 1);
|
|
308
|
-
renderCalendar(currentDate.getFullYear(), currentDate.getMonth());
|
|
309
|
-
});
|
|
310
|
-
nextMonthButton.addEventListener("click", () => {
|
|
311
|
-
currentDate.setMonth(currentDate.getMonth() + 1);
|
|
312
|
-
renderCalendar(currentDate.getFullYear(), currentDate.getMonth());
|
|
313
|
-
});
|
|
314
|
-
datepickerMonthTrigger.addEventListener("click", (e) => {
|
|
315
|
-
e.stopPropagation();
|
|
316
|
-
toggleMonthPopover();
|
|
317
|
-
});
|
|
318
|
-
datepickerYearTrigger.addEventListener("click", (e) => {
|
|
319
|
-
e.stopPropagation();
|
|
320
|
-
toggleYearPopover();
|
|
321
|
-
});
|
|
322
|
-
document.addEventListener("click", (e) => {
|
|
323
|
-
if (!datepickerPopover.contains(e.target) && e.target !== datepickerTrigger && !datepickerTrigger.contains(e.target)) {
|
|
324
|
-
datepickerPopover.style.display = "none";
|
|
325
|
-
}
|
|
461
|
+
toggle(!isOpen);
|
|
326
462
|
});
|
|
327
463
|
document.addEventListener("click", (e) => {
|
|
328
|
-
if (!
|
|
329
|
-
datepickerMonthPopover.style.display = "none";
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
document.addEventListener("click", (e) => {
|
|
333
|
-
if (!datepickerYearPopover.contains(e.target) && e.target !== datepickerYearTrigger && !datepickerYearTrigger.contains(e.target)) {
|
|
334
|
-
datepickerYearPopover.style.display = "none";
|
|
335
|
-
}
|
|
464
|
+
if (!datepicker.contains(e.target)) toggle(false);
|
|
336
465
|
});
|
|
337
|
-
datepickerMonthPopover.addEventListener("click", (e) => {
|
|
338
|
-
e.stopPropagation();
|
|
339
|
-
const target = e.target;
|
|
340
|
-
if (target.classList.contains("ina-date-picker__month-item")) {
|
|
341
|
-
const monthIndex = parseInt(target.dataset.month);
|
|
342
|
-
currentDate.setMonth(monthIndex);
|
|
343
|
-
renderCalendar(currentDate.getFullYear(), currentDate.getMonth());
|
|
344
|
-
datepickerMonthPopover.style.display = "none";
|
|
345
|
-
}
|
|
346
|
-
});
|
|
347
|
-
datepickerYearPopover.addEventListener("click", (e) => {
|
|
348
|
-
e.stopPropagation();
|
|
349
|
-
const target = e.target;
|
|
350
|
-
if (target.classList.contains("ina-date-picker__year-nav-prev")) {
|
|
351
|
-
const currentYearRange = datepickerYearCurrent.textContent.split(" - ").map((y) => parseInt(y));
|
|
352
|
-
const newStartYear = currentYearRange[0] - 20;
|
|
353
|
-
const newEndYear = currentYearRange[1] - 20;
|
|
354
|
-
renderYear(newStartYear, newEndYear);
|
|
355
|
-
} else if (target.classList.contains("ina-date-picker__year-nav-next")) {
|
|
356
|
-
const currentYearRange = datepickerYearCurrent.textContent.split(" - ").map((y) => parseInt(y));
|
|
357
|
-
const newStartYear = currentYearRange[0] + 20;
|
|
358
|
-
const newEndYear = currentYearRange[1] + 20;
|
|
359
|
-
renderYear(newStartYear, newEndYear);
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
datepickerYearContent.addEventListener("click", (e) => {
|
|
363
|
-
e.stopPropagation();
|
|
364
|
-
const target = e.target;
|
|
365
|
-
if (target.classList.contains("ina-date-picker__year-item")) {
|
|
366
|
-
const yearValue = parseInt(target.dataset.year);
|
|
367
|
-
currentDate.setFullYear(yearValue);
|
|
368
|
-
renderCalendar(currentDate.getFullYear(), currentDate.getMonth());
|
|
369
|
-
datepickerYearPopover.style.display = "none";
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
datepickerContent.addEventListener("click", (e) => {
|
|
373
|
-
const target = e.target;
|
|
374
|
-
if (target.classList.contains("ina-date-picker__calendar-day") && !target.classList.contains("outside-month")) {
|
|
375
|
-
if (target.classList.contains("selected")) {
|
|
376
|
-
target.classList.remove("selected");
|
|
377
|
-
selectedDateTarget = null;
|
|
378
|
-
} else {
|
|
379
|
-
const selectedDateEl = datepickerContent.querySelector(
|
|
380
|
-
".ina-date-picker__calendar-day.selected"
|
|
381
|
-
);
|
|
382
|
-
selectedDateEl?.classList.remove("selected");
|
|
383
|
-
target.classList.add("selected");
|
|
384
|
-
selectedDateTarget = target;
|
|
385
|
-
}
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
datepickerSubmitButton.addEventListener("click", () => {
|
|
389
|
-
selectedDate = selectedDateTarget ? new Date(selectedDateTarget.dataset.date) : null;
|
|
390
|
-
currentDate = selectedDate ? new Date(selectedDate) : /* @__PURE__ */ new Date();
|
|
391
|
-
datepicker.dispatchEvent(
|
|
392
|
-
new CustomEvent("date:changed", { detail: { selectedDate } })
|
|
393
|
-
);
|
|
394
|
-
datepickerPopover.style.display = "none";
|
|
395
|
-
});
|
|
396
|
-
renderCalendar(currentDate.getFullYear(), currentDate.getMonth());
|
|
397
466
|
});
|
|
398
467
|
}
|
|
399
|
-
document.addEventListener("DOMContentLoaded", () => {
|
|
400
|
-
});
|
|
401
468
|
|
|
402
469
|
// src/js/components/stateless/modal.js
|
|
403
470
|
function initModal(rootSelector = `.${PREFIX}-modal`) {
|