@cypress-design/react-tooltip 0.6.3 → 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.
@@ -2,5 +2,5 @@ $ yarn build:module && yarn build:types
2
2
  $ rollup -c ./rollup.config.mjs
3
3
  
4
4
  ./index.ts → ./dist/index.umd.js, ./dist/index.es.mjs...
5
- created ./dist/index.umd.js, ./dist/index.es.mjs in 30.4s
5
+ created ./dist/index.umd.js, ./dist/index.es.mjs in 42.9s
6
6
  $ tsc --project ./tsconfig.build.json
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # @cypress-design/react-tooltip
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#265](https://github.com/cypress-io/cypress-design/pull/265) [`a69b7ee`](https://github.com/cypress-io/cypress-design/commit/a69b7ee3e7ca0900362b463f9925ba6ff6f4332f) Thanks [@elevatebart](https://github.com/elevatebart)! - add forceOpen prop
8
+
9
+ ### Patch Changes
10
+
11
+ - [#265](https://github.com/cypress-io/cypress-design/pull/265) [`a69b7ee`](https://github.com/cypress-io/cypress-design/commit/a69b7ee3e7ca0900362b463f9925ba6ff6f4332f) Thanks [@elevatebart](https://github.com/elevatebart)! - avoid creating empty divs
12
+
3
13
  ## 0.6.3
4
14
 
5
15
  ### Patch Changes
package/Tooltip.tsx CHANGED
@@ -45,6 +45,11 @@ export interface TooltipProps {
45
45
  * If set, the tooltip will always respect the given placement
46
46
  */
47
47
  forcePlacement?: boolean
48
+ /**
49
+ * Make sure the tooltip stays always open.
50
+ * This is useful for debugging.
51
+ */
52
+ forceOpen?: boolean
48
53
  }
49
54
 
50
55
  const ROTATE_MAP = {
@@ -65,23 +70,17 @@ export const Tooltip: React.FC<
65
70
  disabled,
66
71
  interactive,
67
72
  forcePlacement,
73
+ forceOpen = false,
68
74
  ...rest
69
75
  }) => {
70
76
  const arrowRef = React.useRef(null)
71
77
  const [open, setOpen] = React.useState(false)
72
78
 
73
- const [container] = React.useState(() => {
74
- // This will be executed only on the initial render
75
- // https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
76
- return document.createElement('div')
77
- })
78
-
79
79
  React.useEffect(() => {
80
- document.body.appendChild(container)
81
- return () => {
82
- document.body.removeChild(container)
80
+ if (forceOpen) {
81
+ setOpen(true)
83
82
  }
84
- }, [])
83
+ }, [forceOpen])
85
84
 
86
85
  const {
87
86
  x,
@@ -113,13 +112,13 @@ export const Tooltip: React.FC<
113
112
  const { getReferenceProps, getFloatingProps } = useInteractions([
114
113
  useHover(context, {
115
114
  handleClose: interactive ? safePolygon() : undefined,
116
- enabled: !disabled,
115
+ enabled: !disabled && !forceOpen,
117
116
  }),
118
117
  useFocus(context, {
119
- enabled: !disabled,
118
+ enabled: !disabled && !forceOpen,
120
119
  }),
121
120
  useRole(context, { role: 'tooltip' }),
122
- useDismiss(context),
121
+ ...(!forceOpen ? [useDismiss(context)] : []),
123
122
  ])
124
123
 
125
124
  const placementSide = calculatedPlacement.split(
@@ -98,4 +98,19 @@ describe('Tooltip', { viewportHeight: 800, viewportWidth: 800 }, () => {
98
98
  }
99
99
 
100
100
  assertions(mountStory, 'react')
101
+
102
+ it('forceOpen', () => {
103
+ mount(
104
+ <div className="text-center">
105
+ <Tooltip
106
+ className="border inline-block m-16 p-3"
107
+ popper="should be visible"
108
+ forceOpen
109
+ >
110
+ make sure its open
111
+ </Tooltip>
112
+ </div>
113
+ )
114
+ cy.findByText('should be visible').should('be.visible')
115
+ })
101
116
  })
package/dist/Tooltip.d.ts CHANGED
@@ -28,6 +28,11 @@ export interface TooltipProps {
28
28
  * If set, the tooltip will always respect the given placement
29
29
  */
30
30
  forcePlacement?: boolean;
31
+ /**
32
+ * Make sure the tooltip stays always open.
33
+ * This is useful for debugging.
34
+ */
35
+ forceOpen?: boolean;
31
36
  }
32
37
  export declare const Tooltip: React.FC<TooltipProps & React.HTMLProps<HTMLDivElement>>;
33
38
  export default Tooltip;
@@ -1 +1 @@
1
- {"version":3,"file":"Tooltip.d.ts","sourceRoot":"./","sources":["Tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,SAAS,EAcV,MAAM,qCAAqC,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AASD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAC5B,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CAkL/C,CAAA;AAED,eAAe,OAAO,CAAA"}
1
+ {"version":3,"file":"Tooltip.d.ts","sourceRoot":"./","sources":["Tooltip.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,SAAS,EAcV,MAAM,qCAAqC,CAAA;AAE5C,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,SAAS,CAAC,EAAE,SAAS,CAAA;IACrB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,MAAM,CAAA;IACxB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B;;OAEG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IACxB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AASD,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAC5B,YAAY,GAAG,KAAK,CAAC,SAAS,CAAC,cAAc,CAAC,CA4K/C,CAAA;AAED,eAAe,OAAO,CAAA"}
package/dist/index.es.mjs CHANGED
@@ -40,6 +40,16 @@ function __rest(s, e) {
40
40
  t[p[i]] = s[p[i]];
41
41
  }
42
42
  return t;
43
+ }
44
+
45
+ function __spreadArray(to, from, pack) {
46
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
47
+ if (ar || !(i in from)) {
48
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
49
+ ar[i] = from[i];
50
+ }
51
+ }
52
+ return to.concat(ar || Array.prototype.slice.call(from));
43
53
  }
44
54
 
45
55
  function getSide(placement) {
@@ -33517,21 +33527,15 @@ var ROTATE_MAP = {
33517
33527
  };
33518
33528
  var Tooltip = function (_a) {
33519
33529
  var _b;
33520
- 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"]);
33530
+ 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"]);
33521
33531
  var arrowRef = React.useRef(null);
33522
- var _d = React.useState(false), open = _d[0], setOpen = _d[1];
33523
- var container = React.useState(function () {
33524
- // This will be executed only on the initial render
33525
- // https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
33526
- return document.createElement('div');
33527
- })[0];
33532
+ var _e = React.useState(false), open = _e[0], setOpen = _e[1];
33528
33533
  React.useEffect(function () {
33529
- document.body.appendChild(container);
33530
- return function () {
33531
- document.body.removeChild(container);
33532
- };
33533
- }, []);
33534
- var _e = useFloating({
33534
+ if (forceOpen) {
33535
+ setOpen(true);
33536
+ }
33537
+ }, [forceOpen]);
33538
+ var _f = useFloating({
33535
33539
  placement: placement,
33536
33540
  open: open,
33537
33541
  onOpenChange: setOpen,
@@ -33547,18 +33551,17 @@ var Tooltip = function (_a) {
33547
33551
  shift({ padding: 16 }),
33548
33552
  ],
33549
33553
  whileElementsMounted: autoUpdate,
33550
- }), 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;
33551
- var _h = useInteractions([
33554
+ }), 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;
33555
+ var _j = useInteractions(__spreadArray([
33552
33556
  useHover(context, {
33553
33557
  handleClose: interactive ? safePolygon() : undefined,
33554
- enabled: !disabled,
33558
+ enabled: !disabled && !forceOpen,
33555
33559
  }),
33556
33560
  useFocus(context, {
33557
- enabled: !disabled,
33561
+ enabled: !disabled && !forceOpen,
33558
33562
  }),
33559
- useRole(context, { role: 'tooltip' }),
33560
- useDismiss(context),
33561
- ]), getReferenceProps = _h.getReferenceProps, getFloatingProps = _h.getFloatingProps;
33563
+ useRole(context, { role: 'tooltip' })
33564
+ ], (!forceOpen ? [useDismiss(context)] : []), true)), getReferenceProps = _j.getReferenceProps, getFloatingProps = _j.getFloatingProps;
33562
33565
  var placementSide = calculatedPlacement.split('-')[0];
33563
33566
  var arrowRotate = ROTATE_MAP[placementSide];
33564
33567
  var arrowXRule = 'left', arrowYRule = 'top';
@@ -33621,4 +33624,4 @@ var Tooltip = function (_a) {
33621
33624
  export { Tooltip as default };
33622
33625
  //# sourceMappingURL=index.es.mjs.map
33623
33626
 
33624
- /* <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"> */
33627
+ /* <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"> */