scb-wc-test 0.1.118 → 0.1.120

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.
@@ -7,6 +7,13 @@ export declare class ScbTextField extends LitElement {
7
7
  private _kbShouldShowRing;
8
8
  private _onGlobalKeydown;
9
9
  private _onGlobalPointerDown;
10
+ private _hasRenderedOnce;
11
+ private _boundField;
12
+ private _onFieldInput;
13
+ private _onFieldChange;
14
+ private _onFieldSelect;
15
+ private _onFieldFocus;
16
+ private _onFieldBlur;
10
17
  constructor();
11
18
  type: 'number' | 'email' | 'password' | 'search' | 'tel' | 'text' | 'url' | 'textarea' | 'color' | 'date' | 'datetime-local' | 'file' | 'month' | 'time' | 'week';
12
19
  label: string;
@@ -1,23 +1,46 @@
1
- import { css as v, LitElement as x, html as d } from "lit";
2
- import { property as a, state as g, customElement as y } from "lit/decorators.js";
1
+ import { css as _, LitElement as w, html as o } from "lit";
2
+ import { property as n, state as $, customElement as k } from "lit/decorators.js";
3
3
  import "@material/web/icon/icon.js";
4
4
  import "@material/web/ripple/ripple.js";
5
5
  import "@material/web/focus/md-focus-ring.js";
6
6
  import "../scb-datepicker/scb-datepicker.js";
7
7
  import "../scb-icon-button/scb-icon-button.js";
8
- var w = Object.defineProperty, _ = Object.getOwnPropertyDescriptor, m = (t) => {
8
+ var E = Object.defineProperty, S = Object.getOwnPropertyDescriptor, g = (t) => {
9
9
  throw TypeError(t);
10
- }, r = (t, e, i, n) => {
11
- for (var l = n > 1 ? void 0 : n ? _(e, i) : e, p = t.length - 1, h; p >= 0; p--)
12
- (h = t[p]) && (l = (n ? h(e, i, l) : h(l)) || l);
13
- return n && l && w(e, i, l), l;
14
- }, $ = (t, e, i) => e.has(t) || m("Cannot " + i), k = (t, e, i) => e.has(t) ? m("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), c = (t, e, i) => ($(t, e, "access private method"), i), o, f, b, u;
15
- let s = class extends x {
10
+ }, a = (t, e, i, d) => {
11
+ for (var c = d > 1 ? void 0 : d ? S(e, i) : e, p = t.length - 1, h; p >= 0; p--)
12
+ (h = t[p]) && (c = (d ? h(e, i, c) : h(c)) || c);
13
+ return d && c && E(e, i, c), c;
14
+ }, L = (t, e, i) => e.has(t) || g("Cannot " + i), F = (t, e, i) => e.has(t) ? g("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, i), l = (t, e, i) => (L(t, e, "access private method"), i), r, f, b, m, v, x, y, u;
15
+ let s = class extends w {
16
16
  constructor() {
17
- super(), k(this, o), this._internals = null, this._inputFocused = !1, this._kbShouldShowRing = !1, this._onGlobalKeydown = (t) => {
18
- t.key === "Tab" && (this._kbShouldShowRing = !0, this._inputFocused && c(this, o, u).call(this));
17
+ super(), F(this, r), this._internals = null, this._inputFocused = !1, this._kbShouldShowRing = !1, this._onGlobalKeydown = (t) => {
18
+ t.key === "Tab" && (this._kbShouldShowRing = !0, this._inputFocused && l(this, r, u).call(this));
19
19
  }, this._onGlobalPointerDown = () => {
20
- this._kbShouldShowRing = !1, this._inputFocused && c(this, o, u).call(this);
20
+ this._kbShouldShowRing = !1, this._inputFocused && l(this, r, u).call(this);
21
+ }, this._hasRenderedOnce = !1, this._boundField = null, this._onFieldInput = () => {
22
+ const t = this._boundField;
23
+ if (!t) return;
24
+ const e = t;
25
+ if (this.value = e.value, this._internals) {
26
+ const i = this.disabled ? null : this.value;
27
+ this._internals.setFormValue(i);
28
+ }
29
+ l(this, r, m).call(this), this.dispatchEvent(new Event("input", { bubbles: !0, composed: !0 })), this.dispatchEvent(
30
+ new CustomEvent("onValueChanged", {
31
+ detail: { value: this.value },
32
+ bubbles: !0,
33
+ composed: !0
34
+ })
35
+ );
36
+ }, this._onFieldChange = () => {
37
+ this.dispatchEvent(new Event("change", { bubbles: !0, composed: !0 }));
38
+ }, this._onFieldSelect = () => {
39
+ this.dispatchEvent(new Event("select", { bubbles: !0, composed: !0 }));
40
+ }, this._onFieldFocus = () => {
41
+ this._inputFocused = !0, l(this, r, u).call(this);
42
+ }, this._onFieldBlur = () => {
43
+ this._inputFocused = !1, l(this, r, u).call(this);
21
44
  }, this.type = "text", this.label = "", this.supportingText = "", this.errorText = "", this.leadingIcon = "", this.name = "", this.pattern = "", this.value = "", this.underLabel = "", this.error = !1, this.disabled = !1, this.required = !1, this.spacing = "", this.spacingTop = "", this.spacingBottom = "", this._form = null, this._formSubmitHandler = null, this._formResetHandler = null, this._initialValue = "", this._inputId = "", this._showDatepicker = !1, this._toggleDatepicker = () => {
22
45
  this._showDatepicker = !this._showDatepicker;
23
46
  }, this._onDateSelected = (t) => {
@@ -25,14 +48,7 @@ let s = class extends x {
25
48
  const e = this.disabled ? null : this.value;
26
49
  this._internals.setFormValue(e);
27
50
  }
28
- if (this.pattern)
29
- if (!this.value)
30
- this.error = !1;
31
- else {
32
- const e = new RegExp(this.pattern);
33
- this.error = !e.test(this.value);
34
- }
35
- this.dispatchEvent(new Event("input", { bubbles: !0, composed: !0 })), this.dispatchEvent(
51
+ l(this, r, m).call(this), this.dispatchEvent(new Event("input", { bubbles: !0, composed: !0 })), this.dispatchEvent(
36
52
  new CustomEvent("onValueChanged", {
37
53
  detail: { value: this.value },
38
54
  bubbles: !0,
@@ -42,9 +58,9 @@ let s = class extends x {
42
58
  }, "attachInternals" in this && (this._internals = this.attachInternals());
43
59
  }
44
60
  render() {
45
- const t = this.leadingIcon ? d`<md-icon class="scb-textfield-icon">${this.leadingIcon}</md-icon>` : null, e = this.error ? d`<md-icon class="scb-textfield-error-icon" aria-hidden="true">error</md-icon>` : null;
61
+ const t = this.leadingIcon ? o`<md-icon class="scb-textfield-icon">${this.leadingIcon}</md-icon>` : null, e = this.error ? o`<md-icon class="scb-textfield-error-icon" aria-hidden="true">error</md-icon>` : null;
46
62
  this.underLabel = this.error ? this.errorText || "Ogiltig inmatning." : this.supportingText, this.value = this.value || "";
47
- const i = this.underLabel ? `${this._inputId}-supporting-text` : void 0, n = this.type === "search" && this.value ? d`
63
+ const i = this.underLabel ? `${this._inputId}-supporting-text` : void 0, d = this.type === "search" && this.value ? o`
48
64
  <button
49
65
  type="button"
50
66
  class="scb-textfield-clear"
@@ -52,13 +68,34 @@ let s = class extends x {
52
68
  aria-label="Rensa fält"
53
69
  >
54
70
  <svg viewBox="0 0 24 24" aria-hidden="true" focusable="false">
55
- <circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-width="2"></circle>
56
- <line x1="8" y1="8" x2="16" y2="16" stroke="currentColor" stroke-width="2"></line>
57
- <line x1="16" y1="8" x2="8" y2="16" stroke="currentColor" stroke-width="2"></line>
71
+ <circle
72
+ cx="12"
73
+ cy="12"
74
+ r="10"
75
+ fill="none"
76
+ stroke="currentColor"
77
+ stroke-width="2"
78
+ ></circle>
79
+ <line
80
+ x1="8"
81
+ y1="8"
82
+ x2="16"
83
+ y2="16"
84
+ stroke="currentColor"
85
+ stroke-width="2"
86
+ ></line>
87
+ <line
88
+ x1="16"
89
+ y1="8"
90
+ x2="8"
91
+ y2="16"
92
+ stroke="currentColor"
93
+ stroke-width="2"
94
+ ></line>
58
95
  </svg>
59
96
  </button>
60
97
  ` : null;
61
- return this.type === "textarea" ? d`
98
+ return this.type === "textarea" ? o`
62
99
  <label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
63
100
  <span
64
101
  class="scb-textfield-supporting-text"
@@ -82,7 +119,7 @@ ${this.value}</textarea
82
119
  <md-focus-ring class="input-ring"></md-focus-ring>
83
120
  </div>
84
121
  </div>
85
- ` : this.type === "date" ? d`
122
+ ` : this.type === "date" ? o`
86
123
  <label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
87
124
  <span
88
125
  class="scb-textfield-supporting-text"
@@ -109,7 +146,7 @@ ${this.value}</textarea
109
146
  <md-ripple></md-ripple>
110
147
  <md-focus-ring class="input-ring"></md-focus-ring>
111
148
  </div>
112
- ${this.error ? e : d`
149
+ ${this.error ? e : o`
113
150
  <scb-icon-button
114
151
  class="scb-textfield-datepicker-button"
115
152
  icon="calendar_today"
@@ -123,7 +160,7 @@ ${this.value}</textarea
123
160
  @date-selected=${this._onDateSelected}
124
161
  ></scb-datepicker>
125
162
  </div>
126
- ` : this.type === "datetime-local" ? d`
163
+ ` : this.type === "datetime-local" ? o`
127
164
  <label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
128
165
  <span
129
166
  class="scb-textfield-supporting-text"
@@ -152,7 +189,7 @@ ${this.value}</textarea
152
189
  <md-focus-ring class="input-ring"></md-focus-ring>
153
190
  </div>
154
191
 
155
- ${this.error ? e : d`
192
+ ${this.error ? e : o`
156
193
  <scb-icon-button
157
194
  class="scb-textfield-datepicker-button"
158
195
  icon="calendar_today"
@@ -167,7 +204,7 @@ ${this.value}</textarea
167
204
  @date-selected=${this._onDateSelected}
168
205
  ></scb-datepicker>
169
206
  </div>
170
- ` : this.type === "time" ? d`
207
+ ` : this.type === "time" ? o`
171
208
  <label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
172
209
  <span
173
210
  class="scb-textfield-supporting-text"
@@ -187,8 +224,8 @@ ${this.value}</textarea
187
224
  ?required=${this.required}
188
225
  aria-invalid=${this.error ? "true" : "false"}
189
226
  aria-describedby=${i}
190
- @input=${(l) => {
191
- const p = l.target;
227
+ @input=${(c) => {
228
+ const p = c.target;
192
229
  if (this.value = p.value, this._internals) {
193
230
  const h = this.disabled ? null : this.value;
194
231
  this._internals.setFormValue(h);
@@ -207,7 +244,7 @@ ${this.value}</textarea
207
244
  <md-focus-ring class="input-ring"></md-focus-ring>
208
245
  </div>
209
246
  </div>
210
- ` : d`
247
+ ` : o`
211
248
  <label class="scb-textfield-label" for="${this._inputId}">${this.label}</label>
212
249
  <span
213
250
  class="scb-textfield-supporting-text"
@@ -228,7 +265,7 @@ ${this.value}</textarea
228
265
  aria-invalid=${this.error ? "true" : "false"}
229
266
  aria-describedby=${i}
230
267
  />
231
- ${n}
268
+ ${d}
232
269
  ${e}
233
270
  <md-ripple></md-ripple>
234
271
  <md-focus-ring class="input-ring"></md-focus-ring>
@@ -241,45 +278,14 @@ ${this.value}</textarea
241
278
  * Vi kör också ett customevent onValueChanged.
242
279
  */
243
280
  firstUpdated(t) {
244
- var i;
245
- super.firstUpdated(t), this._initialValue = this.value;
246
- const e = (i = this.shadowRoot) == null ? void 0 : i.querySelector(".scb-textfield");
247
- e && (e.addEventListener("input", () => {
248
- const n = e;
249
- if (this.value = n.value, this._internals) {
250
- const l = this.disabled ? null : this.value;
251
- this._internals.setFormValue(l);
252
- }
253
- if (this.pattern)
254
- if (!this.value)
255
- this.error = !1;
256
- else {
257
- const l = new RegExp(this.pattern);
258
- this.error = !l.test(this.value);
259
- }
260
- this.dispatchEvent(new Event("input", { bubbles: !0, composed: !0 })), this.dispatchEvent(
261
- new CustomEvent("onValueChanged", {
262
- detail: { value: this.value },
263
- bubbles: !0,
264
- composed: !0
265
- })
266
- );
267
- }), e.addEventListener("change", () => {
268
- this.dispatchEvent(new Event("change", { bubbles: !0, composed: !0 }));
269
- }), e.addEventListener("select", () => {
270
- this.dispatchEvent(new Event("select", { bubbles: !0, composed: !0 }));
271
- }), e.addEventListener("focus", () => {
272
- this._inputFocused = !0, c(this, o, u).call(this);
273
- }), e.addEventListener("blur", () => {
274
- this._inputFocused = !1, c(this, o, u).call(this);
275
- })), c(this, o, f).call(this);
281
+ super.firstUpdated(t), this._initialValue = this.value, l(this, r, v).call(this), l(this, r, f).call(this), this._hasRenderedOnce = !0;
276
282
  }
277
283
  updated(t) {
278
284
  if (super.updated(t), this.toggleAttribute("aria-disabled", this.disabled), this._internals && (t.has("value") || t.has("disabled"))) {
279
285
  const e = this.disabled ? null : this.value;
280
286
  this._internals.setFormValue(e);
281
287
  }
282
- (t.has("spacing") || t.has("spacingTop") || t.has("spacingBottom")) && c(this, o, f).call(this);
288
+ t.has("type") && (l(this, r, v).call(this), this._hasRenderedOnce && l(this, r, y).call(this)), (t.has("spacing") || t.has("spacingTop") || t.has("spacingBottom")) && l(this, r, f).call(this);
283
289
  }
284
290
  // Körs av webbläsaren när formuläret sätter disabled på kontrollen
285
291
  formDisabledCallback(t) {
@@ -297,7 +303,7 @@ ${this.value}</textarea
297
303
  }, this._form.addEventListener("reset", this._formResetHandler, !0)), window.addEventListener("keydown", this._onGlobalKeydown, !0), window.addEventListener("pointerdown", this._onGlobalPointerDown, !0);
298
304
  }
299
305
  disconnectedCallback() {
300
- super.disconnectedCallback(), this._form && this._formSubmitHandler && (this._form.removeEventListener("submit", this._formSubmitHandler, !0), this._formResetHandler && this._form.removeEventListener("reset", this._formResetHandler, !0)), window.removeEventListener("keydown", this._onGlobalKeydown, !0), window.removeEventListener("pointerdown", this._onGlobalPointerDown, !0);
306
+ super.disconnectedCallback(), this._form && this._formSubmitHandler && (this._form.removeEventListener("submit", this._formSubmitHandler, !0), this._formResetHandler && this._form.removeEventListener("reset", this._formResetHandler, !0)), l(this, r, x).call(this), window.removeEventListener("keydown", this._onGlobalKeydown, !0), window.removeEventListener("pointerdown", this._onGlobalPointerDown, !0);
301
307
  }
302
308
  /**
303
309
  * Kallar på reportValidity på den inbyggda input/textarea och sätter felstatus till error-text.
@@ -309,8 +315,8 @@ ${this.value}</textarea
309
315
  this.required && !t.value ? t.setCustomValidity(this.errorText || "Ogiltig inmatning.") : t.setCustomValidity("");
310
316
  const i = t.reportValidity();
311
317
  this.error = !i;
312
- const n = i ? "" : this.errorText || t.validationMessage || "Ogiltig inmatning.";
313
- return i || (this.errorText = n), this._internals && (i ? this._internals.setValidity({}) : this._internals.setValidity({ customError: !0 }, n, t)), i;
318
+ const d = i ? "" : this.errorText || t.validationMessage || "Ogiltig inmatning.";
319
+ return i || (this.errorText = d), this._internals && (i ? this._internals.setValidity({}) : this._internals.setValidity({ customError: !0 }, d, t)), i;
314
320
  }
315
321
  return !0;
316
322
  }
@@ -336,9 +342,9 @@ ${this.value}</textarea
336
342
  }
337
343
  }
338
344
  };
339
- o = /* @__PURE__ */ new WeakSet();
345
+ r = /* @__PURE__ */ new WeakSet();
340
346
  f = function() {
341
- const t = c(this, o, b).call(this, this.spacing), e = c(this, o, b).call(this, this.spacingTop) ?? t, i = c(this, o, b).call(this, this.spacingBottom) ?? t;
347
+ const t = l(this, r, b).call(this, this.spacing), e = l(this, r, b).call(this, this.spacingTop) ?? t, i = l(this, r, b).call(this, this.spacingBottom) ?? t;
342
348
  e ? this.style.setProperty("--scb-textfield-spacing-block-start", e) : this.style.removeProperty("--scb-textfield-spacing-block-start"), i ? this.style.setProperty("--scb-textfield-spacing-block-end", i) : this.style.removeProperty("--scb-textfield-spacing-block-end");
343
349
  };
344
350
  b = function(t) {
@@ -347,6 +353,33 @@ b = function(t) {
347
353
  if (e)
348
354
  return /^\d+$/.test(e) ? `var(--spacing-${Math.max(0, Math.min(14, parseInt(e, 10)))})` : e;
349
355
  };
356
+ m = function() {
357
+ if (!this.pattern) return;
358
+ if (!this.value) {
359
+ this.error = !1;
360
+ return;
361
+ }
362
+ const t = new RegExp(this.pattern);
363
+ this.error = !t.test(this.value);
364
+ };
365
+ v = function() {
366
+ var e;
367
+ const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".scb-textfield");
368
+ t && (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement) && this._boundField !== t && (l(this, r, x).call(this), this._boundField = t, this.type !== "time" && t.addEventListener("input", this._onFieldInput), t.addEventListener("change", this._onFieldChange), t.addEventListener("select", this._onFieldSelect), t.addEventListener("focus", this._onFieldFocus), t.addEventListener("blur", this._onFieldBlur));
369
+ };
370
+ x = function() {
371
+ const t = this._boundField;
372
+ t && (t.removeEventListener("input", this._onFieldInput), t.removeEventListener("change", this._onFieldChange), t.removeEventListener("select", this._onFieldSelect), t.removeEventListener("focus", this._onFieldFocus), t.removeEventListener("blur", this._onFieldBlur), this._boundField = null);
373
+ };
374
+ y = function() {
375
+ var e;
376
+ this._showDatepicker = !1;
377
+ const t = (e = this.shadowRoot) == null ? void 0 : e.querySelector(".scb-textfield");
378
+ if (t && (t instanceof HTMLInputElement || t instanceof HTMLTextAreaElement) && (t.value = "", t.setCustomValidity("")), this.value = "", this.error = !1, this._internals) {
379
+ const i = this.disabled ? null : "";
380
+ this._internals.setFormValue(i), this._internals.setValidity({});
381
+ }
382
+ };
350
383
  u = function() {
351
384
  var e;
352
385
  const t = (e = this.renderRoot) == null ? void 0 : e.querySelector(".ripple-wrapper");
@@ -354,7 +387,7 @@ u = function() {
354
387
  };
355
388
  s.formAssociated = !0;
356
389
  s.styles = [
357
- v`
390
+ _`
358
391
  :host {
359
392
  --scb-textfield-number-max-width: 280px;
360
393
  --scb-textfield-text-max-width: 400px;
@@ -598,56 +631,56 @@ s.styles = [
598
631
  }
599
632
  `
600
633
  ];
601
- r([
602
- a({ type: String, reflect: !0 })
634
+ a([
635
+ n({ type: String, reflect: !0 })
603
636
  ], s.prototype, "type", 2);
604
- r([
605
- a({ type: String })
637
+ a([
638
+ n({ type: String })
606
639
  ], s.prototype, "label", 2);
607
- r([
608
- a({ type: String, attribute: "supporting-text" })
640
+ a([
641
+ n({ type: String, attribute: "supporting-text" })
609
642
  ], s.prototype, "supportingText", 2);
610
- r([
611
- a({ type: String, attribute: "error-text" })
643
+ a([
644
+ n({ type: String, attribute: "error-text" })
612
645
  ], s.prototype, "errorText", 2);
613
- r([
614
- a({ type: String, attribute: "leading-icon" })
646
+ a([
647
+ n({ type: String, attribute: "leading-icon" })
615
648
  ], s.prototype, "leadingIcon", 2);
616
- r([
617
- a({ type: String })
649
+ a([
650
+ n({ type: String })
618
651
  ], s.prototype, "name", 2);
619
- r([
620
- a({ type: String })
652
+ a([
653
+ n({ type: String })
621
654
  ], s.prototype, "pattern", 2);
622
- r([
623
- a({ type: String, attribute: "value" })
655
+ a([
656
+ n({ type: String, attribute: "value" })
624
657
  ], s.prototype, "value", 2);
625
- r([
626
- a({ type: String })
658
+ a([
659
+ n({ type: String })
627
660
  ], s.prototype, "underLabel", 2);
628
- r([
629
- a({ type: Boolean, reflect: !0 })
661
+ a([
662
+ n({ type: Boolean, reflect: !0 })
630
663
  ], s.prototype, "error", 2);
631
- r([
632
- a({ type: Boolean, reflect: !0 })
664
+ a([
665
+ n({ type: Boolean, reflect: !0 })
633
666
  ], s.prototype, "disabled", 2);
634
- r([
635
- a({ type: Boolean, reflect: !0 })
667
+ a([
668
+ n({ type: Boolean, reflect: !0 })
636
669
  ], s.prototype, "required", 2);
637
- r([
638
- a({ type: String, reflect: !0 })
670
+ a([
671
+ n({ type: String, reflect: !0 })
639
672
  ], s.prototype, "spacing", 2);
640
- r([
641
- a({ type: String, attribute: "spacing-top", reflect: !0 })
673
+ a([
674
+ n({ type: String, attribute: "spacing-top", reflect: !0 })
642
675
  ], s.prototype, "spacingTop", 2);
643
- r([
644
- a({ type: String, attribute: "spacing-bottom", reflect: !0 })
676
+ a([
677
+ n({ type: String, attribute: "spacing-bottom", reflect: !0 })
645
678
  ], s.prototype, "spacingBottom", 2);
646
- r([
647
- g()
679
+ a([
680
+ $()
648
681
  ], s.prototype, "_showDatepicker", 2);
649
- s = r([
650
- y("scb-textfield")
682
+ s = a([
683
+ k("scb-textfield")
651
684
  ], s);
652
685
  export {
653
686
  s as ScbTextField
@@ -167,7 +167,7 @@ let a = class extends h {
167
167
  @keydown=${this._onKeyDown}
168
168
  >
169
169
  <md-ripple></md-ripple>
170
- <md-icon class="toc-chevron-icon" aria-hidden="true">expand_more</md-icon>
170
+ <md-icon class="toc-chevron-icon" aria-hidden="true">keyboard_arrow_down</md-icon>
171
171
  </button>
172
172
  <md-focus-ring for=${i} inward></md-focus-ring>
173
173
  </div>