@cypress-design/react-tooltip 0.6.1 → 0.6.3

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 39.2s
5
+ created ./dist/index.umd.js, ./dist/index.es.mjs in 30.4s
6
6
  $ tsc --project ./tsconfig.build.json
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @cypress-design/react-tooltip
2
2
 
3
+ ## 0.6.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#259](https://github.com/cypress-io/cypress-design/pull/259) [`fdd8839`](https://github.com/cypress-io/cypress-design/commit/fdd883952476a852973adc671dadc817883251ec) Thanks [@elevatebart](https://github.com/elevatebart)! - when tooltip overflows, shift it back
8
+
9
+ ## 0.6.2
10
+
11
+ ### Patch Changes
12
+
13
+ - [#245](https://github.com/cypress-io/cypress-design/pull/245) [`d52d023`](https://github.com/cypress-io/cypress-design/commit/d52d02301bb851d514661a8c258d0c4ae5baf171) Thanks [@elevatebart](https://github.com/elevatebart)! - use tailwind to rollup classes in the final package
14
+
3
15
  ## 0.6.1
4
16
 
5
17
  ### Patch Changes
package/Tooltip.tsx CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  offset,
6
6
  flip,
7
7
  arrow,
8
+ shift,
8
9
  autoUpdate,
9
10
  useFloating,
10
11
  useInteractions,
@@ -26,7 +27,6 @@ export interface TooltipProps {
26
27
  */
27
28
  color?: 'light' | 'dark'
28
29
  className?: string
29
- tabIndex?: number | string
30
30
  children?: React.ReactNode
31
31
  /**
32
32
  * The content of the tooltip.
@@ -105,6 +105,7 @@ export const Tooltip: React.FC<
105
105
  : flip(),
106
106
  offset(interactive ? 0 : 16),
107
107
  arrow({ element: arrowRef, padding: 24 }),
108
+ shift({ padding: 16 }),
108
109
  ],
109
110
  whileElementsMounted: autoUpdate,
110
111
  })
@@ -2,13 +2,100 @@
2
2
 
3
3
  import * as React from 'react'
4
4
  import { mount } from 'cypress/react18'
5
- import TooltipStory from './Tooltip.rootstory'
5
+ import { Placement } from '@floating-ui/react-dom-interactions'
6
6
  import assertions from '../assertions'
7
+ import Tooltip from './Tooltip'
8
+
9
+ const TooltipStoryMulti = ({
10
+ color = 'light',
11
+ placement,
12
+ disabled,
13
+ tabindex = 1,
14
+ }: {
15
+ color?: 'light' | 'dark'
16
+ placement?: Placement
17
+ disabled?: boolean
18
+ tabindex?: number
19
+ } = {}) => (
20
+ <div className="flex flex-col items-center center gap-20">
21
+ <Tooltip
22
+ className="w-1/2 p-4 bg-red-200"
23
+ popper={<div className="p-4 text-gray-800 bg-jade-200">PopovDyn</div>}
24
+ color={color}
25
+ placement={placement}
26
+ tabIndex={tabindex}
27
+ disabled={disabled}
28
+ >
29
+ <div>Hover Me (dynamic: {placement?.toString()})</div>
30
+ </Tooltip>
31
+ <Tooltip
32
+ className="w-1/2 p-4 bg-red-200"
33
+ popper={
34
+ <div className="h-[200px] flex items-center justify-center">Popov</div>
35
+ }
36
+ color={color}
37
+ placement="top"
38
+ forcePlacement
39
+ >
40
+ <div>Force Placement to the top</div>
41
+ </Tooltip>
42
+ <Tooltip
43
+ className="w-1/2 p-4 bg-red-200"
44
+ popper={<div>PopovInt</div>}
45
+ color={color}
46
+ placement={placement}
47
+ interactive
48
+ >
49
+ <div>Interactive {placement?.toString()}</div>
50
+ </Tooltip>
51
+ {(['top', 'right', 'bottom', 'left', 'top-start'] as const).map(
52
+ (placement) => (
53
+ <Tooltip
54
+ className="w-1/2 p-4 bg-indigo-200"
55
+ placement={placement}
56
+ key={placement}
57
+ color={color}
58
+ tabIndex={tabindex}
59
+ disabled={disabled}
60
+ popper={
61
+ <div className="p-4 text-gray-800 bg-jade-200">
62
+ Popover ({placement})
63
+ </div>
64
+ }
65
+ >
66
+ <div>Hover Me ({placement})</div>
67
+ </Tooltip>
68
+ )
69
+ )}
70
+ </div>
71
+ )
7
72
 
8
73
  describe('Tooltip', { viewportHeight: 800, viewportWidth: 800 }, () => {
9
- function mountStory(options: Parameters<typeof TooltipStory>[0] = {}) {
10
- mount(<TooltipStory {...options} tabIndex={1} />)
74
+ function mountStory(
75
+ options: { single?: boolean } & Parameters<typeof TooltipStoryMulti>[0] = {}
76
+ ) {
77
+ const { single, tabindex = 1, ...rest } = options
78
+ if (single) {
79
+ mount(
80
+ <Tooltip
81
+ {...rest}
82
+ tabIndex={tabindex}
83
+ popper={
84
+ <div className="w-[300px]">
85
+ popit: Lorem ipsum dolor sit amet consectetur adipisicing elit.
86
+ Quisquam, voluptatum.
87
+ </div>
88
+ }
89
+ className="m-4 p-4 bg-red-300 w-[150px]"
90
+ >
91
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam,
92
+ voluptatum.
93
+ </Tooltip>
94
+ )
95
+ } else {
96
+ mount(<TooltipStoryMulti {...rest} tabindex={tabindex} />)
97
+ }
11
98
  }
12
99
 
13
- assertions(mountStory)
100
+ assertions(mountStory, 'react')
14
101
  })
package/dist/Tooltip.d.ts CHANGED
@@ -10,7 +10,6 @@ export interface TooltipProps {
10
10
  */
11
11
  color?: 'light' | 'dark';
12
12
  className?: string;
13
- tabIndex?: number | string;
14
13
  children?: React.ReactNode;
15
14
  /**
16
15
  * The content of the 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,EAaV,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,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@ -16,6 +16,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
16
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
17
  PERFORMANCE OF THIS SOFTWARE.
18
18
  ***************************************************************************** */
19
+ /* global Reflect, Promise */
20
+
19
21
 
20
22
  var __assign = function() {
21
23
  __assign = Object.assign || function __assign(t) {
@@ -628,6 +630,88 @@ const offset = function (value) {
628
630
  };
629
631
  };
630
632
 
633
+ function getCrossAxis(axis) {
634
+ return axis === 'x' ? 'y' : 'x';
635
+ }
636
+
637
+ /**
638
+ * Shifts the floating element in order to keep it in view when it will overflow
639
+ * a clipping boundary.
640
+ * @see https://floating-ui.com/docs/shift
641
+ */
642
+ const shift = function (options) {
643
+ if (options === void 0) {
644
+ options = {};
645
+ }
646
+
647
+ return {
648
+ name: 'shift',
649
+ options,
650
+
651
+ async fn(middlewareArguments) {
652
+ const {
653
+ x,
654
+ y,
655
+ placement
656
+ } = middlewareArguments;
657
+ const {
658
+ mainAxis: checkMainAxis = true,
659
+ crossAxis: checkCrossAxis = false,
660
+ limiter = {
661
+ fn: _ref => {
662
+ let {
663
+ x,
664
+ y
665
+ } = _ref;
666
+ return {
667
+ x,
668
+ y
669
+ };
670
+ }
671
+ },
672
+ ...detectOverflowOptions
673
+ } = options;
674
+ const coords = {
675
+ x,
676
+ y
677
+ };
678
+ const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
679
+ const mainAxis = getMainAxisFromPlacement(getSide(placement));
680
+ const crossAxis = getCrossAxis(mainAxis);
681
+ let mainAxisCoord = coords[mainAxis];
682
+ let crossAxisCoord = coords[crossAxis];
683
+
684
+ if (checkMainAxis) {
685
+ const minSide = mainAxis === 'y' ? 'top' : 'left';
686
+ const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
687
+ const min = mainAxisCoord + overflow[minSide];
688
+ const max = mainAxisCoord - overflow[maxSide];
689
+ mainAxisCoord = within(min, mainAxisCoord, max);
690
+ }
691
+
692
+ if (checkCrossAxis) {
693
+ const minSide = crossAxis === 'y' ? 'top' : 'left';
694
+ const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
695
+ const min = crossAxisCoord + overflow[minSide];
696
+ const max = crossAxisCoord - overflow[maxSide];
697
+ crossAxisCoord = within(min, crossAxisCoord, max);
698
+ }
699
+
700
+ const limitedCoords = limiter.fn({ ...middlewareArguments,
701
+ [mainAxis]: mainAxisCoord,
702
+ [crossAxis]: crossAxisCoord
703
+ });
704
+ return { ...limitedCoords,
705
+ data: {
706
+ x: limitedCoords.x - x,
707
+ y: limitedCoords.y - y
708
+ }
709
+ };
710
+ }
711
+
712
+ };
713
+ };
714
+
631
715
  function isWindow(value) {
632
716
  return value && value.document && value.location && value.alert && value.setInterval;
633
717
  }
@@ -33460,6 +33544,7 @@ var Tooltip = function (_a) {
33460
33544
  : flip(),
33461
33545
  offset(interactive ? 0 : 16),
33462
33546
  arrow({ element: arrowRef, padding: 24 }),
33547
+ shift({ padding: 16 }),
33463
33548
  ],
33464
33549
  whileElementsMounted: autoUpdate,
33465
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;
@@ -33536,4 +33621,4 @@ var Tooltip = function (_a) {
33536
33621
  export { Tooltip as default };
33537
33622
  //# sourceMappingURL=index.es.mjs.map
33538
33623
 
33539
- /* <wind-keep class="container stroke-none fill-white 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 text-[16px] leading-[24px] min-w-[160px] text-center p-[8px] relative z-20"> */
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"> */