@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.esm.js CHANGED
@@ -41317,8 +41317,8 @@ function Tooltip(_ref2) {
41317
41317
  _useState6 = _slicedToArray(_useState5, 2),
41318
41318
  resolvedPosition = _useState6[0],
41319
41319
  setResolvedPosition = _useState6[1];
41320
- useLayoutEffect(function () {
41321
- if (!isVisible || !triggerRef.current || !tooltipRef.current) return;
41320
+ var recalculate = useCallback(function () {
41321
+ if (!triggerRef.current || !tooltipRef.current) return;
41322
41322
  var triggerRect = triggerRef.current.getBoundingClientRect();
41323
41323
  var tooltipRect = tooltipRef.current.getBoundingClientRect();
41324
41324
  var vw = window.innerWidth;
@@ -41326,7 +41326,6 @@ function Tooltip(_ref2) {
41326
41326
  var top = 0;
41327
41327
  var left = 0;
41328
41328
  var resolved = position;
41329
- // Calculate preferred position
41330
41329
  var calc = function calc(pos) {
41331
41330
  switch (pos) {
41332
41331
  case 'top':
@@ -41348,7 +41347,6 @@ function Tooltip(_ref2) {
41348
41347
  }
41349
41348
  };
41350
41349
  calc(position);
41351
- // Flip if overflowing viewport
41352
41350
  if (position === 'top' && top < PADDING) {
41353
41351
  resolved = 'bottom';
41354
41352
  calc('bottom');
@@ -41362,10 +41360,8 @@ function Tooltip(_ref2) {
41362
41360
  resolved = 'left';
41363
41361
  calc('left');
41364
41362
  }
41365
- // Clamp horizontal to stay within viewport
41366
41363
  if (left < PADDING) left = PADDING;
41367
41364
  if (left + tooltipRect.width > vw - PADDING) left = vw - PADDING - tooltipRect.width;
41368
- // Clamp vertical
41369
41365
  if (top < PADDING) top = PADDING;
41370
41366
  if (top + tooltipRect.height > vh - PADDING) top = vh - PADDING - tooltipRect.height;
41371
41367
  setCoords({
@@ -41373,10 +41369,20 @@ function Tooltip(_ref2) {
41373
41369
  left: left
41374
41370
  });
41375
41371
  setResolvedPosition(resolved);
41376
- }, [isVisible, position]);
41372
+ }, [position]);
41373
+ // Recalculate on visibility change
41374
+ useLayoutEffect(function () {
41375
+ if (!isVisible) return;
41376
+ recalculate();
41377
+ }, [isVisible, recalculate]);
41378
+ // Use callback ref to recalculate once the portal element is mounted in the DOM
41379
+ var tooltipCallbackRef = useCallback(function (node) {
41380
+ tooltipRef.current = node;
41381
+ if (node && isVisible) recalculate();
41382
+ }, [isVisible, recalculate]);
41377
41383
  var show = useCallback(function () {
41378
- return setIsVisible(true);
41379
- }, []);
41384
+ if (content != null && content !== '') setIsVisible(true);
41385
+ }, [content]);
41380
41386
  var hide = useCallback(function () {
41381
41387
  setIsVisible(false);
41382
41388
  setCoords(null);
@@ -41412,16 +41418,18 @@ function Tooltip(_ref2) {
41412
41418
  onFocus: show,
41413
41419
  onBlur: hide,
41414
41420
  children: children
41415
- }), isVisible && /*#__PURE__*/createPortal(jsxs("div", {
41416
- ref: tooltipRef,
41421
+ }), isVisible && content != null && content !== '' && /*#__PURE__*/createPortal(jsxs("div", {
41422
+ ref: tooltipCallbackRef,
41417
41423
  style: coords ? {
41418
41424
  top: coords.top,
41419
- left: coords.left
41425
+ left: coords.left,
41426
+ zIndex: 999999
41420
41427
  } : {
41421
41428
  top: -9999,
41422
- left: -9999
41429
+ left: -9999,
41430
+ zIndex: 999999
41423
41431
  },
41424
- 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),
41432
+ 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),
41425
41433
  children: [content, jsx("div", {
41426
41434
  className: clsx('w-0 h-0 border-4', arrowClasses[resolvedPosition]),
41427
41435
  style: arrowStyle()