@justeattakeaway/pie-tooltip 0.1.0 → 0.2.0
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 +161 -15
- package/custom-elements.json +459 -3
- package/dist/index.d.ts +123 -2
- package/dist/index.js +266 -18
- package/dist/react.d.ts +128 -3
- package/dist/react.js +21 -7
- package/package.json +5 -3
- package/src/defs.ts +117 -3
- package/src/index.ts +395 -9
- package/src/react.ts +9 -3
- package/src/tooltip.scss +364 -2
package/dist/index.js
CHANGED
|
@@ -1,27 +1,275 @@
|
|
|
1
|
-
import { LitElement as
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { LitElement as C, unsafeCSS as T, nothing as f } from "lit";
|
|
2
|
+
import { property as v, queryAssignedElements as E, query as P, state as $ } from "lit/decorators.js";
|
|
3
|
+
import { classMap as k } from "lit/directives/class-map.js";
|
|
4
|
+
import { ifDefined as A } from "lit/directives/if-defined.js";
|
|
5
|
+
import { unsafeStatic as B, html as y } from "lit/static-html.js";
|
|
6
|
+
import { validPropertyValues as m, safeCustomElement as S } from "@justeattakeaway/pie-webc-core";
|
|
7
|
+
import "@justeattakeaway/pie-icon-button";
|
|
8
|
+
import "@justeattakeaway/pie-icons-webc/dist/IconClose.js";
|
|
9
|
+
const b = class b extends C {
|
|
4
10
|
willUpdate() {
|
|
5
|
-
this.getAttribute("v") || this.setAttribute("v",
|
|
11
|
+
this.getAttribute("v") || this.setAttribute("v", b.v);
|
|
6
12
|
}
|
|
7
13
|
};
|
|
8
|
-
|
|
9
|
-
let
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
b.v = "0.2.0";
|
|
15
|
+
let u = b;
|
|
16
|
+
const F = [
|
|
17
|
+
"top",
|
|
18
|
+
"top-start",
|
|
19
|
+
"top-end",
|
|
20
|
+
"bottom",
|
|
21
|
+
"bottom-start",
|
|
22
|
+
"bottom-end",
|
|
23
|
+
"left",
|
|
24
|
+
"left-start",
|
|
25
|
+
"left-end",
|
|
26
|
+
"right",
|
|
27
|
+
"right-start",
|
|
28
|
+
"right-end"
|
|
29
|
+
], M = ["default", "fit-to-content", "fill-container"], D = ["default", "inverse"], L = ["default", "icon"], R = ["h2", "h3", "h4", "h5", "h6"], W = ["tooltip", "dialog"], p = "pie-tooltip", a = "c-tooltip", j = `${p}-close`, d = {
|
|
30
|
+
isOpen: !1,
|
|
31
|
+
position: "top",
|
|
32
|
+
size: "default",
|
|
33
|
+
variant: "default",
|
|
34
|
+
type: "default",
|
|
35
|
+
isDismissible: !1,
|
|
36
|
+
headingLevel: "h2"
|
|
37
|
+
}, I = "*,*:after,*:before{box-sizing:inherit}:host{--tooltip-anchor-top: 0;--tooltip-anchor-left: 0;--tooltip-anchor-width: 0;--tooltip-anchor-height: 0;--tooltip-container-inline-size: 0;--tooltip-offset: var(--dt-spacing-a);--tooltip-arrow-size: 8px;--tooltip-layer-offset: calc(var(--tooltip-offset) + var(--tooltip-arrow-size));position:absolute;top:0;left:0;z-index:var(--dt-z-index-tooltip);display:block;inline-size:0;block-size:0;pointer-events:none}.c-tooltip-origin{position:absolute;top:0;left:0;inline-size:0;block-size:0}.c-tooltip-anchor{position:absolute;top:var(--tooltip-anchor-top);left:var(--tooltip-anchor-left);inline-size:var(--tooltip-anchor-width);block-size:var(--tooltip-anchor-height)}.c-tooltip-layer{position:absolute;display:grid;grid-template-columns:100%;grid-template-rows:100%;visibility:hidden;transition:visibility 0s linear .15s}.c-tooltip-layer.is-open.is-positioned{visibility:visible;transition-delay:0s}.c-tooltip-layer--type-icon{--tooltip-layer-offset: var(--tooltip-offset)}.c-tooltip-layer--top,.c-tooltip-layer--bottom{inset-inline-start:0;inline-size:100%}.c-tooltip-layer--left,.c-tooltip-layer--right{inset-block-start:0;block-size:100%}.c-tooltip-layer--top{inset-block-end:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--bottom{inset-block-start:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--left{inset-inline-end:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--right{inset-inline-start:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--top-start,.c-tooltip-layer--bottom-start{inset-inline-start:0;inline-size:100%}.c-tooltip-layer--left-start,.c-tooltip-layer--right-start{inset-block-start:0;block-size:100%}.c-tooltip-layer--top-start{inset-block-end:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--bottom-start{inset-block-start:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--left-start{inset-inline-end:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--right-start{inset-inline-start:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--top-end,.c-tooltip-layer--bottom-end{inset-inline-start:0;inline-size:100%}.c-tooltip-layer--left-end,.c-tooltip-layer--right-end{inset-block-start:0;block-size:100%}.c-tooltip-layer--top-end{inset-block-end:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--bottom-end{inset-block-start:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--left-end{inset-inline-end:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--right-end{inset-inline-start:calc(100% + var(--tooltip-layer-offset))}.c-tooltip-layer--top{place-items:center}.c-tooltip-layer--top-start{place-items:start}.c-tooltip-layer--top-end{place-items:end}.c-tooltip-layer--bottom{place-items:center}.c-tooltip-layer--bottom-start{place-items:start}.c-tooltip-layer--bottom-end{place-items:end}.c-tooltip-layer--left{place-items:center}.c-tooltip-layer--left-start{place-items:start}.c-tooltip-layer--left-end{place-items:end}.c-tooltip-layer--right{place-items:center}.c-tooltip-layer--right-start{place-items:start}.c-tooltip-layer--right-end{place-items:end}.c-tooltip{--tooltip-inline-size: 280px;--tooltip-max-inline-size: calc(100vw - var(--dt-spacing-d) * 2);--tooltip-background-color: var(--dt-color-container-inverse);--tooltip-content-color: var(--dt-color-content-inverse);--tooltip-border-radius: var(--dt-radius-rounded-b);--tooltip-padding-block: var(--dt-spacing-b);--tooltip-padding-inline: var(--dt-spacing-c);--tooltip-close-size: 32px;--tooltip-motion-duration: .15s;--tooltip-motion-easing: cubic-bezier(.45, 0, .55, 1);--tooltip-motion-translate-x: 0;--tooltip-motion-translate-y: 0;--tooltip-arrow-inset: calc(var(--tooltip-border-radius) + var(--tooltip-arrow-size));--tooltip-arrow-cross-inset: calc(var(--tooltip-arrow-cross-position, 50%) - var(--tooltip-arrow-size));--tooltip-arrow-main-inset-far: calc(100% - 2px) ;--tooltip-arrow-main-inset-near: calc(var(--tooltip-arrow-size) * -1);font-family:var(--dt-font-body-s-family),var(--dt-font-family-secondary),sans-serif;font-weight:var(--dt-font-body-s-weight);font-size:calc(var(--dt-font-body-s-size) * 1px);line-height:calc(var(--dt-font-body-s-line-height) * 1px);position:relative;inline-size:var(--tooltip-width, var(--tooltip-inline-size));max-inline-size:var(--tooltip-max-inline-size);padding-block-start:var(--tooltip-padding-block);padding-block-end:var(--tooltip-padding-block);padding-inline-start:var(--tooltip-padding-inline);padding-inline-end:var(--tooltip-padding-inline);border-radius:var(--tooltip-border-radius);background-color:var(--tooltip-background-color);color:var(--tooltip-content-color);pointer-events:auto;opacity:0;transform:translate(var(--tooltip-motion-translate-x),var(--tooltip-motion-translate-y));transition:opacity var(--tooltip-motion-duration) var(--tooltip-motion-easing),transform var(--tooltip-motion-duration) var(--tooltip-motion-easing)}.c-tooltip-layer.is-open.is-positioned .c-tooltip{--tooltip-motion-duration: .2s;opacity:1;transform:translate(0)}.c-tooltip--top{--tooltip-motion-translate-y: 4px}.c-tooltip--bottom{--tooltip-motion-translate-y: -4px}.c-tooltip--left{--tooltip-motion-translate-x: 4px}.c-tooltip--right{--tooltip-motion-translate-x: -4px}.c-tooltip--top-start{--tooltip-motion-translate-y: 4px}.c-tooltip--bottom-start{--tooltip-motion-translate-y: -4px}.c-tooltip--left-start{--tooltip-motion-translate-x: 4px}.c-tooltip--right-start{--tooltip-motion-translate-x: -4px}.c-tooltip--top-end{--tooltip-motion-translate-y: 4px}.c-tooltip--bottom-end{--tooltip-motion-translate-y: -4px}.c-tooltip--left-end{--tooltip-motion-translate-x: 4px}.c-tooltip--right-end{--tooltip-motion-translate-x: -4px}:host(:dir(rtl)) .c-tooltip--left{--tooltip-motion-translate-x: -4px}:host(:dir(rtl)) .c-tooltip--right{--tooltip-motion-translate-x: 4px}:host(:dir(rtl)) .c-tooltip--left-start{--tooltip-motion-translate-x: -4px}:host(:dir(rtl)) .c-tooltip--right-start{--tooltip-motion-translate-x: 4px}:host(:dir(rtl)) .c-tooltip--left-end{--tooltip-motion-translate-x: -4px}:host(:dir(rtl)) .c-tooltip--right-end{--tooltip-motion-translate-x: 4px}@media(prefers-reduced-motion:reduce){.c-tooltip-layer,.c-tooltip{transition:none}}.c-tooltip--inverse{--tooltip-background-color: var(--dt-color-container-default);--tooltip-content-color: var(--dt-color-content-default)}.c-tooltip--size-fit-to-content{--tooltip-inline-size: max-content}.c-tooltip--size-fill-container{--tooltip-inline-size: var(--tooltip-container-inline-size);--tooltip-max-inline-size: none}.c-tooltip--type-icon{--tooltip-border-radius: var(--dt-radius-rounded-e);--tooltip-padding-block: var(--dt-spacing-a);--tooltip-padding-inline: var(--dt-spacing-c);inline-size:max-content}.c-tooltip.is-dismissible{min-block-size:calc(var(--tooltip-close-size) + var(--dt-spacing-b) * 2);padding-inline-end:calc(var(--tooltip-padding-inline) + var(--tooltip-close-size))}.c-tooltip.is-dismissible:not(.has-heading){display:flex;flex-direction:column;justify-content:center}.c-tooltip--top{--tooltip-arrow-cross-position: 50%}.c-tooltip--top-start{--tooltip-arrow-cross-position: var(--tooltip-arrow-inset)}.c-tooltip--top-end{--tooltip-arrow-cross-position: calc(100% - var(--tooltip-arrow-inset))}.c-tooltip--bottom{--tooltip-arrow-cross-position: 50%}.c-tooltip--bottom-start{--tooltip-arrow-cross-position: var(--tooltip-arrow-inset)}.c-tooltip--bottom-end{--tooltip-arrow-cross-position: calc(100% - var(--tooltip-arrow-inset))}.c-tooltip--left{--tooltip-arrow-cross-position: 50%}.c-tooltip--left-start{--tooltip-arrow-cross-position: var(--tooltip-arrow-inset)}.c-tooltip--left-end{--tooltip-arrow-cross-position: calc(100% - var(--tooltip-arrow-inset))}.c-tooltip--right{--tooltip-arrow-cross-position: 50%}.c-tooltip--right-start{--tooltip-arrow-cross-position: var(--tooltip-arrow-inset)}.c-tooltip--right-end{--tooltip-arrow-cross-position: calc(100% - var(--tooltip-arrow-inset))}.c-tooltip-arrow{position:absolute;background-color:var(--tooltip-background-color)}.c-tooltip--top .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) * 2);block-size:calc(var(--tooltip-arrow-size) + 2px);clip-path:polygon(0% 0%,100% 0%,100% 2px,50% 100%,0% 2px);inset-block-start:var(--tooltip-arrow-main-inset-far);inset-inline-start:var(--tooltip-arrow-cross-inset)}.c-tooltip--bottom .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) * 2);block-size:calc(var(--tooltip-arrow-size) + 2px);clip-path:polygon(50% 0%,100% var(--tooltip-arrow-size),100% 100%,0% 100%,0% var(--tooltip-arrow-size));inset-block-start:var(--tooltip-arrow-main-inset-near);inset-inline-start:var(--tooltip-arrow-cross-inset)}.c-tooltip--left .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) + 2px);block-size:calc(var(--tooltip-arrow-size) * 2);clip-path:polygon(0% 0%,2px 0%,100% 50%,2px 100%,0% 100%);inset-block-start:var(--tooltip-arrow-cross-inset);inset-inline-start:var(--tooltip-arrow-main-inset-far)}.c-tooltip--right .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) + 2px);block-size:calc(var(--tooltip-arrow-size) * 2);clip-path:polygon(0% 50%,var(--tooltip-arrow-size) 0%,100% 0%,100% 100%,var(--tooltip-arrow-size) 100%);inset-block-start:var(--tooltip-arrow-cross-inset);inset-inline-start:var(--tooltip-arrow-main-inset-near)}.c-tooltip--top-start .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) * 2);block-size:calc(var(--tooltip-arrow-size) + 2px);clip-path:polygon(0% 0%,100% 0%,100% 2px,50% 100%,0% 2px);inset-block-start:var(--tooltip-arrow-main-inset-far);inset-inline-start:var(--tooltip-arrow-cross-inset)}.c-tooltip--bottom-start .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) * 2);block-size:calc(var(--tooltip-arrow-size) + 2px);clip-path:polygon(50% 0%,100% var(--tooltip-arrow-size),100% 100%,0% 100%,0% var(--tooltip-arrow-size));inset-block-start:var(--tooltip-arrow-main-inset-near);inset-inline-start:var(--tooltip-arrow-cross-inset)}.c-tooltip--left-start .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) + 2px);block-size:calc(var(--tooltip-arrow-size) * 2);clip-path:polygon(0% 0%,2px 0%,100% 50%,2px 100%,0% 100%);inset-block-start:var(--tooltip-arrow-cross-inset);inset-inline-start:var(--tooltip-arrow-main-inset-far)}.c-tooltip--right-start .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) + 2px);block-size:calc(var(--tooltip-arrow-size) * 2);clip-path:polygon(0% 50%,var(--tooltip-arrow-size) 0%,100% 0%,100% 100%,var(--tooltip-arrow-size) 100%);inset-block-start:var(--tooltip-arrow-cross-inset);inset-inline-start:var(--tooltip-arrow-main-inset-near)}.c-tooltip--top-end .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) * 2);block-size:calc(var(--tooltip-arrow-size) + 2px);clip-path:polygon(0% 0%,100% 0%,100% 2px,50% 100%,0% 2px);inset-block-start:var(--tooltip-arrow-main-inset-far);inset-inline-start:var(--tooltip-arrow-cross-inset)}.c-tooltip--bottom-end .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) * 2);block-size:calc(var(--tooltip-arrow-size) + 2px);clip-path:polygon(50% 0%,100% var(--tooltip-arrow-size),100% 100%,0% 100%,0% var(--tooltip-arrow-size));inset-block-start:var(--tooltip-arrow-main-inset-near);inset-inline-start:var(--tooltip-arrow-cross-inset)}.c-tooltip--left-end .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) + 2px);block-size:calc(var(--tooltip-arrow-size) * 2);clip-path:polygon(0% 0%,2px 0%,100% 50%,2px 100%,0% 100%);inset-block-start:var(--tooltip-arrow-cross-inset);inset-inline-start:var(--tooltip-arrow-main-inset-far)}.c-tooltip--right-end .c-tooltip-arrow{inline-size:calc(var(--tooltip-arrow-size) + 2px);block-size:calc(var(--tooltip-arrow-size) * 2);clip-path:polygon(0% 50%,var(--tooltip-arrow-size) 0%,100% 0%,100% 100%,var(--tooltip-arrow-size) 100%);inset-block-start:var(--tooltip-arrow-cross-inset);inset-inline-start:var(--tooltip-arrow-main-inset-near)}:host(:dir(rtl)) .c-tooltip--left .c-tooltip-arrow,:host(:dir(rtl)) .c-tooltip--right .c-tooltip-arrow{transform:scaleX(-1)}:host(:dir(rtl)) .c-tooltip--left-start .c-tooltip-arrow,:host(:dir(rtl)) .c-tooltip--right-start .c-tooltip-arrow{transform:scaleX(-1)}:host(:dir(rtl)) .c-tooltip--left-end .c-tooltip-arrow,:host(:dir(rtl)) .c-tooltip--right-end .c-tooltip-arrow{transform:scaleX(-1)}.c-tooltip-heading{font-family:var(--dt-font-body-strong-s-family),var(--dt-font-family-secondary),sans-serif;font-weight:var(--dt-font-body-strong-s-weight);font-size:calc(var(--dt-font-body-strong-s-size) * 1px);line-height:calc(var(--dt-font-body-strong-s-line-height) * 1px);margin-block-start:0;margin-block-end:0}.c-tooltip-content{overflow-wrap:break-word}.c-tooltip.has-action .c-tooltip-action{display:flex;justify-content:flex-end;margin-block-start:var(--dt-spacing-a)}.c-tooltip.is-dismissible.has-action .c-tooltip-action{margin-inline-end:calc(var(--tooltip-close-size) * -1)}.c-tooltip.is-dismissible.has-action .c-tooltip-body{min-block-size:var(--tooltip-close-size)}.c-tooltip.is-dismissible.has-action:not(.has-heading) .c-tooltip-body{display:grid;align-content:center}.c-tooltip-close{position:absolute;inset-block-start:var(--dt-spacing-b);inset-inline-end:var(--dt-spacing-b)}";
|
|
38
|
+
var V = Object.defineProperty, N = Object.getOwnPropertyDescriptor, n = (t, o, i, r) => {
|
|
39
|
+
for (var e = r > 1 ? void 0 : r ? N(o, i) : o, c = t.length - 1, s; c >= 0; c--)
|
|
40
|
+
(s = t[c]) && (e = (r ? s(o, i, e) : s(e)) || e);
|
|
41
|
+
return r && e && V(o, i, e), e;
|
|
15
42
|
};
|
|
16
|
-
|
|
43
|
+
const w = "pie-tooltip-heading", X = (t) => {
|
|
44
|
+
const o = (r) => !!r && r !== "none";
|
|
45
|
+
return [
|
|
46
|
+
t.transform,
|
|
47
|
+
t.perspective,
|
|
48
|
+
t.filter,
|
|
49
|
+
t.backdropFilter,
|
|
50
|
+
t.translate,
|
|
51
|
+
t.rotate,
|
|
52
|
+
t.scale
|
|
53
|
+
].some(o) || /\b(paint|layout|content|strict)\b/.test(t.contain) || t.containerType && t.containerType !== "normal" ? !0 : /\b(transform|perspective|filter|backdrop-filter|contain|translate|rotate|scale)\b/.test(t.willChange);
|
|
54
|
+
};
|
|
55
|
+
let l = class extends u {
|
|
56
|
+
constructor() {
|
|
57
|
+
super(...arguments), this.isOpen = d.isOpen, this.position = d.position, this.size = d.size, this.variant = d.variant, this.type = d.type, this.isDismissible = d.isDismissible, this.headingLevel = d.headingLevel, this._isPositioned = !1, this._reanchorFrame = 0, this._shouldResolveOverlayMode = !1;
|
|
58
|
+
}
|
|
59
|
+
get _mode() {
|
|
60
|
+
if (this._hasActionContent !== void 0)
|
|
61
|
+
return this._hasActionContent ? "dialog" : "tooltip";
|
|
62
|
+
}
|
|
63
|
+
firstUpdated() {
|
|
64
|
+
this.resolveMode(), this.projectOverTrigger();
|
|
65
|
+
}
|
|
66
|
+
updated(t) {
|
|
67
|
+
const o = ["trigger", "isOpen", "position", "size"];
|
|
68
|
+
this.isOpen && t.has("isOpen") && this.resolveOverlayMode(), o.some((i) => t.has(i)) && this.projectOverTrigger(), this.isOpen ? this.startTrackingTrigger() : this.stopTrackingTrigger();
|
|
69
|
+
}
|
|
70
|
+
disconnectedCallback() {
|
|
71
|
+
this.stopTrackingTrigger(), super.disconnectedCallback();
|
|
72
|
+
}
|
|
73
|
+
// Listens for scroll (capture — catches any ancestor), resize, and dir-attribute changes to
|
|
74
|
+
// re-anchor the panel. Multiple events per frame coalesce into one requestAnimationFrame call.
|
|
75
|
+
startTrackingTrigger() {
|
|
76
|
+
if (this._triggerTrackingController)
|
|
77
|
+
return;
|
|
78
|
+
const t = new AbortController(), { signal: o } = t, i = () => {
|
|
79
|
+
this._reanchorFrame || (this._reanchorFrame = requestAnimationFrame(() => {
|
|
80
|
+
this._reanchorFrame = 0, this._shouldResolveOverlayMode && (this._shouldResolveOverlayMode = !1, this.resolveOverlayMode()), this.projectOverTrigger();
|
|
81
|
+
}));
|
|
82
|
+
}, r = () => {
|
|
83
|
+
this._shouldResolveOverlayMode = !0, i();
|
|
84
|
+
};
|
|
85
|
+
window.addEventListener("scroll", i, { capture: !0, passive: !0, signal: o }), window.addEventListener("resize", r, { passive: !0, signal: o }), this._directionObserver = new MutationObserver(i), this._directionObserver.observe(this.ownerDocument.documentElement, {
|
|
86
|
+
attributeFilter: ["dir"],
|
|
87
|
+
subtree: !0
|
|
88
|
+
}), this._triggerTrackingController = t;
|
|
89
|
+
}
|
|
90
|
+
stopTrackingTrigger() {
|
|
91
|
+
var t, o;
|
|
92
|
+
(t = this._triggerTrackingController) == null || t.abort(), this._triggerTrackingController = void 0, (o = this._directionObserver) == null || o.disconnect(), this._directionObserver = void 0, this._shouldResolveOverlayMode = !1, this._reanchorFrame && (cancelAnimationFrame(this._reanchorFrame), this._reanchorFrame = 0);
|
|
93
|
+
}
|
|
94
|
+
resolveMode() {
|
|
95
|
+
this._hasActionContent = this._assignedActionElements.length > 0;
|
|
96
|
+
}
|
|
97
|
+
// Picks between `absolute` (browser handles scrolling, but clipped by overflow ancestors) and
|
|
98
|
+
// `fixed` (escapes overflow clips, but must re-offset on every scroll). Switches to `fixed`
|
|
99
|
+
// only when it escapes a clip that `absolute` would not.
|
|
100
|
+
resolveOverlayMode() {
|
|
101
|
+
let t = !1, o = !1, i = !1, r = !1, e = this.parentNode;
|
|
102
|
+
for (; e; ) {
|
|
103
|
+
const c = e instanceof ShadowRoot ? e.host : e;
|
|
104
|
+
if (!(c instanceof Element))
|
|
105
|
+
break;
|
|
106
|
+
const s = getComputedStyle(c), h = X(s);
|
|
107
|
+
if ((h || s.position !== "static") && (t = !0), h && (o = !0), (s.overflowX !== "visible" || s.overflowY !== "visible") && (i = i || t, r = r || o), c === this.ownerDocument.documentElement)
|
|
108
|
+
break;
|
|
109
|
+
e = c.parentNode;
|
|
110
|
+
}
|
|
111
|
+
this.style.position = i && !r ? "fixed" : "";
|
|
112
|
+
}
|
|
113
|
+
// Measures the trigger relative to the origin marker (which sits at the containing block's
|
|
114
|
+
// origin) and writes CSS custom properties. Self-referential: correct for any containing
|
|
115
|
+
// block. Physical values; shadow-root CSS uses logical properties for RTL mirroring.
|
|
116
|
+
projectOverTrigger() {
|
|
117
|
+
this._isPositioned = !1;
|
|
118
|
+
const t = this.trigger ? this.ownerDocument.getElementById(this.trigger) : null;
|
|
119
|
+
if (!t || !this._originElement) {
|
|
120
|
+
["top", "left", "width", "height"].forEach((g) => {
|
|
121
|
+
this.style.removeProperty(`--tooltip-anchor-${g}`);
|
|
122
|
+
}), this.style.removeProperty("--tooltip-container-inline-size"), this._isPositioned = !0;
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const o = this._originElement.getBoundingClientRect(), {
|
|
126
|
+
top: i,
|
|
127
|
+
left: r,
|
|
128
|
+
width: e,
|
|
129
|
+
height: c
|
|
130
|
+
} = t.getBoundingClientRect();
|
|
131
|
+
this.style.setProperty("--tooltip-anchor-top", `${i - o.top}px`), this.style.setProperty("--tooltip-anchor-left", `${r - o.left}px`), this.style.setProperty("--tooltip-anchor-width", `${e}px`), this.style.setProperty("--tooltip-anchor-height", `${c}px`);
|
|
132
|
+
const s = t.parentElement, h = s ? s.getBoundingClientRect().width : e;
|
|
133
|
+
this.style.setProperty("--tooltip-container-inline-size", `${h}px`), this._isPositioned = !0;
|
|
134
|
+
}
|
|
135
|
+
handleCloseButtonClick() {
|
|
136
|
+
this.dispatchEvent(new Event(j, { bubbles: !0, composed: !0 }));
|
|
137
|
+
}
|
|
138
|
+
renderHeading() {
|
|
139
|
+
const t = B(this.headingLevel);
|
|
140
|
+
return y`<${t}
|
|
141
|
+
id="${w}"
|
|
142
|
+
class="${a}-heading"
|
|
143
|
+
data-test-id="${w}">${this.heading}</${t}>`;
|
|
144
|
+
}
|
|
145
|
+
renderCloseButton() {
|
|
146
|
+
var t;
|
|
147
|
+
return y`
|
|
148
|
+
<pie-icon-button
|
|
149
|
+
class="${a}-close"
|
|
150
|
+
data-test-id="${p}-close"
|
|
151
|
+
size="xsmall"
|
|
152
|
+
variant="${this.variant === "inverse" ? "ghost-secondary" : "ghost-inverse"}"
|
|
153
|
+
.aria="${{ label: (t = this.aria) == null ? void 0 : t.close }}"
|
|
154
|
+
@click="${this.handleCloseButtonClick}">
|
|
155
|
+
<icon-close></icon-close>
|
|
156
|
+
</pie-icon-button>`;
|
|
157
|
+
}
|
|
17
158
|
render() {
|
|
18
|
-
|
|
159
|
+
const {
|
|
160
|
+
aria: t,
|
|
161
|
+
heading: o,
|
|
162
|
+
isDismissible: i,
|
|
163
|
+
isOpen: r,
|
|
164
|
+
position: e,
|
|
165
|
+
size: c,
|
|
166
|
+
type: s,
|
|
167
|
+
variant: h,
|
|
168
|
+
_mode: g
|
|
169
|
+
} = this, z = s === "icon", _ = {
|
|
170
|
+
[`${a}-layer`]: !0,
|
|
171
|
+
[`${a}-layer--${e}`]: !0,
|
|
172
|
+
[`${a}-layer--type-${s}`]: !0,
|
|
173
|
+
"is-open": !!r,
|
|
174
|
+
"is-positioned": this._isPositioned
|
|
175
|
+
}, O = {
|
|
176
|
+
[a]: !0,
|
|
177
|
+
[`${a}--${e}`]: !0,
|
|
178
|
+
[`${a}--${h}`]: !0,
|
|
179
|
+
[`${a}--type-${s}`]: !0,
|
|
180
|
+
[`${a}--size-${c}`]: !z,
|
|
181
|
+
"is-dismissible": !!i,
|
|
182
|
+
"has-action": g === "dialog",
|
|
183
|
+
"has-heading": !!o
|
|
184
|
+
}, x = g === "dialog";
|
|
185
|
+
return y`
|
|
186
|
+
<div class="${a}-origin" data-test-id="${p}-origin"></div>
|
|
187
|
+
<div class="${a}-anchor" data-test-id="${p}-anchor">
|
|
188
|
+
<div class="${k(_)}" data-test-id="${p}-layer">
|
|
189
|
+
<div
|
|
190
|
+
class="${k(O)}"
|
|
191
|
+
data-test-id="${p}"
|
|
192
|
+
role="${A(g)}"
|
|
193
|
+
aria-hidden="${!r}"
|
|
194
|
+
aria-labelledby="${x && o ? w : f}"
|
|
195
|
+
aria-label="${x && !o && (t != null && t.label) ? t.label : f}">
|
|
196
|
+
${z ? f : y`<div class="${a}-arrow" data-test-id="${p}-arrow"></div>`}
|
|
197
|
+
<div class="${a}-body">
|
|
198
|
+
${o ? this.renderHeading() : f}
|
|
199
|
+
<div class="${a}-content" data-test-id="${p}-content">
|
|
200
|
+
<slot name="content"></slot>
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
<div class="${a}-action" data-test-id="${p}-action">
|
|
204
|
+
<slot name="action" @slotchange="${this.resolveMode}"></slot>
|
|
205
|
+
</div>
|
|
206
|
+
${i ? this.renderCloseButton() : f}
|
|
207
|
+
</div>
|
|
208
|
+
</div>
|
|
209
|
+
</div>`;
|
|
19
210
|
}
|
|
20
211
|
};
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
],
|
|
212
|
+
l.styles = T(I);
|
|
213
|
+
n([
|
|
214
|
+
v({ type: String })
|
|
215
|
+
], l.prototype, "trigger", 2);
|
|
216
|
+
n([
|
|
217
|
+
v({ type: Boolean })
|
|
218
|
+
], l.prototype, "isOpen", 2);
|
|
219
|
+
n([
|
|
220
|
+
v({ type: String }),
|
|
221
|
+
m(p, F, d.position)
|
|
222
|
+
], l.prototype, "position", 2);
|
|
223
|
+
n([
|
|
224
|
+
v({ type: String }),
|
|
225
|
+
m(p, M, d.size)
|
|
226
|
+
], l.prototype, "size", 2);
|
|
227
|
+
n([
|
|
228
|
+
v({ type: String }),
|
|
229
|
+
m(p, D, d.variant)
|
|
230
|
+
], l.prototype, "variant", 2);
|
|
231
|
+
n([
|
|
232
|
+
v({ type: String }),
|
|
233
|
+
m(p, L, d.type)
|
|
234
|
+
], l.prototype, "type", 2);
|
|
235
|
+
n([
|
|
236
|
+
v({ type: Boolean })
|
|
237
|
+
], l.prototype, "isDismissible", 2);
|
|
238
|
+
n([
|
|
239
|
+
v({ type: String })
|
|
240
|
+
], l.prototype, "heading", 2);
|
|
241
|
+
n([
|
|
242
|
+
v({ type: String }),
|
|
243
|
+
m(p, R, d.headingLevel)
|
|
244
|
+
], l.prototype, "headingLevel", 2);
|
|
245
|
+
n([
|
|
246
|
+
v({ type: Object })
|
|
247
|
+
], l.prototype, "aria", 2);
|
|
248
|
+
n([
|
|
249
|
+
E({ slot: "action" })
|
|
250
|
+
], l.prototype, "_assignedActionElements", 2);
|
|
251
|
+
n([
|
|
252
|
+
P(".c-tooltip-origin")
|
|
253
|
+
], l.prototype, "_originElement", 2);
|
|
254
|
+
n([
|
|
255
|
+
$()
|
|
256
|
+
], l.prototype, "_hasActionContent", 2);
|
|
257
|
+
n([
|
|
258
|
+
$()
|
|
259
|
+
], l.prototype, "_isPositioned", 2);
|
|
260
|
+
l = n([
|
|
261
|
+
S("pie-tooltip")
|
|
262
|
+
], l);
|
|
25
263
|
export {
|
|
26
|
-
|
|
264
|
+
j as ON_TOOLTIP_CLOSE_EVENT,
|
|
265
|
+
l as PieTooltip,
|
|
266
|
+
a as componentClass,
|
|
267
|
+
p as componentSelector,
|
|
268
|
+
d as defaultProps,
|
|
269
|
+
R as headingLevels,
|
|
270
|
+
W as modes,
|
|
271
|
+
F as positions,
|
|
272
|
+
M as sizes,
|
|
273
|
+
L as types,
|
|
274
|
+
D as variants
|
|
27
275
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,21 +1,146 @@
|
|
|
1
|
+
import { ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
1
2
|
import { CSSResult } from 'lit';
|
|
2
3
|
import { PieElement } from '@justeattakeaway/pie-webc-core/src/internals/PieElement';
|
|
4
|
+
import { PropertyValues } from 'lit';
|
|
3
5
|
import * as React_2 from 'react';
|
|
4
|
-
import { TemplateResult } from 'lit
|
|
6
|
+
import { TemplateResult } from 'lit';
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
declare type AriaProps = {
|
|
9
|
+
/**
|
|
10
|
+
* The accessible name for the close button. Required whenever `isDismissible` is set.
|
|
11
|
+
*/
|
|
12
|
+
close?: string;
|
|
13
|
+
/**
|
|
14
|
+
* The accessible name for the panel in dialog mode. Only used when `heading` is not provided.
|
|
15
|
+
*/
|
|
16
|
+
label?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export declare const componentClass = "c-tooltip";
|
|
20
|
+
|
|
21
|
+
export declare const componentSelector = "pie-tooltip";
|
|
22
|
+
|
|
23
|
+
export declare type DefaultProps = ComponentDefaultProps<TooltipProps, keyof Omit<TooltipProps, 'trigger' | 'heading' | 'aria'>>;
|
|
24
|
+
|
|
25
|
+
export declare const defaultProps: DefaultProps;
|
|
26
|
+
|
|
27
|
+
export declare const headingLevels: readonly ["h2", "h3", "h4", "h5", "h6"];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The two patterns the panel can present as. Inferred from the `action` slot rather than
|
|
31
|
+
* configured: an empty `action` slot is a tooltip, a filled one is a non-modal dialog.
|
|
32
|
+
*/
|
|
33
|
+
export declare const modes: readonly ["tooltip", "dialog"];
|
|
34
|
+
|
|
35
|
+
export declare const ON_TOOLTIP_CLOSE_EVENT = "pie-tooltip-close";
|
|
36
|
+
|
|
37
|
+
export declare const PieTooltip: React_2.ForwardRefExoticComponent<React_2.PropsWithChildren<Omit<React_2.PropsWithoutRef<TooltipProps>, "children">> & React_2.RefAttributes<PieTooltip_2> & PieTooltipEvents & ReactBaseType>;
|
|
7
38
|
|
|
8
39
|
/**
|
|
9
40
|
* @tagname pie-tooltip
|
|
41
|
+
* @event {Event} pie-tooltip-close - When the close button is clicked. Set `isOpen` to `false` in response.
|
|
42
|
+
* @slot content - The descriptive content of the panel. Must not contain focusable elements.
|
|
43
|
+
* @slot action - An optional slot for interactive content such as a `pie-button`. Filling this slot switches the panel to a non-modal dialog.
|
|
10
44
|
*/
|
|
11
45
|
declare class PieTooltip_2 extends PieElement implements TooltipProps {
|
|
12
|
-
|
|
46
|
+
trigger: TooltipProps['trigger'];
|
|
47
|
+
isOpen: boolean;
|
|
48
|
+
position: "top" | "top-start" | "top-end" | "bottom" | "bottom-start" | "bottom-end" | "left" | "left-start" | "left-end" | "right" | "right-start" | "right-end";
|
|
49
|
+
size: "default" | "fit-to-content" | "fill-container";
|
|
50
|
+
variant: "default" | "inverse";
|
|
51
|
+
type: "default" | "icon";
|
|
52
|
+
isDismissible: boolean;
|
|
53
|
+
heading: TooltipProps['heading'];
|
|
54
|
+
headingLevel: "h2" | "h3" | "h4" | "h5" | "h6";
|
|
55
|
+
aria: TooltipProps['aria'];
|
|
56
|
+
private _assignedActionElements;
|
|
57
|
+
private _originElement;
|
|
58
|
+
private _hasActionContent;
|
|
59
|
+
private _isPositioned;
|
|
60
|
+
private _triggerTrackingController;
|
|
61
|
+
private _directionObserver;
|
|
62
|
+
private _reanchorFrame;
|
|
63
|
+
private _shouldResolveOverlayMode;
|
|
13
64
|
static styles: CSSResult;
|
|
65
|
+
private get _mode();
|
|
66
|
+
protected firstUpdated(): void;
|
|
67
|
+
protected updated(changedProperties: PropertyValues<this>): void;
|
|
68
|
+
disconnectedCallback(): void;
|
|
69
|
+
private startTrackingTrigger;
|
|
70
|
+
private stopTrackingTrigger;
|
|
71
|
+
private resolveMode;
|
|
72
|
+
private resolveOverlayMode;
|
|
73
|
+
private projectOverTrigger;
|
|
74
|
+
private handleCloseButtonClick;
|
|
75
|
+
private renderHeading;
|
|
76
|
+
private renderCloseButton;
|
|
77
|
+
render(): TemplateResult;
|
|
14
78
|
}
|
|
15
79
|
|
|
80
|
+
declare type PieTooltipEvents = {
|
|
81
|
+
onPieTooltipClose?: (event: Event) => void;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export declare const positions: readonly ["top", "top-start", "top-end", "bottom", "bottom-start", "bottom-end", "left", "left-start", "left-end", "right", "right-start", "right-end"];
|
|
85
|
+
|
|
16
86
|
declare type ReactBaseType = React_2.HTMLAttributes<HTMLElement>;
|
|
17
87
|
|
|
88
|
+
export declare const sizes: readonly ["default", "fit-to-content", "fill-container"];
|
|
89
|
+
|
|
90
|
+
export declare type TooltipMode = typeof modes[number];
|
|
91
|
+
|
|
18
92
|
export declare interface TooltipProps {
|
|
93
|
+
/**
|
|
94
|
+
* The `id` of the element the panel is anchored to. The trigger lives elsewhere in the
|
|
95
|
+
* DOM and is never slotted into the tooltip.
|
|
96
|
+
*/
|
|
97
|
+
trigger?: string;
|
|
98
|
+
/**
|
|
99
|
+
* When true, the panel is visible. The component never writes to this property: the
|
|
100
|
+
* consumer owns it and updates it in response to the close event.
|
|
101
|
+
*/
|
|
102
|
+
isOpen?: boolean;
|
|
103
|
+
/**
|
|
104
|
+
* The side of the trigger the panel sits on, and its alignment along the cross axis.
|
|
105
|
+
*/
|
|
106
|
+
position?: typeof positions[number];
|
|
107
|
+
/**
|
|
108
|
+
* How the panel sizes itself. `default` is a fixed 280px and wraps, `fit-to-content` is as
|
|
109
|
+
* wide as its content, and `fill-container` matches the inline size of the trigger's parent
|
|
110
|
+
* element. Not applied when `type` is `icon`.
|
|
111
|
+
*/
|
|
112
|
+
size?: typeof sizes[number];
|
|
113
|
+
/**
|
|
114
|
+
* The colour treatment of the panel. `default` is the dark panel, `inverse` the light one.
|
|
115
|
+
*/
|
|
116
|
+
variant?: typeof variants[number];
|
|
117
|
+
/**
|
|
118
|
+
* The presentation of the panel. `icon` is the compact treatment intended for icon triggers:
|
|
119
|
+
* it has no arrow and is always as wide as its content, so `size` and `--tooltip-width` have
|
|
120
|
+
* no effect on it.
|
|
121
|
+
*/
|
|
122
|
+
type?: typeof types[number];
|
|
123
|
+
/**
|
|
124
|
+
* When true, a close button is rendered inside the panel.
|
|
125
|
+
*/
|
|
126
|
+
isDismissible?: boolean;
|
|
127
|
+
/**
|
|
128
|
+
* The text to display in the panel's heading. In dialog mode this also provides the
|
|
129
|
+
* panel's accessible name.
|
|
130
|
+
*/
|
|
131
|
+
heading?: string;
|
|
132
|
+
/**
|
|
133
|
+
* The HTML heading tag to use for the panel's heading. Can be h2-h6.
|
|
134
|
+
*/
|
|
135
|
+
headingLevel?: typeof headingLevels[number];
|
|
136
|
+
/**
|
|
137
|
+
* The ARIA labels used for various parts of the tooltip.
|
|
138
|
+
*/
|
|
139
|
+
aria?: AriaProps;
|
|
19
140
|
}
|
|
20
141
|
|
|
142
|
+
export declare const types: readonly ["default", "icon"];
|
|
143
|
+
|
|
144
|
+
export declare const variants: readonly ["default", "inverse"];
|
|
145
|
+
|
|
21
146
|
export { }
|
package/dist/react.js
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import * as o from "react";
|
|
2
|
-
import { createComponent as
|
|
3
|
-
import { PieTooltip as
|
|
4
|
-
|
|
2
|
+
import { createComponent as e } from "@lit/react";
|
|
3
|
+
import { PieTooltip as t } from "./index.js";
|
|
4
|
+
import { ON_TOOLTIP_CLOSE_EVENT as n, componentClass as r, componentSelector as c, defaultProps as T, headingLevels as P, modes as f, positions as C, sizes as d, types as N, variants as O } from "./index.js";
|
|
5
|
+
const i = e({
|
|
5
6
|
displayName: "PieTooltip",
|
|
6
|
-
elementClass:
|
|
7
|
+
elementClass: t,
|
|
7
8
|
react: o,
|
|
8
9
|
tagName: "pie-tooltip",
|
|
9
|
-
events: {
|
|
10
|
-
|
|
10
|
+
events: {
|
|
11
|
+
onPieTooltipClose: "pie-tooltip-close"
|
|
12
|
+
// When the close button is clicked. Set `isOpen` to `false` in response.
|
|
13
|
+
}
|
|
14
|
+
}), l = i;
|
|
11
15
|
export {
|
|
12
|
-
|
|
16
|
+
n as ON_TOOLTIP_CLOSE_EVENT,
|
|
17
|
+
l as PieTooltip,
|
|
18
|
+
r as componentClass,
|
|
19
|
+
c as componentSelector,
|
|
20
|
+
T as defaultProps,
|
|
21
|
+
P as headingLevels,
|
|
22
|
+
f as modes,
|
|
23
|
+
C as positions,
|
|
24
|
+
d as sizes,
|
|
25
|
+
N as types,
|
|
26
|
+
O as variants
|
|
13
27
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-tooltip",
|
|
3
3
|
"description": "PIE Design System Tooltip built using Web Components",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -36,11 +36,13 @@
|
|
|
36
36
|
"license": "Apache-2.0",
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@justeattakeaway/pie-components-config": "0.21.4",
|
|
39
|
-
"@justeattakeaway/pie-css": "1.
|
|
39
|
+
"@justeattakeaway/pie-css": "1.8.0",
|
|
40
40
|
"@justeattakeaway/pie-monorepo-utils": "0.9.9"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@justeattakeaway/pie-
|
|
43
|
+
"@justeattakeaway/pie-icon-button": "2.7.32",
|
|
44
|
+
"@justeattakeaway/pie-icons-webc": "1.29.1",
|
|
45
|
+
"@justeattakeaway/pie-webc-core": "21.0.0"
|
|
44
46
|
},
|
|
45
47
|
"customElements": "custom-elements.json",
|
|
46
48
|
"sideEffects": [
|
package/src/defs.ts
CHANGED
|
@@ -1,3 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { type ComponentDefaultProps } from '@justeattakeaway/pie-webc-core';
|
|
2
|
+
|
|
3
|
+
export const positions = [
|
|
4
|
+
'top',
|
|
5
|
+
'top-start',
|
|
6
|
+
'top-end',
|
|
7
|
+
'bottom',
|
|
8
|
+
'bottom-start',
|
|
9
|
+
'bottom-end',
|
|
10
|
+
'left',
|
|
11
|
+
'left-start',
|
|
12
|
+
'left-end',
|
|
13
|
+
'right',
|
|
14
|
+
'right-start',
|
|
15
|
+
'right-end',
|
|
16
|
+
] as const;
|
|
17
|
+
|
|
18
|
+
export const sizes = ['default', 'fit-to-content', 'fill-container'] as const;
|
|
19
|
+
export const variants = ['default', 'inverse'] as const;
|
|
20
|
+
export const types = ['default', 'icon'] as const;
|
|
21
|
+
export const headingLevels = ['h2', 'h3', 'h4', 'h5', 'h6'] as const;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The two patterns the panel can present as. Inferred from the `action` slot rather than
|
|
25
|
+
* configured: an empty `action` slot is a tooltip, a filled one is a non-modal dialog.
|
|
26
|
+
*/
|
|
27
|
+
export const modes = ['tooltip', 'dialog'] as const;
|
|
28
|
+
|
|
29
|
+
export type TooltipMode = typeof modes[number];
|
|
30
|
+
|
|
31
|
+
type AriaProps = {
|
|
32
|
+
/**
|
|
33
|
+
* The accessible name for the close button. Required whenever `isDismissible` is set.
|
|
34
|
+
*/
|
|
35
|
+
close?: string;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The accessible name for the panel in dialog mode. Only used when `heading` is not provided.
|
|
39
|
+
*/
|
|
40
|
+
label?: string;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export interface TooltipProps {
|
|
44
|
+
/**
|
|
45
|
+
* The `id` of the element the panel is anchored to. The trigger lives elsewhere in the
|
|
46
|
+
* DOM and is never slotted into the tooltip.
|
|
47
|
+
*/
|
|
48
|
+
trigger?: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* When true, the panel is visible. The component never writes to this property: the
|
|
52
|
+
* consumer owns it and updates it in response to the close event.
|
|
53
|
+
*/
|
|
54
|
+
isOpen?: boolean;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* The side of the trigger the panel sits on, and its alignment along the cross axis.
|
|
58
|
+
*/
|
|
59
|
+
position?: typeof positions[number];
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* How the panel sizes itself. `default` is a fixed 280px and wraps, `fit-to-content` is as
|
|
63
|
+
* wide as its content, and `fill-container` matches the inline size of the trigger's parent
|
|
64
|
+
* element. Not applied when `type` is `icon`.
|
|
65
|
+
*/
|
|
66
|
+
size?: typeof sizes[number];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* The colour treatment of the panel. `default` is the dark panel, `inverse` the light one.
|
|
70
|
+
*/
|
|
71
|
+
variant?: typeof variants[number];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The presentation of the panel. `icon` is the compact treatment intended for icon triggers:
|
|
75
|
+
* it has no arrow and is always as wide as its content, so `size` and `--tooltip-width` have
|
|
76
|
+
* no effect on it.
|
|
77
|
+
*/
|
|
78
|
+
type?: typeof types[number];
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* When true, a close button is rendered inside the panel.
|
|
82
|
+
*/
|
|
83
|
+
isDismissible?: boolean;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The text to display in the panel's heading. In dialog mode this also provides the
|
|
87
|
+
* panel's accessible name.
|
|
88
|
+
*/
|
|
89
|
+
heading?: string;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The HTML heading tag to use for the panel's heading. Can be h2-h6.
|
|
93
|
+
*/
|
|
94
|
+
headingLevel?: typeof headingLevels[number];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The ARIA labels used for various parts of the tooltip.
|
|
98
|
+
*/
|
|
99
|
+
aria?: AriaProps;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export const componentSelector = 'pie-tooltip';
|
|
103
|
+
export const componentClass = 'c-tooltip';
|
|
104
|
+
|
|
105
|
+
export const ON_TOOLTIP_CLOSE_EVENT = `${componentSelector}-close`;
|
|
106
|
+
|
|
107
|
+
export type DefaultProps = ComponentDefaultProps<TooltipProps, keyof Omit<TooltipProps, 'trigger' | 'heading' | 'aria'>>;
|
|
108
|
+
|
|
109
|
+
export const defaultProps: DefaultProps = {
|
|
110
|
+
isOpen: false,
|
|
111
|
+
position: 'top',
|
|
112
|
+
size: 'default',
|
|
113
|
+
variant: 'default',
|
|
114
|
+
type: 'default',
|
|
115
|
+
isDismissible: false,
|
|
116
|
+
headingLevel: 'h2',
|
|
117
|
+
};
|