@sebgroup/green-core 3.30.0 → 3.32.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/form-summary/summary.component.d.ts +3 -0
- package/components/form-summary/summary.component.js +17 -16
- 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 +15281 -14800
- package/gds-element.js +1 -1
- package/generated/locales/da.d.ts +5 -0
- package/generated/locales/da.js +5 -0
- package/generated/locales/de.d.ts +5 -0
- package/generated/locales/de.js +5 -0
- package/generated/locales/fi.d.ts +5 -0
- package/generated/locales/fi.js +5 -0
- package/generated/locales/fr.d.ts +5 -0
- package/generated/locales/fr.js +5 -0
- package/generated/locales/it.d.ts +5 -0
- package/generated/locales/it.js +5 -0
- package/generated/locales/nl.d.ts +5 -0
- package/generated/locales/nl.js +5 -0
- package/generated/locales/no.d.ts +5 -0
- package/generated/locales/no.js +5 -0
- package/generated/locales/sv.d.ts +5 -0
- package/generated/locales/sv.js +5 -0
- package/generated/mcp/alert/guidelines.md +105 -0
- package/generated/mcp/alert/index.json +1 -0
- package/generated/mcp/avatar/guidelines.md +40 -0
- package/generated/mcp/avatar/index.json +1 -0
- package/generated/mcp/badge/guidelines.md +56 -0
- package/generated/mcp/badge/index.json +1 -0
- package/generated/mcp/blur/guidelines.md +3 -0
- package/generated/mcp/blur/index.json +1 -0
- package/generated/mcp/breadcrumbs/guidelines.md +35 -0
- package/generated/mcp/breadcrumbs/index.json +1 -0
- package/generated/mcp/button/guidelines.md +83 -0
- package/generated/mcp/button/index.json +1 -0
- package/generated/mcp/calendar/guidelines.md +3 -0
- package/generated/mcp/calendar/index.json +1 -0
- package/generated/mcp/card/guidelines.md +78 -0
- package/generated/mcp/card/index.json +1 -0
- package/generated/mcp/card-pattern-01/guidelines.md +52 -0
- package/generated/mcp/card-pattern-01/index.json +1 -0
- package/generated/mcp/checkbox/guidelines.md +91 -0
- package/generated/mcp/checkbox/index.json +1 -0
- package/generated/mcp/coachmark/guidelines.md +8 -0
- package/generated/mcp/coachmark/index.json +1 -0
- package/generated/mcp/components.json +59 -1
- package/generated/mcp/context-menu/guidelines.md +33 -0
- package/generated/mcp/context-menu/index.json +1 -0
- package/generated/mcp/datepicker/guidelines.md +44 -0
- package/generated/mcp/datepicker/index.json +1 -0
- package/generated/mcp/details/guidelines.md +24 -0
- package/generated/mcp/details/index.json +1 -0
- package/generated/mcp/dialog/guidelines.md +35 -0
- package/generated/mcp/dialog/index.json +1 -0
- package/generated/mcp/div/guidelines.md +3 -0
- package/generated/mcp/div/index.json +1 -0
- package/generated/mcp/divider/guidelines.md +24 -0
- package/generated/mcp/divider/index.json +1 -0
- package/generated/mcp/dropdown/guidelines.md +96 -0
- package/generated/mcp/dropdown/index.json +1 -0
- package/generated/mcp/fab/guidelines.md +27 -0
- package/generated/mcp/fab/index.json +1 -0
- package/generated/mcp/filter-chips/guidelines.md +47 -0
- package/generated/mcp/filter-chips/index.json +1 -0
- package/generated/mcp/flex/guidelines.md +1 -0
- package/generated/mcp/flex/index.json +1 -0
- package/generated/mcp/form-summary/angular.md +8 -0
- package/generated/mcp/form-summary/api.md +7 -0
- package/generated/mcp/form-summary/guidelines.md +39 -0
- package/generated/mcp/form-summary/index.json +1 -0
- package/generated/mcp/form-summary/react.md +8 -0
- package/generated/mcp/grid/guidelines.md +3 -0
- package/generated/mcp/grid/index.json +1 -0
- package/generated/mcp/icons.json +1 -1
- package/generated/mcp/index.json +1 -1
- package/generated/mcp/input/guidelines.md +127 -0
- package/generated/mcp/input/index.json +1 -0
- package/generated/mcp/link/guidelines.md +43 -0
- package/generated/mcp/link/index.json +1 -0
- package/generated/mcp/list/guidelines.md +16 -0
- package/generated/mcp/list/index.json +1 -0
- package/generated/mcp/list-item-pattern-01/guidelines.md +49 -0
- package/generated/mcp/list-item-pattern-01/index.json +1 -0
- package/generated/mcp/menu-button/guidelines.md +39 -0
- package/generated/mcp/menu-button/index.json +1 -0
- package/generated/mcp/pagination/guidelines.md +24 -0
- package/generated/mcp/pagination/index.json +1 -0
- package/generated/mcp/popover/guidelines.md +3 -0
- package/generated/mcp/popover/index.json +1 -0
- package/generated/mcp/progress/guidelines.md +42 -0
- package/generated/mcp/progress/index.json +1 -0
- package/generated/mcp/radio/guidelines.md +74 -0
- package/generated/mcp/radio/index.json +1 -0
- package/generated/mcp/rich-text/guidelines.md +3 -0
- package/generated/mcp/rich-text/index.json +1 -0
- package/generated/mcp/segmented-control/guidelines.md +31 -0
- package/generated/mcp/segmented-control/index.json +1 -0
- package/generated/mcp/select/guidelines.md +29 -0
- package/generated/mcp/select/index.json +1 -0
- package/generated/mcp/signal/guidelines.md +14 -0
- package/generated/mcp/signal/index.json +1 -0
- package/generated/mcp/slider/guidelines.md +86 -0
- package/generated/mcp/slider/index.json +1 -0
- package/generated/mcp/spinner/guidelines.md +6 -0
- package/generated/mcp/spinner/index.json +1 -0
- package/generated/mcp/switch/guidelines.md +41 -0
- package/generated/mcp/switch/index.json +1 -0
- package/generated/mcp/table/guidelines.md +169 -0
- package/generated/mcp/table/index.json +1 -0
- package/generated/mcp/tabs/guidelines.md +64 -0
- package/generated/mcp/tabs/index.json +1 -0
- package/generated/mcp/text/guidelines.md +3 -0
- package/generated/mcp/text/index.json +1 -0
- package/generated/mcp/textarea/guidelines.md +73 -0
- package/generated/mcp/textarea/index.json +1 -0
- package/generated/mcp/theme/guidelines.md +3 -0
- package/generated/mcp/theme/index.json +1 -0
- 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/guidelines.md +107 -0
- package/generated/mcp/tooltip/index.json +9 -0
- package/generated/mcp/tooltip/react.md +25 -0
- package/generated/mcp/video/guidelines.md +3 -0
- package/generated/mcp/video/index.json +1 -0
- package/generated/react/form-summary/index.d.ts +6 -1
- package/generated/react/index.d.ts +11 -10
- package/generated/react/index.js +11 -10
- 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);
|
|
@@ -8,6 +8,9 @@ import { GdsElement } from '../../gds-element';
|
|
|
8
8
|
* in a consolidated manner. It provides a clear indication of what went wrong and what needs to be corrected.
|
|
9
9
|
*
|
|
10
10
|
* @slot header - Optional slot for customizing the header of the summary.
|
|
11
|
+
*
|
|
12
|
+
* @event gds-control-focus - Fired when an item in the summary is clicked, before focus moves to the related control.
|
|
13
|
+
* The detail object contains the control. Can be cancelled with event.preventDefault() to handle focus yourself.
|
|
11
14
|
*/
|
|
12
15
|
export declare class GdsFormSummary extends GdsElement {
|
|
13
16
|
#private;
|
|
@@ -7,9 +7,7 @@ import {
|
|
|
7
7
|
} from "../../chunks/chunk.H2T4A5YY.js";
|
|
8
8
|
var _form, _formObserver, _GdsFormSummary_instances, renderControlItem_fn, groupByFieldset_fn, getFormControls_fn, getErrorControls_fn, renderArrowIcon_fn;
|
|
9
9
|
import { msg, str } from "@lit/localize";
|
|
10
|
-
import { nothing } from "lit";
|
|
11
10
|
import { property, queryAsync } from "lit/decorators.js";
|
|
12
|
-
import { until } from "lit/directives/until.js";
|
|
13
11
|
import { when } from "lit/directives/when.js";
|
|
14
12
|
import { GdsElement } from "../../gds-element.js";
|
|
15
13
|
import { gdsCustomElement, html } from "../../scoping.js";
|
|
@@ -43,9 +41,9 @@ let GdsFormSummary = class extends GdsElement {
|
|
|
43
41
|
* Focuses the first focusable element in the summary.
|
|
44
42
|
*/
|
|
45
43
|
focus(options) {
|
|
46
|
-
this._elRoot.then((el) => {
|
|
47
|
-
const firstFocusable = el
|
|
48
|
-
'[gds-element="gds-button"]'
|
|
44
|
+
void this._elRoot.then((el) => {
|
|
45
|
+
const firstFocusable = el?.querySelector(
|
|
46
|
+
'li.item:not([inert]) [gds-element="gds-button"]'
|
|
49
47
|
);
|
|
50
48
|
if (firstFocusable) {
|
|
51
49
|
firstFocusable.focus(options);
|
|
@@ -89,7 +87,6 @@ let GdsFormSummary = class extends GdsElement {
|
|
|
89
87
|
border-color="negative-01"
|
|
90
88
|
border-radius="m"
|
|
91
89
|
overflow="hidden"
|
|
92
|
-
aria-describedby="description"
|
|
93
90
|
aria-label=${msg(`Form error summary`)}
|
|
94
91
|
>
|
|
95
92
|
<gds-flex gap="0" flex-direction="column">
|
|
@@ -137,6 +134,7 @@ _form = new WeakMap();
|
|
|
137
134
|
_formObserver = new WeakMap();
|
|
138
135
|
_GdsFormSummary_instances = new WeakSet();
|
|
139
136
|
renderControlItem_fn = function(el) {
|
|
137
|
+
const label = el.dataset.label || el.label || el.ariaLabel;
|
|
140
138
|
return html`<li
|
|
141
139
|
class="item"
|
|
142
140
|
?inert=${!(el.ariaInvalid === "true" || el.invalid)}
|
|
@@ -155,20 +153,23 @@ renderControlItem_fn = function(el) {
|
|
|
155
153
|
padding="xs s"
|
|
156
154
|
@click=${(e) => {
|
|
157
155
|
e.preventDefault();
|
|
158
|
-
|
|
156
|
+
const proceed = this.dispatchCustomEvent("gds-control-focus", {
|
|
157
|
+
detail: { control: el },
|
|
158
|
+
bubbles: false,
|
|
159
|
+
composed: false
|
|
160
|
+
});
|
|
161
|
+
if (proceed) el.focus();
|
|
159
162
|
}}
|
|
160
163
|
>
|
|
161
164
|
<div>
|
|
162
|
-
<gds-div font-weight="book"
|
|
163
|
-
>${el.dataset.label || el.label || el.ariaLabel}</gds-div
|
|
164
|
-
>
|
|
165
|
+
<gds-div font-weight="book">${label}</gds-div>
|
|
165
166
|
</div>
|
|
166
167
|
<gds-button
|
|
167
168
|
size="xs"
|
|
168
169
|
rank="secondary"
|
|
169
|
-
label=${`Move focus to ${
|
|
170
|
+
label=${msg(str`Move focus to ${label} field`)}
|
|
170
171
|
>
|
|
171
|
-
${
|
|
172
|
+
${__privateMethod(this, _GdsFormSummary_instances, renderArrowIcon_fn).call(this, el)}
|
|
172
173
|
</gds-button>
|
|
173
174
|
</gds-card>
|
|
174
175
|
</li>`;
|
|
@@ -204,10 +205,10 @@ getErrorControls_fn = function() {
|
|
|
204
205
|
(el) => el.ariaInvalid === "true" || el.invalid
|
|
205
206
|
);
|
|
206
207
|
};
|
|
207
|
-
renderArrowIcon_fn =
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
208
|
+
renderArrowIcon_fn = function(el) {
|
|
209
|
+
const isAbove = Boolean(
|
|
210
|
+
this.compareDocumentPosition(el) & Node.DOCUMENT_POSITION_PRECEDING
|
|
211
|
+
);
|
|
211
212
|
return when(
|
|
212
213
|
isAbove,
|
|
213
214
|
() => html`<gds-icon-arrow-up></gds-icon-arrow-up>`,
|
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
|
+
};
|