@fluid-topics/ft-tooltip 1.1.3 → 1.1.5

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.
@@ -5,10 +5,11 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
5
5
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6
6
  };
7
7
  import { html } from "lit";
8
- import { property, query, queryAssignedNodes, state } from "lit/decorators.js";
8
+ import { eventOptions, 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 { FtTooltipCssVariables, styles } from "./ft-tooltip.css";
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
- const target = this.slottedElement;
104
- if (this.tooltip && target) {
105
- const tooltipWidth = this.tooltip.offsetWidth;
106
- const tooltipHeight = this.tooltip.offsetHeight;
107
- const verticalCenter = (target.offsetHeight - tooltipHeight) / 2;
108
- const horizontalCenter = (target.offsetWidth - tooltipWidth) / 2;
109
- let left = 0;
110
- let top = 0;
111
- this.tooltip.style.top = "0";
112
- this.tooltip.style.left = "0";
113
- switch (this.validPosition) {
114
- case "top":
115
- top = target.offsetTop - tooltipHeight - this.tooltip.offsetTop;
116
- left = target.offsetLeft + horizontalCenter - this.tooltip.offsetLeft;
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) {
@@ -208,4 +184,13 @@ __decorate([
208
184
  __decorate([
209
185
  state()
210
186
  ], FtTooltip.prototype, "visible", void 0);
187
+ __decorate([
188
+ eventOptions({ passive: true })
189
+ ], FtTooltip.prototype, "onTouch", null);
190
+ __decorate([
191
+ eventOptions({ passive: true })
192
+ ], FtTooltip.prototype, "onHover", null);
193
+ __decorate([
194
+ eventOptions({ passive: true })
195
+ ], FtTooltip.prototype, "onOut", null);
211
196
  export { FtTooltip };