scb-wc-test 0.1.117 → 0.1.118

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.
@@ -0,0 +1,212 @@
1
+ import { css as _, LitElement as w, html as i } from "lit";
2
+ import { property as f, customElement as $ } from "lit/decorators.js";
3
+ import "./scb-calendar-event.js";
4
+ import "../scb-icon-button/scb-icon-button.js";
5
+ var M = Object.defineProperty, D = Object.getOwnPropertyDescriptor, b = (t, e, o, s) => {
6
+ for (var a = s > 1 ? void 0 : s ? D(e, o) : e, c = t.length - 1, d; c >= 0; c--)
7
+ (d = t[c]) && (a = (s ? d(e, o, a) : d(a)) || a);
8
+ return s && a && M(e, o, a), a;
9
+ };
10
+ let u = class extends w {
11
+ constructor() {
12
+ super(...arguments), this.label = "", this.value = "", this._today = /* @__PURE__ */ new Date(), this._current = /* @__PURE__ */ new Date(), this._popupEvent = null;
13
+ }
14
+ _daysInMonth(t, e) {
15
+ return new Date(t, e + 1, 0).getDate();
16
+ }
17
+ _firstDayOfWeek(t, e) {
18
+ return new Date(t, e, 1).getDay();
19
+ }
20
+ _prevMonth() {
21
+ this._current = new Date(this._current.getFullYear(), this._current.getMonth() - 1, 1), this.requestUpdate();
22
+ }
23
+ _nextMonth() {
24
+ this._current = new Date(this._current.getFullYear(), this._current.getMonth() + 1, 1), this.requestUpdate();
25
+ }
26
+ _showEventPopup(t) {
27
+ this._popupEvent = t, this.requestUpdate(), setTimeout(() => {
28
+ const e = (o) => {
29
+ var s;
30
+ (s = o.target) != null && s.closest(".event-popup") || this._closePopup();
31
+ };
32
+ window.addEventListener("mousedown", e, { once: !0 });
33
+ }, 0);
34
+ }
35
+ _closePopup() {
36
+ this._popupEvent = null, this.requestUpdate();
37
+ }
38
+ render() {
39
+ const t = this._current.getFullYear(), e = this._current.getMonth(), o = this._daysInMonth(t, e), s = this._firstDayOfWeek(t, e), a = this._today, c = Array.from(this.querySelectorAll("scb-calendar-event")), d = /* @__PURE__ */ new Map();
40
+ for (const r of c)
41
+ if (r.date && r.title) {
42
+ const p = d.get(r.date) || [];
43
+ p.push({ title: r.title, description: r.description }), d.set(r.date, p);
44
+ }
45
+ const m = [];
46
+ let l = 1;
47
+ for (let r = 0; r < 6; r++) {
48
+ const p = [];
49
+ for (let h = 0; h < 7; h++)
50
+ if (r === 0 && h < s) {
51
+ const g = e === 0 ? 11 : e - 1, y = e === 0 ? t - 1 : t, v = this._daysInMonth(y, g) - (s - h - 1);
52
+ p.push(i`
53
+ <div class="calendar-day calendar-day--other">
54
+ <span class="calendar-day-number">${v}</span>
55
+ </div>
56
+ `);
57
+ } else if (l > o)
58
+ p.push(i`<div></div>`);
59
+ else {
60
+ const g = a.getFullYear() === t && a.getMonth() === e && a.getDate() === l, y = `${t}-${String(e + 1).padStart(2, "0")}-${String(l).padStart(2, "0")}`, n = d.get(y) || [];
61
+ p.push(i`
62
+ <div
63
+ class="calendar-day${g ? " today" : ""}${n.length ? " has-event" : ""}"
64
+ @click=${n.length ? () => this._showEventPopup({ date: y, events: n }) : null}
65
+ title=${n.length === 1 ? n[0].title : n.length > 1 ? n.map((v) => v.title).join(", ") : ""}
66
+ >
67
+ <span class="calendar-day-number">${l}</span>
68
+ <div class="calendar-titles-wrapper">
69
+ ${n.map((v) => i`<span class="calendar-day-event-title">${v.title}</span>`)}
70
+ </div>
71
+ </div>
72
+ `), l++;
73
+ }
74
+ if (m.push(i`<div class="calendar-grid">${p}</div>`), l > o) break;
75
+ }
76
+ const x = [
77
+ "Januari",
78
+ "Februari",
79
+ "Mars",
80
+ "April",
81
+ "Maj",
82
+ "Juni",
83
+ "Juli",
84
+ "Augusti",
85
+ "September",
86
+ "Oktober",
87
+ "November",
88
+ "December"
89
+ ];
90
+ return i`
91
+ <div class="calendar-header">
92
+ <scb-icon-button @click=${this._prevMonth} icon="chevron_left" aria-label="Föregående månad"></scb-icon-button>
93
+ <span>${x[e]} ${t}</span>
94
+ <scb-icon-button @click=${this._nextMonth} icon="chevron_right" aria-label="Nästa månad"></scb-icon-button>
95
+ </div>
96
+ <div class="calendar-grid calendar-grid-days">
97
+ <div>Mån</div><div>Tis</div><div>Ons</div><div>Tor</div><div>Fre</div><div>Lör</div><div>Sön</div>
98
+ </div>
99
+ <div class="calendar-weeks">
100
+ ${m}
101
+ <div>
102
+ ${this._popupEvent && Array.isArray(this._popupEvent.events) ? i`
103
+ <div class="event-popup-backdrop" @click=${this._closePopup}></div>
104
+ <div class="event-popup">
105
+ <button class="close-btn" @click=${this._closePopup} title="Stäng">×</button>
106
+ <div>${this._popupEvent.date}</div>
107
+ <ul>
108
+ ${this._popupEvent.events.map((r) => i`<li><strong>${r.title}</strong>${r.description ? i`<div>${r.description}</div>` : ""}</li>`)}
109
+ </ul>
110
+ </div>
111
+ ` : ""}
112
+ `;
113
+ }
114
+ };
115
+ u.styles = _`
116
+ :host {
117
+ display: block;
118
+ font-family: var(--brand-font, Arial, sans-serif);
119
+ background: var(--md-sys-color-surface, #fff);
120
+ color: var(--md-sys-color-on-surface, #222);
121
+ border-radius: 12px;
122
+ border: var(--scb-elevation-2, 0 2px 8px rgba(0,0,0,0.08));
123
+ padding: 16px;
124
+ }
125
+ .calendar-header {
126
+ display: flex;
127
+ align-items: center;
128
+ justify-content: space-between;
129
+ margin-bottom: 16px;
130
+ border-bottom: 1px solid rgb(224, 224, 224);
131
+ padding-bottom: 8px;
132
+ }
133
+ .calendar-grid {
134
+ display: grid;
135
+ grid-template-columns: repeat(7, 1fr);
136
+ gap: 4px;
137
+ margin-bottom: 4px;
138
+ }
139
+ .calendar-grid-days{
140
+ font-weight: 600;
141
+ margin-bottom: 16px;
142
+ }
143
+ .calendar-weeks {
144
+ display: grid;
145
+ grid-auto-rows: 1fr;
146
+ }
147
+ .calendar-titles-wrapper{
148
+ display: grid;
149
+ gap: 4px;
150
+ }
151
+ .calendar-day {
152
+ border-radius: 6px;
153
+ min-height: 3.2em;
154
+ display: flex;
155
+ padding: 8px;
156
+ box-sizing: border-box;
157
+ overflow: hidden;
158
+ gap: 8px;
159
+ border: 1px solid #e0e0e0;
160
+ flex-direction: column;
161
+ }
162
+ .calendar-day--other {
163
+ opacity: 0.4;
164
+ }
165
+ .calendar-day-number {
166
+ font-size: 1em;
167
+ line-height: 1.2;
168
+ }
169
+ .calendar-day-event-title {
170
+ font-size: 12px;
171
+ color: var(--md-sys-color-primary);
172
+ white-space: nowrap;
173
+ overflow: hidden;
174
+ text-overflow: ellipsis;
175
+ display: block;
176
+ width: 100%;
177
+ }
178
+ .calendar-day.today {
179
+ border: 1px solid var(--md-sys-color-primary);
180
+ }
181
+ .calendar-day.has-event {
182
+ cursor: pointer;
183
+ border: 2px solid var(--md-sys-color-primary);
184
+ position: relative;
185
+ }
186
+ .event-popup {
187
+ position: fixed;
188
+ z-index: 1000;
189
+ background: #fff;
190
+ color: #222;
191
+ border-radius: 10px;
192
+ box-shadow: 0 4px 24px rgba(0,0,0,0.18);
193
+ min-width: 220px;
194
+ max-width: 320px;
195
+ padding: 16px 20px 16px 20px;
196
+ top: 30%;
197
+ left: 50%;
198
+ }
199
+
200
+ `;
201
+ b([
202
+ f({ type: String })
203
+ ], u.prototype, "label", 2);
204
+ b([
205
+ f({ type: String })
206
+ ], u.prototype, "value", 2);
207
+ u = b([
208
+ $("scb-calendar")
209
+ ], u);
210
+ export {
211
+ u as ScbCalendar
212
+ };