@lazhus/kg-ui 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +128 -0
  2. package/custom-elements.json +3815 -0
  3. package/dist/components/kg-accordion-item.js +117 -0
  4. package/dist/components/kg-accordion.js +32 -0
  5. package/dist/components/kg-button.js +241 -0
  6. package/dist/components/kg-card.js +129 -0
  7. package/dist/components/kg-checkbox.js +147 -0
  8. package/dist/components/kg-colorpicker.js +240 -0
  9. package/dist/components/kg-column.js +48 -0
  10. package/dist/components/kg-datagrid.js +428 -0
  11. package/dist/components/kg-datepicker.js +650 -0
  12. package/dist/components/kg-divider.js +118 -0
  13. package/dist/components/kg-drawer.js +178 -0
  14. package/dist/components/kg-file-upload.js +274 -0
  15. package/dist/components/kg-grid.js +46 -0
  16. package/dist/components/kg-image.js +100 -0
  17. package/dist/components/kg-input.js +318 -0
  18. package/dist/components/kg-loader.js +175 -0
  19. package/dist/components/kg-modal.js +165 -0
  20. package/dist/components/kg-progress.js +82 -0
  21. package/dist/components/kg-radio-group.js +75 -0
  22. package/dist/components/kg-radio.js +121 -0
  23. package/dist/components/kg-row.js +42 -0
  24. package/dist/components/kg-select.js +331 -0
  25. package/dist/components/kg-skeleton.js +108 -0
  26. package/dist/components/kg-slider.js +196 -0
  27. package/dist/components/kg-spinner.js +79 -0
  28. package/dist/components/kg-stepper.js +214 -0
  29. package/dist/components/kg-switch.js +106 -0
  30. package/dist/components/kg-tab-panel.js +35 -0
  31. package/dist/components/kg-tabs.js +158 -0
  32. package/dist/components/kg-text.js +141 -0
  33. package/dist/components/kg-textarea.js +162 -0
  34. package/dist/components/kg-toast.js +200 -0
  35. package/dist/index.js +68 -0
  36. package/dist/kg-ui.css +1 -0
  37. package/package.json +57 -0
  38. package/types/components/kg-accordion-item.d.ts +25 -0
  39. package/types/components/kg-accordion.d.ts +22 -0
  40. package/types/components/kg-button.d.ts +34 -0
  41. package/types/components/kg-card.d.ts +31 -0
  42. package/types/components/kg-checkbox.d.ts +28 -0
  43. package/types/components/kg-colorpicker.d.ts +28 -0
  44. package/types/components/kg-column.d.ts +20 -0
  45. package/types/components/kg-datagrid.d.ts +55 -0
  46. package/types/components/kg-datepicker.d.ts +43 -0
  47. package/types/components/kg-divider.d.ts +34 -0
  48. package/types/components/kg-drawer.d.ts +31 -0
  49. package/types/components/kg-file-upload.d.ts +40 -0
  50. package/types/components/kg-grid.d.ts +20 -0
  51. package/types/components/kg-image.d.ts +40 -0
  52. package/types/components/kg-input.d.ts +34 -0
  53. package/types/components/kg-loader.d.ts +31 -0
  54. package/types/components/kg-modal.d.ts +31 -0
  55. package/types/components/kg-progress.d.ts +37 -0
  56. package/types/components/kg-radio-group.d.ts +25 -0
  57. package/types/components/kg-radio.d.ts +25 -0
  58. package/types/components/kg-row.d.ts +20 -0
  59. package/types/components/kg-select.d.ts +37 -0
  60. package/types/components/kg-skeleton.d.ts +34 -0
  61. package/types/components/kg-slider.d.ts +40 -0
  62. package/types/components/kg-spinner.d.ts +28 -0
  63. package/types/components/kg-stepper.d.ts +31 -0
  64. package/types/components/kg-switch.d.ts +28 -0
  65. package/types/components/kg-tab-panel.d.ts +28 -0
  66. package/types/components/kg-tabs.d.ts +25 -0
  67. package/types/components/kg-text.d.ts +31 -0
  68. package/types/components/kg-textarea.d.ts +43 -0
  69. package/types/components/kg-toast.d.ts +28 -0
  70. package/types/index.d.ts +335 -0
@@ -0,0 +1,650 @@
1
+ import { LitElement as k, css as $, html as g } from "lit";
2
+ import { classMap as w } from "lit/directives/class-map.js";
3
+ class b extends k {
4
+ static properties = {
5
+ value: { type: String, reflect: !0 },
6
+ open: { type: Boolean, reflect: !0 },
7
+ disabled: { type: Boolean, reflect: !0 },
8
+ placeholder: { type: String },
9
+ label: { type: String },
10
+ showTime: { type: Boolean },
11
+ mode: { type: String },
12
+ // 'date', 'month', 'year'
13
+ locale: { type: String },
14
+ min: { type: String },
15
+ max: { type: String },
16
+ _viewDate: { type: Object },
17
+ _selectedDate: { type: Object }
18
+ };
19
+ static styles = $`
20
+ :host {
21
+ display: inline-block;
22
+ width: 100%;
23
+ position: relative;
24
+ font-family: inherit;
25
+ }
26
+
27
+ :host([disabled]) {
28
+ pointer-events: none;
29
+ }
30
+
31
+ .datepicker-trigger {
32
+ width: 100%;
33
+ }
34
+
35
+ .datepicker-popup {
36
+ position: absolute;
37
+ top: calc(100% + 8px);
38
+ left: 0;
39
+ z-index: 1000;
40
+ background: var(--kg-bg);
41
+ border: 1px solid var(--kg-border);
42
+ border-radius: var(--kg-radius-lg);
43
+ box-shadow: var(--kg-shadow-lg);
44
+ padding: 1.25rem;
45
+ width: 300px;
46
+ display: none;
47
+ user-select: none;
48
+ animation: slideDown 0.2s cubic-bezier(0.4, 0, 0.2, 1);
49
+ }
50
+
51
+ .datepicker-popup.open {
52
+ display: block;
53
+ }
54
+
55
+ @keyframes slideDown {
56
+ from { opacity: 0; transform: translateY(-10px); }
57
+ to { opacity: 1; transform: translateY(0); }
58
+ }
59
+
60
+ /* Calendar Styles */
61
+ .calendar-header {
62
+ display: flex;
63
+ justify-content: space-between;
64
+ align-items: center;
65
+ margin-bottom: 1rem;
66
+ }
67
+
68
+ .month-year {
69
+ display: flex;
70
+ gap: 4px;
71
+ font-weight: 700;
72
+ font-size: 1rem;
73
+ color: var(--kg-text);
74
+ }
75
+
76
+ .header-select {
77
+ background: transparent;
78
+ border: none;
79
+ color: inherit;
80
+ font-family: inherit;
81
+ font-weight: 700;
82
+ font-size: 0.95rem;
83
+ cursor: pointer;
84
+ padding: 4px;
85
+ border-radius: 4px;
86
+ outline: none;
87
+ transition: background 0.2s;
88
+ -webkit-appearance: none;
89
+ }
90
+
91
+ .header-select:hover {
92
+ background: var(--kg-surface);
93
+ }
94
+
95
+ .nav-btn {
96
+ background: none;
97
+ border: none;
98
+ cursor: pointer;
99
+ padding: 5px;
100
+ border-radius: 6px;
101
+ color: var(--kg-text-muted);
102
+ display: flex;
103
+ align-items: center;
104
+ justify-content: center;
105
+ transition: all 0.2s;
106
+ }
107
+
108
+ .nav-btn:hover {
109
+ background: var(--kg-surface);
110
+ color: var(--kg-text);
111
+ }
112
+
113
+ .calendar-grid {
114
+ display: grid;
115
+ grid-template-columns: repeat(7, 1fr);
116
+ gap: 2px;
117
+ }
118
+
119
+ .weekday {
120
+ text-align: center;
121
+ font-size: 0.75rem;
122
+ font-weight: 700;
123
+ color: var(--kg-text-muted);
124
+ padding-bottom: 0.5rem;
125
+ }
126
+
127
+ .day {
128
+ aspect-ratio: 1;
129
+ display: flex;
130
+ align-items: center;
131
+ justify-content: center;
132
+ font-size: 0.875rem;
133
+ cursor: pointer;
134
+ border-radius: 8px;
135
+ transition: all 0.2s;
136
+ color: var(--kg-text);
137
+ }
138
+
139
+ .day:hover:not(.other-month):not(.selected) {
140
+ background: var(--kg-bg-secondary, rgba(0,0,0,0.05));
141
+ color: var(--kg-primary);
142
+ transform: scale(1.1);
143
+ z-index: 1;
144
+ }
145
+
146
+ .day.other-month {
147
+ color: var(--kg-text-muted);
148
+ opacity: 0.3;
149
+ cursor: default;
150
+ }
151
+
152
+ .day.selected {
153
+ background: var(--kg-primary);
154
+ color: white;
155
+ font-weight: 700;
156
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
157
+ }
158
+
159
+ .day.today {
160
+ box-shadow: 0 0 0 2px var(--kg-primary) inset;
161
+ color: var(--kg-primary);
162
+ font-weight: 700;
163
+ }
164
+
165
+ .day.today.selected {
166
+ color: white;
167
+ border-color: rgba(255, 255, 255, 0.4);
168
+ }
169
+
170
+ .day.focused {
171
+ background: var(--kg-surface);
172
+ box-shadow: 0 0 0 2px var(--kg-primary) inset;
173
+ }
174
+
175
+ .day.selected.focused {
176
+ background: var(--kg-primary);
177
+ box-shadow: 0 0 0 2px rgba(255,255,255,0.4) inset;
178
+ }
179
+
180
+ .day.today.focused:not(.selected) {
181
+ background: var(--kg-surface);
182
+ }
183
+
184
+ /* Time Picker Styles */
185
+ .time-picker {
186
+ margin-top: 1rem;
187
+ padding-top: 1rem;
188
+ border-top: 1px solid var(--kg-border);
189
+ display: flex;
190
+ align-items: center;
191
+ justify-content: center;
192
+ gap: 8px;
193
+ }
194
+
195
+ .time-unit {
196
+ display: flex;
197
+ flex-direction: column;
198
+ align-items: center;
199
+ gap: 4px;
200
+ }
201
+
202
+ .time-select {
203
+ background: var(--kg-surface);
204
+ border: 1px solid var(--kg-border);
205
+ color: var(--kg-text);
206
+ padding: 6px 8px;
207
+ border-radius: 6px;
208
+ font-weight: 700;
209
+ outline: none;
210
+ cursor: pointer;
211
+ }
212
+
213
+ .time-separator {
214
+ font-weight: 700;
215
+ font-size: 1.25rem;
216
+ color: var(--kg-text-muted);
217
+ }
218
+
219
+ .day.disabled {
220
+ opacity: 0.3;
221
+ cursor: not-allowed;
222
+ pointer-events: none;
223
+ background: transparent;
224
+ color: var(--kg-text-muted);
225
+ }
226
+
227
+ /* Month/Year selector grids */
228
+ .selector-grid {
229
+ display: grid;
230
+ grid-template-columns: repeat(3, 1fr);
231
+ gap: 8px;
232
+ margin-top: 0.5rem;
233
+ }
234
+
235
+ .selector-item {
236
+ padding: 10px 4px;
237
+ text-align: center;
238
+ border-radius: 8px;
239
+ cursor: pointer;
240
+ font-size: 0.9rem;
241
+ color: var(--kg-text);
242
+ transition: all 0.2s;
243
+ font-weight: 500;
244
+ }
245
+
246
+ .selector-item:hover {
247
+ background: var(--kg-bg-secondary, rgba(0,0,0,0.05));
248
+ color: var(--kg-primary);
249
+ transform: translateY(-1px);
250
+ }
251
+
252
+ .selector-item.selected {
253
+ background: var(--kg-primary);
254
+ color: white;
255
+ font-weight: 700;
256
+ box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
257
+ }
258
+ `;
259
+ constructor() {
260
+ super(), this.open = !1, this.disabled = !1, this.mode = "date", this.locale = "tr-TR", this.placeholder = "Tarih seçiniz...", this.min = "", this.max = "", this._viewDate = /* @__PURE__ */ new Date(), this.value = "", this._handleOutsideClick = this._handleOutsideClick.bind(this);
261
+ }
262
+ connectedCallback() {
263
+ super.connectedCallback(), document.addEventListener("click", this._handleOutsideClick);
264
+ }
265
+ disconnectedCallback() {
266
+ super.disconnectedCallback(), document.removeEventListener("click", this._handleOutsideClick);
267
+ }
268
+ _handleOutsideClick(t) {
269
+ this.open && !t.composedPath().includes(this) && (this.open = !1);
270
+ }
271
+ togglePopup(t) {
272
+ t && t.stopPropagation(), !this.disabled && (this.open = !this.open);
273
+ }
274
+ _handleInputKeydown(t) {
275
+ ["Backspace", "Delete", "Tab", "Escape", "Enter", "ArrowLeft", "ArrowRight", "Home", "End"].includes(t.key) || (t.ctrlKey || t.metaKey) && ["a", "c", "v", "x"].includes(t.key.toLowerCase()) || /^\d$/.test(t.key) || t.preventDefault();
276
+ }
277
+ _getDateFormat() {
278
+ const t = new Date(2023, 11, 31), e = new Intl.DateTimeFormat(this.locale).formatToParts(t), n = e.filter((i) => i.type !== "literal").map((i) => i.type), r = e.find((i) => i.type === "literal");
279
+ let s = r ? r.value : ".";
280
+ return s.includes(".") ? s = "." : s.includes("/") ? s = "/" : s.includes("-") ? s = "-" : s = ".", { parts: n, separator: s };
281
+ }
282
+ _handleManualInput(t) {
283
+ let e = t.detail.value;
284
+ e = e.replace(/\D/g, "");
285
+ const { parts: n, separator: r } = this._getDateFormat(), s = n[0] === "year";
286
+ let i = "";
287
+ if (e.length > 0 && (s ? e.length <= 4 ? i = e : e.length <= 6 ? i = `${e.slice(0, 4)}${r}${e.slice(4)}` : e.length <= 8 && (i = `${e.slice(0, 4)}${r}${e.slice(4, 6)}${r}${e.slice(6)}`) : e.length <= 2 ? i = e : e.length <= 4 ? i = `${e.slice(0, 2)}${r}${e.slice(2)}` : e.length <= 8 && (i = `${e.slice(0, 2)}${r}${e.slice(2, 4)}${r}${e.slice(4)}`), this.showTime && e.length > 8)) {
288
+ const l = i, c = e.slice(8);
289
+ c.length <= 2 ? i = `${l} ${c}` : i = `${l} ${c.slice(0, 2)}:${c.slice(2, 4)}`;
290
+ }
291
+ if (e.length >= 8) {
292
+ let l, c, p;
293
+ if (s)
294
+ p = parseInt(e.slice(0, 4)), c = parseInt(e.slice(4, 6)), l = parseInt(e.slice(6, 8));
295
+ else {
296
+ const o = parseInt(e.slice(0, 2)), m = parseInt(e.slice(2, 4)), d = parseInt(e.slice(4, 8));
297
+ n[0] === "day" ? (l = o, c = m, p = d) : (c = o, l = m, p = d);
298
+ }
299
+ l > 31 && (l = 31), l === 0 && (l = 1), c > 12 && (c = 12), c === 0 && (c = 1), p > 2100 && (p = 2100);
300
+ const u = String(l).padStart(2, "0"), v = String(c).padStart(2, "0"), f = String(p);
301
+ if (s ? i = `${f}${r}${v}${r}${u}` : n[0] === "day" ? i = `${u}${r}${v}${r}${f}` : i = `${v}${r}${u}${r}${f}`, this.showTime && e.length > 8) {
302
+ i.split(" ")[1];
303
+ let o = parseInt(e.slice(8, 10) || "0"), m = parseInt(e.slice(10, 12) || "0");
304
+ o > 23 && (o = 23), m > 59 && (m = 59);
305
+ const d = String(o).padStart(2, "0"), D = String(m).padStart(2, "0");
306
+ e.length <= 10 ? i += ` ${d}` : i += ` ${d}:${D}`;
307
+ }
308
+ }
309
+ if (this.value = i || e, this.value.length >= 8) {
310
+ const l = this.value.split(" ")[0].split(r);
311
+ if (this.value.split(" ")[1]?.split(":"), l.length === 3) {
312
+ let c, p, u;
313
+ if (s) {
314
+ currentParts[0] === "year" ? (u = parseInt(dateComponents[0]), p = parseInt(dateComponents[1]), c = parseInt(dateComponents[2])) : currentParts[0] === "day" ? (c = parseInt(dateComponents[0]), p = parseInt(dateComponents[1]), u = parseInt(dateComponents[2])) : (p = parseInt(dateComponents[0]), c = parseInt(dateComponents[1]), u = parseInt(dateComponents[2]));
315
+ let v = 0, f = 0;
316
+ if (timePartStr) {
317
+ const o = timePartStr.split(":");
318
+ o.length >= 2 && (v = parseInt(o[0]), f = parseInt(o[1]));
319
+ }
320
+ if (u > 999) {
321
+ let o = new Date(u, p - 1, c, v, f);
322
+ if (!isNaN(o.getTime())) {
323
+ if (this.min) {
324
+ const d = this._parseDateStr(this.min);
325
+ if (d) {
326
+ const D = new Date(o.getFullYear(), o.getMonth(), o.getDate()), a = new Date(d.getFullYear(), d.getMonth(), d.getDate());
327
+ D < a && (o = new Date(d));
328
+ }
329
+ }
330
+ if (this.max) {
331
+ const d = this._parseDateStr(this.max);
332
+ if (d) {
333
+ const D = new Date(o.getFullYear(), o.getMonth(), o.getDate()), a = new Date(d.getFullYear(), d.getMonth(), d.getDate());
334
+ D > a && (o = new Date(d));
335
+ }
336
+ }
337
+ this._viewDate = o, this._selectedDate = o;
338
+ const m = this._formatValue(o);
339
+ this.value !== m && (this.value = m), this.dispatchEvent(new CustomEvent("change", {
340
+ detail: { value: this.value, date: this._selectedDate },
341
+ bubbles: !0,
342
+ composed: !0
343
+ }));
344
+ }
345
+ }
346
+ }
347
+ }
348
+ }
349
+ }
350
+ _changeMonth(t) {
351
+ const e = new Date(this._viewDate);
352
+ e.setMonth(e.getMonth() + t), this._viewDate = e;
353
+ }
354
+ _setViewMonth(t) {
355
+ const e = new Date(this._viewDate);
356
+ e.setMonth(parseInt(t)), this._viewDate = e;
357
+ }
358
+ _setViewYear(t) {
359
+ const e = new Date(this._viewDate);
360
+ e.setFullYear(parseInt(t)), this._viewDate = e;
361
+ }
362
+ _setTime(t, e) {
363
+ const n = new Date(this._viewDate);
364
+ if (t === "hour" && n.setHours(parseInt(e)), t === "minute" && n.setMinutes(parseInt(e)), this._viewDate = n, this._selectedDate) {
365
+ const r = new Date(this._selectedDate);
366
+ t === "hour" && r.setHours(parseInt(e)), t === "minute" && r.setMinutes(parseInt(e)), this._selectedDate = r, this.value = this._formatValue(r);
367
+ }
368
+ }
369
+ _formatValue(t) {
370
+ if (!t) return "";
371
+ const { separator: e, parts: n } = this._getDateFormat(), r = String(t.getDate()).padStart(2, "0"), s = String(t.getMonth() + 1).padStart(2, "0"), i = String(t.getFullYear());
372
+ let l = "";
373
+ if (n[0] === "year" ? l = `${i}${e}${s}${e}${r}` : n[0] === "day" ? l = `${r}${e}${s}${e}${i}` : l = `${s}${e}${r}${e}${i}`, this.mode === "year") return String(i);
374
+ if (this.mode === "month") return `${s}${e}${i}`;
375
+ if (this.showTime) {
376
+ const c = String(t.getHours()).padStart(2, "0"), p = String(t.getMinutes()).padStart(2, "0");
377
+ l += ` ${c}:${p}`;
378
+ }
379
+ return l;
380
+ }
381
+ _handleToday(t) {
382
+ t && t.stopPropagation();
383
+ const e = /* @__PURE__ */ new Date();
384
+ this._viewDate = e, this._selectDate(e.getDate(), !0);
385
+ }
386
+ _handleDone(t) {
387
+ t && t.stopPropagation(), this.open = !1;
388
+ }
389
+ _handleKeydown(t) {
390
+ if (!this.open) {
391
+ (t.key === "Enter" || t.key === " ") && (t.preventDefault(), this.open = !0);
392
+ return;
393
+ }
394
+ if (t.key === "Escape") {
395
+ this.open = !1;
396
+ return;
397
+ }
398
+ const e = new Date(this._viewDate);
399
+ let n = !0;
400
+ switch (t.key) {
401
+ case "ArrowLeft":
402
+ e.setDate(e.getDate() - 1);
403
+ break;
404
+ case "ArrowRight":
405
+ e.setDate(e.getDate() + 1);
406
+ break;
407
+ case "ArrowUp":
408
+ e.setDate(e.getDate() - 7);
409
+ break;
410
+ case "ArrowDown":
411
+ e.setDate(e.getDate() + 7);
412
+ break;
413
+ case "Enter":
414
+ const r = new Date(this._viewDate);
415
+ this._isDisabled(r) || this._selectDate(this._viewDate.getDate(), !0);
416
+ break;
417
+ default:
418
+ n = !1;
419
+ }
420
+ n && (t.preventDefault(), this._viewDate = e);
421
+ }
422
+ _parseDateStr(t) {
423
+ return t ? t.match(/^\d{4}-\d{2}-\d{2}$/) ? new Date(t) : new Date(t) : null;
424
+ }
425
+ _isDisabled(t) {
426
+ if (!t) return !1;
427
+ const e = this._parseDateStr(this.min), n = this._parseDateStr(this.max), r = new Date(t.getFullYear(), t.getMonth(), t.getDate());
428
+ if (e) {
429
+ const s = new Date(e.getFullYear(), e.getMonth(), e.getDate());
430
+ if (r < s) return !0;
431
+ }
432
+ if (n) {
433
+ const s = new Date(n.getFullYear(), n.getMonth(), n.getDate());
434
+ if (r > s) return !0;
435
+ }
436
+ return !1;
437
+ }
438
+ _selectDate(t, e) {
439
+ if (!e) return;
440
+ const n = new Date(this._viewDate);
441
+ this.mode === "date" && n.setDate(t), !this._isDisabled(n) && (this._selectedDate = n, this.value = this._formatValue(n), (!this.showTime || this.mode !== "date") && (this.open = !1), this.dispatchEvent(new CustomEvent("change", {
442
+ detail: { value: this.value, date: this._selectedDate },
443
+ bubbles: !0,
444
+ composed: !0
445
+ })));
446
+ }
447
+ _selectMonth(t) {
448
+ const e = new Date(this._viewDate);
449
+ e.setMonth(t), this._viewDate = e, this._selectedDate = e, this.value = this._formatValue(e), this.open = !1, this.dispatchEvent(new CustomEvent("change", {
450
+ detail: { value: this.value, date: this._selectedDate },
451
+ bubbles: !0,
452
+ composed: !0
453
+ }));
454
+ }
455
+ _selectYear(t) {
456
+ const e = new Date(this._viewDate);
457
+ e.setFullYear(t), this._viewDate = e, this._selectedDate = e, this.value = this._formatValue(e), this.open = !1, this.dispatchEvent(new CustomEvent("change", {
458
+ detail: { value: this.value, date: this._selectedDate },
459
+ bubbles: !0,
460
+ composed: !0
461
+ }));
462
+ }
463
+ _renderCalendar() {
464
+ const t = this._viewDate.getFullYear(), e = this._viewDate.getMonth(), n = this._viewDate.getDate(), r = Array.from({ length: 12 }, (a, h) => {
465
+ const y = new Date(2e3, h, 1);
466
+ return new Intl.DateTimeFormat(this.locale, { month: "long" }).format(y);
467
+ });
468
+ new Intl.DateTimeFormat(this.locale, { weekday: "narrow" }).format(new Date(2024, 0, 7)), new Intl.DateTimeFormat(this.locale, { weekday: "narrow" }).format(new Date(2024, 0, 7));
469
+ let s = 1;
470
+ (this.locale.startsWith("en-US") || this.locale.startsWith("ja") || this.locale.startsWith("zh")) && (s = 0);
471
+ const i = [];
472
+ for (let a = 0; a < 7; a++) {
473
+ const h = new Date(2024, 0, 7 + a + s);
474
+ i.push(new Intl.DateTimeFormat(this.locale, { weekday: "short" }).format(h));
475
+ }
476
+ let l = (new Date(t, e, 1).getDay() - s + 7) % 7;
477
+ const c = new Date(t, e + 1, 0).getDate(), p = new Date(t, e, 0).getDate(), u = [];
478
+ for (let a = l - 1; a >= 0; a--)
479
+ u.push({ day: p - a, current: !1 });
480
+ for (let a = 1; a <= c; a++)
481
+ u.push({ day: a, current: !0 });
482
+ const v = 42 - u.length;
483
+ for (let a = 1; a <= v; a++)
484
+ u.push({ day: a, current: !1 });
485
+ const f = (/* @__PURE__ */ new Date()).getFullYear(), o = [];
486
+ for (let a = f - 50; a <= f + 50; a++)
487
+ o.push(a);
488
+ const m = /* @__PURE__ */ new Date(), d = (a) => a === m.getDate() && e === m.getMonth() && t === m.getFullYear(), D = (a) => this._selectedDate ? a === this._selectedDate.getDate() && e === this._selectedDate.getMonth() && t === this._selectedDate.getFullYear() : !1;
489
+ return g`
490
+ <div class="calendar-header">
491
+ <button class="nav-btn" @click="${(a) => {
492
+ a.stopPropagation(), this._changeMonth(-1);
493
+ }}">←</button>
494
+ <div class="month-year">
495
+ <select class="header-select" @click="${(a) => a.stopPropagation()}" @change="${(a) => this._setViewMonth(a.target.value)}">
496
+ ${r.map((a, h) => g`<option value="${h}" ?selected="${h === e}">${a}</option>`)}
497
+ </select>
498
+ <select class="header-select" @click="${(a) => a.stopPropagation()}" @change="${(a) => this._setViewYear(a.target.value)}">
499
+ ${o.map((a) => g`<option value="${a}" ?selected="${a === t}">${a}</option>`)}
500
+ </select>
501
+ </div>
502
+ <button class="nav-btn" @click="${(a) => {
503
+ a.stopPropagation(), this._changeMonth(1);
504
+ }}">→</button>
505
+ </div>
506
+ <div class="calendar-grid">
507
+ ${i.map((a) => g`<div class="weekday">${a}</div>`)}
508
+ ${u.map((a) => g`
509
+ <div class="${w({
510
+ day: !0,
511
+ "other-month": !a.current,
512
+ today: a.current && d(a.day),
513
+ selected: a.current && D(a.day),
514
+ focused: a.current && a.day === n,
515
+ disabled: a.current && this._isDisabled(new Date(t, e, a.day))
516
+ })}" @click="${(h) => {
517
+ h.stopPropagation(), this._selectDate(a.day, a.current);
518
+ }}">
519
+ ${a.day}
520
+ </div>
521
+ `)}
522
+ </div>
523
+
524
+ ${this.showTime ? g`
525
+ <div class="time-picker" @click="${(a) => a.stopPropagation()}">
526
+ <select class="time-select" @change="${(a) => this._setTime("hour", a.target.value)}">
527
+ ${Array.from({ length: 24 }, (a, h) => g`
528
+ <option value="${h}" ?selected="${h === this._viewDate.getHours()}">
529
+ ${String(h).padStart(2, "0")}
530
+ </option>
531
+ `)}
532
+ </select>
533
+ <span class="time-separator">:</span>
534
+ <select class="time-select" @change="${(a) => this._setTime("minute", a.target.value)}">
535
+ ${Array.from({ length: 60 }, (a, h) => g`
536
+ <option value="${h}" ?selected="${h === this._viewDate.getMinutes()}">
537
+ ${String(h).padStart(2, "0")}
538
+ </option>
539
+ `)}
540
+ </select>
541
+ </div>
542
+ ` : ""}
543
+
544
+ <div style="margin-top: 1rem; border-top: 1px solid var(--kg-border); padding-top: 0.75rem; display: flex; justify-content: center; gap: 8px;">
545
+ <kg-button size="mini" basic fullwidth @click="${this._handleToday}">Bugün</kg-button>
546
+ ${this.showTime ? g`
547
+ <kg-button size="mini" color="primary" fullwidth @click="${this._handleDone}">Tamam</kg-button>
548
+ ` : ""}
549
+ </div>
550
+ `;
551
+ }
552
+ _renderMonthView() {
553
+ this._viewDate.getMonth();
554
+ const t = Array.from({ length: 12 }, (s, i) => {
555
+ const l = new Date(2e3, i, 1);
556
+ return new Intl.DateTimeFormat(this.locale, { month: "long" }).format(l);
557
+ }), e = this._viewDate.getFullYear(), n = [];
558
+ for (let s = e - 10; s <= e + 10; s++) n.push(s);
559
+ const r = (s) => this._selectedDate ? s === this._selectedDate.getMonth() && e === this._selectedDate.getFullYear() : !1;
560
+ return g`
561
+ <div class="calendar-header">
562
+ <button class="nav-btn" @click="${(s) => {
563
+ s.stopPropagation(), this._setViewYear(e - 1);
564
+ }}">←</button>
565
+ <div class="month-year">
566
+ <select class="header-select" @click="${(s) => s.stopPropagation()}" @change="${(s) => this._setViewYear(s.target.value)}">
567
+ ${n.map((s) => g`<option value="${s}" ?selected="${s === e}">${s}</option>`)}
568
+ </select>
569
+ </div>
570
+ <button class="nav-btn" @click="${(s) => {
571
+ s.stopPropagation(), this._setViewYear(e + 1);
572
+ }}">→</button>
573
+ </div>
574
+ <div class="selector-grid">
575
+ ${t.map((s, i) => g`
576
+ <div class="selector-item ${r(i) ? "selected" : ""}" @click="${(l) => {
577
+ l.stopPropagation(), this._selectMonth(i);
578
+ }}">
579
+ ${s}
580
+ </div>
581
+ `)}
582
+ </div>
583
+ `;
584
+ }
585
+ _renderYearView() {
586
+ const t = this._viewDate.getFullYear(), e = Math.floor(t / 12) * 12, n = [];
587
+ for (let s = 0; s < 12; s++)
588
+ n.push(e + s);
589
+ const r = (s) => this._selectedDate ? s === this._selectedDate.getFullYear() : !1;
590
+ return g`
591
+ <div class="calendar-header">
592
+ <button class="nav-btn" @click="${(s) => {
593
+ s.stopPropagation(), this._setViewYear(t - 12);
594
+ }}">←</button>
595
+ <div class="month-year">
596
+ <span>${e} - ${e + 11}</span>
597
+ </div>
598
+ <button class="nav-btn" @click="${(s) => {
599
+ s.stopPropagation(), this._setViewYear(t + 12);
600
+ }}">→</button>
601
+ </div>
602
+ <div class="selector-grid">
603
+ ${n.map((s) => g`
604
+ <div class="selector-item ${r(s) ? "selected" : ""}" @click="${(i) => {
605
+ i.stopPropagation(), this._selectYear(s);
606
+ }}">
607
+ ${s}
608
+ </div>
609
+ `)}
610
+ </div>
611
+ `;
612
+ }
613
+ render() {
614
+ let t;
615
+ return this.mode === "year" ? t = this._renderYearView() : this.mode === "month" ? t = this._renderMonthView() : t = this._renderCalendar(), g`
616
+ <div
617
+ class="datepicker-trigger ${this.disabled ? "disabled" : ""}"
618
+ @keydown="${this._handleKeydown}"
619
+ tabindex="${this.disabled ? "-1" : "0"}"
620
+ >
621
+ <kg-input
622
+ .placeholder="${this.placeholder}"
623
+ .value="${this.value}"
624
+ .label="${this.label}"
625
+ ?disabled="${this.disabled}"
626
+ @kg-input="${this._handleManualInput}"
627
+ @keydown="${this._handleInputKeydown}"
628
+ @click="${this.togglePopup}"
629
+ >
630
+ <div slot="right" style="display: flex; align-items: center; color: var(--kg-text-muted); opacity: 0.7;">
631
+ <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
632
+ <rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
633
+ <line x1="16" y1="2" x2="16" y2="6"></line>
634
+ <line x1="8" y1="2" x2="8" y2="6"></line>
635
+ <line x1="3" y1="10" x2="21" y2="10"></line>
636
+ </svg>
637
+ </div>
638
+ </kg-input>
639
+ </div>
640
+
641
+ <div class="${w({ "datepicker-popup": !0, open: this.open })}">
642
+ ${t}
643
+ </div>
644
+ `;
645
+ }
646
+ }
647
+ customElements.define("kg-datepicker", b);
648
+ export {
649
+ b as kgdatepicker
650
+ };