@moving-walls/design-system 1.0.22 → 1.0.23

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/index.js CHANGED
@@ -41337,8 +41337,8 @@ function Tooltip(_ref2) {
41337
41337
  _useState6 = _slicedToArray(_useState5, 2),
41338
41338
  resolvedPosition = _useState6[0],
41339
41339
  setResolvedPosition = _useState6[1];
41340
- React.useLayoutEffect(function () {
41341
- if (!isVisible || !triggerRef.current || !tooltipRef.current) return;
41340
+ var recalculate = React.useCallback(function () {
41341
+ if (!triggerRef.current || !tooltipRef.current) return;
41342
41342
  var triggerRect = triggerRef.current.getBoundingClientRect();
41343
41343
  var tooltipRect = tooltipRef.current.getBoundingClientRect();
41344
41344
  var vw = window.innerWidth;
@@ -41346,7 +41346,6 @@ function Tooltip(_ref2) {
41346
41346
  var top = 0;
41347
41347
  var left = 0;
41348
41348
  var resolved = position;
41349
- // Calculate preferred position
41350
41349
  var calc = function calc(pos) {
41351
41350
  switch (pos) {
41352
41351
  case 'top':
@@ -41368,7 +41367,6 @@ function Tooltip(_ref2) {
41368
41367
  }
41369
41368
  };
41370
41369
  calc(position);
41371
- // Flip if overflowing viewport
41372
41370
  if (position === 'top' && top < PADDING) {
41373
41371
  resolved = 'bottom';
41374
41372
  calc('bottom');
@@ -41382,10 +41380,8 @@ function Tooltip(_ref2) {
41382
41380
  resolved = 'left';
41383
41381
  calc('left');
41384
41382
  }
41385
- // Clamp horizontal to stay within viewport
41386
41383
  if (left < PADDING) left = PADDING;
41387
41384
  if (left + tooltipRect.width > vw - PADDING) left = vw - PADDING - tooltipRect.width;
41388
- // Clamp vertical
41389
41385
  if (top < PADDING) top = PADDING;
41390
41386
  if (top + tooltipRect.height > vh - PADDING) top = vh - PADDING - tooltipRect.height;
41391
41387
  setCoords({
@@ -41393,10 +41389,20 @@ function Tooltip(_ref2) {
41393
41389
  left: left
41394
41390
  });
41395
41391
  setResolvedPosition(resolved);
41396
- }, [isVisible, position]);
41392
+ }, [position]);
41393
+ // Recalculate on visibility change
41394
+ React.useLayoutEffect(function () {
41395
+ if (!isVisible) return;
41396
+ recalculate();
41397
+ }, [isVisible, recalculate]);
41398
+ // Use callback ref to recalculate once the portal element is mounted in the DOM
41399
+ var tooltipCallbackRef = React.useCallback(function (node) {
41400
+ tooltipRef.current = node;
41401
+ if (node && isVisible) recalculate();
41402
+ }, [isVisible, recalculate]);
41397
41403
  var show = React.useCallback(function () {
41398
- return setIsVisible(true);
41399
- }, []);
41404
+ if (content != null && content !== '') setIsVisible(true);
41405
+ }, [content]);
41400
41406
  var hide = React.useCallback(function () {
41401
41407
  setIsVisible(false);
41402
41408
  setCoords(null);
@@ -41432,16 +41438,18 @@ function Tooltip(_ref2) {
41432
41438
  onFocus: show,
41433
41439
  onBlur: hide,
41434
41440
  children: children
41435
- }), isVisible && /*#__PURE__*/ReactDOM.createPortal(require$$1.jsxs("div", {
41436
- ref: tooltipRef,
41441
+ }), isVisible && content != null && content !== '' && /*#__PURE__*/ReactDOM.createPortal(require$$1.jsxs("div", {
41442
+ ref: tooltipCallbackRef,
41437
41443
  style: coords ? {
41438
41444
  top: coords.top,
41439
- left: coords.left
41445
+ left: coords.left,
41446
+ zIndex: 999999
41440
41447
  } : {
41441
41448
  top: -9999,
41442
- left: -9999
41449
+ left: -9999,
41450
+ zIndex: 999999
41443
41451
  },
41444
- className: clsx('fixed z-[9999] px-2 py-1 text-sm text-mw-neutral-500 bg-white border border-mw-neutral-100 rounded-md shadow-sm max-w-xs whitespace-normal', className),
41452
+ className: clsx('fixed px-2 py-1 text-sm text-mw-neutral-500 bg-white border border-mw-neutral-100 rounded-md shadow-sm max-w-sm whitespace-normal', className),
41445
41453
  children: [content, require$$1.jsx("div", {
41446
41454
  className: clsx('w-0 h-0 border-4', arrowClasses[resolvedPosition]),
41447
41455
  style: arrowStyle()