scb-wc-test 0.1.115 → 0.1.117

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.
@@ -1,21 +1,19 @@
1
- import { css as m, LitElement as g, html as n } from "lit";
2
- import { state as h, property as p, customElement as w } from "lit/decorators.js";
1
+ import { css as m, LitElement as w, html as a } from "lit";
2
+ import { state as p, property as u, customElement as v } from "lit/decorators.js";
3
3
  import "../scb-icon-button/scb-icon-button.js";
4
4
  import "../scb-button/scb-button.js";
5
5
  import "@material/web/icon/icon.js";
6
6
  import "@material/web/ripple/ripple.js";
7
7
  import "@material/web/focus/md-focus-ring.js";
8
8
  import "../scb-divider/scb-divider.js";
9
- var v = Object.defineProperty, b = Object.getOwnPropertyDescriptor, d = (e, t, c, l) => {
10
- for (var i = l > 1 ? void 0 : l ? b(t, c) : t, o = e.length - 1, s; o >= 0; o--)
11
- (s = e[o]) && (i = (l ? s(t, c, i) : s(i)) || i);
12
- return l && i && v(t, c, i), i;
9
+ var _ = Object.defineProperty, b = Object.getOwnPropertyDescriptor, h = (e, t, i, d) => {
10
+ for (var r = d > 1 ? void 0 : d ? b(t, i) : t, n = e.length - 1, o; n >= 0; n--)
11
+ (o = e[n]) && (r = (d ? o(t, i, r) : o(r)) || r);
12
+ return d && r && _(t, i, r), r;
13
13
  };
14
- let a = class extends g {
14
+ let c = class extends w {
15
15
  constructor() {
16
- super(...arguments), this._currentDate = /* @__PURE__ */ new Date(), this._selectedDate = null, this._showMonthDropdown = !1, this._showYearDropdown = !1, this.variant = "static", this.lang = "sv", this.selectedValue = "", this.open = !0, this._outsideClickHandler = (e) => {
17
- this.variant !== "static" && this.open && (e.composedPath().includes(this) || this._close());
18
- }, this._monthNames = [
16
+ super(...arguments), this._currentDate = /* @__PURE__ */ new Date(), this._selectedDate = null, this._showMonthDropdown = !1, this._showYearDropdown = !1, this.variant = "date", this.lang = "sv", this.selectedValue = "", this.open = !0, this._selectedHour = 0, this._selectedMinute = 0, this._monthNames = [
19
17
  this.lang == "sv" ? "Januari" : "January",
20
18
  this.lang == "sv" ? "Februari" : "February",
21
19
  this.lang == "sv" ? "Mars" : "March",
@@ -28,50 +26,41 @@ let a = class extends g {
28
26
  this.lang == "sv" ? "Oktober" : "October",
29
27
  (this.lang == "sv", "November"),
30
28
  (this.lang == "sv", "December")
31
- ], this._prevYear = () => {
29
+ ], this._outsideClickHandler = (e) => {
30
+ this.open && (e.composedPath().includes(this) || this._close());
31
+ }, this._prevMonth = () => {
32
+ const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
33
+ t === 0 ? this._currentDate = new Date(e - 1, 11, 1) : this._currentDate = new Date(e, t - 1, 1);
34
+ }, this._prevYear = () => {
32
35
  const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
33
36
  this._currentDate = new Date(e - 1, t, 1);
37
+ }, this._nextMonth = () => {
38
+ const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
39
+ t === 11 ? this._currentDate = new Date(e + 1, 0, 1) : this._currentDate = new Date(e, t + 1, 1);
34
40
  }, this._nextYear = () => {
35
41
  const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
36
42
  this._currentDate = new Date(e + 1, t, 1);
37
- }, this._prevMonth = () => {
38
- const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
39
- this._currentDate = new Date(e, t - 1, 1);
40
- }, this._nextMonth = () => {
41
- const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth();
42
- this._currentDate = new Date(e, t + 1, 1);
43
+ }, this._onTimeChange = (e) => {
44
+ const t = e.target.value, [i, d] = t.split(":"), r = parseInt(i, 10), n = parseInt(d, 10);
45
+ this._selectedHour = isNaN(r) ? 0 : Math.max(0, Math.min(23, r)), this._selectedMinute = isNaN(n) ? 0 : Math.max(0, Math.min(59, n)), this._fireDateTimeChange();
43
46
  }, this._close = () => {
44
47
  this.open = !1, this.dispatchEvent(new CustomEvent("datepicker-closed", {
45
48
  bubbles: !0,
46
49
  composed: !0
47
- })), window.removeEventListener("mousedown", this._outsideClickHandler);
50
+ }));
48
51
  };
49
52
  }
50
53
  updated(e) {
51
- if (super.updated(e), this.variant !== "static" && this.open ? window.addEventListener("mousedown", this._outsideClickHandler) : window.removeEventListener("mousedown", this._outsideClickHandler), e.has("selectedValue") && this.selectedValue) {
54
+ if (super.updated(e), this.open ? window.addEventListener("mousedown", this._outsideClickHandler) : window.removeEventListener("mousedown", this._outsideClickHandler), e.has("selectedValue") && this.selectedValue) {
52
55
  const t = new Date(this.selectedValue);
53
- isNaN(t.getTime()) || (this._selectedDate = t, this._currentDate = new Date(t.getFullYear(), t.getMonth(), 1));
56
+ isNaN(t.getTime()) || (this._selectedDate = t, this._currentDate = new Date(t.getFullYear(), t.getMonth(), 1), this.variant === "datetime-local" && (this._selectedHour = t.getHours(), this._selectedMinute = t.getMinutes()));
54
57
  }
55
58
  }
56
- _getMonthDays(e, t) {
57
- const c = new Date(e, t, 1), l = new Date(e, t + 1, 0), i = [];
58
- let o = [], s = (c.getDay() + 6) % 7;
59
- for (let r = 0; r < s; r++) o.push(null);
60
- for (let r = 1; r <= l.getDate(); r++) {
61
- const u = new Date(e, t, r);
62
- o.push(u), o.length === 7 && (i.push(o), o = []);
63
- }
64
- if (o.length) {
65
- for (; o.length < 7; ) o.push(null);
66
- i.push(o);
67
- }
68
- return i;
69
- }
70
59
  render() {
71
- if (!this.open) return n``;
72
- const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth(), c = /* @__PURE__ */ new Date(), l = this._getMonthDays(e, t), i = Array.from({ length: 101 }, (o, s) => c.getFullYear() - 50 + s);
73
- return n`
74
- <div class="datepicker-popup ${this.variant === "popup" ? "popup" : "static"}">
60
+ if (!this.open) return a``;
61
+ const e = this._currentDate.getFullYear(), t = this._currentDate.getMonth(), i = /* @__PURE__ */ new Date(), d = this._getMonthDays(e, t), r = Array.from({ length: 101 }, (o, s) => i.getFullYear() - 50 + s), n = this.variant === "datetime-local" && !this._showMonthDropdown && !this._showYearDropdown;
62
+ return a`
63
+ <div class="datepicker-popup popup">
75
64
  <div class="header">
76
65
  <div class="month-selector ${this._showMonthDropdown ? "open" : ""} ${this._showYearDropdown ? "disable" : ""}">
77
66
  <scb-icon-button icon="chevron_left" @click=${this._prevMonth} aria-label=${this.lang == "sv" ? "Föregående månad" : "Previous month"}></scb-icon-button>
@@ -112,30 +101,30 @@ let a = class extends g {
112
101
  <scb-icon-button icon="chevron_right" @click=${this._nextYear} aria-label=${this.lang == "sv" ? "Nästa år" : "Next year"}></scb-icon-button>
113
102
  </div>
114
103
  </div>
115
- ${this._showMonthDropdown || this._showYearDropdown ? n`<scb-divider></scb-divider>` : ""}
104
+ ${this._showMonthDropdown || this._showYearDropdown ? a`<scb-divider></scb-divider>` : ""}
116
105
  <div class="datepicker-content" style="position:relative;">
117
- ${this._showMonthDropdown ? n`
106
+ ${this._showMonthDropdown ? a`
118
107
  <div class="dropdown-list">
119
- ${this._monthNames.map((o, s) => n`
108
+ ${this._monthNames.map((o, s) => a`
120
109
  <div
121
- @keydown=${(r) => {
122
- (r.key === "Enter" || r.key === " ") && (r.preventDefault(), this._onMonthChangeCustom(s));
110
+ @keydown=${(l) => {
111
+ (l.key === "Enter" || l.key === " ") && (l.preventDefault(), this._onMonthChangeCustom(s));
123
112
  }}
124
113
  tabindex="0"
125
114
  class="dropdown-item${s === t ? " selected" : ""}"
126
115
  @click=${() => this._onMonthChangeCustom(s)}
127
116
  id=${s === t ? "selected-month" : ""}
128
117
  >
129
- ${s === t ? n`<md-icon>check</md-icon>` : ""}
118
+ ${s === t ? a`<md-icon>check</md-icon>` : ""}
130
119
  ${o}
131
120
  <md-ripple></md-ripple><md-focus-ring inward></md-focus-ring>
132
121
  </div>
133
122
  `)}
134
123
  </div>
135
124
  ` : ""}
136
- ${this._showYearDropdown ? n`
125
+ ${this._showYearDropdown ? a`
137
126
  <div class="dropdown-list">
138
- ${i.map((o) => n`
127
+ ${r.map((o) => a`
139
128
  <div
140
129
  @keydown=${(s) => {
141
130
  (s.key === "Enter" || s.key === " ") && (s.preventDefault(), this._onYearChangeCustom(o));
@@ -145,14 +134,14 @@ let a = class extends g {
145
134
  @click=${() => this._onYearChangeCustom(o)}
146
135
  id=${o === e ? "selected-year" : ""}
147
136
  >
148
- ${o === e ? n`<md-icon>check</md-icon>` : ""}
137
+ ${o === e ? a`<md-icon>check</md-icon>` : ""}
149
138
  ${o}
150
139
  <md-ripple></md-ripple><md-focus-ring inward></md-focus-ring>
151
140
  </div>
152
141
  `)}
153
142
  </div>
154
143
  ` : ""}
155
- ${!this._showMonthDropdown && !this._showYearDropdown ? n`
144
+ ${!this._showMonthDropdown && !this._showYearDropdown ? a`
156
145
  <div class="datepicker-calendar">
157
146
  <table>
158
147
  <thead>
@@ -161,21 +150,21 @@ let a = class extends g {
161
150
  </tr>
162
151
  </thead>
163
152
  <tbody>
164
- ${l.map((o) => n`
153
+ ${d.map((o) => a`
165
154
  <tr>
166
- ${o.map((s) => s ? n`
155
+ ${o.map((s) => s ? a`
167
156
  <td>
168
157
  <div
169
- @keydown=${(r) => {
170
- (r.key === "Enter" || r.key === " ") && (r.preventDefault(), this._selectDate(s));
158
+ @keydown=${(l) => {
159
+ (l.key === "Enter" || l.key === " ") && (l.preventDefault(), this._selectDate(s));
171
160
  }}
172
161
  role="button"
173
162
  tabindex="0"
174
- class="day${this._isToday(s, c) ? " today" : ""}${this._isSelected(s) ? " selected" : ""}"
163
+ class="day${this._isToday(s, i) ? " today" : ""}${this._isSelected(s) ? " selected" : ""}"
175
164
  @click=${() => this._selectDate(s)}
176
165
  >${s.getDate()}<md-ripple></md-ripple><md-focus-ring></md-focus-ring></div>
177
166
  </td>
178
- ` : n`<td></td>`)}
167
+ ` : a`<td></td>`)}
179
168
  </tr>
180
169
  `)}
181
170
  </tbody>
@@ -183,14 +172,36 @@ let a = class extends g {
183
172
  </div>
184
173
  ` : ""}
185
174
  </div>
175
+ ${n ? a`
176
+ <div style="padding: 0 24px;">
177
+ <label style="display:flex;align-items:center;gap:8px;">
178
+ <span>${this.lang == "sv" ? "Tid:" : "Time:"}</span>
179
+ <scb-textfield type="time" .value=${`${String(this._selectedHour).padStart(2, "0")}:${String(this._selectedMinute).padStart(2, "0")}`} @blur=${this._onTimeChange} aria-label="${this.lang == "sv" ? "Tid" : "Time"}"></scb-textfield>
180
+ </label>
181
+ </div>
182
+ ` : ""}
186
183
  <div class="datepicker-footer">
187
- ${!this._showMonthDropdown && !this._showYearDropdown && this.variant == "popup" ? n`
184
+ ${!this._showMonthDropdown && !this._showYearDropdown ? a`
188
185
  <scb-button variant="text" label=${this.lang == "sv" ? "Stäng" : "Close"} @click=${this._close}></scb-button>
189
186
  ` : ""}
190
187
  </div>
191
188
  </div>
192
189
  `;
193
190
  }
191
+ _getMonthDays(e, t) {
192
+ const i = new Date(Date.UTC(e, t, 1)), d = new Date(Date.UTC(e, t + 1, 0)), r = [];
193
+ let n = [], o = i.getUTCDay(), s = o === 0 ? 6 : o - 1;
194
+ for (let l = 0; l < s; l++) n.push(null);
195
+ for (let l = 1; l <= d.getUTCDate(); l++) {
196
+ const g = new Date(Date.UTC(e, t, l));
197
+ n.push(g), n.length === 7 && (r.push(n), n = []);
198
+ }
199
+ if (n.length) {
200
+ for (; n.length < 7; ) n.push(null);
201
+ r.push(n);
202
+ }
203
+ return r;
204
+ }
194
205
  _toggleMonthDropdown() {
195
206
  this._showMonthDropdown = !this._showMonthDropdown, this._showMonthDropdown && (this._showYearDropdown = !1, setTimeout(() => {
196
207
  const e = this.renderRoot.querySelector("#selected-month");
@@ -218,16 +229,38 @@ let a = class extends g {
218
229
  return this._selectedDate && e.getDate() === this._selectedDate.getDate() && e.getMonth() === this._selectedDate.getMonth() && e.getFullYear() === this._selectedDate.getFullYear();
219
230
  }
220
231
  _selectDate(e) {
221
- this._selectedDate = e;
222
- const t = e.toISOString().slice(0, 10);
223
- this.dispatchEvent(new CustomEvent("date-selected", {
224
- detail: { value: t },
225
- bubbles: !0,
226
- composed: !0
227
- }));
232
+ if (this._selectedDate = e, this.variant === "datetime-local") {
233
+ const t = new Date(e);
234
+ t.setHours(this._selectedHour ?? 0, this._selectedMinute ?? 0, 0, 0), this._selectedHour = t.getHours(), this._selectedMinute = t.getMinutes();
235
+ const i = (r) => r.toString().padStart(2, "0"), d = `${t.getFullYear()}-${i(t.getMonth() + 1)}-${i(t.getDate())} ${i(t.getHours())}:${i(t.getMinutes())}`;
236
+ this.dispatchEvent(new CustomEvent("date-selected", {
237
+ detail: { value: d },
238
+ bubbles: !0,
239
+ composed: !0
240
+ }));
241
+ } else {
242
+ const t = e.toISOString().slice(0, 10);
243
+ this.dispatchEvent(new CustomEvent("date-selected", {
244
+ detail: { value: t },
245
+ bubbles: !0,
246
+ composed: !0
247
+ }));
248
+ }
249
+ }
250
+ _fireDateTimeChange() {
251
+ if (this.variant === "datetime-local" && this._selectedDate) {
252
+ const e = new Date(this._selectedDate);
253
+ e.setHours(this._selectedHour ?? 0, this._selectedMinute ?? 0, 0, 0);
254
+ const t = (d) => d.toString().padStart(2, "0"), i = `${e.getFullYear()}-${t(e.getMonth() + 1)}-${t(e.getDate())} ${t(e.getHours())}:${t(e.getMinutes())}`;
255
+ this.dispatchEvent(new CustomEvent("date-selected", {
256
+ detail: { value: i },
257
+ bubbles: !0,
258
+ composed: !0
259
+ }));
260
+ }
228
261
  }
229
262
  };
230
- a.styles = [
263
+ c.styles = [
231
264
  m`
232
265
  :host {
233
266
  --scb-datepicker-width: 380px;
@@ -396,33 +429,39 @@ a.styles = [
396
429
  }
397
430
  `
398
431
  ];
399
- d([
400
- h()
401
- ], a.prototype, "_currentDate", 2);
402
- d([
403
- h()
404
- ], a.prototype, "_selectedDate", 2);
405
- d([
406
- h()
407
- ], a.prototype, "_showMonthDropdown", 2);
408
- d([
409
- h()
410
- ], a.prototype, "_showYearDropdown", 2);
411
- d([
412
- p({ type: String })
413
- ], a.prototype, "variant", 2);
414
- d([
415
- p({ type: String })
416
- ], a.prototype, "lang", 2);
417
- d([
418
- p({ type: String })
419
- ], a.prototype, "selectedValue", 2);
420
- d([
421
- p({ type: Boolean })
422
- ], a.prototype, "open", 2);
423
- a = d([
424
- w("scb-datepicker")
425
- ], a);
432
+ h([
433
+ p()
434
+ ], c.prototype, "_currentDate", 2);
435
+ h([
436
+ p()
437
+ ], c.prototype, "_selectedDate", 2);
438
+ h([
439
+ p()
440
+ ], c.prototype, "_showMonthDropdown", 2);
441
+ h([
442
+ p()
443
+ ], c.prototype, "_showYearDropdown", 2);
444
+ h([
445
+ u({ type: String })
446
+ ], c.prototype, "variant", 2);
447
+ h([
448
+ u({ type: String })
449
+ ], c.prototype, "lang", 2);
450
+ h([
451
+ u({ type: String })
452
+ ], c.prototype, "selectedValue", 2);
453
+ h([
454
+ u({ type: Boolean })
455
+ ], c.prototype, "open", 2);
456
+ h([
457
+ p()
458
+ ], c.prototype, "_selectedHour", 2);
459
+ h([
460
+ p()
461
+ ], c.prototype, "_selectedMinute", 2);
462
+ c = h([
463
+ v("scb-datepicker")
464
+ ], c);
426
465
  export {
427
- a as ScbDatepicker
466
+ c as ScbDatepicker
428
467
  };