scb-wc-test 0.1.99 → 0.1.100

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,29 +1,43 @@
1
1
  import { LitElement, TemplateResult, PropertyValues } from 'lit';
2
+ type IconVariant = 'filled' | 'outlined' | 'filled-tonal' | 'standard';
2
3
  export declare class ScbIconButton extends LitElement {
3
- ariaLabel: string;
4
- tooltip: string;
5
- variant: 'filled' | 'outlined' | 'filled-tonal' | 'standard';
4
+ /** Visuell ikon. */
6
5
  icon: string;
6
+ /** Tooltiptext. Används som native title. */
7
+ tooltip: string;
8
+ /** Tillgänglighetslabel. Speglas till md-icon-button. */
9
+ ariaLabel: string;
10
+ /** Variant enligt Material. */
11
+ variant: IconVariant;
12
+ /** Toggle-läge. */
7
13
  toggle: boolean;
14
+ /** Om komponenten är vald i toggle-läge. */
8
15
  selected: boolean;
16
+ /** Ikon i otoggla(t) läge. */
9
17
  toggleofficon: string;
18
+ /** Ikon i togglat läge. */
10
19
  toggleonicon: string;
20
+ /** Inaktiverad. */
11
21
  disabled: boolean;
12
22
  private __loadedVariants;
13
23
  private __iconLoaded;
14
- private __lastBtn?;
15
- private __ariaObserver?;
24
+ private __lastMdHost;
16
25
  protected firstUpdated(): Promise<void>;
17
26
  protected updated(changed: PropertyValues): void;
18
27
  disconnectedCallback(): void;
19
28
  private __ensureDepsLoaded;
29
+ /** Hitta md-* host i shadow DOM. */
20
30
  private __getMdHost;
21
- private __getInnerButton;
22
- private __stripNativeTitles;
23
- private __syncAria;
31
+ /** Synka selected från md-* upp till wrappern och emit change. */
24
32
  private __onInnerChange;
33
+ /** Koppla change-event från md-* samt spegla selected. */
25
34
  private __attachChangeListener;
35
+ /**
36
+ * Synkar native title och aria-* mellan host och md-*. */
37
+ private __syncTitleAndAria;
26
38
  static styles: import('lit').CSSResult;
39
+ private __renderToggleIcons;
40
+ private __renderSingleIcon;
27
41
  private __renderMd;
28
42
  render(): TemplateResult;
29
43
  }
@@ -32,3 +46,4 @@ declare global {
32
46
  'scb-icon-button': ScbIconButton;
33
47
  }
34
48
  }
49
+ export {};
@@ -1,15 +1,14 @@
1
- import { css as p, LitElement as m, html as s } from "lit";
2
- import { property as d, customElement as f } from "lit/decorators.js";
1
+ import { css as h, LitElement as u, html as o } from "lit";
2
+ import { property as a, customElement as _ } from "lit/decorators.js";
3
3
  import "@material/web/icon/icon.js";
4
- import "../scb-tooltip/scb-tooltip.js";
5
- var g = Object.defineProperty, v = Object.getOwnPropertyDescriptor, l = (t, e, i, r) => {
6
- for (var n = r > 1 ? void 0 : r ? v(e, i) : e, u = t.length - 1, a; u >= 0; u--)
7
- (a = t[u]) && (n = (r ? a(e, i, n) : a(n)) || n);
8
- return r && n && g(e, i, n), n;
4
+ var b = Object.defineProperty, p = Object.getOwnPropertyDescriptor, n = (t, e, l, r) => {
5
+ for (var s = r > 1 ? void 0 : r ? p(e, l) : e, d = t.length - 1, c; d >= 0; d--)
6
+ (c = t[d]) && (s = (r ? c(e, l, s) : c(s)) || s);
7
+ return r && s && b(e, l, s), s;
9
8
  };
10
- let o = class extends m {
9
+ let i = class extends u {
11
10
  constructor() {
12
- super(...arguments), this.ariaLabel = "", this.tooltip = "", this.variant = "standard", this.icon = "home", this.toggle = !1, this.selected = !1, this.toggleofficon = "add", this.toggleonicon = "remove", this.disabled = !1, this.__loadedVariants = /* @__PURE__ */ new Set(), this.__iconLoaded = !1, this.__onInnerChange = () => {
11
+ super(...arguments), this.icon = "home", this.tooltip = "", this.ariaLabel = "", this.variant = "standard", this.toggle = !1, this.selected = !1, this.toggleofficon = "add", this.toggleonicon = "remove", this.disabled = !1, this.__loadedVariants = /* @__PURE__ */ new Set(), this.__iconLoaded = !1, this.__lastMdHost = null, this.__onInnerChange = () => {
13
12
  const t = this.__getMdHost(), e = !!(t != null && t.selected);
14
13
  this.toggle && (this.selected = e), this.dispatchEvent(
15
14
  new CustomEvent("change", {
@@ -21,18 +20,24 @@ let o = class extends m {
21
20
  };
22
21
  }
23
22
  async firstUpdated() {
24
- await this.__ensureDepsLoaded(), await this.updateComplete, this.__attachChangeListener(), this.__syncAria();
23
+ await this.__ensureDepsLoaded(), await this.updateComplete, this.__attachChangeListener(), this.__syncTitleAndAria();
25
24
  }
26
25
  updated(t) {
27
- super.updated(t), t.has("variant") || t.has("toggle") || t.has("icon") || t.has("ariaLabel") || t.has("selected") || t.has("disabled") || t.has("tooltip") ? this.__ensureDepsLoaded().then(
28
- () => queueMicrotask(() => {
29
- this.__attachChangeListener(), this.__syncAria();
30
- })
31
- ) : queueMicrotask(() => this.__attachChangeListener());
26
+ if (super.updated(t), t.has("variant")) {
27
+ this.__ensureDepsLoaded().then(() => {
28
+ queueMicrotask(() => {
29
+ this.__attachChangeListener(), this.__syncTitleAndAria();
30
+ });
31
+ });
32
+ return;
33
+ }
34
+ (t.has("toggle") || t.has("icon") || t.has("toggleofficon") || t.has("toggleonicon") || t.has("selected") || t.has("disabled") || t.has("tooltip") || t.has("ariaLabel")) && queueMicrotask(() => {
35
+ this.__attachChangeListener(), this.__syncTitleAndAria();
36
+ });
32
37
  }
33
38
  disconnectedCallback() {
34
- var t, e, i;
35
- super.disconnectedCallback(), (e = (t = this.__lastBtn) == null ? void 0 : t.removeEventListener) == null || e.call(t, "change", this.__onInnerChange), this.__lastBtn = null, (i = this.__ariaObserver) == null || i.disconnect();
39
+ var t, e;
40
+ (e = (t = this.__lastMdHost) == null ? void 0 : t.removeEventListener) == null || e.call(t, "change", this.__onInnerChange), this.__lastMdHost = null, super.disconnectedCallback();
36
41
  }
37
42
  async __ensureDepsLoaded() {
38
43
  if (!this.__loadedVariants.has(this.variant)) {
@@ -54,172 +59,140 @@ let o = class extends m {
54
59
  }
55
60
  this.__iconLoaded || (await import("@material/web/icon/icon.js"), this.__iconLoaded = !0);
56
61
  }
57
- // Hämta md-* host. Om den är inuti <scb-tooltip>, sök i dess light DOM.
62
+ /** Hitta md-* host i shadow DOM. */
58
63
  __getMdHost() {
59
- const t = this.renderRoot.querySelector(
64
+ return this.renderRoot.querySelector(
60
65
  "md-filled-icon-button, md-outlined-icon-button, md-filled-tonal-icon-button, md-icon-button"
61
66
  );
62
- if (t) return t;
63
- const e = this.renderRoot.querySelector("scb-tooltip");
64
- if (e) {
65
- const i = e.querySelector(
66
- "md-filled-icon-button, md-outlined-icon-button, md-filled-tonal-icon-button, md-icon-button"
67
- );
68
- if (i) return i;
69
- }
70
- return null;
71
- }
72
- __getInnerButton(t) {
73
- const e = t == null ? void 0 : t.shadowRoot;
74
- return e ? e.querySelector("button") || e.querySelector('[role="button"]') : null;
75
67
  }
76
- // Ta bort alla native title-tooltips (förhindrar visning av t.ex. ikonnamn).
77
- __stripNativeTitles(t) {
78
- if (!t) return;
79
- t.removeAttribute("title");
80
- const e = this.__getInnerButton(t);
81
- e == null || e.removeAttribute("title");
82
- const i = t.shadowRoot;
83
- i && i.querySelectorAll("[title]").forEach((r) => r.removeAttribute("title"));
84
- }
85
- __syncAria() {
86
- var u;
68
+ /** Koppla change-event från md-* samt spegla selected. */
69
+ __attachChangeListener() {
70
+ var e, l;
87
71
  const t = this.__getMdHost();
88
- if (!t) return;
89
- const e = this.__getInnerButton(t), i = (this.ariaLabel || this.getAttribute("aria-label") || "").trim() || this.icon.trim(), r = this.getAttribute("aria-controls"), n = this.getAttribute("aria-expanded");
90
- e && (i ? e.setAttribute("aria-label", i) : e.removeAttribute("aria-label"), r !== null ? e.setAttribute("aria-controls", r) : e.removeAttribute("aria-controls"), n !== null ? e.setAttribute("aria-expanded", n) : e.removeAttribute("aria-expanded"), e.removeAttribute("title")), t.removeAttribute("aria-label"), t.removeAttribute("aria-controls"), t.removeAttribute("aria-expanded"), t.removeAttribute("title"), this.hasAttribute("aria-label") && this.removeAttribute("aria-label"), this.hasAttribute("aria-controls") && this.removeAttribute("aria-controls"), this.hasAttribute("aria-expanded") && this.removeAttribute("aria-expanded"), this.__stripNativeTitles(t), (u = this.__ariaObserver) == null || u.disconnect(), this.__ariaObserver = new MutationObserver(() => {
91
- const a = this.__getMdHost(), c = this.__getInnerButton(a);
92
- if (!a || !c) return;
93
- const b = (this.ariaLabel || this.getAttribute("aria-label") || "").trim() || this.icon.trim(), h = this.getAttribute("aria-controls"), _ = this.getAttribute("aria-expanded");
94
- b ? c.setAttribute("aria-label", b) : c.removeAttribute("aria-label"), h !== null ? c.setAttribute("aria-controls", h) : c.removeAttribute("aria-controls"), _ !== null ? c.setAttribute("aria-expanded", _) : c.removeAttribute("aria-expanded"), this.__stripNativeTitles(a), a.removeAttribute("aria-label"), a.removeAttribute("aria-controls"), a.removeAttribute("aria-expanded"), a.removeAttribute("title"), this.hasAttribute("aria-label") && this.removeAttribute("aria-label"), this.hasAttribute("aria-controls") && this.removeAttribute("aria-controls"), this.hasAttribute("aria-expanded") && this.removeAttribute("aria-expanded");
95
- }), this.__ariaObserver.observe(this, {
96
- attributes: !0,
97
- attributeFilter: ["aria-label", "aria-controls", "aria-expanded"]
98
- });
72
+ t && t !== this.__lastMdHost && ((l = (e = this.__lastMdHost) == null ? void 0 : e.removeEventListener) == null || l.call(e, "change", this.__onInnerChange), t.addEventListener("change", this.__onInnerChange), this.__lastMdHost = t), this.toggle && t && "selected" in t && (t.selected = this.selected);
99
73
  }
100
- __attachChangeListener() {
101
- var e, i;
74
+ /**
75
+ * Synkar native title och aria-* mellan host och md-*. */
76
+ __syncTitleAndAria() {
102
77
  const t = this.__getMdHost();
103
- t && t !== this.__lastBtn && ((i = (e = this.__lastBtn) == null ? void 0 : e.removeEventListener) == null || i.call(e, "change", this.__onInnerChange), t.addEventListener("change", this.__onInnerChange), this.__lastBtn = t), this.toggle && t && "selected" in t && (t.selected = this.selected), this.__stripNativeTitles(t || null);
78
+ if (!t) return;
79
+ const e = (this.tooltip || this.getAttribute("title") || "").trim(), l = (this.ariaLabel || this.getAttribute("aria-label") || "").trim(), r = this.getAttribute("aria-controls"), s = this.getAttribute("aria-expanded");
80
+ this.tooltip && this.setAttribute("title", e);
81
+ const d = l || e || this.icon.trim() || void 0;
82
+ d ? t.setAttribute("aria-label", d) : t.removeAttribute("aria-label"), e ? t.setAttribute("title", e) : t.removeAttribute("title"), r !== null ? t.setAttribute("aria-controls", r) : t.removeAttribute("aria-controls"), s !== null ? t.setAttribute("aria-expanded", s) : t.removeAttribute("aria-expanded");
104
83
  }
105
- __renderMd(t = !1) {
106
- const e = !!t, i = s`
84
+ __renderToggleIcons() {
85
+ return o`
107
86
  <md-icon aria-hidden="true">${this.toggleofficon}</md-icon>
108
87
  <md-icon slot="selected" aria-hidden="true">${this.toggleonicon}</md-icon>
109
- `, r = s`<md-icon aria-hidden="true">${this.icon}</md-icon>`;
88
+ `;
89
+ }
90
+ __renderSingleIcon() {
91
+ return o`<md-icon aria-hidden="true">${this.icon}</md-icon>`;
92
+ }
93
+ __renderMd() {
94
+ const t = this.toggle ? this.__renderToggleIcons() : this.__renderSingleIcon();
110
95
  if (this.toggle)
111
96
  switch (this.variant) {
112
97
  case "filled":
113
- return s`
98
+ return o`
114
99
  <md-filled-icon-button
115
- ?scb-tooltip-button=${e}
116
100
  toggle
117
101
  ?selected=${this.selected}
118
102
  ?disabled=${this.disabled}
119
- >${i}</md-filled-icon-button>
103
+ >
104
+ ${t}
105
+ </md-filled-icon-button>
120
106
  `;
121
107
  case "outlined":
122
- return s`
108
+ return o`
123
109
  <md-outlined-icon-button
124
- ?scb-tooltip-button=${e}
125
110
  toggle
126
111
  ?selected=${this.selected}
127
112
  ?disabled=${this.disabled}
128
- >${i}</md-outlined-icon-button>
113
+ >
114
+ ${t}
115
+ </md-outlined-icon-button>
129
116
  `;
130
117
  case "filled-tonal":
131
- return s`
118
+ return o`
132
119
  <md-filled-tonal-icon-button
133
- ?scb-tooltip-button=${e}
134
120
  toggle
135
121
  ?selected=${this.selected}
136
122
  ?disabled=${this.disabled}
137
- >${i}</md-filled-tonal-icon-button>
123
+ >
124
+ ${t}
125
+ </md-filled-tonal-icon-button>
138
126
  `;
139
127
  default:
140
- return s`
141
- <md-icon-button
142
- ?scb-tooltip-button=${e}
143
- toggle
144
- ?selected=${this.selected}
145
- ?disabled=${this.disabled}
146
- >${i}</md-icon-button>
128
+ return o`
129
+ <md-icon-button toggle ?selected=${this.selected} ?disabled=${this.disabled}>
130
+ ${t}
131
+ </md-icon-button>
147
132
  `;
148
133
  }
149
134
  switch (this.variant) {
150
135
  case "filled":
151
- return s`
152
- <md-filled-icon-button ?scb-tooltip-button=${e} ?disabled=${this.disabled}>
153
- ${r}
136
+ return o`
137
+ <md-filled-icon-button ?disabled=${this.disabled}>
138
+ ${t}
154
139
  </md-filled-icon-button>
155
140
  `;
156
141
  case "outlined":
157
- return s`
158
- <md-outlined-icon-button ?scb-tooltip-button=${e} ?disabled=${this.disabled}>
159
- ${r}
142
+ return o`
143
+ <md-outlined-icon-button ?disabled=${this.disabled}>
144
+ ${t}
160
145
  </md-outlined-icon-button>
161
146
  `;
162
147
  case "filled-tonal":
163
- return s`
164
- <md-filled-tonal-icon-button ?scb-tooltip-button=${e} ?disabled=${this.disabled}>
165
- ${r}
148
+ return o`
149
+ <md-filled-tonal-icon-button ?disabled=${this.disabled}>
150
+ ${t}
166
151
  </md-filled-tonal-icon-button>
167
152
  `;
168
153
  default:
169
- return s`
170
- <md-icon-button ?scb-tooltip-button=${e} ?disabled=${this.disabled}>
171
- ${r}
154
+ return o`
155
+ <md-icon-button ?disabled=${this.disabled}>
156
+ ${t}
172
157
  </md-icon-button>
173
158
  `;
174
159
  }
175
160
  }
176
161
  render() {
177
- const t = (this.tooltip || this.ariaLabel || "").trim();
178
- return t ? s`
179
- <scb-tooltip
180
- variant="plain"
181
- position="top"
182
- trigger="hover"
183
- .delay=${0.12}
184
- .arrow=${!0}
185
- supporting-text=${t}
186
- >
187
- ${this.__renderMd(!0)}
188
- </scb-tooltip>
189
- ` : this.__renderMd(!1);
162
+ return this.__renderMd();
190
163
  }
191
164
  };
192
- o.styles = p``;
193
- l([
194
- d({ type: String, attribute: "aria-label" })
195
- ], o.prototype, "ariaLabel", 2);
196
- l([
197
- d({ type: String })
198
- ], o.prototype, "tooltip", 2);
199
- l([
200
- d({ type: String })
201
- ], o.prototype, "variant", 2);
202
- l([
203
- d({ type: String })
204
- ], o.prototype, "icon", 2);
205
- l([
206
- d({ type: Boolean, reflect: !0 })
207
- ], o.prototype, "toggle", 2);
208
- l([
209
- d({ type: Boolean, reflect: !0 })
210
- ], o.prototype, "selected", 2);
211
- l([
212
- d({ type: String })
213
- ], o.prototype, "toggleofficon", 2);
214
- l([
215
- d({ type: String })
216
- ], o.prototype, "toggleonicon", 2);
217
- l([
218
- d({ type: Boolean, reflect: !0 })
219
- ], o.prototype, "disabled", 2);
220
- o = l([
221
- f("scb-icon-button")
222
- ], o);
165
+ i.styles = h``;
166
+ n([
167
+ a({ type: String })
168
+ ], i.prototype, "icon", 2);
169
+ n([
170
+ a({ type: String })
171
+ ], i.prototype, "tooltip", 2);
172
+ n([
173
+ a({ type: String, attribute: "aria-label" })
174
+ ], i.prototype, "ariaLabel", 2);
175
+ n([
176
+ a({ type: String })
177
+ ], i.prototype, "variant", 2);
178
+ n([
179
+ a({ type: Boolean, reflect: !0 })
180
+ ], i.prototype, "toggle", 2);
181
+ n([
182
+ a({ type: Boolean, reflect: !0 })
183
+ ], i.prototype, "selected", 2);
184
+ n([
185
+ a({ type: String })
186
+ ], i.prototype, "toggleofficon", 2);
187
+ n([
188
+ a({ type: String })
189
+ ], i.prototype, "toggleonicon", 2);
190
+ n([
191
+ a({ type: Boolean, reflect: !0 })
192
+ ], i.prototype, "disabled", 2);
193
+ i = n([
194
+ _("scb-icon-button")
195
+ ], i);
223
196
  export {
224
- o as ScbIconButton
197
+ i as ScbIconButton
225
198
  };