inclusive-elements 0.4.1 → 0.4.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/README.md +1 -1
- package/dist/inclusive-elements10.js +23 -16
- package/dist/types/tooltip/tooltip.d.ts +3 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Basic interactive UI patterns like popup menus, tooltips, and modals are surpris
|
|
|
9
9
|
`inclusive-elements` provides those basic behaviors in the form of Custom Elements, without any of the cruft. They are:
|
|
10
10
|
|
|
11
11
|
- **🦮 Accessible.** Designed following the [ARIA Authoring Practices Guide](https://www.w3.org/WAI/ARIA/apg/) so everyone can use them.
|
|
12
|
-
- **🌳 Lightweight.**
|
|
12
|
+
- **🌳 Lightweight.** Tree-shake only the elements you need.
|
|
13
13
|
- **🎨 Unstyled.** Easily integrate with your design bottom-up without having to fight defaults.
|
|
14
14
|
- **🚀 Easy to use.** Simple API, works with any framework that supports Custom Elements.
|
|
15
15
|
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
var d = Object.defineProperty;
|
|
2
2
|
var l = (o, i, t) => i in o ? d(o, i, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[i] = t;
|
|
3
3
|
var e = (o, i, t) => (l(o, typeof i != "symbol" ? i + "" : i, t), t);
|
|
4
|
-
import {
|
|
5
|
-
import { hello as
|
|
4
|
+
import { autoUpdate as p, computePosition as u, shift as c, flip as m } from "@floating-ui/dom";
|
|
5
|
+
import { hello as v, goodbye as b } from "hello-goodbye";
|
|
6
6
|
const r = class extends HTMLElement {
|
|
7
7
|
constructor() {
|
|
8
8
|
super(...arguments);
|
|
9
9
|
e(this, "parent");
|
|
10
10
|
e(this, "tooltip");
|
|
11
11
|
e(this, "timeout");
|
|
12
|
-
e(this, "
|
|
12
|
+
e(this, "disabledObserver");
|
|
13
13
|
e(this, "showing", !1);
|
|
14
|
+
e(this, "cleanup");
|
|
15
|
+
e(this, "prevInnerHTML");
|
|
14
16
|
e(this, "onMouseEnter", this.afterDelay.bind(this, this.show));
|
|
15
17
|
e(this, "onFocus", this.show.bind(this));
|
|
16
18
|
e(this, "onMouseLeave", this.afterDelay.bind(this, this.hide));
|
|
@@ -23,15 +25,15 @@ const r = class extends HTMLElement {
|
|
|
23
25
|
});
|
|
24
26
|
}
|
|
25
27
|
connectedCallback() {
|
|
26
|
-
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("pointerup", this.onPointerUp), this.
|
|
28
|
+
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("pointerup", this.onPointerUp), this.disabledObserver = new MutationObserver((t) => {
|
|
27
29
|
t.forEach((s) => {
|
|
28
30
|
s.attributeName === "disabled" && this.hide();
|
|
29
31
|
});
|
|
30
|
-
}), this.
|
|
32
|
+
}), this.disabledObserver.observe(this.parent, { attributes: !0 })), document.addEventListener("keydown", this.onKeyDown), document.addEventListener("scroll", this.onBlur);
|
|
31
33
|
}
|
|
32
34
|
disconnectedCallback() {
|
|
33
35
|
var t;
|
|
34
|
-
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("pointerup", this.onPointerUp), this.parent = void 0), document.removeEventListener("keydown", this.onKeyDown), document.removeEventListener("scroll", this.onBlur), (t = this.
|
|
36
|
+
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("pointerup", this.onPointerUp), this.parent = void 0), document.removeEventListener("keydown", this.onKeyDown), document.removeEventListener("scroll", this.onBlur), (t = this.disabledObserver) == null || t.disconnect(), clearTimeout(this.timeout);
|
|
35
37
|
}
|
|
36
38
|
get disabled() {
|
|
37
39
|
return this.hasAttribute("disabled");
|
|
@@ -43,18 +45,23 @@ const r = class extends HTMLElement {
|
|
|
43
45
|
if (this.disabled)
|
|
44
46
|
return;
|
|
45
47
|
const t = this.createTooltip();
|
|
46
|
-
clearTimeout(this.timeout), this.showing || (t.hidden = !1,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
clearTimeout(this.timeout), this.showing || (t.hidden = !1, v(t), this.showing = !0), this.innerHTML !== this.prevInnerHTML && (this.prevInnerHTML = t.innerHTML = this.innerHTML), t.style.position = "absolute", this.cleanup = p(
|
|
49
|
+
this.parent,
|
|
50
|
+
t,
|
|
51
|
+
() => u(this.parent, t, {
|
|
52
|
+
placement: this.getAttribute("placement") || r.placement,
|
|
53
|
+
middleware: [c(), m()]
|
|
54
|
+
}).then(({ x: s, y: h, placement: a }) => {
|
|
55
|
+
Object.assign(t.style, {
|
|
56
|
+
left: `${s}px`,
|
|
57
|
+
top: `${h}px`
|
|
58
|
+
}), t.dataset.placement = a;
|
|
59
|
+
})
|
|
60
|
+
);
|
|
55
61
|
}
|
|
56
62
|
hide() {
|
|
57
|
-
|
|
63
|
+
var t;
|
|
64
|
+
clearTimeout(this.timeout), (t = this.cleanup) == null || t.call(this), this.showing && (this.showing = !1, b(this.tooltip).then(() => {
|
|
58
65
|
this.tooltip && (this.tooltip.hidden = !0);
|
|
59
66
|
}));
|
|
60
67
|
}
|
|
@@ -5,8 +5,10 @@ export default class TooltipElement extends HTMLElement {
|
|
|
5
5
|
private parent?;
|
|
6
6
|
private tooltip?;
|
|
7
7
|
private timeout?;
|
|
8
|
-
private
|
|
8
|
+
private disabledObserver?;
|
|
9
9
|
private showing;
|
|
10
|
+
private cleanup?;
|
|
11
|
+
private prevInnerHTML?;
|
|
10
12
|
private onMouseEnter;
|
|
11
13
|
private onFocus;
|
|
12
14
|
private onMouseLeave;
|