@nectary/components 5.50.7 → 5.51.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/bundle.js +76 -10
- package/package.json +1 -1
- package/popover/types.d.ts +1 -1
- package/popover/utils.js +3 -1
- package/tooltip/index.js +73 -9
- package/tooltip/types.d.ts +5 -2
package/bundle.js
CHANGED
|
@@ -4461,7 +4461,7 @@ const getPopOrientation$1 = (orientation) => {
|
|
|
4461
4461
|
}
|
|
4462
4462
|
return orientation;
|
|
4463
4463
|
};
|
|
4464
|
-
const templateHTML$Y = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content" role="tooltip"><sinch-text id="text" type="s"></sinch-text><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
|
|
4464
|
+
const templateHTML$Y = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#text.hidden{display:none}#content-slot{display:block;font:var(--sinch-comp-tooltip-font-body);color:var(--sinch-comp-tooltip-color-text);word-break:break-word}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}:host([text-align=right]) #content-slot{text-align:right}:host([text-align=center]) #content-slot{text-align:center}:host([text-align=left]) #content-slot{text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content" role="tooltip"><sinch-text id="text" type="s"></sinch-text><slot id="content-slot"></slot><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
|
|
4465
4465
|
const TIP_SIZE$1 = 8;
|
|
4466
4466
|
const SHOW_DELAY_SLOW = 1e3;
|
|
4467
4467
|
const SHOW_DELAY_FAST = 250;
|
|
@@ -4469,6 +4469,7 @@ const HIDE_DELAY = 0;
|
|
|
4469
4469
|
const ANIMATION_DURATION = 100;
|
|
4470
4470
|
const FOCUSABLE_OUTSIDE_TARGET_SELECTOR = 'a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"]), [contenteditable=""], [contenteditable="true"]';
|
|
4471
4471
|
const OPEN_FLOATING_LAYER_SELECTOR = "sinch-popover[open], sinch-pop[open], dialog[open]";
|
|
4472
|
+
const CONTENT_SLOT_NAME = "tooltip-content";
|
|
4472
4473
|
const OVERLAP_TOLERANCE = 1;
|
|
4473
4474
|
const MAX_ZERO_DIMENSION_PLACEMENT_RETRIES = 8;
|
|
4474
4475
|
const MIN_FIRST_REVEAL_STABILITY_FRAMES = 3;
|
|
@@ -4479,6 +4480,17 @@ let hoveredTooltip = null;
|
|
|
4479
4480
|
let suspendedFocusedTooltip = null;
|
|
4480
4481
|
const template$Y = document.createElement("template");
|
|
4481
4482
|
template$Y.innerHTML = templateHTML$Y;
|
|
4483
|
+
const TEXT_BREAK_TAGS = ["BR", "P", "DIV", "UL", "OL", "LI"];
|
|
4484
|
+
function getNodeText(node) {
|
|
4485
|
+
if (!(node instanceof Element)) {
|
|
4486
|
+
return node.textContent ?? "";
|
|
4487
|
+
}
|
|
4488
|
+
let text = "";
|
|
4489
|
+
for (const child of node.childNodes) {
|
|
4490
|
+
text += child instanceof Element && TEXT_BREAK_TAGS.includes(child.tagName) ? ` ${getNodeText(child)} ` : getNodeText(child);
|
|
4491
|
+
}
|
|
4492
|
+
return text;
|
|
4493
|
+
}
|
|
4482
4494
|
class Tooltip extends NectaryElement {
|
|
4483
4495
|
#$pop;
|
|
4484
4496
|
#$tooltipText;
|
|
@@ -4486,6 +4498,7 @@ class Tooltip extends NectaryElement {
|
|
|
4486
4498
|
#$contentWrapper;
|
|
4487
4499
|
#$tip;
|
|
4488
4500
|
#$target;
|
|
4501
|
+
#$contentSlot;
|
|
4489
4502
|
#targetElements = [];
|
|
4490
4503
|
#resizeObserver = null;
|
|
4491
4504
|
#tooltipState;
|
|
@@ -4512,6 +4525,7 @@ class Tooltip extends NectaryElement {
|
|
|
4512
4525
|
this.#$contentWrapper = shadowRoot.querySelector("#content-wrapper");
|
|
4513
4526
|
this.#$tip = shadowRoot.querySelector("#tip");
|
|
4514
4527
|
this.#$target = shadowRoot.querySelector("#target");
|
|
4528
|
+
this.#$contentSlot = shadowRoot.querySelector("#content-slot");
|
|
4515
4529
|
this.#shouldReduceMotion = shouldReduceMotion();
|
|
4516
4530
|
this.#controller = null;
|
|
4517
4531
|
this.#tooltipState = new TooltipState({
|
|
@@ -4532,11 +4546,26 @@ class Tooltip extends NectaryElement {
|
|
|
4532
4546
|
};
|
|
4533
4547
|
this.#$pop.addEventListener("-close", this.#onPopClose, options);
|
|
4534
4548
|
this.#$target.addEventListener("slotchange", this.#onTargetSlotChange, options);
|
|
4549
|
+
this.#$contentSlot.addEventListener("slotchange", this.#onContentSlotChange, options);
|
|
4535
4550
|
this.#assignTargetNodes();
|
|
4536
|
-
this.#childObserver = new MutationObserver(() => {
|
|
4537
|
-
|
|
4551
|
+
this.#childObserver = new MutationObserver((mutations) => {
|
|
4552
|
+
const affectsAssignment = mutations.some((mutation) => {
|
|
4553
|
+
return mutation.type === "childList" ? mutation.target === this : mutation.target.parentNode === this;
|
|
4554
|
+
});
|
|
4555
|
+
if (affectsAssignment) {
|
|
4556
|
+
this.#assignTargetNodes();
|
|
4557
|
+
}
|
|
4558
|
+
if (this.#hasSlottedContent()) {
|
|
4559
|
+
this.#updatePopA11yAttrs();
|
|
4560
|
+
}
|
|
4561
|
+
});
|
|
4562
|
+
this.#childObserver.observe(this, {
|
|
4563
|
+
childList: true,
|
|
4564
|
+
subtree: true,
|
|
4565
|
+
characterData: true,
|
|
4566
|
+
attributes: true,
|
|
4567
|
+
attributeFilter: ["slot", "text"]
|
|
4538
4568
|
});
|
|
4539
|
-
this.#childObserver.observe(this, { childList: true });
|
|
4540
4569
|
this.addEventListener("-show", this.#onShowReactHandler, options);
|
|
4541
4570
|
this.addEventListener("-hide", this.#onHideReactHandler, options);
|
|
4542
4571
|
this.#resizeObserver = new ResizeObserver(() => {
|
|
@@ -4841,7 +4870,18 @@ class Tooltip extends NectaryElement {
|
|
|
4841
4870
|
const nodes = Array.from(this.childNodes).filter(
|
|
4842
4871
|
(node) => node instanceof Element || node instanceof Text
|
|
4843
4872
|
);
|
|
4844
|
-
|
|
4873
|
+
const contentNodes = nodes.filter((node) => {
|
|
4874
|
+
return node instanceof Element && node.getAttribute("slot") === CONTENT_SLOT_NAME;
|
|
4875
|
+
});
|
|
4876
|
+
const targetNodes = nodes.filter((node) => !contentNodes.includes(node));
|
|
4877
|
+
this.#$target.assign(...targetNodes);
|
|
4878
|
+
this.#$contentSlot.assign(...contentNodes);
|
|
4879
|
+
}
|
|
4880
|
+
#hasSlottedContent() {
|
|
4881
|
+
return this.#$contentSlot.assignedNodes().length !== 0;
|
|
4882
|
+
}
|
|
4883
|
+
#hasContent() {
|
|
4884
|
+
return this.text.length !== 0 || this.#hasSlottedContent();
|
|
4845
4885
|
}
|
|
4846
4886
|
#targetContains(node) {
|
|
4847
4887
|
return this.#$target.assignedElements().some((el) => composedContains(el, node));
|
|
@@ -5188,14 +5228,23 @@ class Tooltip extends NectaryElement {
|
|
|
5188
5228
|
}
|
|
5189
5229
|
const text = this.text;
|
|
5190
5230
|
this.#$tooltipText.textContent = text;
|
|
5191
|
-
if (
|
|
5231
|
+
if (this.#hasContent()) {
|
|
5192
5232
|
this.#subscribeMouseEnterEvent();
|
|
5193
5233
|
}
|
|
5194
5234
|
}
|
|
5235
|
+
#updateTextVisibility() {
|
|
5236
|
+
setClass(this.#$tooltipText, "hidden", this.#hasSlottedContent());
|
|
5237
|
+
}
|
|
5238
|
+
#getContentText() {
|
|
5239
|
+
if (!this.#hasSlottedContent()) {
|
|
5240
|
+
return this.text;
|
|
5241
|
+
}
|
|
5242
|
+
return this.#$contentSlot.assignedNodes().map((node) => getNodeText(node)).join(" ").replace(/\s+/g, " ").trim();
|
|
5243
|
+
}
|
|
5195
5244
|
#updatePopA11yAttrs() {
|
|
5196
5245
|
const rawAriaLabel = getAttribute(this, "aria-label");
|
|
5197
5246
|
const explicitAriaLabel = rawAriaLabel !== null && rawAriaLabel.trim().length > 0 ? rawAriaLabel.trim() : null;
|
|
5198
|
-
const fallbackAriaLabel = this
|
|
5247
|
+
const fallbackAriaLabel = this.#getContentText();
|
|
5199
5248
|
const ariaLabel = explicitAriaLabel ?? (fallbackAriaLabel.length === 0 ? null : fallbackAriaLabel);
|
|
5200
5249
|
updateAttribute(this.#$content, "aria-label", ariaLabel);
|
|
5201
5250
|
const rawAriaDescription = getAttribute(this, "aria-description");
|
|
@@ -5210,7 +5259,7 @@ class Tooltip extends NectaryElement {
|
|
|
5210
5259
|
this.#targetElements = this.#getTargetElements();
|
|
5211
5260
|
if (this.#targetElements.length === 0) {
|
|
5212
5261
|
requestAnimationFrame(() => {
|
|
5213
|
-
if (!this.isDomConnected || this.#isSubscribed || this
|
|
5262
|
+
if (!this.isDomConnected || this.#isSubscribed || !this.#hasContent()) {
|
|
5214
5263
|
return;
|
|
5215
5264
|
}
|
|
5216
5265
|
this.#subscribeMouseEnterEvent();
|
|
@@ -5250,8 +5299,23 @@ class Tooltip extends NectaryElement {
|
|
|
5250
5299
|
this.#$contentWrapper.removeEventListener("mouseenter", this.#onContentMouseEnter);
|
|
5251
5300
|
this.#$contentWrapper.removeEventListener("mouseleave", this.#onMouseLeave);
|
|
5252
5301
|
}
|
|
5302
|
+
#onContentSlotChange = () => {
|
|
5303
|
+
if (!this.isDomConnected) {
|
|
5304
|
+
return;
|
|
5305
|
+
}
|
|
5306
|
+
this.#updateTextVisibility();
|
|
5307
|
+
this.#updatePopA11yAttrs();
|
|
5308
|
+
if (!this.#hasContent()) {
|
|
5309
|
+
if (this.#isSubscribed) {
|
|
5310
|
+
this.#tooltipState.destroy();
|
|
5311
|
+
this.#unsubscribeMouseEnterEvent();
|
|
5312
|
+
}
|
|
5313
|
+
return;
|
|
5314
|
+
}
|
|
5315
|
+
this.#subscribeMouseEnterEvent();
|
|
5316
|
+
};
|
|
5253
5317
|
#onTargetSlotChange = () => {
|
|
5254
|
-
if (!this.isDomConnected || this
|
|
5318
|
+
if (!this.isDomConnected || !this.#hasContent()) {
|
|
5255
5319
|
return;
|
|
5256
5320
|
}
|
|
5257
5321
|
const isOpen = this.#isOpen();
|
|
@@ -7599,7 +7663,9 @@ const orientationValues = [
|
|
|
7599
7663
|
"left",
|
|
7600
7664
|
"right",
|
|
7601
7665
|
"bottom",
|
|
7602
|
-
"top"
|
|
7666
|
+
"top",
|
|
7667
|
+
"top-center",
|
|
7668
|
+
"bottom-center"
|
|
7603
7669
|
];
|
|
7604
7670
|
const getPopOrientation = (orientation) => {
|
|
7605
7671
|
if (orientation === "top") {
|
package/package.json
CHANGED
package/popover/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NectaryComponentReactByType, NectaryComponentVanillaByType, TRect, NectaryComponentReact, NectaryComponentVanilla } from '../types';
|
|
2
|
-
export type TSinchPopoverOrientation = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'bottom' | 'top' | 'left' | 'right';
|
|
2
|
+
export type TSinchPopoverOrientation = 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | 'bottom' | 'top' | 'top-center' | 'bottom-center' | 'left' | 'right';
|
|
3
3
|
export type TSinchPopoverProps = {
|
|
4
4
|
/** Allow scrolling of the page when popover is open */
|
|
5
5
|
'allow-scroll'?: boolean;
|
package/popover/utils.js
CHANGED
package/tooltip/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { getReactEventHandler } from "../utils/get-react-event-handler.js";
|
|
|
7
7
|
import { getPlacementContext, toLocalRect } from "../utils/placement.js";
|
|
8
8
|
import { TooltipState } from "./tooltip-state.js";
|
|
9
9
|
import { getPopOrientation, orientationValues, textAlignValues, typeValues } from "./utils.js";
|
|
10
|
-
const templateHTML = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content" role="tooltip"><sinch-text id="text" type="s"></sinch-text><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
|
|
10
|
+
const templateHTML = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#text.hidden{display:none}#content-slot{display:block;font:var(--sinch-comp-tooltip-font-body);color:var(--sinch-comp-tooltip-color-text);word-break:break-word}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}:host([text-align=right]) #content-slot{text-align:right}:host([text-align=center]) #content-slot{text-align:center}:host([text-align=left]) #content-slot{text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content" role="tooltip"><sinch-text id="text" type="s"></sinch-text><slot id="content-slot"></slot><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
|
|
11
11
|
const TIP_SIZE = 8;
|
|
12
12
|
const SHOW_DELAY_SLOW = 1e3;
|
|
13
13
|
const SHOW_DELAY_FAST = 250;
|
|
@@ -15,6 +15,7 @@ const HIDE_DELAY = 0;
|
|
|
15
15
|
const ANIMATION_DURATION = 100;
|
|
16
16
|
const FOCUSABLE_OUTSIDE_TARGET_SELECTOR = 'a[href], button, input, select, textarea, [tabindex]:not([tabindex="-1"]), [contenteditable=""], [contenteditable="true"]';
|
|
17
17
|
const OPEN_FLOATING_LAYER_SELECTOR = "sinch-popover[open], sinch-pop[open], dialog[open]";
|
|
18
|
+
const CONTENT_SLOT_NAME = "tooltip-content";
|
|
18
19
|
const OVERLAP_TOLERANCE = 1;
|
|
19
20
|
const MAX_ZERO_DIMENSION_PLACEMENT_RETRIES = 8;
|
|
20
21
|
const MIN_FIRST_REVEAL_STABILITY_FRAMES = 3;
|
|
@@ -25,6 +26,17 @@ let hoveredTooltip = null;
|
|
|
25
26
|
let suspendedFocusedTooltip = null;
|
|
26
27
|
const template = document.createElement("template");
|
|
27
28
|
template.innerHTML = templateHTML;
|
|
29
|
+
const TEXT_BREAK_TAGS = ["BR", "P", "DIV", "UL", "OL", "LI"];
|
|
30
|
+
function getNodeText(node) {
|
|
31
|
+
if (!(node instanceof Element)) {
|
|
32
|
+
return node.textContent ?? "";
|
|
33
|
+
}
|
|
34
|
+
let text = "";
|
|
35
|
+
for (const child of node.childNodes) {
|
|
36
|
+
text += child instanceof Element && TEXT_BREAK_TAGS.includes(child.tagName) ? ` ${getNodeText(child)} ` : getNodeText(child);
|
|
37
|
+
}
|
|
38
|
+
return text;
|
|
39
|
+
}
|
|
28
40
|
class Tooltip extends NectaryElement {
|
|
29
41
|
#$pop;
|
|
30
42
|
#$tooltipText;
|
|
@@ -32,6 +44,7 @@ class Tooltip extends NectaryElement {
|
|
|
32
44
|
#$contentWrapper;
|
|
33
45
|
#$tip;
|
|
34
46
|
#$target;
|
|
47
|
+
#$contentSlot;
|
|
35
48
|
#targetElements = [];
|
|
36
49
|
#resizeObserver = null;
|
|
37
50
|
#tooltipState;
|
|
@@ -58,6 +71,7 @@ class Tooltip extends NectaryElement {
|
|
|
58
71
|
this.#$contentWrapper = shadowRoot.querySelector("#content-wrapper");
|
|
59
72
|
this.#$tip = shadowRoot.querySelector("#tip");
|
|
60
73
|
this.#$target = shadowRoot.querySelector("#target");
|
|
74
|
+
this.#$contentSlot = shadowRoot.querySelector("#content-slot");
|
|
61
75
|
this.#shouldReduceMotion = shouldReduceMotion();
|
|
62
76
|
this.#controller = null;
|
|
63
77
|
this.#tooltipState = new TooltipState({
|
|
@@ -78,11 +92,26 @@ class Tooltip extends NectaryElement {
|
|
|
78
92
|
};
|
|
79
93
|
this.#$pop.addEventListener("-close", this.#onPopClose, options);
|
|
80
94
|
this.#$target.addEventListener("slotchange", this.#onTargetSlotChange, options);
|
|
95
|
+
this.#$contentSlot.addEventListener("slotchange", this.#onContentSlotChange, options);
|
|
81
96
|
this.#assignTargetNodes();
|
|
82
|
-
this.#childObserver = new MutationObserver(() => {
|
|
83
|
-
|
|
97
|
+
this.#childObserver = new MutationObserver((mutations) => {
|
|
98
|
+
const affectsAssignment = mutations.some((mutation) => {
|
|
99
|
+
return mutation.type === "childList" ? mutation.target === this : mutation.target.parentNode === this;
|
|
100
|
+
});
|
|
101
|
+
if (affectsAssignment) {
|
|
102
|
+
this.#assignTargetNodes();
|
|
103
|
+
}
|
|
104
|
+
if (this.#hasSlottedContent()) {
|
|
105
|
+
this.#updatePopA11yAttrs();
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
this.#childObserver.observe(this, {
|
|
109
|
+
childList: true,
|
|
110
|
+
subtree: true,
|
|
111
|
+
characterData: true,
|
|
112
|
+
attributes: true,
|
|
113
|
+
attributeFilter: ["slot", "text"]
|
|
84
114
|
});
|
|
85
|
-
this.#childObserver.observe(this, { childList: true });
|
|
86
115
|
this.addEventListener("-show", this.#onShowReactHandler, options);
|
|
87
116
|
this.addEventListener("-hide", this.#onHideReactHandler, options);
|
|
88
117
|
this.#resizeObserver = new ResizeObserver(() => {
|
|
@@ -387,7 +416,18 @@ class Tooltip extends NectaryElement {
|
|
|
387
416
|
const nodes = Array.from(this.childNodes).filter(
|
|
388
417
|
(node) => node instanceof Element || node instanceof Text
|
|
389
418
|
);
|
|
390
|
-
|
|
419
|
+
const contentNodes = nodes.filter((node) => {
|
|
420
|
+
return node instanceof Element && node.getAttribute("slot") === CONTENT_SLOT_NAME;
|
|
421
|
+
});
|
|
422
|
+
const targetNodes = nodes.filter((node) => !contentNodes.includes(node));
|
|
423
|
+
this.#$target.assign(...targetNodes);
|
|
424
|
+
this.#$contentSlot.assign(...contentNodes);
|
|
425
|
+
}
|
|
426
|
+
#hasSlottedContent() {
|
|
427
|
+
return this.#$contentSlot.assignedNodes().length !== 0;
|
|
428
|
+
}
|
|
429
|
+
#hasContent() {
|
|
430
|
+
return this.text.length !== 0 || this.#hasSlottedContent();
|
|
391
431
|
}
|
|
392
432
|
#targetContains(node) {
|
|
393
433
|
return this.#$target.assignedElements().some((el) => composedContains(el, node));
|
|
@@ -734,14 +774,23 @@ class Tooltip extends NectaryElement {
|
|
|
734
774
|
}
|
|
735
775
|
const text = this.text;
|
|
736
776
|
this.#$tooltipText.textContent = text;
|
|
737
|
-
if (
|
|
777
|
+
if (this.#hasContent()) {
|
|
738
778
|
this.#subscribeMouseEnterEvent();
|
|
739
779
|
}
|
|
740
780
|
}
|
|
781
|
+
#updateTextVisibility() {
|
|
782
|
+
setClass(this.#$tooltipText, "hidden", this.#hasSlottedContent());
|
|
783
|
+
}
|
|
784
|
+
#getContentText() {
|
|
785
|
+
if (!this.#hasSlottedContent()) {
|
|
786
|
+
return this.text;
|
|
787
|
+
}
|
|
788
|
+
return this.#$contentSlot.assignedNodes().map((node) => getNodeText(node)).join(" ").replace(/\s+/g, " ").trim();
|
|
789
|
+
}
|
|
741
790
|
#updatePopA11yAttrs() {
|
|
742
791
|
const rawAriaLabel = getAttribute(this, "aria-label");
|
|
743
792
|
const explicitAriaLabel = rawAriaLabel !== null && rawAriaLabel.trim().length > 0 ? rawAriaLabel.trim() : null;
|
|
744
|
-
const fallbackAriaLabel = this
|
|
793
|
+
const fallbackAriaLabel = this.#getContentText();
|
|
745
794
|
const ariaLabel = explicitAriaLabel ?? (fallbackAriaLabel.length === 0 ? null : fallbackAriaLabel);
|
|
746
795
|
updateAttribute(this.#$content, "aria-label", ariaLabel);
|
|
747
796
|
const rawAriaDescription = getAttribute(this, "aria-description");
|
|
@@ -756,7 +805,7 @@ class Tooltip extends NectaryElement {
|
|
|
756
805
|
this.#targetElements = this.#getTargetElements();
|
|
757
806
|
if (this.#targetElements.length === 0) {
|
|
758
807
|
requestAnimationFrame(() => {
|
|
759
|
-
if (!this.isDomConnected || this.#isSubscribed || this
|
|
808
|
+
if (!this.isDomConnected || this.#isSubscribed || !this.#hasContent()) {
|
|
760
809
|
return;
|
|
761
810
|
}
|
|
762
811
|
this.#subscribeMouseEnterEvent();
|
|
@@ -796,8 +845,23 @@ class Tooltip extends NectaryElement {
|
|
|
796
845
|
this.#$contentWrapper.removeEventListener("mouseenter", this.#onContentMouseEnter);
|
|
797
846
|
this.#$contentWrapper.removeEventListener("mouseleave", this.#onMouseLeave);
|
|
798
847
|
}
|
|
848
|
+
#onContentSlotChange = () => {
|
|
849
|
+
if (!this.isDomConnected) {
|
|
850
|
+
return;
|
|
851
|
+
}
|
|
852
|
+
this.#updateTextVisibility();
|
|
853
|
+
this.#updatePopA11yAttrs();
|
|
854
|
+
if (!this.#hasContent()) {
|
|
855
|
+
if (this.#isSubscribed) {
|
|
856
|
+
this.#tooltipState.destroy();
|
|
857
|
+
this.#unsubscribeMouseEnterEvent();
|
|
858
|
+
}
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
this.#subscribeMouseEnterEvent();
|
|
862
|
+
};
|
|
799
863
|
#onTargetSlotChange = () => {
|
|
800
|
-
if (!this.isDomConnected || this
|
|
864
|
+
if (!this.isDomConnected || !this.#hasContent()) {
|
|
801
865
|
return;
|
|
802
866
|
}
|
|
803
867
|
const isOpen = this.#isOpen();
|
package/tooltip/types.d.ts
CHANGED
|
@@ -4,8 +4,11 @@ export type TSinchTooltipTextAlign = 'center' | 'right' | 'left';
|
|
|
4
4
|
export type TSinchTooltipType = 'slow' | 'fast';
|
|
5
5
|
export type TSinchTooltipProps = {
|
|
6
6
|
'is-opened'?: string;
|
|
7
|
-
/**
|
|
8
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Text. Rendered as plain text; use a `slot="tooltip-content"` child for markup.
|
|
9
|
+
* Ignored when a `slot="tooltip-content"` child is present.
|
|
10
|
+
*/
|
|
11
|
+
text?: string;
|
|
9
12
|
/** Orientation, where it *points to* from origin */
|
|
10
13
|
orientation?: TSinchTooltipOrientation;
|
|
11
14
|
/** Type */
|