inclusive-elements 0.2.0 → 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.
- package/dist/inclusive-elements.js +422 -0
- package/dist/types/alerts/alerts.d.ts +19 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/menu/menu.d.ts +10 -0
- package/dist/types/modal/modal.d.ts +17 -0
- package/dist/types/popup/popup.d.ts +21 -0
- package/dist/types/toolbar/toolbar.d.ts +8 -0
- package/dist/types/tooltip/tooltip.d.ts +23 -0
- package/dist/types/utils.d.ts +4 -0
- package/package.json +4 -5
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
var C = Object.defineProperty;
|
|
2
|
+
var T = (o, r, t) => r in o ? C(o, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[r] = t;
|
|
3
|
+
var s = (o, r, t) => (T(o, typeof r != "symbol" ? r + "" : r, t), t);
|
|
4
|
+
import { move as k, hello as h, goodbye as l, cancel as E } from "hello-goodbye";
|
|
5
|
+
import { isFocusable as D, focusable as A } from "tabbable";
|
|
6
|
+
import { createFocusTrap as H } from "focus-trap";
|
|
7
|
+
import { autoUpdate as K, computePosition as L, shift as g, flip as x, size as M } from "@floating-ui/dom";
|
|
8
|
+
const v = class extends HTMLElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
s(this, "timeouts", /* @__PURE__ */ new Map());
|
|
12
|
+
s(this, "index", 0);
|
|
13
|
+
new MutationObserver((e) => {
|
|
14
|
+
e.forEach((i) => {
|
|
15
|
+
i.addedNodes.forEach((n) => {
|
|
16
|
+
n instanceof HTMLElement && this.show(n);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
}).observe(this, { childList: !0 });
|
|
20
|
+
}
|
|
21
|
+
connectedCallback() {
|
|
22
|
+
this.hasAttribute("role") || this.setAttribute("role", "status"), this.hasAttribute("aria-live") || this.setAttribute("aria-live", "polite"), this.hasAttribute("aria-relevant") || this.setAttribute("aria-relevant", "additions");
|
|
23
|
+
for (const t of this.children)
|
|
24
|
+
this.show(t, { animate: !1 });
|
|
25
|
+
}
|
|
26
|
+
show(t, e = {}) {
|
|
27
|
+
const i = e.key || t.dataset.key || String(this.index++);
|
|
28
|
+
t.dataset.key = i, this.contains(t) ? h(t) : e.animate === !1 ? this.append(t) : k(this.children, () => {
|
|
29
|
+
this.append(t), h(t);
|
|
30
|
+
});
|
|
31
|
+
const n = Number(
|
|
32
|
+
e.duration !== void 0 ? e.duration : t.dataset.duration || v.duration
|
|
33
|
+
);
|
|
34
|
+
return n > 0 && (this.startTimeout(t, n), t.addEventListener("mouseenter", this.clearTimeout.bind(this, t)), t.addEventListener("focusin", this.clearTimeout.bind(this, t)), t.addEventListener(
|
|
35
|
+
"mouseleave",
|
|
36
|
+
this.startTimeout.bind(this, t, n)
|
|
37
|
+
), t.addEventListener(
|
|
38
|
+
"focusout",
|
|
39
|
+
this.startTimeout.bind(this, t, n)
|
|
40
|
+
)), i;
|
|
41
|
+
}
|
|
42
|
+
dismiss(t) {
|
|
43
|
+
if (typeof t == "string") {
|
|
44
|
+
this.querySelectorAll(
|
|
45
|
+
`[data-key="${t}"]`
|
|
46
|
+
).forEach((e) => {
|
|
47
|
+
this.dismiss(e);
|
|
48
|
+
});
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
k(this.children, () => {
|
|
52
|
+
l(t, {
|
|
53
|
+
finish: () => this.removeChild(t)
|
|
54
|
+
});
|
|
55
|
+
}), this.clearTimeout(t);
|
|
56
|
+
}
|
|
57
|
+
clear() {
|
|
58
|
+
Array.from(this.children).forEach((t) => {
|
|
59
|
+
this.dismiss(t);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
speak(t) {
|
|
63
|
+
const e = document.createElement("div");
|
|
64
|
+
Object.assign(e.style, {
|
|
65
|
+
clip: "rect(0 0 0 0)",
|
|
66
|
+
clipPath: "inset(50%)",
|
|
67
|
+
height: "1px",
|
|
68
|
+
overflow: "hidden",
|
|
69
|
+
position: "absolute",
|
|
70
|
+
whiteSpace: "nowrap",
|
|
71
|
+
width: "1px"
|
|
72
|
+
}), e.textContent = t, this.show(e);
|
|
73
|
+
}
|
|
74
|
+
startTimeout(t, e) {
|
|
75
|
+
this.clearTimeout(t), this.timeouts.set(
|
|
76
|
+
t,
|
|
77
|
+
window.setTimeout(() => {
|
|
78
|
+
this.dismiss(t);
|
|
79
|
+
}, e)
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
clearTimeout(t) {
|
|
83
|
+
this.timeouts.has(t) && clearTimeout(this.timeouts.get(t));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
let f = v;
|
|
87
|
+
s(f, "duration", 1e4);
|
|
88
|
+
const w = class extends HTMLElement {
|
|
89
|
+
constructor() {
|
|
90
|
+
super(...arguments);
|
|
91
|
+
s(this, "search", "");
|
|
92
|
+
s(this, "searchTimeout");
|
|
93
|
+
s(this, "onKeyDown", (t) => {
|
|
94
|
+
if (!this.hidden) {
|
|
95
|
+
if (t.key === "ArrowUp") {
|
|
96
|
+
this.navigate(-1), t.preventDefault();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (t.key === "ArrowDown") {
|
|
100
|
+
this.navigate(1), t.preventDefault();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
t.key.length > 1 || t.ctrlKey || t.metaKey || t.altKey || (this.search += t.key.toLowerCase(), t.preventDefault(), clearTimeout(this.searchTimeout), this.searchTimeout = window.setTimeout(() => {
|
|
104
|
+
this.search = "";
|
|
105
|
+
}, w.searchDelay), this.items.some((e) => {
|
|
106
|
+
var i;
|
|
107
|
+
return ((i = e.textContent) == null ? void 0 : i.trim().toLowerCase().indexOf(this.search)) === 0 ? (e.focus(), !0) : !1;
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
connectedCallback() {
|
|
113
|
+
this.hasAttribute("role") || this.setAttribute("role", "menu"), this.hasAttribute("tabindex") || this.setAttribute("tabindex", "-1"), this.items.forEach((t) => {
|
|
114
|
+
t.hasAttribute("tabindex") || t.setAttribute("tabindex", "-1");
|
|
115
|
+
}), this.addEventListener("keydown", this.onKeyDown);
|
|
116
|
+
}
|
|
117
|
+
disconnectedCallback() {
|
|
118
|
+
this.removeEventListener("keydown", this.onKeyDown);
|
|
119
|
+
}
|
|
120
|
+
get items() {
|
|
121
|
+
return Array.from(
|
|
122
|
+
this.querySelectorAll("[role^=menuitem]")
|
|
123
|
+
).filter((t) => D(t));
|
|
124
|
+
}
|
|
125
|
+
navigate(t) {
|
|
126
|
+
var n;
|
|
127
|
+
const e = this.items;
|
|
128
|
+
let i = (document.activeElement instanceof HTMLElement ? e.indexOf(document.activeElement) : -1) + t;
|
|
129
|
+
i < 0 && (i = e.length - 1), i >= e.length && (i = 0), (n = e[i]) == null || n.focus();
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
let b = w;
|
|
133
|
+
s(b, "searchDelay", 800);
|
|
134
|
+
const c = class extends HTMLElement {
|
|
135
|
+
constructor() {
|
|
136
|
+
super();
|
|
137
|
+
s(this, "focusTrap");
|
|
138
|
+
s(this, "connected", !1);
|
|
139
|
+
const t = document.createElement("template");
|
|
140
|
+
t.innerHTML = `
|
|
141
|
+
<div part="backdrop" style="position: fixed; top: 0; left: 0; right: 0; bottom: 0"></div>
|
|
142
|
+
<div part="content" style="z-index: 1"><slot></slot></div>
|
|
143
|
+
`;
|
|
144
|
+
const e = this.attachShadow({ mode: "open" });
|
|
145
|
+
e.appendChild(t.content.cloneNode(!0)), this.backdrop.addEventListener("click", () => {
|
|
146
|
+
var i;
|
|
147
|
+
this.hasAttribute("static") ? (i = c.attention) == null || i.call(c, e.children[1]) : this.close();
|
|
148
|
+
}), this.focusTrap = H(this, {
|
|
149
|
+
escapeDeactivates: !1,
|
|
150
|
+
allowOutsideClick: !0
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
static get observedAttributes() {
|
|
154
|
+
return ["open"];
|
|
155
|
+
}
|
|
156
|
+
connectedCallback() {
|
|
157
|
+
var t, e, i, n, a, y;
|
|
158
|
+
this.connected = !0, (t = this.content) != null && t.hasAttribute("role") || (e = this.content) == null || e.setAttribute("role", "dialog"), (i = this.content) != null && i.hasAttribute("aria-modal") || (n = this.content) == null || n.setAttribute("aria-modal", "true"), (a = this.content) != null && a.hasAttribute("tabindex") || (y = this.content) == null || y.setAttribute("tabindex", "-1"), this.addEventListener("keydown", (p) => {
|
|
159
|
+
p.key === "Escape" && this.open && (p.preventDefault(), p.stopPropagation(), this.close());
|
|
160
|
+
}), this.open && this.wasOpened();
|
|
161
|
+
}
|
|
162
|
+
disconnectedCallback() {
|
|
163
|
+
this.connected = !1;
|
|
164
|
+
}
|
|
165
|
+
get open() {
|
|
166
|
+
return this.hasAttribute("open");
|
|
167
|
+
}
|
|
168
|
+
set open(t) {
|
|
169
|
+
t ? this.setAttribute("open", "") : this.removeAttribute("open");
|
|
170
|
+
}
|
|
171
|
+
close() {
|
|
172
|
+
if (!this.open)
|
|
173
|
+
return;
|
|
174
|
+
const t = new Event("beforeclose", { cancelable: !0 });
|
|
175
|
+
this.dispatchEvent(t) && (this.open = !1);
|
|
176
|
+
}
|
|
177
|
+
attributeChangedCallback(t, e, i) {
|
|
178
|
+
t !== "open" || !this.connected || (i !== null ? this.wasOpened() : this.wasClosed());
|
|
179
|
+
}
|
|
180
|
+
wasOpened() {
|
|
181
|
+
var t, e;
|
|
182
|
+
this.hidden = !1, h(this), (t = this.focusTrap) == null || t.activate(), (e = this.querySelector("[autofocus]")) == null || e.focus(), this.dispatchEvent(new Event("open"));
|
|
183
|
+
}
|
|
184
|
+
wasClosed() {
|
|
185
|
+
var t;
|
|
186
|
+
(t = this.focusTrap) == null || t.deactivate(), l(this, {
|
|
187
|
+
finish: () => this.hidden = !0
|
|
188
|
+
}), this.dispatchEvent(new Event("close"));
|
|
189
|
+
}
|
|
190
|
+
get backdrop() {
|
|
191
|
+
var t;
|
|
192
|
+
return (t = this.shadowRoot) == null ? void 0 : t.firstElementChild;
|
|
193
|
+
}
|
|
194
|
+
get content() {
|
|
195
|
+
return this.firstElementChild;
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
let m = c;
|
|
199
|
+
s(m, "attention", (t) => t.animate(
|
|
200
|
+
[
|
|
201
|
+
{ transform: "scale(1)" },
|
|
202
|
+
{ transform: "scale(1.1)" },
|
|
203
|
+
{ transform: "scale(1)" }
|
|
204
|
+
],
|
|
205
|
+
300
|
|
206
|
+
));
|
|
207
|
+
function O(o) {
|
|
208
|
+
return o.altKey || o.ctrlKey || o.metaKey || o.shiftKey || o.button !== void 0 && o.button !== 0;
|
|
209
|
+
}
|
|
210
|
+
class $ extends HTMLElement {
|
|
211
|
+
constructor() {
|
|
212
|
+
super();
|
|
213
|
+
s(this, "cleanup");
|
|
214
|
+
s(this, "onButtonClick", (t) => {
|
|
215
|
+
!O(t) && !this.disabled && (this.open = !this.open, t.preventDefault());
|
|
216
|
+
});
|
|
217
|
+
s(this, "onButtonKeyDown", (t) => {
|
|
218
|
+
var e;
|
|
219
|
+
t.key === "ArrowDown" && !this.disabled && (t.preventDefault(), this.open = !0, (e = A(this.content)[0]) == null || e.focus());
|
|
220
|
+
});
|
|
221
|
+
s(this, "onKeyDown", (t) => {
|
|
222
|
+
t.key === "Escape" && this.open && (t.preventDefault(), t.stopPropagation(), this.open = !1, this.button.focus());
|
|
223
|
+
});
|
|
224
|
+
s(this, "onFocusOut", (t) => {
|
|
225
|
+
(!(t.relatedTarget instanceof Node) || !this.contains(t.relatedTarget)) && (this.open = !1);
|
|
226
|
+
});
|
|
227
|
+
s(this, "onContentClick", (t) => {
|
|
228
|
+
t.target instanceof Element && t.target.closest("[role=menuitem], [role=menuitemradio]") && (this.open = !1, this.button.focus());
|
|
229
|
+
});
|
|
230
|
+
const t = document.createElement("template");
|
|
231
|
+
t.innerHTML = `
|
|
232
|
+
<div part="backdrop" hidden style="position: fixed; top: 0; left: 0; right: 0; bottom: 0"></div>
|
|
233
|
+
<slot></slot>
|
|
234
|
+
`, this.attachShadow({ mode: "open" }).appendChild(t.content.cloneNode(!0)), this.backdrop.onclick = () => this.open = !1;
|
|
235
|
+
}
|
|
236
|
+
static get observedAttributes() {
|
|
237
|
+
return ["open"];
|
|
238
|
+
}
|
|
239
|
+
connectedCallback() {
|
|
240
|
+
this.backdrop.hidden = !0, this.content.hidden = !0, this.open = !1, this.button.setAttribute("aria-expanded", "false"), setTimeout(() => {
|
|
241
|
+
this.content.getAttribute("role") === "menu" && this.button.setAttribute("aria-haspopup", "true");
|
|
242
|
+
}), this.button.addEventListener("click", this.onButtonClick), this.button.addEventListener("keydown", this.onButtonKeyDown), this.addEventListener("keydown", this.onKeyDown), this.addEventListener("focusout", this.onFocusOut), this.content.addEventListener("click", this.onContentClick);
|
|
243
|
+
}
|
|
244
|
+
disconnectedCallback() {
|
|
245
|
+
E(this.backdrop), E(this.content), this.button.removeAttribute("aria-expanded"), this.button.removeAttribute("aria-haspopup"), this.button.removeEventListener("click", this.onButtonClick), this.button.removeEventListener("keydown", this.onButtonKeyDown), this.removeEventListener("keydown", this.onKeyDown), this.removeEventListener("focusout", this.onFocusOut), this.content.removeEventListener("click", this.onContentClick);
|
|
246
|
+
}
|
|
247
|
+
get open() {
|
|
248
|
+
return this.hasAttribute("open");
|
|
249
|
+
}
|
|
250
|
+
set open(t) {
|
|
251
|
+
t ? this.setAttribute("open", "") : this.removeAttribute("open");
|
|
252
|
+
}
|
|
253
|
+
get disabled() {
|
|
254
|
+
return this.hasAttribute("disabled");
|
|
255
|
+
}
|
|
256
|
+
attributeChangedCallback(t, e, i) {
|
|
257
|
+
t === "open" && (i !== null ? this.wasOpened() : this.wasClosed());
|
|
258
|
+
}
|
|
259
|
+
wasOpened() {
|
|
260
|
+
if (!this.content.hidden)
|
|
261
|
+
return;
|
|
262
|
+
this.content.hidden = !1, this.backdrop.hidden = !1, h(this.content), h(this.backdrop), this.button.setAttribute("aria-expanded", "true"), this.content.style.position = "absolute", this.cleanup = K(
|
|
263
|
+
this.button,
|
|
264
|
+
this.content,
|
|
265
|
+
() => {
|
|
266
|
+
L(this.button, this.content, {
|
|
267
|
+
placement: this.getAttribute("placement") || "bottom",
|
|
268
|
+
middleware: [
|
|
269
|
+
g(),
|
|
270
|
+
x(),
|
|
271
|
+
M({
|
|
272
|
+
apply: ({ availableWidth: e, availableHeight: i }) => {
|
|
273
|
+
Object.assign(this.content.style, {
|
|
274
|
+
maxWidth: "",
|
|
275
|
+
maxHeight: ""
|
|
276
|
+
});
|
|
277
|
+
const n = getComputedStyle(this.content);
|
|
278
|
+
(n.maxWidth === "none" || e < parseInt(n.maxWidth)) && (this.content.style.maxWidth = `${e}px`), (n.maxHeight === "none" || i < parseInt(n.maxHeight)) && (this.content.style.maxHeight = `${i}px`);
|
|
279
|
+
}
|
|
280
|
+
})
|
|
281
|
+
]
|
|
282
|
+
}).then(({ x: e, y: i, placement: n }) => {
|
|
283
|
+
Object.assign(this.content.style, {
|
|
284
|
+
left: `${e}px`,
|
|
285
|
+
top: `${i}px`
|
|
286
|
+
}), this.content.dataset.placement = n;
|
|
287
|
+
});
|
|
288
|
+
},
|
|
289
|
+
{ ancestorScroll: !1 }
|
|
290
|
+
);
|
|
291
|
+
const t = this.content.querySelector("[autofocus]");
|
|
292
|
+
t ? t.focus() : this.content.focus(), this.dispatchEvent(new Event("open"));
|
|
293
|
+
}
|
|
294
|
+
wasClosed() {
|
|
295
|
+
var t;
|
|
296
|
+
this.content.hidden || (this.button.setAttribute("aria-expanded", "false"), (t = this.cleanup) == null || t.call(this), l(this.backdrop, {
|
|
297
|
+
finish: () => this.backdrop.hidden = !0
|
|
298
|
+
}), l(this.content, {
|
|
299
|
+
finish: () => this.content.hidden = !0
|
|
300
|
+
}), this.dispatchEvent(new Event("close")));
|
|
301
|
+
}
|
|
302
|
+
get backdrop() {
|
|
303
|
+
var t;
|
|
304
|
+
return (t = this.shadowRoot) == null ? void 0 : t.firstElementChild;
|
|
305
|
+
}
|
|
306
|
+
get button() {
|
|
307
|
+
return this.children[0];
|
|
308
|
+
}
|
|
309
|
+
get content() {
|
|
310
|
+
return this.children[1];
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
class P extends HTMLElement {
|
|
314
|
+
constructor() {
|
|
315
|
+
super(...arguments);
|
|
316
|
+
s(this, "onInitialFocus", () => {
|
|
317
|
+
this.removeAttribute("tabindex"), this.focusControlAtIndex(0);
|
|
318
|
+
});
|
|
319
|
+
s(this, "onKeyDown", (t) => {
|
|
320
|
+
if (t.key !== "ArrowRight" && t.key !== "ArrowLeft" && t.key !== "Home" && t.key !== "End")
|
|
321
|
+
return;
|
|
322
|
+
const e = this.controls, i = this.controls.length, n = e.indexOf(t.target);
|
|
323
|
+
if (n === -1)
|
|
324
|
+
return;
|
|
325
|
+
let a = 0;
|
|
326
|
+
t.key === "ArrowLeft" && (a = n - 1), t.key === "ArrowRight" && (a = n + 1), t.key === "End" && (a = i - 1), a < 0 && (a = i - 1), a > i - 1 && (a = 0), this.focusControlAtIndex(a), t.preventDefault();
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
connectedCallback() {
|
|
330
|
+
this.hasAttribute("role") || this.setAttribute("role", "toolbar"), this.setAttribute("tabindex", "0"), this.addEventListener("focus", this.onInitialFocus, { once: !0 }), this.addEventListener("keydown", this.onKeyDown);
|
|
331
|
+
}
|
|
332
|
+
disconnectedCallback() {
|
|
333
|
+
this.removeEventListener("keydown", this.onKeyDown);
|
|
334
|
+
}
|
|
335
|
+
focusControlAtIndex(t) {
|
|
336
|
+
this.controls.forEach((e, i) => {
|
|
337
|
+
i === t ? (e.setAttribute("tabindex", "0"), e.focus()) : e.setAttribute("tabindex", "-1");
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
get controls() {
|
|
341
|
+
return A(this);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const u = class extends HTMLElement {
|
|
345
|
+
constructor() {
|
|
346
|
+
super(...arguments);
|
|
347
|
+
s(this, "parent");
|
|
348
|
+
s(this, "tooltip");
|
|
349
|
+
s(this, "timeout");
|
|
350
|
+
s(this, "observer");
|
|
351
|
+
s(this, "showing", !1);
|
|
352
|
+
s(this, "onMouseEnter", this.afterDelay.bind(this, this.show));
|
|
353
|
+
s(this, "onFocus", this.show.bind(this));
|
|
354
|
+
s(this, "onMouseLeave", this.afterDelay.bind(this, this.hide));
|
|
355
|
+
s(this, "onBlur", this.hide.bind(this));
|
|
356
|
+
s(this, "onKeyDown", (t) => {
|
|
357
|
+
t.key === "Escape" && this.hide();
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
connectedCallback() {
|
|
361
|
+
this.parent = this.parentNode, this.parent && (this.parent.addEventListener("mouseenter", this.onMouseEnter), this.parent.addEventListener("focus", this.onFocus), this.parent.addEventListener("mouseleave", this.onMouseLeave), this.parent.addEventListener("blur", this.onBlur), this.parent.addEventListener("click", this.onBlur), this.observer = new MutationObserver((t) => {
|
|
362
|
+
t.forEach((e) => {
|
|
363
|
+
e.attributeName === "disabled" && this.hide();
|
|
364
|
+
});
|
|
365
|
+
}), this.observer.observe(this.parent, { attributes: !0 })), document.addEventListener("keydown", this.onKeyDown), document.addEventListener("scroll", this.onBlur);
|
|
366
|
+
}
|
|
367
|
+
disconnectedCallback() {
|
|
368
|
+
var t;
|
|
369
|
+
this.tooltip && (this.tooltip.remove(), this.tooltip = void 0), this.parent && (this.parent.removeEventListener("mouseenter", this.onMouseEnter), this.parent.removeEventListener("focus", this.onFocus), this.parent.removeEventListener("mouseleave", this.onMouseLeave), this.parent.removeEventListener("blur", this.onBlur), this.parent.removeEventListener("click", this.onBlur), this.parent = void 0), document.removeEventListener("keydown", this.onKeyDown), document.removeEventListener("scroll", this.onBlur), (t = this.observer) == null || t.disconnect(), clearTimeout(this.timeout);
|
|
370
|
+
}
|
|
371
|
+
get disabled() {
|
|
372
|
+
return this.hasAttribute("disabled");
|
|
373
|
+
}
|
|
374
|
+
set disabled(t) {
|
|
375
|
+
t ? this.setAttribute("disabled", "") : this.removeAttribute("disabled");
|
|
376
|
+
}
|
|
377
|
+
show() {
|
|
378
|
+
if (this.disabled)
|
|
379
|
+
return;
|
|
380
|
+
const t = this.createTooltip();
|
|
381
|
+
clearTimeout(this.timeout), this.showing || (t.hidden = !1, h(t), this.showing = !0), t.innerHTML !== this.innerHTML && (t.innerHTML = this.innerHTML), t.style.position = "absolute", L(this.parent, t, {
|
|
382
|
+
placement: this.getAttribute("placement") || u.placement,
|
|
383
|
+
middleware: [g(), x()]
|
|
384
|
+
}).then(({ x: e, y: i, placement: n }) => {
|
|
385
|
+
Object.assign(t.style, {
|
|
386
|
+
left: `${e}px`,
|
|
387
|
+
top: `${i}px`
|
|
388
|
+
}), t.dataset.placement = n;
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
hide() {
|
|
392
|
+
clearTimeout(this.timeout), this.showing && (this.showing = !1, l(this.tooltip, {
|
|
393
|
+
finish: () => {
|
|
394
|
+
this.tooltip && (this.tooltip.hidden = !0);
|
|
395
|
+
}
|
|
396
|
+
}));
|
|
397
|
+
}
|
|
398
|
+
afterDelay(t) {
|
|
399
|
+
clearTimeout(this.timeout);
|
|
400
|
+
const e = parseInt(this.getAttribute("delay") || "");
|
|
401
|
+
this.timeout = window.setTimeout(
|
|
402
|
+
t.bind(this),
|
|
403
|
+
isNaN(e) ? u.delay : e
|
|
404
|
+
);
|
|
405
|
+
}
|
|
406
|
+
createTooltip() {
|
|
407
|
+
return this.tooltip || (this.tooltip = document.createElement("div"), this.tooltip.className = this.getAttribute("tooltip-class") || u.tooltipClass, this.tooltip.hidden = !0, this.tooltip.addEventListener("mouseenter", this.show.bind(this)), this.tooltip.addEventListener(
|
|
408
|
+
"mouseleave",
|
|
409
|
+
this.afterDelay.bind(this, this.hide)
|
|
410
|
+
), document.body.appendChild(this.tooltip)), this.tooltip;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
let d = u;
|
|
414
|
+
s(d, "delay", 100), s(d, "placement", "top"), s(d, "tooltipClass", "tooltip");
|
|
415
|
+
export {
|
|
416
|
+
f as AlertsElement,
|
|
417
|
+
b as MenuElement,
|
|
418
|
+
m as ModalElement,
|
|
419
|
+
$ as PopupElement,
|
|
420
|
+
P as ToolbarElement,
|
|
421
|
+
d as TooltipElement
|
|
422
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare type AlertOptions = {
|
|
2
|
+
key?: string;
|
|
3
|
+
duration?: number;
|
|
4
|
+
animate?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export default class AlertsElement extends HTMLElement {
|
|
7
|
+
static duration: number;
|
|
8
|
+
private timeouts;
|
|
9
|
+
private index;
|
|
10
|
+
constructor();
|
|
11
|
+
connectedCallback(): void;
|
|
12
|
+
show(el: HTMLElement, options?: AlertOptions): string;
|
|
13
|
+
dismiss(el: HTMLElement): void;
|
|
14
|
+
dismiss(key: string): void;
|
|
15
|
+
clear(): void;
|
|
16
|
+
speak(message: string): void;
|
|
17
|
+
private startTimeout;
|
|
18
|
+
private clearTimeout;
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as AlertsElement } from './alerts/alerts';
|
|
2
|
+
export { default as MenuElement } from './menu/menu';
|
|
3
|
+
export { default as ModalElement } from './modal/modal';
|
|
4
|
+
export { default as PopupElement } from './popup/popup';
|
|
5
|
+
export { default as ToolbarElement } from './toolbar/toolbar';
|
|
6
|
+
export { default as TooltipElement } from './tooltip/tooltip';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export default class ModalElement extends HTMLElement {
|
|
2
|
+
static attention: (el: Element) => void;
|
|
3
|
+
static get observedAttributes(): string[];
|
|
4
|
+
private focusTrap?;
|
|
5
|
+
private connected;
|
|
6
|
+
constructor();
|
|
7
|
+
connectedCallback(): void;
|
|
8
|
+
disconnectedCallback(): void;
|
|
9
|
+
get open(): boolean;
|
|
10
|
+
set open(val: boolean);
|
|
11
|
+
close(): void;
|
|
12
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
13
|
+
private wasOpened;
|
|
14
|
+
private wasClosed;
|
|
15
|
+
private get backdrop();
|
|
16
|
+
private get content();
|
|
17
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export default class PopupElement extends HTMLElement {
|
|
2
|
+
cleanup?: () => void;
|
|
3
|
+
static get observedAttributes(): string[];
|
|
4
|
+
constructor();
|
|
5
|
+
connectedCallback(): void;
|
|
6
|
+
disconnectedCallback(): void;
|
|
7
|
+
private onButtonClick;
|
|
8
|
+
private onButtonKeyDown;
|
|
9
|
+
private onKeyDown;
|
|
10
|
+
private onFocusOut;
|
|
11
|
+
private onContentClick;
|
|
12
|
+
get open(): boolean;
|
|
13
|
+
set open(val: boolean);
|
|
14
|
+
get disabled(): boolean;
|
|
15
|
+
attributeChangedCallback(name: string, oldValue: string, newValue: string): void;
|
|
16
|
+
private wasOpened;
|
|
17
|
+
private wasClosed;
|
|
18
|
+
private get backdrop();
|
|
19
|
+
private get button();
|
|
20
|
+
private get content();
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export default class TooltipElement extends HTMLElement {
|
|
2
|
+
static delay: number;
|
|
3
|
+
static placement: string;
|
|
4
|
+
static tooltipClass: string;
|
|
5
|
+
private parent?;
|
|
6
|
+
private tooltip?;
|
|
7
|
+
private timeout?;
|
|
8
|
+
private observer?;
|
|
9
|
+
private showing;
|
|
10
|
+
private onMouseEnter;
|
|
11
|
+
private onFocus;
|
|
12
|
+
private onMouseLeave;
|
|
13
|
+
private onBlur;
|
|
14
|
+
connectedCallback(): void;
|
|
15
|
+
disconnectedCallback(): void;
|
|
16
|
+
get disabled(): boolean;
|
|
17
|
+
set disabled(val: boolean);
|
|
18
|
+
private onKeyDown;
|
|
19
|
+
private show;
|
|
20
|
+
private hide;
|
|
21
|
+
private afterDelay;
|
|
22
|
+
private createTooltip;
|
|
23
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "inclusive-elements",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Accessible, lightweight, unstyled implementations of common UI controls.",
|
|
5
|
-
"module": "
|
|
5
|
+
"module": "dist/inclusive-elements.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"types": "
|
|
7
|
+
"types": "dist/types/index.d.ts",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"repository": "tobyzerner/inclusive-elements",
|
|
10
10
|
"files": [
|
|
11
|
-
"
|
|
12
|
-
"./README.md"
|
|
11
|
+
"dist"
|
|
13
12
|
],
|
|
14
13
|
"sideEffects": false,
|
|
15
14
|
"scripts": {
|