@cypress-design/react-tooltip 0.6.3 → 0.7.1
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 +16 -15
- package/TooltipReact.cy.tsx +15 -0
- package/dist/Tooltip.d.ts +5 -0
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/index.es.mjs +32 -23
- package/dist/index.es.mjs.map +1 -1
- package/dist/index.umd.js +32 -23
- package/dist/index.umd.js.map +1 -1
- package/package.json +2 -2
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 [1m47.7s[22m[39m
|
|
6
6
|
$ tsc --project ./tsconfig.build.json
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @cypress-design/react-tooltip
|
|
2
2
|
|
|
3
|
+
## 0.7.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#310](https://github.com/cypress-io/cypress-design/pull/310) [`a3a323f`](https://github.com/cypress-io/cypress-design/commit/a3a323fde7acf5e5407b298b4faa0c90314c6139) Thanks [@elevatebart](https://github.com/elevatebart)! - Add-eslint-react-hooks
|
|
8
|
+
|
|
9
|
+
## 0.7.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#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
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#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
|
|
18
|
+
|
|
3
19
|
## 0.6.3
|
|
4
20
|
|
|
5
21
|
### 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
|
-
|
|
81
|
-
|
|
82
|
-
document.body.removeChild(container)
|
|
80
|
+
if (forceOpen) {
|
|
81
|
+
setOpen(true)
|
|
83
82
|
}
|
|
84
|
-
}, [])
|
|
83
|
+
}, [forceOpen])
|
|
85
84
|
|
|
86
85
|
const {
|
|
87
86
|
x,
|
|
@@ -110,20 +109,22 @@ export const Tooltip: React.FC<
|
|
|
110
109
|
whileElementsMounted: autoUpdate,
|
|
111
110
|
})
|
|
112
111
|
|
|
112
|
+
const contextHook = useDismiss(context)
|
|
113
|
+
|
|
113
114
|
const { getReferenceProps, getFloatingProps } = useInteractions([
|
|
114
115
|
useHover(context, {
|
|
115
116
|
handleClose: interactive ? safePolygon() : undefined,
|
|
116
|
-
enabled: !disabled,
|
|
117
|
+
enabled: !disabled && !forceOpen,
|
|
117
118
|
}),
|
|
118
119
|
useFocus(context, {
|
|
119
|
-
enabled: !disabled,
|
|
120
|
+
enabled: !disabled && !forceOpen,
|
|
120
121
|
}),
|
|
121
122
|
useRole(context, { role: 'tooltip' }),
|
|
122
|
-
|
|
123
|
+
...(!forceOpen ? [contextHook] : []),
|
|
123
124
|
])
|
|
124
125
|
|
|
125
126
|
const placementSide = calculatedPlacement.split(
|
|
126
|
-
'-'
|
|
127
|
+
'-',
|
|
127
128
|
)[0] as keyof typeof ROTATE_MAP
|
|
128
129
|
const arrowRotate = ROTATE_MAP[placementSide]
|
|
129
130
|
|
|
@@ -221,7 +222,7 @@ export const Tooltip: React.FC<
|
|
|
221
222
|
<div
|
|
222
223
|
className={clsx(
|
|
223
224
|
'rounded text-[16px] leading-[24px] min-w-[160px] text-center p-[8px] relative z-20',
|
|
224
|
-
colors.background
|
|
225
|
+
colors.background,
|
|
225
226
|
)}
|
|
226
227
|
>
|
|
227
228
|
{popper}
|
package/TooltipReact.cy.tsx
CHANGED
|
@@ -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;
|
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,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;
|
|
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,CA8K/C,CAAA;AAED,eAAe,OAAO,CAAA"}
|
package/dist/index.es.mjs
CHANGED
|
@@ -16,7 +16,7 @@ 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 */
|
|
19
|
+
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
var __assign = function() {
|
|
@@ -40,7 +40,22 @@ function __rest(s, e) {
|
|
|
40
40
|
t[p[i]] = s[p[i]];
|
|
41
41
|
}
|
|
42
42
|
return t;
|
|
43
|
-
}
|
|
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));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
56
|
+
var e = new Error(message);
|
|
57
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
58
|
+
};
|
|
44
59
|
|
|
45
60
|
function getSide(placement) {
|
|
46
61
|
return placement.split('-')[0];
|
|
@@ -33517,21 +33532,15 @@ var ROTATE_MAP = {
|
|
|
33517
33532
|
};
|
|
33518
33533
|
var Tooltip = function (_a) {
|
|
33519
33534
|
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"]);
|
|
33535
|
+
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
33536
|
var arrowRef = React.useRef(null);
|
|
33522
|
-
var
|
|
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];
|
|
33537
|
+
var _e = React.useState(false), open = _e[0], setOpen = _e[1];
|
|
33528
33538
|
React.useEffect(function () {
|
|
33529
|
-
|
|
33530
|
-
|
|
33531
|
-
|
|
33532
|
-
|
|
33533
|
-
|
|
33534
|
-
var _e = useFloating({
|
|
33539
|
+
if (forceOpen) {
|
|
33540
|
+
setOpen(true);
|
|
33541
|
+
}
|
|
33542
|
+
}, [forceOpen]);
|
|
33543
|
+
var _f = useFloating({
|
|
33535
33544
|
placement: placement,
|
|
33536
33545
|
open: open,
|
|
33537
33546
|
onOpenChange: setOpen,
|
|
@@ -33547,18 +33556,18 @@ var Tooltip = function (_a) {
|
|
|
33547
33556
|
shift({ padding: 16 }),
|
|
33548
33557
|
],
|
|
33549
33558
|
whileElementsMounted: autoUpdate,
|
|
33550
|
-
}), x =
|
|
33551
|
-
var
|
|
33559
|
+
}), 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;
|
|
33560
|
+
var contextHook = useDismiss(context);
|
|
33561
|
+
var _j = useInteractions(__spreadArray([
|
|
33552
33562
|
useHover(context, {
|
|
33553
33563
|
handleClose: interactive ? safePolygon() : undefined,
|
|
33554
|
-
enabled: !disabled,
|
|
33564
|
+
enabled: !disabled && !forceOpen,
|
|
33555
33565
|
}),
|
|
33556
33566
|
useFocus(context, {
|
|
33557
|
-
enabled: !disabled,
|
|
33567
|
+
enabled: !disabled && !forceOpen,
|
|
33558
33568
|
}),
|
|
33559
|
-
useRole(context, { role: 'tooltip' })
|
|
33560
|
-
|
|
33561
|
-
]), getReferenceProps = _h.getReferenceProps, getFloatingProps = _h.getFloatingProps;
|
|
33569
|
+
useRole(context, { role: 'tooltip' })
|
|
33570
|
+
], (!forceOpen ? [contextHook] : []), true)), getReferenceProps = _j.getReferenceProps, getFloatingProps = _j.getFloatingProps;
|
|
33562
33571
|
var placementSide = calculatedPlacement.split('-')[0];
|
|
33563
33572
|
var arrowRotate = ROTATE_MAP[placementSide];
|
|
33564
33573
|
var arrowXRule = 'left', arrowYRule = 'top';
|
|
@@ -33621,4 +33630,4 @@ var Tooltip = function (_a) {
|
|
|
33621
33630
|
export { Tooltip as default };
|
|
33622
33631
|
//# sourceMappingURL=index.es.mjs.map
|
|
33623
33632
|
|
|
33624
|
-
/* <wind-keep class="
|
|
33633
|
+
/* <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"> */
|