@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/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +16 -0
- package/Tooltip.tsx +14 -13
- package/TooltipReact.cy.tsx +105 -3
- package/dist/Tooltip.d.ts +5 -0
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/index.es.mjs +107 -21
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +107 -21
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/Tooltip.rootstory.tsx +0 -67
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
|
|
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
|
-
|
|
33468
|
-
|
|
33469
|
-
|
|
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 =
|
|
33488
|
-
var
|
|
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
|
-
|
|
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="
|
|
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"> */
|