@sebgroup/green-core 3.30.0 → 3.31.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/components/coachmark/coachmark.component.js +3 -1
- package/components/index.d.ts +1 -0
- package/components/index.js +1 -0
- package/components/popover/popover.component.js +16 -2
- package/components/tooltip/index.d.ts +1 -0
- package/components/tooltip/index.js +1 -0
- package/components/tooltip/tooltip.component.d.ts +52 -0
- package/components/tooltip/tooltip.component.js +339 -0
- package/components/tooltip/tooltip.d.ts +2 -0
- package/components/tooltip/tooltip.js +6 -0
- package/components/tooltip/tooltip.styles.d.ts +2 -0
- package/components/tooltip/tooltip.styles.js +120 -0
- package/custom-elements.json +26288 -25828
- package/gds-element.js +1 -1
- package/generated/mcp/components.json +13 -1
- package/generated/mcp/icons.json +1 -1
- package/generated/mcp/index.json +1 -1
- package/generated/mcp/tokens.json +1 -1
- package/generated/mcp/tooltip/angular.md +25 -0
- package/generated/mcp/tooltip/api.md +30 -0
- package/generated/mcp/tooltip/index.json +8 -0
- package/generated/mcp/tooltip/react.md +25 -0
- package/generated/react/index.d.ts +6 -5
- package/generated/react/index.js +6 -5
- package/generated/react/tooltip/index.d.ts +683 -0
- package/generated/react/tooltip/index.js +14 -0
- package/package.json +3 -1
- package/pure.d.ts +1 -0
- package/pure.js +1 -0
- package/utils/helpers/custom-element-scoping.js +1 -1
|
@@ -43,7 +43,9 @@ let GdsCoachmark = class extends GdsElement {
|
|
|
43
43
|
}
|
|
44
44
|
connectedCallback() {
|
|
45
45
|
super.connectedCallback();
|
|
46
|
-
document.addEventListener("click", () => {
|
|
46
|
+
document.addEventListener("click", (event) => {
|
|
47
|
+
const clickedOtherCoachmark = event.composedPath().some((node) => node instanceof GdsCoachmark && node !== this);
|
|
48
|
+
if (clickedOtherCoachmark) return;
|
|
47
49
|
setTimeout(() => {
|
|
48
50
|
__privateMethod(this, _GdsCoachmark_instances, updateCoachmarks_fn).call(this);
|
|
49
51
|
__privateMethod(this, _GdsCoachmark_instances, closeCoachMark_fn).call(this);
|
package/components/index.d.ts
CHANGED
package/components/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
__privateMethod,
|
|
6
6
|
__privateSet
|
|
7
7
|
} from "../../chunks/chunk.H2T4A5YY.js";
|
|
8
|
-
var _GdsPopover_instances, handleTriggerSlotChange_fn, _autoPositionCleanupFn, _isMobileViewport, _backdropEl, _clickOutsideTarget, registerClickOutside_fn, unregisterClickOutside_fn, _handleCancel, _dispatchUiStateEvent, _handleCloseButton, registerTriggerEvents_fn, unregisterTriggerEvents_fn, setupTriggerAttributes_fn, registerAutoPositioning_fn, _handleTriggerKeyDown, _handleTriggerClick, _focusFirstSlottedChild, _handleClickOutside, _handlePageScroll;
|
|
8
|
+
var _GdsPopover_instances, handleTriggerSlotChange_fn, _autoPositionCleanupFn, _isMobileViewport, _backdropEl, _clickOutsideTarget, _hideVirtKbAfterGesture, cancelPendingVirtKbHide_fn, registerClickOutside_fn, unregisterClickOutside_fn, _handleCancel, _dispatchUiStateEvent, _handleCloseButton, registerTriggerEvents_fn, unregisterTriggerEvents_fn, setupTriggerAttributes_fn, registerAutoPositioning_fn, _handleTriggerKeyDown, _handleTriggerClick, _focusFirstSlottedChild, _handleClickOutside, _handlePageScroll;
|
|
9
9
|
import { localized, msg } from "@lit/localize";
|
|
10
10
|
import { property, query, state } from "lit/decorators.js";
|
|
11
11
|
import { classMap } from "lit/directives/class-map.js";
|
|
@@ -67,6 +67,9 @@ let GdsPopover = class extends GdsElement {
|
|
|
67
67
|
// The node the click outside listener is currently attached to. Kept so that removal always
|
|
68
68
|
// targets the same node it was added to, even if the resolved target would differ by then.
|
|
69
69
|
__privateAdd(this, _clickOutsideTarget);
|
|
70
|
+
__privateAdd(this, _hideVirtKbAfterGesture, () => {
|
|
71
|
+
this._isVirtKbVisible = false;
|
|
72
|
+
});
|
|
70
73
|
__privateAdd(this, _handleCancel, () => {
|
|
71
74
|
if (__privateGet(this, _dispatchUiStateEvent).call(this, "cancel")) this.open = false;
|
|
72
75
|
});
|
|
@@ -165,9 +168,15 @@ let GdsPopover = class extends GdsElement {
|
|
|
165
168
|
const t = e.target;
|
|
166
169
|
if (t === this) return;
|
|
167
170
|
if (t.tagName === "INPUT" || t.tagName === "TEXTAREA") {
|
|
171
|
+
__privateMethod(this, _GdsPopover_instances, cancelPendingVirtKbHide_fn).call(this);
|
|
168
172
|
this._isVirtKbVisible = true;
|
|
169
173
|
} else {
|
|
170
|
-
this
|
|
174
|
+
__privateMethod(this, _GdsPopover_instances, cancelPendingVirtKbHide_fn).call(this);
|
|
175
|
+
window.addEventListener(
|
|
176
|
+
"pointerup",
|
|
177
|
+
__privateGet(this, _hideVirtKbAfterGesture),
|
|
178
|
+
{ once: true }
|
|
179
|
+
);
|
|
171
180
|
}
|
|
172
181
|
});
|
|
173
182
|
this.addEventListener("blurin", (_) => {
|
|
@@ -178,6 +187,7 @@ let GdsPopover = class extends GdsElement {
|
|
|
178
187
|
super.disconnectedCallback();
|
|
179
188
|
__privateMethod(this, _GdsPopover_instances, unregisterTriggerEvents_fn).call(this);
|
|
180
189
|
__privateMethod(this, _GdsPopover_instances, unregisterClickOutside_fn).call(this);
|
|
190
|
+
__privateMethod(this, _GdsPopover_instances, cancelPendingVirtKbHide_fn).call(this);
|
|
181
191
|
window.removeEventListener("scroll", __privateGet(this, _handlePageScroll));
|
|
182
192
|
}
|
|
183
193
|
render() {
|
|
@@ -270,6 +280,10 @@ _autoPositionCleanupFn = new WeakMap();
|
|
|
270
280
|
_isMobileViewport = new WeakMap();
|
|
271
281
|
_backdropEl = new WeakMap();
|
|
272
282
|
_clickOutsideTarget = new WeakMap();
|
|
283
|
+
_hideVirtKbAfterGesture = new WeakMap();
|
|
284
|
+
cancelPendingVirtKbHide_fn = function() {
|
|
285
|
+
window.removeEventListener("pointerup", __privateGet(this, _hideVirtKbAfterGesture));
|
|
286
|
+
};
|
|
273
287
|
registerClickOutside_fn = function() {
|
|
274
288
|
if (!this.open || !this.isConnected) return;
|
|
275
289
|
__privateMethod(this, _GdsPopover_instances, unregisterClickOutside_fn).call(this);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './tooltip';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./tooltip.js";
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Placement } from '@floating-ui/dom';
|
|
2
|
+
import { GdsElement } from '../../gds-element';
|
|
3
|
+
export type TooltipUIStateChangeReason = 'show' | 'close' | 'cancel';
|
|
4
|
+
/**
|
|
5
|
+
* @element gds-tooltip
|
|
6
|
+
*
|
|
7
|
+
* A tooltip shows short, supplementary text about an element on hover or keyboard focus.
|
|
8
|
+
*
|
|
9
|
+
* Point the tooltip at its trigger with the `for` attribute, using the id of the trigger element.
|
|
10
|
+
* The tooltip is linked to the trigger through `aria-describedby`, so it does not replace the
|
|
11
|
+
* accessible name of the trigger. An icon-only button still needs its own label.
|
|
12
|
+
*
|
|
13
|
+
* Use a popover instead when the content is interactive or needs to stay open.
|
|
14
|
+
*
|
|
15
|
+
* @event gds-ui-state - Fired when the tooltip is about to open or close. Can be cancelled to prevent the state change. The `detail` object contains the `open` boolean for the resulting state, and the `reason` string, which is one of `show`, `close` or `cancel`.
|
|
16
|
+
*
|
|
17
|
+
* @slot - The tooltip text.
|
|
18
|
+
*
|
|
19
|
+
* @status beta
|
|
20
|
+
*/
|
|
21
|
+
export declare class GdsTooltip extends GdsElement {
|
|
22
|
+
#private;
|
|
23
|
+
static styles: (import("lit").CSSResult | import("lit").CSSResult[])[];
|
|
24
|
+
/**
|
|
25
|
+
* Whether the tooltip is visible.
|
|
26
|
+
*/
|
|
27
|
+
open: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* The id of the trigger element. The id is resolved in the same document or shadow root as the tooltip.
|
|
30
|
+
*/
|
|
31
|
+
for?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The preferred placement of the tooltip relative to the trigger. The tooltip flips and shifts
|
|
34
|
+
* automatically when there is not enough space.
|
|
35
|
+
* Accepts any of the placements supported by Floating UI.
|
|
36
|
+
*/
|
|
37
|
+
placement: Placement;
|
|
38
|
+
/**
|
|
39
|
+
* Delay in milliseconds before the tooltip opens on hover. Keyboard focus opens it without delay,
|
|
40
|
+
* and so does hovering another trigger right after a tooltip was shown.
|
|
41
|
+
*/
|
|
42
|
+
delay: number;
|
|
43
|
+
private _side?;
|
|
44
|
+
private _multiline;
|
|
45
|
+
private _elContainer;
|
|
46
|
+
connectedCallback(): void;
|
|
47
|
+
disconnectedCallback(): void;
|
|
48
|
+
render(): any;
|
|
49
|
+
private _handleForChange;
|
|
50
|
+
private _handleOpenChange;
|
|
51
|
+
private _handlePlacementChange;
|
|
52
|
+
}
|
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__decorateClass,
|
|
3
|
+
__privateAdd,
|
|
4
|
+
__privateGet,
|
|
5
|
+
__privateMethod,
|
|
6
|
+
__privateSet
|
|
7
|
+
} from "../../chunks/chunk.H2T4A5YY.js";
|
|
8
|
+
var _trigger, _autoUpdateCleanup, _showTimeout, _hideTimeout, _triggerObserver, _resizeObserver, _suppressed, _GdsTooltip_instances, observeLineCount_fn, resolveTrigger_fn, connectTrigger_fn, disconnectTrigger_fn, observeTriggerReplacement_fn, triggerObservationRoot_fn, describedByAttr_fn, startPositioning_fn, stopPositioning_fn, updatePosition_fn, show_fn, hide_fn, dispatchUiStateEvent_fn, _handleTriggerPointerEnter, _handleTriggerPointerLeave, _handleTriggerPointerDown, _handleTriggerFocusIn, _handleTriggerFocusOut, _scheduleHide, _cancelHide, _handleDocumentKeydown;
|
|
9
|
+
import { property, query, state } from "lit/decorators.js";
|
|
10
|
+
import {
|
|
11
|
+
autoUpdate,
|
|
12
|
+
computePosition,
|
|
13
|
+
flip,
|
|
14
|
+
hide,
|
|
15
|
+
offset,
|
|
16
|
+
shift
|
|
17
|
+
} from "@floating-ui/dom";
|
|
18
|
+
import { GdsElement } from "../../gds-element.js";
|
|
19
|
+
import { gdsCustomElement, html } from "../../scoping.js";
|
|
20
|
+
import { tokens } from "../../tokens.style.js";
|
|
21
|
+
import { watch } from "../../utils/decorators/index.js";
|
|
22
|
+
import { randomId } from "../../utils/helpers/id.js";
|
|
23
|
+
import TooltipStyles from "./tooltip.styles.js";
|
|
24
|
+
const HIDE_DELAY = 100;
|
|
25
|
+
const SKIP_DELAY_WINDOW = 300;
|
|
26
|
+
const openTooltips = /* @__PURE__ */ new Set();
|
|
27
|
+
let lastClosedAt = 0;
|
|
28
|
+
let GdsTooltip = class extends GdsElement {
|
|
29
|
+
constructor() {
|
|
30
|
+
super(...arguments);
|
|
31
|
+
__privateAdd(this, _GdsTooltip_instances);
|
|
32
|
+
this.open = false;
|
|
33
|
+
this.placement = "top";
|
|
34
|
+
this.delay = 300;
|
|
35
|
+
this._multiline = false;
|
|
36
|
+
__privateAdd(this, _trigger);
|
|
37
|
+
__privateAdd(this, _autoUpdateCleanup);
|
|
38
|
+
__privateAdd(this, _showTimeout);
|
|
39
|
+
__privateAdd(this, _hideTimeout);
|
|
40
|
+
__privateAdd(this, _triggerObserver);
|
|
41
|
+
__privateAdd(this, _resizeObserver);
|
|
42
|
+
// Set by pressing the trigger, so the tooltip stays out of the way until the pointer leaves.
|
|
43
|
+
__privateAdd(this, _suppressed, false);
|
|
44
|
+
__privateAdd(this, _handleTriggerPointerEnter, (e) => {
|
|
45
|
+
if (e.pointerType === "touch" || __privateGet(this, _suppressed)) return;
|
|
46
|
+
__privateGet(this, _cancelHide).call(this);
|
|
47
|
+
clearTimeout(__privateGet(this, _showTimeout));
|
|
48
|
+
const skipDelay = openTooltips.size > 0 || Date.now() - lastClosedAt < SKIP_DELAY_WINDOW;
|
|
49
|
+
if (skipDelay) __privateMethod(this, _GdsTooltip_instances, show_fn).call(this);
|
|
50
|
+
else __privateSet(this, _showTimeout, setTimeout(() => __privateMethod(this, _GdsTooltip_instances, show_fn).call(this), this.delay));
|
|
51
|
+
});
|
|
52
|
+
__privateAdd(this, _handleTriggerPointerLeave, () => {
|
|
53
|
+
__privateSet(this, _suppressed, false);
|
|
54
|
+
__privateGet(this, _scheduleHide).call(this);
|
|
55
|
+
});
|
|
56
|
+
__privateAdd(this, _handleTriggerPointerDown, () => {
|
|
57
|
+
__privateSet(this, _suppressed, true);
|
|
58
|
+
__privateMethod(this, _GdsTooltip_instances, hide_fn).call(this, "close");
|
|
59
|
+
});
|
|
60
|
+
__privateAdd(this, _handleTriggerFocusIn, (e) => {
|
|
61
|
+
if (__privateGet(this, _suppressed)) return;
|
|
62
|
+
const focused = e.composedPath()[0];
|
|
63
|
+
if (focused instanceof Element && !focused.matches(":focus-visible")) return;
|
|
64
|
+
__privateGet(this, _cancelHide).call(this);
|
|
65
|
+
__privateMethod(this, _GdsTooltip_instances, show_fn).call(this);
|
|
66
|
+
});
|
|
67
|
+
__privateAdd(this, _handleTriggerFocusOut, (e) => {
|
|
68
|
+
const next = e.relatedTarget;
|
|
69
|
+
if (next instanceof Node && __privateGet(this, _trigger)?.contains(next)) return;
|
|
70
|
+
__privateSet(this, _suppressed, false);
|
|
71
|
+
__privateMethod(this, _GdsTooltip_instances, hide_fn).call(this, "close");
|
|
72
|
+
});
|
|
73
|
+
__privateAdd(this, _scheduleHide, () => {
|
|
74
|
+
clearTimeout(__privateGet(this, _showTimeout));
|
|
75
|
+
clearTimeout(__privateGet(this, _hideTimeout));
|
|
76
|
+
__privateSet(this, _hideTimeout, setTimeout(() => __privateMethod(this, _GdsTooltip_instances, hide_fn).call(this, "close"), HIDE_DELAY));
|
|
77
|
+
});
|
|
78
|
+
__privateAdd(this, _cancelHide, () => {
|
|
79
|
+
clearTimeout(__privateGet(this, _hideTimeout));
|
|
80
|
+
});
|
|
81
|
+
__privateAdd(this, _handleDocumentKeydown, (e) => {
|
|
82
|
+
if (e.key === "Escape" && __privateMethod(this, _GdsTooltip_instances, hide_fn).call(this, "cancel")) {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
connectedCallback() {
|
|
88
|
+
super.connectedCallback();
|
|
89
|
+
this.setAttribute("role", "tooltip");
|
|
90
|
+
this.setAttribute("popover", "manual");
|
|
91
|
+
if (!this.id) this.id = randomId();
|
|
92
|
+
this.addEventListener("pointerenter", __privateGet(this, _cancelHide));
|
|
93
|
+
this.addEventListener("pointerleave", __privateGet(this, _scheduleHide));
|
|
94
|
+
this.updateComplete.then(() => {
|
|
95
|
+
__privateMethod(this, _GdsTooltip_instances, connectTrigger_fn).call(this);
|
|
96
|
+
__privateMethod(this, _GdsTooltip_instances, observeTriggerReplacement_fn).call(this);
|
|
97
|
+
__privateMethod(this, _GdsTooltip_instances, observeLineCount_fn).call(this);
|
|
98
|
+
this._handleOpenChange();
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
disconnectedCallback() {
|
|
102
|
+
super.disconnectedCallback();
|
|
103
|
+
this.removeEventListener("pointerenter", __privateGet(this, _cancelHide));
|
|
104
|
+
this.removeEventListener("pointerleave", __privateGet(this, _scheduleHide));
|
|
105
|
+
clearTimeout(__privateGet(this, _showTimeout));
|
|
106
|
+
clearTimeout(__privateGet(this, _hideTimeout));
|
|
107
|
+
__privateGet(this, _triggerObserver)?.disconnect();
|
|
108
|
+
__privateSet(this, _triggerObserver, void 0);
|
|
109
|
+
__privateGet(this, _resizeObserver)?.disconnect();
|
|
110
|
+
__privateSet(this, _resizeObserver, void 0);
|
|
111
|
+
__privateMethod(this, _GdsTooltip_instances, stopPositioning_fn).call(this);
|
|
112
|
+
__privateMethod(this, _GdsTooltip_instances, disconnectTrigger_fn).call(this);
|
|
113
|
+
document.removeEventListener("keydown", __privateGet(this, _handleDocumentKeydown));
|
|
114
|
+
openTooltips.delete(this);
|
|
115
|
+
}
|
|
116
|
+
render() {
|
|
117
|
+
const side = this._side ?? this.placement.split("-")[0];
|
|
118
|
+
return html`<div
|
|
119
|
+
class="container side-${side} ${this._multiline ? "multiline" : ""}"
|
|
120
|
+
>
|
|
121
|
+
<slot></slot>
|
|
122
|
+
</div>`;
|
|
123
|
+
}
|
|
124
|
+
_handleForChange() {
|
|
125
|
+
if (!this.isConnected) return;
|
|
126
|
+
this.updateComplete.then(() => __privateMethod(this, _GdsTooltip_instances, connectTrigger_fn).call(this));
|
|
127
|
+
}
|
|
128
|
+
_handleOpenChange() {
|
|
129
|
+
this.updateComplete.then(() => {
|
|
130
|
+
if (!this.isConnected) return;
|
|
131
|
+
const supportsPopover = typeof this.showPopover === "function";
|
|
132
|
+
const isShowing = supportsPopover && this.matches(":popover-open");
|
|
133
|
+
if (this.open) {
|
|
134
|
+
openTooltips.add(this);
|
|
135
|
+
if (supportsPopover && !isShowing) this.showPopover();
|
|
136
|
+
__privateMethod(this, _GdsTooltip_instances, startPositioning_fn).call(this);
|
|
137
|
+
document.addEventListener("keydown", __privateGet(this, _handleDocumentKeydown));
|
|
138
|
+
} else {
|
|
139
|
+
if (openTooltips.delete(this)) lastClosedAt = Date.now();
|
|
140
|
+
if (isShowing) this.hidePopover();
|
|
141
|
+
__privateMethod(this, _GdsTooltip_instances, stopPositioning_fn).call(this);
|
|
142
|
+
document.removeEventListener("keydown", __privateGet(this, _handleDocumentKeydown));
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
_handlePlacementChange() {
|
|
147
|
+
this._side = void 0;
|
|
148
|
+
if (!this.open) return;
|
|
149
|
+
this.updateComplete.then(() => __privateMethod(this, _GdsTooltip_instances, startPositioning_fn).call(this));
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
_trigger = new WeakMap();
|
|
153
|
+
_autoUpdateCleanup = new WeakMap();
|
|
154
|
+
_showTimeout = new WeakMap();
|
|
155
|
+
_hideTimeout = new WeakMap();
|
|
156
|
+
_triggerObserver = new WeakMap();
|
|
157
|
+
_resizeObserver = new WeakMap();
|
|
158
|
+
_suppressed = new WeakMap();
|
|
159
|
+
_GdsTooltip_instances = new WeakSet();
|
|
160
|
+
// The content box excludes padding, so the padding change cannot flip the result back.
|
|
161
|
+
observeLineCount_fn = function() {
|
|
162
|
+
__privateGet(this, _resizeObserver)?.disconnect();
|
|
163
|
+
__privateSet(this, _resizeObserver, new ResizeObserver(([entry]) => {
|
|
164
|
+
const lineHeight = parseFloat(
|
|
165
|
+
getComputedStyle(this._elContainer).lineHeight
|
|
166
|
+
);
|
|
167
|
+
this._multiline = entry.contentRect.height > lineHeight * 1.5;
|
|
168
|
+
}));
|
|
169
|
+
__privateGet(this, _resizeObserver).observe(this._elContainer);
|
|
170
|
+
};
|
|
171
|
+
resolveTrigger_fn = function() {
|
|
172
|
+
if (!this.for) return void 0;
|
|
173
|
+
const root = this.getRootNode();
|
|
174
|
+
return root.getElementById?.(this.for) ?? this.ownerDocument.getElementById(this.for) ?? void 0;
|
|
175
|
+
};
|
|
176
|
+
connectTrigger_fn = function() {
|
|
177
|
+
const trigger = __privateMethod(this, _GdsTooltip_instances, resolveTrigger_fn).call(this);
|
|
178
|
+
if (trigger === __privateGet(this, _trigger)) return;
|
|
179
|
+
__privateMethod(this, _GdsTooltip_instances, disconnectTrigger_fn).call(this);
|
|
180
|
+
__privateSet(this, _trigger, trigger);
|
|
181
|
+
if (!trigger) return;
|
|
182
|
+
trigger.addEventListener("pointerenter", __privateGet(this, _handleTriggerPointerEnter));
|
|
183
|
+
trigger.addEventListener("pointerleave", __privateGet(this, _handleTriggerPointerLeave));
|
|
184
|
+
trigger.addEventListener("pointerdown", __privateGet(this, _handleTriggerPointerDown));
|
|
185
|
+
trigger.addEventListener("focusin", __privateGet(this, _handleTriggerFocusIn));
|
|
186
|
+
trigger.addEventListener("focusout", __privateGet(this, _handleTriggerFocusOut));
|
|
187
|
+
const attr = __privateMethod(this, _GdsTooltip_instances, describedByAttr_fn).call(this, trigger);
|
|
188
|
+
const ids = (trigger.getAttribute(attr) ?? "").split(/\s+/).filter(Boolean);
|
|
189
|
+
if (!ids.includes(this.id)) {
|
|
190
|
+
trigger.setAttribute(attr, [...ids, this.id].join(" "));
|
|
191
|
+
}
|
|
192
|
+
if (this.open) __privateMethod(this, _GdsTooltip_instances, startPositioning_fn).call(this);
|
|
193
|
+
};
|
|
194
|
+
disconnectTrigger_fn = function() {
|
|
195
|
+
const trigger = __privateGet(this, _trigger);
|
|
196
|
+
if (!trigger) return;
|
|
197
|
+
trigger.removeEventListener("pointerenter", __privateGet(this, _handleTriggerPointerEnter));
|
|
198
|
+
trigger.removeEventListener("pointerleave", __privateGet(this, _handleTriggerPointerLeave));
|
|
199
|
+
trigger.removeEventListener("pointerdown", __privateGet(this, _handleTriggerPointerDown));
|
|
200
|
+
trigger.removeEventListener("focusin", __privateGet(this, _handleTriggerFocusIn));
|
|
201
|
+
trigger.removeEventListener("focusout", __privateGet(this, _handleTriggerFocusOut));
|
|
202
|
+
const attr = __privateMethod(this, _GdsTooltip_instances, describedByAttr_fn).call(this, trigger);
|
|
203
|
+
const ids = (trigger.getAttribute(attr) ?? "").split(/\s+/).filter((id) => id && id !== this.id);
|
|
204
|
+
if (ids.length) trigger.setAttribute(attr, ids.join(" "));
|
|
205
|
+
else trigger.removeAttribute(attr);
|
|
206
|
+
__privateMethod(this, _GdsTooltip_instances, stopPositioning_fn).call(this);
|
|
207
|
+
__privateSet(this, _trigger, void 0);
|
|
208
|
+
__privateSet(this, _suppressed, false);
|
|
209
|
+
};
|
|
210
|
+
// Re-resolves the trigger when it is re-rendered, replaced, or its id changes.
|
|
211
|
+
observeTriggerReplacement_fn = function() {
|
|
212
|
+
__privateGet(this, _triggerObserver)?.disconnect();
|
|
213
|
+
__privateSet(this, _triggerObserver, new MutationObserver(() => {
|
|
214
|
+
if (this.for) __privateMethod(this, _GdsTooltip_instances, connectTrigger_fn).call(this);
|
|
215
|
+
}));
|
|
216
|
+
__privateGet(this, _triggerObserver).observe(__privateMethod(this, _GdsTooltip_instances, triggerObservationRoot_fn).call(this), {
|
|
217
|
+
childList: true,
|
|
218
|
+
subtree: true,
|
|
219
|
+
attributes: true,
|
|
220
|
+
attributeFilter: ["id"]
|
|
221
|
+
});
|
|
222
|
+
};
|
|
223
|
+
// Narrows the observer to the nearest ancestor shared with the trigger, so a document-wide
|
|
224
|
+
// mutation elsewhere doesn't re-run this tooltip's reconnect logic. Falls back to the tooltip's
|
|
225
|
+
// own parent when the trigger hasn't resolved yet.
|
|
226
|
+
triggerObservationRoot_fn = function() {
|
|
227
|
+
const trigger = __privateGet(this, _trigger) ?? __privateMethod(this, _GdsTooltip_instances, resolveTrigger_fn).call(this);
|
|
228
|
+
if (!trigger) return this.parentNode ?? this.getRootNode();
|
|
229
|
+
const ancestors = /* @__PURE__ */ new Set();
|
|
230
|
+
ancestors.add(this);
|
|
231
|
+
for (let n = this.parentNode; n; n = n.parentNode)
|
|
232
|
+
ancestors.add(n);
|
|
233
|
+
for (let n = trigger; n; n = n.parentNode) {
|
|
234
|
+
if (ancestors.has(n)) return n;
|
|
235
|
+
}
|
|
236
|
+
return this.getRootNode();
|
|
237
|
+
};
|
|
238
|
+
// GDS elements forward `gds-aria-*` to the element that carries their semantics.
|
|
239
|
+
describedByAttr_fn = function(trigger) {
|
|
240
|
+
return trigger.nodeName.startsWith("GDS-") ? "gds-aria-describedby" : "aria-describedby";
|
|
241
|
+
};
|
|
242
|
+
startPositioning_fn = function() {
|
|
243
|
+
__privateMethod(this, _GdsTooltip_instances, stopPositioning_fn).call(this);
|
|
244
|
+
const trigger = __privateGet(this, _trigger);
|
|
245
|
+
if (!trigger || !this.open) return;
|
|
246
|
+
__privateSet(this, _autoUpdateCleanup, autoUpdate(
|
|
247
|
+
trigger,
|
|
248
|
+
this,
|
|
249
|
+
() => __privateMethod(this, _GdsTooltip_instances, updatePosition_fn).call(this, trigger)
|
|
250
|
+
));
|
|
251
|
+
};
|
|
252
|
+
stopPositioning_fn = function() {
|
|
253
|
+
var _a;
|
|
254
|
+
(_a = __privateGet(this, _autoUpdateCleanup)) == null ? void 0 : _a.call(this);
|
|
255
|
+
__privateSet(this, _autoUpdateCleanup, void 0);
|
|
256
|
+
};
|
|
257
|
+
updatePosition_fn = async function(trigger) {
|
|
258
|
+
const { x, y, placement, middlewareData } = await computePosition(
|
|
259
|
+
trigger,
|
|
260
|
+
this,
|
|
261
|
+
{
|
|
262
|
+
placement: this.placement,
|
|
263
|
+
strategy: "fixed",
|
|
264
|
+
middleware: [offset(8), flip(), shift({ padding: 8 }), hide()]
|
|
265
|
+
}
|
|
266
|
+
);
|
|
267
|
+
this._side = placement.split("-")[0];
|
|
268
|
+
Object.assign(this.style, {
|
|
269
|
+
left: `${x}px`,
|
|
270
|
+
top: `${y}px`,
|
|
271
|
+
visibility: middlewareData.hide?.referenceHidden ? "hidden" : ""
|
|
272
|
+
});
|
|
273
|
+
};
|
|
274
|
+
show_fn = function() {
|
|
275
|
+
clearTimeout(__privateGet(this, _showTimeout));
|
|
276
|
+
if (this.open) return;
|
|
277
|
+
if (__privateMethod(this, _GdsTooltip_instances, dispatchUiStateEvent_fn).call(this, "show")) this.open = true;
|
|
278
|
+
};
|
|
279
|
+
hide_fn = function(reason) {
|
|
280
|
+
clearTimeout(__privateGet(this, _showTimeout));
|
|
281
|
+
clearTimeout(__privateGet(this, _hideTimeout));
|
|
282
|
+
if (!this.open) return false;
|
|
283
|
+
if (!__privateMethod(this, _GdsTooltip_instances, dispatchUiStateEvent_fn).call(this, reason)) return false;
|
|
284
|
+
this.open = false;
|
|
285
|
+
return true;
|
|
286
|
+
};
|
|
287
|
+
dispatchUiStateEvent_fn = function(reason) {
|
|
288
|
+
return this.dispatchCustomEvent("gds-ui-state", {
|
|
289
|
+
detail: { open: reason === "show", reason },
|
|
290
|
+
bubbles: false,
|
|
291
|
+
composed: false,
|
|
292
|
+
cancelable: true
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
_handleTriggerPointerEnter = new WeakMap();
|
|
296
|
+
_handleTriggerPointerLeave = new WeakMap();
|
|
297
|
+
_handleTriggerPointerDown = new WeakMap();
|
|
298
|
+
_handleTriggerFocusIn = new WeakMap();
|
|
299
|
+
_handleTriggerFocusOut = new WeakMap();
|
|
300
|
+
_scheduleHide = new WeakMap();
|
|
301
|
+
_cancelHide = new WeakMap();
|
|
302
|
+
_handleDocumentKeydown = new WeakMap();
|
|
303
|
+
GdsTooltip.styles = [tokens, TooltipStyles];
|
|
304
|
+
__decorateClass([
|
|
305
|
+
property({ type: Boolean, reflect: true })
|
|
306
|
+
], GdsTooltip.prototype, "open", 2);
|
|
307
|
+
__decorateClass([
|
|
308
|
+
property({ attribute: "for" })
|
|
309
|
+
], GdsTooltip.prototype, "for", 2);
|
|
310
|
+
__decorateClass([
|
|
311
|
+
property()
|
|
312
|
+
], GdsTooltip.prototype, "placement", 2);
|
|
313
|
+
__decorateClass([
|
|
314
|
+
property({ type: Number })
|
|
315
|
+
], GdsTooltip.prototype, "delay", 2);
|
|
316
|
+
__decorateClass([
|
|
317
|
+
state()
|
|
318
|
+
], GdsTooltip.prototype, "_side", 2);
|
|
319
|
+
__decorateClass([
|
|
320
|
+
state()
|
|
321
|
+
], GdsTooltip.prototype, "_multiline", 2);
|
|
322
|
+
__decorateClass([
|
|
323
|
+
query(".container")
|
|
324
|
+
], GdsTooltip.prototype, "_elContainer", 2);
|
|
325
|
+
__decorateClass([
|
|
326
|
+
watch("for")
|
|
327
|
+
], GdsTooltip.prototype, "_handleForChange", 1);
|
|
328
|
+
__decorateClass([
|
|
329
|
+
watch("open")
|
|
330
|
+
], GdsTooltip.prototype, "_handleOpenChange", 1);
|
|
331
|
+
__decorateClass([
|
|
332
|
+
watch("placement")
|
|
333
|
+
], GdsTooltip.prototype, "_handlePlacementChange", 1);
|
|
334
|
+
GdsTooltip = __decorateClass([
|
|
335
|
+
gdsCustomElement("gds-tooltip")
|
|
336
|
+
], GdsTooltip);
|
|
337
|
+
export {
|
|
338
|
+
GdsTooltip
|
|
339
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import "../../chunks/chunk.H2T4A5YY.js";
|
|
2
|
+
import { css } from "lit";
|
|
3
|
+
const style = css`
|
|
4
|
+
@layer base {
|
|
5
|
+
:host {
|
|
6
|
+
--_max-width: 28ch;
|
|
7
|
+
--_padding-block: var(--gds-sys-space-2xs);
|
|
8
|
+
--_padding-inline: var(--gds-sys-space-s);
|
|
9
|
+
--_radius: var(--gds-sys-radius-max);
|
|
10
|
+
--_enter-duration: var(--gds-sys-motion-duration-fastest);
|
|
11
|
+
--_exit-duration: calc(var(--_enter-duration) / 2);
|
|
12
|
+
--_scale-from: 0.6;
|
|
13
|
+
/* Same zero-velocity curves as the indeterminate progress, so motion settles instead of stopping */
|
|
14
|
+
--_easing-lead: cubic-bezier(0.2, 0, 0.3, 1);
|
|
15
|
+
--_easing-trail: cubic-bezier(0.7, 0, 0.8, 1);
|
|
16
|
+
|
|
17
|
+
/* Reset the UA popover styles, the host is positioned by Floating UI */
|
|
18
|
+
position: fixed;
|
|
19
|
+
inset: auto;
|
|
20
|
+
margin: 0;
|
|
21
|
+
padding: 0;
|
|
22
|
+
border: 0;
|
|
23
|
+
background: transparent;
|
|
24
|
+
color: inherit;
|
|
25
|
+
overflow: visible;
|
|
26
|
+
width: max-content;
|
|
27
|
+
height: auto;
|
|
28
|
+
pointer-events: auto;
|
|
29
|
+
/* Keeps the host rendered, and in the top layer, until the exit transition has finished */
|
|
30
|
+
transition:
|
|
31
|
+
display var(--_exit-duration) allow-discrete,
|
|
32
|
+
overlay var(--_exit-duration) allow-discrete;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
:host(:not([open])) {
|
|
36
|
+
display: none;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* Without the Popover API there is no top layer to render in */
|
|
40
|
+
@supports not selector(:popover-open) {
|
|
41
|
+
:host {
|
|
42
|
+
z-index: 1060;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.container {
|
|
47
|
+
box-sizing: border-box;
|
|
48
|
+
/* The text width stays the same when the padding grows on wrapped text */
|
|
49
|
+
max-inline-size: min(
|
|
50
|
+
calc(var(--_max-width) + 2 * var(--_padding-inline)),
|
|
51
|
+
calc(100vw - var(--gds-sys-space-m))
|
|
52
|
+
);
|
|
53
|
+
padding: var(--_padding-block) var(--_padding-inline);
|
|
54
|
+
border-radius: var(--_radius);
|
|
55
|
+
background-color: var(--gds-sys-color-l3-neutral-03);
|
|
56
|
+
color: var(--gds-sys-color-content-neutral-03);
|
|
57
|
+
font: var(--gds-sys-text-detail-s-regular);
|
|
58
|
+
overflow-wrap: break-word;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.container.multiline {
|
|
62
|
+
--_padding-block: var(--gds-sys-space-s);
|
|
63
|
+
--_padding-inline: var(--gds-sys-space-s);
|
|
64
|
+
--_radius: var(--gds-sys-radius-s);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/* The bubble grows from the edge that faces the trigger */
|
|
68
|
+
.side-top {
|
|
69
|
+
transform-origin: 50% 100%;
|
|
70
|
+
}
|
|
71
|
+
.side-bottom {
|
|
72
|
+
transform-origin: 50% 0;
|
|
73
|
+
}
|
|
74
|
+
.side-left {
|
|
75
|
+
transform-origin: 100% 50%;
|
|
76
|
+
}
|
|
77
|
+
.side-right {
|
|
78
|
+
transform-origin: 0 50%;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
:host([open]) .container {
|
|
82
|
+
scale: 1;
|
|
83
|
+
opacity: 1;
|
|
84
|
+
transition:
|
|
85
|
+
scale var(--_enter-duration) var(--_easing-lead),
|
|
86
|
+
opacity var(--_enter-duration) var(--_easing-lead);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
:host(:not([open])) .container {
|
|
90
|
+
scale: var(--_scale-from);
|
|
91
|
+
opacity: 0;
|
|
92
|
+
transition:
|
|
93
|
+
scale var(--_exit-duration) var(--_easing-trail),
|
|
94
|
+
opacity var(--_exit-duration) var(--_easing-trail);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@starting-style {
|
|
98
|
+
:host([open]) .container {
|
|
99
|
+
scale: var(--_scale-from);
|
|
100
|
+
opacity: 0;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
@media (prefers-reduced-motion: reduce) {
|
|
105
|
+
:host {
|
|
106
|
+
--_scale-from: 1;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
@media (forced-colors: active) {
|
|
111
|
+
.container {
|
|
112
|
+
border: var(--gds-sys-space-5xs) solid CanvasText;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
`;
|
|
117
|
+
var tooltip_styles_default = style;
|
|
118
|
+
export {
|
|
119
|
+
tooltip_styles_default as default
|
|
120
|
+
};
|