@cypress-design/react-tooltip 0.6.2 → 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.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +6 -0
- package/Tooltip.tsx +2 -0
- package/TooltipReact.cy.tsx +90 -3
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/index.es.mjs +83 -0
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +83 -0
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
- package/Tooltip.rootstory.tsx +0 -67
package/.turbo/turbo-build.log
CHANGED
|
@@ -2,5 +2,5 @@ $ yarn build:module && yarn build:types
|
|
|
2
2
|
$ rollup -c ./rollup.config.mjs
|
|
3
3
|
[36m
|
|
4
4
|
[1m./index.ts[22m → [1m./dist/index.umd.js, ./dist/index.es.mjs[22m...[39m
|
|
5
|
-
[32mcreated [1m./dist/index.umd.js, ./dist/index.es.mjs[22m in [
|
|
5
|
+
[32mcreated [1m./dist/index.umd.js, ./dist/index.es.mjs[22m in [1m30.4s[22m[39m
|
|
6
6
|
$ tsc --project ./tsconfig.build.json
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 0.6.2
|
|
4
10
|
|
|
5
11
|
### 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,
|
|
@@ -104,6 +105,7 @@ export const Tooltip: React.FC<
|
|
|
104
105
|
: flip(),
|
|
105
106
|
offset(interactive ? 0 : 16),
|
|
106
107
|
arrow({ element: arrowRef, padding: 24 }),
|
|
108
|
+
shift({ padding: 16 }),
|
|
107
109
|
],
|
|
108
110
|
whileElementsMounted: autoUpdate,
|
|
109
111
|
})
|
package/TooltipReact.cy.tsx
CHANGED
|
@@ -2,12 +2,99 @@
|
|
|
2
2
|
|
|
3
3
|
import * as React from 'react'
|
|
4
4
|
import { mount } from 'cypress/react18'
|
|
5
|
-
import
|
|
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(
|
|
10
|
-
|
|
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
100
|
assertions(mountStory, 'react')
|
package/dist/Tooltip.d.ts.map
CHANGED
|
@@ -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,
|
|
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"}
|
package/dist/index.es.mjs
CHANGED
|
@@ -630,6 +630,88 @@ const offset = function (value) {
|
|
|
630
630
|
};
|
|
631
631
|
};
|
|
632
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
|
+
|
|
633
715
|
function isWindow(value) {
|
|
634
716
|
return value && value.document && value.location && value.alert && value.setInterval;
|
|
635
717
|
}
|
|
@@ -33462,6 +33544,7 @@ var Tooltip = function (_a) {
|
|
|
33462
33544
|
: flip(),
|
|
33463
33545
|
offset(interactive ? 0 : 16),
|
|
33464
33546
|
arrow({ element: arrowRef, padding: 24 }),
|
|
33547
|
+
shift({ padding: 16 }),
|
|
33465
33548
|
],
|
|
33466
33549
|
whileElementsMounted: autoUpdate,
|
|
33467
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;
|