@cypress-design/react-tooltip 0.6.2 → 0.7.0

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.umd.js CHANGED
@@ -60,6 +60,16 @@ function __rest(s, e) {
60
60
  t[p[i]] = s[p[i]];
61
61
  }
62
62
  return t;
63
+ }
64
+
65
+ function __spreadArray(to, from, pack) {
66
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
67
+ if (ar || !(i in from)) {
68
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
69
+ ar[i] = from[i];
70
+ }
71
+ }
72
+ return to.concat(ar || Array.prototype.slice.call(from));
63
73
  }
64
74
 
65
75
  function getSide(placement) {
@@ -650,6 +660,88 @@ const offset = function (value) {
650
660
  };
651
661
  };
652
662
 
663
+ function getCrossAxis(axis) {
664
+ return axis === 'x' ? 'y' : 'x';
665
+ }
666
+
667
+ /**
668
+ * Shifts the floating element in order to keep it in view when it will overflow
669
+ * a clipping boundary.
670
+ * @see https://floating-ui.com/docs/shift
671
+ */
672
+ const shift = function (options) {
673
+ if (options === void 0) {
674
+ options = {};
675
+ }
676
+
677
+ return {
678
+ name: 'shift',
679
+ options,
680
+
681
+ async fn(middlewareArguments) {
682
+ const {
683
+ x,
684
+ y,
685
+ placement
686
+ } = middlewareArguments;
687
+ const {
688
+ mainAxis: checkMainAxis = true,
689
+ crossAxis: checkCrossAxis = false,
690
+ limiter = {
691
+ fn: _ref => {
692
+ let {
693
+ x,
694
+ y
695
+ } = _ref;
696
+ return {
697
+ x,
698
+ y
699
+ };
700
+ }
701
+ },
702
+ ...detectOverflowOptions
703
+ } = options;
704
+ const coords = {
705
+ x,
706
+ y
707
+ };
708
+ const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
709
+ const mainAxis = getMainAxisFromPlacement(getSide(placement));
710
+ const crossAxis = getCrossAxis(mainAxis);
711
+ let mainAxisCoord = coords[mainAxis];
712
+ let crossAxisCoord = coords[crossAxis];
713
+
714
+ if (checkMainAxis) {
715
+ const minSide = mainAxis === 'y' ? 'top' : 'left';
716
+ const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
717
+ const min = mainAxisCoord + overflow[minSide];
718
+ const max = mainAxisCoord - overflow[maxSide];
719
+ mainAxisCoord = within(min, mainAxisCoord, max);
720
+ }
721
+
722
+ if (checkCrossAxis) {
723
+ const minSide = crossAxis === 'y' ? 'top' : 'left';
724
+ const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
725
+ const min = crossAxisCoord + overflow[minSide];
726
+ const max = crossAxisCoord - overflow[maxSide];
727
+ crossAxisCoord = within(min, crossAxisCoord, max);
728
+ }
729
+
730
+ const limitedCoords = limiter.fn({ ...middlewareArguments,
731
+ [mainAxis]: mainAxisCoord,
732
+ [crossAxis]: crossAxisCoord
733
+ });
734
+ return { ...limitedCoords,
735
+ data: {
736
+ x: limitedCoords.x - x,
737
+ y: limitedCoords.y - y
738
+ }
739
+ };
740
+ }
741
+
742
+ };
743
+ };
744
+
653
745
  function isWindow(value) {
654
746
  return value && value.document && value.location && value.alert && value.setInterval;
655
747
  }
@@ -33455,21 +33547,15 @@ var ROTATE_MAP = {
33455
33547
  };
33456
33548
  var Tooltip = function (_a) {
33457
33549
  var _b;
33458
- var placement = _a.placement, _c = _a.color, color = _c === void 0 ? 'light' : _c, className = _a.className, children = _a.children, popper = _a.popper, disabled = _a.disabled, interactive = _a.interactive, forcePlacement = _a.forcePlacement, rest = __rest(_a, ["placement", "color", "className", "children", "popper", "disabled", "interactive", "forcePlacement"]);
33550
+ var placement = _a.placement, _c = _a.color, color = _c === void 0 ? 'light' : _c, className = _a.className, children = _a.children, popper = _a.popper, disabled = _a.disabled, interactive = _a.interactive, forcePlacement = _a.forcePlacement, _d = _a.forceOpen, forceOpen = _d === void 0 ? false : _d, rest = __rest(_a, ["placement", "color", "className", "children", "popper", "disabled", "interactive", "forcePlacement", "forceOpen"]);
33459
33551
  var arrowRef = React__namespace.useRef(null);
33460
- var _d = React__namespace.useState(false), open = _d[0], setOpen = _d[1];
33461
- var container = React__namespace.useState(function () {
33462
- // This will be executed only on the initial render
33463
- // https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
33464
- return document.createElement('div');
33465
- })[0];
33552
+ var _e = React__namespace.useState(false), open = _e[0], setOpen = _e[1];
33466
33553
  React__namespace.useEffect(function () {
33467
- document.body.appendChild(container);
33468
- return function () {
33469
- document.body.removeChild(container);
33470
- };
33471
- }, []);
33472
- var _e = useFloating({
33554
+ if (forceOpen) {
33555
+ setOpen(true);
33556
+ }
33557
+ }, [forceOpen]);
33558
+ var _f = useFloating({
33473
33559
  placement: placement,
33474
33560
  open: open,
33475
33561
  onOpenChange: setOpen,
@@ -33482,20 +33568,20 @@ var Tooltip = function (_a) {
33482
33568
  : flip(),
33483
33569
  offset(interactive ? 0 : 16),
33484
33570
  arrow({ element: arrowRef, padding: 24 }),
33571
+ shift({ padding: 16 }),
33485
33572
  ],
33486
33573
  whileElementsMounted: autoUpdate,
33487
- }), x = _e.x, y = _e.y, reference = _e.reference, floating = _e.floating, strategy = _e.strategy, calculatedPlacement = _e.placement, context = _e.context, _f = _e.middlewareData.arrow, _g = _f === void 0 ? {} : _f, arrowX = _g.x, arrowY = _g.y;
33488
- var _h = useInteractions([
33574
+ }), x = _f.x, y = _f.y, reference = _f.reference, floating = _f.floating, strategy = _f.strategy, calculatedPlacement = _f.placement, context = _f.context, _g = _f.middlewareData.arrow, _h = _g === void 0 ? {} : _g, arrowX = _h.x, arrowY = _h.y;
33575
+ var _j = useInteractions(__spreadArray([
33489
33576
  useHover(context, {
33490
33577
  handleClose: interactive ? safePolygon() : undefined,
33491
- enabled: !disabled,
33578
+ enabled: !disabled && !forceOpen,
33492
33579
  }),
33493
33580
  useFocus(context, {
33494
- enabled: !disabled,
33581
+ enabled: !disabled && !forceOpen,
33495
33582
  }),
33496
- useRole(context, { role: 'tooltip' }),
33497
- useDismiss(context),
33498
- ]), getReferenceProps = _h.getReferenceProps, getFloatingProps = _h.getFloatingProps;
33583
+ useRole(context, { role: 'tooltip' })
33584
+ ], (!forceOpen ? [useDismiss(context)] : []), true)), getReferenceProps = _j.getReferenceProps, getFloatingProps = _j.getFloatingProps;
33499
33585
  var placementSide = calculatedPlacement.split('-')[0];
33500
33586
  var arrowRotate = ROTATE_MAP[placementSide];
33501
33587
  var arrowXRule = 'left', arrowYRule = 'top';
@@ -33558,4 +33644,4 @@ var Tooltip = function (_a) {
33558
33644
  module.exports = Tooltip;
33559
33645
  //# sourceMappingURL=index.umd.js.map
33560
33646
 
33561
- /* <wind-keep class="container stroke-none fill-white block text-gray-900 shadow-gray-100 border-transparent bg-white fill-gray-900 text-white shadow-gray-800 bg-gray-900 rounded shadow border invisible absolute z-10 transform filter text-[16px] leading-[24px] min-w-[160px] text-center p-[8px] relative z-20 drop-shadow"> */
33647
+ /* <wind-keep class="stroke-none fill-white block text-gray-900 shadow-gray-100 border-transparent bg-white fill-gray-900 text-white shadow-gray-800 bg-gray-900 rounded shadow border invisible absolute z-10 transform filter text-[16px] leading-[24px] min-w-[160px] text-center p-[8px] relative z-20 drop-shadow"> */