@idds/js 1.0.35 → 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 +371 -263
- package/dist/index.js +513 -239
- package/package.json +1 -1
package/dist/index.iife.js
CHANGED
|
@@ -119,11 +119,20 @@ var InaUI = (() => {
|
|
|
119
119
|
|
|
120
120
|
// src/js/components/stateful/datepicker.js
|
|
121
121
|
function initDatepicker() {
|
|
122
|
-
document.querySelectorAll(
|
|
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");
|
|
234
|
+
}
|
|
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
|
+
};
|
|
252
|
+
}
|
|
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");
|
|
199
331
|
}
|
|
200
|
-
datepickerYearContent.appendChild(yearEl);
|
|
201
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
|
+
};
|
|
202
343
|
}
|
|
203
|
-
function renderCalendar(
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
241
|
-
}
|
|
242
|
-
datepickerContent.appendChild(dayEl);
|
|
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 = `${PREFIX}-datepicker__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 = `${PREFIX}-datepicker__month-item`;
|
|
258
|
-
monthEl.textContent = monthName.substring(0, 3);
|
|
259
|
-
monthEl.dataset.month = index;
|
|
260
|
-
if (index === month) {
|
|
261
|
-
monthEl.classList.add("selected");
|
|
417
|
+
if (today.getDate() === i && today.getMonth() === month && today.getFullYear() === year) {
|
|
418
|
+
dayBtn.classList.add("ina-date-picker__day--today");
|
|
262
419
|
}
|
|
263
|
-
|
|
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 = `${PREFIX}-datepicker__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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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);
|
|
286
437
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
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);
|
|
293
446
|
}
|
|
447
|
+
calendarContainer.append(header, grid);
|
|
448
|
+
panelContent.appendChild(calendarContainer);
|
|
294
449
|
}
|
|
295
|
-
function
|
|
296
|
-
|
|
297
|
-
|
|
450
|
+
function toggle(show) {
|
|
451
|
+
isOpen = show;
|
|
452
|
+
if (show) {
|
|
453
|
+
panel.classList.add("ina-date-picker__panel--open");
|
|
454
|
+
renderCalendar();
|
|
298
455
|
} else {
|
|
299
|
-
|
|
456
|
+
panel.classList.remove("ina-date-picker__panel--open");
|
|
300
457
|
}
|
|
301
458
|
}
|
|
302
|
-
|
|
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
|
-
}
|
|
326
|
-
});
|
|
327
|
-
document.addEventListener("click", (e) => {
|
|
328
|
-
if (!datepickerMonthPopover.contains(e.target) && e.target !== datepickerMonthTrigger && !datepickerMonthTrigger.contains(e.target)) {
|
|
329
|
-
datepickerMonthPopover.style.display = "none";
|
|
330
|
-
}
|
|
461
|
+
toggle(!isOpen);
|
|
331
462
|
});
|
|
332
463
|
document.addEventListener("click", (e) => {
|
|
333
|
-
if (!
|
|
334
|
-
datepickerYearPopover.style.display = "none";
|
|
335
|
-
}
|
|
336
|
-
});
|
|
337
|
-
datepickerMonthPopover.addEventListener("click", (e) => {
|
|
338
|
-
e.stopPropagation();
|
|
339
|
-
const target = e.target;
|
|
340
|
-
if (target.classList.contains(`${PREFIX}-datepicker__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(`${PREFIX}-datepicker__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(`${PREFIX}-datepicker__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
|
-
}
|
|
464
|
+
if (!datepicker.contains(e.target)) toggle(false);
|
|
361
465
|
});
|
|
362
|
-
datepickerYearContent.addEventListener("click", (e) => {
|
|
363
|
-
e.stopPropagation();
|
|
364
|
-
const target = e.target;
|
|
365
|
-
if (target.classList.contains(`${PREFIX}-datepicker__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(`${PREFIX}-datepicker__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
|
-
`.${PREFIX}-datepicker__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`) {
|
|
@@ -1214,31 +1281,72 @@ var InaUI = (() => {
|
|
|
1214
1281
|
}
|
|
1215
1282
|
|
|
1216
1283
|
// src/js/components/stateless/toast.js
|
|
1217
|
-
function showToast(
|
|
1218
|
-
|
|
1219
|
-
|
|
1284
|
+
function showToast(optionsOrMessage, variant = "default", duration = 3e3) {
|
|
1285
|
+
let message, title, state, style, position, actionHtml;
|
|
1286
|
+
if (typeof optionsOrMessage === "object") {
|
|
1287
|
+
message = optionsOrMessage.message || "";
|
|
1288
|
+
title = optionsOrMessage.title;
|
|
1289
|
+
state = optionsOrMessage.state || "default";
|
|
1290
|
+
style = optionsOrMessage.style || "solid";
|
|
1291
|
+
duration = optionsOrMessage.duration || 3e3;
|
|
1292
|
+
position = optionsOrMessage.position || "top-right";
|
|
1293
|
+
actionHtml = optionsOrMessage.actionHtml || "";
|
|
1294
|
+
} else {
|
|
1295
|
+
message = optionsOrMessage;
|
|
1296
|
+
state = variant;
|
|
1297
|
+
style = "solid";
|
|
1298
|
+
position = "top-right";
|
|
1299
|
+
actionHtml = "";
|
|
1300
|
+
}
|
|
1301
|
+
let containerId = `ina-toast-container-${position}`;
|
|
1302
|
+
let container = document.getElementById(containerId);
|
|
1303
|
+
if (!container) {
|
|
1304
|
+
container = document.createElement("div");
|
|
1305
|
+
container.id = containerId;
|
|
1306
|
+
container.className = `ina-toast-container ina-toast-container--${position}`;
|
|
1307
|
+
document.body.appendChild(container);
|
|
1308
|
+
}
|
|
1309
|
+
const toastItem = document.createElement("div");
|
|
1310
|
+
toastItem.className = "ina-toast-item";
|
|
1220
1311
|
const toast = document.createElement("div");
|
|
1221
|
-
toast.className = `ina-
|
|
1222
|
-
const
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1312
|
+
toast.className = `ina-toast ina-toast--state-${state} ina-toast--style-${style} ina-toast--visible`;
|
|
1313
|
+
const iconMap = {
|
|
1314
|
+
default: '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="16" x2="12" y2="12"/><line x1="12" y1="8" x2="12.01" y2="8"/></svg>',
|
|
1315
|
+
destructive: '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="12"/><line x1="12" y1="16" x2="12.01" y2="16"/></svg>',
|
|
1316
|
+
positive: '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>'
|
|
1317
|
+
};
|
|
1318
|
+
const iconHtml = iconMap[state] || iconMap.default;
|
|
1319
|
+
let contentHtml = `
|
|
1320
|
+
<div class="ina-toast__icon">${iconHtml}</div>
|
|
1321
|
+
<div class="ina-toast__content">
|
|
1322
|
+
<div class="ina-toast__text-area">
|
|
1323
|
+
${title ? `<p class="ina-toast__title">${title}</p>` : ""}
|
|
1324
|
+
${message ? `<p class="ina-toast__description">${message}</p>` : ""}
|
|
1325
|
+
</div>
|
|
1326
|
+
${actionHtml ? `<div class="ina-toast__action-area">${actionHtml}</div>` : ""}
|
|
1327
|
+
</div>
|
|
1328
|
+
<button class="ina-toast__close-button">
|
|
1329
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="ina-toast__close-icon"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
|
|
1330
|
+
</button>
|
|
1331
|
+
`;
|
|
1332
|
+
toast.innerHTML = contentHtml;
|
|
1333
|
+
toastItem.appendChild(toast);
|
|
1334
|
+
const closeBtn = toast.querySelector(".ina-toast__close-button");
|
|
1335
|
+
const close = () => {
|
|
1336
|
+
toast.classList.remove("ina-toast--visible");
|
|
1337
|
+
toast.classList.add("ina-toast--hidden");
|
|
1338
|
+
setTimeout(() => {
|
|
1339
|
+
if (toastItem.parentNode) toastItem.parentNode.removeChild(toastItem);
|
|
1340
|
+
if (container.children.length === 0) {
|
|
1341
|
+
if (container.parentNode) container.parentNode.removeChild(container);
|
|
1342
|
+
}
|
|
1343
|
+
}, 300);
|
|
1344
|
+
};
|
|
1345
|
+
closeBtn.addEventListener("click", close);
|
|
1346
|
+
container.appendChild(toastItem);
|
|
1347
|
+
if (duration > 0) {
|
|
1348
|
+
setTimeout(close, duration);
|
|
1349
|
+
}
|
|
1242
1350
|
}
|
|
1243
1351
|
|
|
1244
1352
|
// src/js/bundle.js
|