@fluid-topics/ft-tooltip 1.1.2 → 1.1.4
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/build/ft-tooltip.js +16 -40
- package/build/ft-tooltip.light.js +47 -47
- package/build/ft-tooltip.min.js +43 -43
- package/package.json +5 -4
package/build/ft-tooltip.js
CHANGED
|
@@ -8,7 +8,8 @@ import { html } from "lit";
|
|
|
8
8
|
import { property, query, queryAssignedNodes, state } from "lit/decorators.js";
|
|
9
9
|
import { Debouncer, FtLitElement } from "@fluid-topics/ft-wc-utils";
|
|
10
10
|
import { FtTypography } from "@fluid-topics/ft-typography";
|
|
11
|
-
import {
|
|
11
|
+
import { styles } from "./ft-tooltip.css";
|
|
12
|
+
import { autoPlacement, computePosition, shift } from "@floating-ui/dom";
|
|
12
13
|
class FtTooltip extends FtLitElement {
|
|
13
14
|
constructor() {
|
|
14
15
|
super(...arguments);
|
|
@@ -100,45 +101,20 @@ class FtTooltip extends FtLitElement {
|
|
|
100
101
|
}
|
|
101
102
|
positionTooltip() {
|
|
102
103
|
this.resetTooltipContent();
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
break;
|
|
118
|
-
case "bottom":
|
|
119
|
-
top = target.offsetTop + target.offsetHeight - this.tooltip.offsetTop;
|
|
120
|
-
left = target.offsetLeft + horizontalCenter - this.tooltip.offsetLeft;
|
|
121
|
-
break;
|
|
122
|
-
case "left":
|
|
123
|
-
top = target.offsetTop + verticalCenter - this.tooltip.offsetTop;
|
|
124
|
-
left = target.offsetLeft - tooltipWidth - this.tooltip.offsetLeft;
|
|
125
|
-
break;
|
|
126
|
-
case "right":
|
|
127
|
-
top = target.offsetTop + verticalCenter - this.tooltip.offsetTop;
|
|
128
|
-
left = target.offsetLeft + target.offsetWidth - this.tooltip.offsetLeft;
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
const style = this.tooltip.style;
|
|
132
|
-
style.left = left + "px";
|
|
133
|
-
style.top = top + "px";
|
|
134
|
-
const boundingClientRect = this.tooltip.getBoundingClientRect();
|
|
135
|
-
let leftOutOfWindowPixels = -boundingClientRect.x;
|
|
136
|
-
let rightOutOfWindowPixels = (boundingClientRect.x + boundingClientRect.width) - window.innerWidth;
|
|
137
|
-
style.left = (left + Math.round(this.correctOutOfWindowPixels(leftOutOfWindowPixels, rightOutOfWindowPixels))) + "px";
|
|
138
|
-
let topOutOfWindowPixels = -boundingClientRect.y;
|
|
139
|
-
let bottomOutOfWindowPixels = (boundingClientRect.y + boundingClientRect.height) - window.innerHeight;
|
|
140
|
-
style.top = (top + Math.round(this.correctOutOfWindowPixels(topOutOfWindowPixels, bottomOutOfWindowPixels))) + "px";
|
|
141
|
-
style.maxWidth = `max(${target.offsetWidth}px, ${FtTooltipCssVariables.maxWidth})`;
|
|
104
|
+
if (this.tooltip && this.slottedElement) {
|
|
105
|
+
this.tooltip.style.left = "";
|
|
106
|
+
this.tooltip.style.top = "";
|
|
107
|
+
computePosition(this.slottedElement, this.tooltip, {
|
|
108
|
+
middleware: [
|
|
109
|
+
shift({ crossAxis: true }),
|
|
110
|
+
autoPlacement({ allowedPlacements: [this.position] })
|
|
111
|
+
],
|
|
112
|
+
}).then(({ x, y }) => {
|
|
113
|
+
if (this.tooltip) {
|
|
114
|
+
this.tooltip.style.left = `${x}px`;
|
|
115
|
+
this.tooltip.style.top = `${y}px`;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
142
118
|
}
|
|
143
119
|
this.revealDebouncer.run(() => {
|
|
144
120
|
if (this.tooltipContent) {
|