@dust-tt/sparkle 0.2.244-rc → 0.2.244-rc-alb

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/dist/cjs/index.js CHANGED
@@ -40400,12 +40400,11 @@ function Tooltip(_a) {
40400
40400
  var _c = __read(React.useState(false), 2), isHovered = _c[0], setIsHovered = _c[1];
40401
40401
  var _d = __read(React.useState(null), 2), timerId = _d[0], setTimerId = _d[1];
40402
40402
  var _e = __read(React.useState(false), 2), isTouchDevice = _e[0], setIsTouchDevice = _e[1];
40403
- var _f = __read(React.useState({ top: 0, left: 0 }), 2), tooltipPosition = _f[0], setTooltipPosition = _f[1];
40404
40403
  var triggerRef = React.useRef(null);
40404
+ var tooltipRef = React.useRef(null);
40405
40405
  var handleMouseOver = function () {
40406
40406
  var id = window.setTimeout(function () {
40407
40407
  setIsHovered(true);
40408
- updateTooltipPosition();
40409
40408
  }, 600);
40410
40409
  setTimerId(id);
40411
40410
  };
@@ -40415,15 +40414,6 @@ function Tooltip(_a) {
40415
40414
  }
40416
40415
  setIsHovered(false);
40417
40416
  };
40418
- var updateTooltipPosition = function () {
40419
- if (triggerRef.current) {
40420
- var rect = triggerRef.current.getBoundingClientRect();
40421
- setTooltipPosition({
40422
- top: position === "above" ? rect.top - 10 : rect.bottom + 10,
40423
- left: rect.left + rect.width / 2,
40424
- });
40425
- }
40426
- };
40427
40417
  React.useEffect(function () {
40428
40418
  setIsTouchDevice("ontouchstart" in window || navigator.maxTouchPoints > 0);
40429
40419
  return function () {
@@ -40433,13 +40423,30 @@ function Tooltip(_a) {
40433
40423
  };
40434
40424
  }, [timerId]);
40435
40425
  React.useEffect(function () {
40436
- window.addEventListener("scroll", updateTooltipPosition);
40437
- window.addEventListener("resize", updateTooltipPosition);
40438
- return function () {
40439
- window.removeEventListener("scroll", updateTooltipPosition);
40440
- window.removeEventListener("resize", updateTooltipPosition);
40441
- };
40442
- }, []);
40426
+ if (isHovered && triggerRef.current && tooltipRef.current) {
40427
+ var triggerRect = triggerRef.current.getBoundingClientRect();
40428
+ var tooltipRect = tooltipRef.current.getBoundingClientRect();
40429
+ var top_1 = position === "above"
40430
+ ? triggerRect.top - tooltipRect.height - 10
40431
+ : triggerRect.bottom + 10;
40432
+ var left = triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
40433
+ // Adjust if tooltip goes off-screen
40434
+ if (left < 0) {
40435
+ left = 0;
40436
+ }
40437
+ if (left + tooltipRect.width > window.innerWidth) {
40438
+ left = window.innerWidth - tooltipRect.width;
40439
+ }
40440
+ if (top_1 < 0) {
40441
+ top_1 = triggerRect.bottom + 10; // Switch to below if above doesn't fit
40442
+ }
40443
+ if (top_1 + tooltipRect.height > window.innerHeight) {
40444
+ top_1 = triggerRect.top - tooltipRect.height - 10; // Switch to above if below doesn't fit
40445
+ }
40446
+ tooltipRef.current.style.top = "".concat(top_1, "px");
40447
+ tooltipRef.current.style.left = "".concat(left, "px");
40448
+ }
40449
+ }, [isHovered, position]);
40443
40450
  if (isTouchDevice) {
40444
40451
  return React.createElement(React.Fragment, null, children);
40445
40452
  }
@@ -40447,15 +40454,11 @@ function Tooltip(_a) {
40447
40454
  var hiddenClasses = "s-translate-y-2 s-opacity-0 s-pointer-events-none";
40448
40455
  var visibleClasses = "-s-translate-y-0 s-opacity-100";
40449
40456
  var hiddenOnMobileClasses = "s-hidden sm:s-block";
40450
- var tooltipCenterClasses = "-s-translate-x-1/2";
40451
40457
  var labelLength = (label === null || label === void 0 ? void 0 : label.length) || 0;
40452
40458
  var labelClasses = labelLength > 80 ? "s-w-[38em]" : "s-whitespace-nowrap";
40453
40459
  return (React.createElement("div", { ref: triggerRef, onMouseEnter: handleMouseOver, onMouseLeave: handleMouseLeave, className: "s-relative s-inline-block" },
40454
40460
  children,
40455
- React.createElement("div", { className: classNames("".concat(isHovered ? visibleClasses : hiddenClasses), baseClasses, hiddenOnMobileClasses, tooltipCenterClasses, contentChildren ? "" : labelClasses), style: {
40456
- top: "".concat(tooltipPosition.top, "px"),
40457
- left: "".concat(tooltipPosition.left, "px"),
40458
- }, onAnimationEnd: function () { return setIsHovered(false); } }, contentChildren || label)));
40461
+ React.createElement("div", { ref: tooltipRef, className: classNames("".concat(isHovered ? visibleClasses : hiddenClasses), baseClasses, hiddenOnMobileClasses, contentChildren ? "" : labelClasses), style: { position: "fixed", top: 0, left: 0 }, onAnimationEnd: function () { return setIsHovered(false); } }, contentChildren || label)));
40459
40462
  }
40460
40463
 
40461
40464
  var textClasses = {