@transferwise/components 0.0.0-experimental-15e023f → 0.0.0-experimental-1b9f42b
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/build/common/panel/Panel.js +56 -40
- package/build/common/panel/Panel.js.map +1 -1
- package/build/common/panel/Panel.mjs +61 -45
- package/build/common/panel/Panel.mjs.map +1 -1
- package/build/tooltip/Tooltip.js +50 -29
- package/build/tooltip/Tooltip.js.map +1 -1
- package/build/tooltip/Tooltip.mjs +51 -30
- package/build/tooltip/Tooltip.mjs.map +1 -1
- package/build/types/common/panel/Panel.d.ts.map +1 -1
- package/build/types/tooltip/Tooltip.d.ts.map +1 -1
- package/package.json +3 -1
- package/src/common/panel/Panel.tsx +50 -42
- package/src/tooltip/Tooltip.tsx +45 -26
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var react = require('@floating-ui/react');
|
|
6
5
|
var clsx = require('clsx');
|
|
7
6
|
var React = require('react');
|
|
7
|
+
var reactPopper = require('react-popper');
|
|
8
8
|
require('../theme.js');
|
|
9
9
|
require('../direction.js');
|
|
10
10
|
require('../propsValues/control.js');
|
|
@@ -32,7 +32,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
32
32
|
var Dimmer = require('../../dimmer/Dimmer.js');
|
|
33
33
|
var OverlayIdProvider = require('../../provider/overlay/OverlayIdProvider.js');
|
|
34
34
|
|
|
35
|
-
const POPOVER_OFFSET = 16;
|
|
35
|
+
const POPOVER_OFFSET = [0, 16];
|
|
36
36
|
// By default the flip positioning explores only the opposite alternative. So if left is passed and there's no enough space
|
|
37
37
|
// the right one gets chosen. If there's no space on both sides popover goes back to the initially chosen one left.
|
|
38
38
|
// This mapping forces popover to try the four available positions before going back to the initial chosen one.
|
|
@@ -55,46 +55,60 @@ const Panel = /*#__PURE__*/React.forwardRef(function Panel({
|
|
|
55
55
|
considerHeight = false,
|
|
56
56
|
...rest
|
|
57
57
|
}, reference) {
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
middleware.push(react.offset(POPOVER_OFFSET));
|
|
62
|
-
}
|
|
63
|
-
if (flip && fallbackPlacements[position$1]) {
|
|
64
|
-
middleware.push(react.flip({
|
|
65
|
-
fallbackPlacements: fallbackPlacements[position$1]
|
|
66
|
-
}));
|
|
67
|
-
}
|
|
58
|
+
const [arrowElement, setArrowElement] = React.useState(null);
|
|
59
|
+
const [popperElement, setPopperElement] = React.useState(null);
|
|
60
|
+
const modifiers = [];
|
|
68
61
|
if (altAxis) {
|
|
69
|
-
|
|
62
|
+
modifiers.push({
|
|
63
|
+
// https://popper.js.org/docs/v2/modifiers/prevent-overflow
|
|
64
|
+
name: 'preventOverflow',
|
|
65
|
+
options: {
|
|
66
|
+
altAxis: true,
|
|
67
|
+
tether: false
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
70
|
}
|
|
71
71
|
if (arrow) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
modifiers.push({
|
|
73
|
+
name: 'arrow',
|
|
74
|
+
options: {
|
|
75
|
+
element: arrowElement,
|
|
76
|
+
options: {
|
|
77
|
+
padding: 8 // 8px from the edges of the popper
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
// This lets you displace a popper element from its reference element.
|
|
82
|
+
modifiers.push({
|
|
83
|
+
name: 'offset',
|
|
84
|
+
options: {
|
|
85
|
+
offset: POPOVER_OFFSET
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
if (flip && fallbackPlacements[position$1]) {
|
|
90
|
+
modifiers.push({
|
|
91
|
+
name: 'flip',
|
|
92
|
+
options: {
|
|
93
|
+
fallbackPlacements: fallbackPlacements[position$1]
|
|
94
|
+
}
|
|
95
|
+
});
|
|
76
96
|
}
|
|
77
97
|
const {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
} = react.useFloating({
|
|
98
|
+
styles,
|
|
99
|
+
attributes,
|
|
100
|
+
forceUpdate
|
|
101
|
+
} = reactPopper.usePopper(anchorRef.current, popperElement, {
|
|
83
102
|
placement: position$1,
|
|
84
|
-
|
|
85
|
-
elements: {
|
|
86
|
-
reference: anchorRef.current
|
|
87
|
-
},
|
|
88
|
-
whileElementsMounted: open ? react.autoUpdate : undefined
|
|
103
|
+
modifiers
|
|
89
104
|
});
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
};
|
|
105
|
+
// If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),
|
|
106
|
+
// it is most simple just to always position before opening
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
if (open && forceUpdate) {
|
|
109
|
+
forceUpdate();
|
|
110
|
+
}
|
|
111
|
+
}, [open]);
|
|
98
112
|
const contentStyle = {
|
|
99
113
|
...(anchorWidth ? {
|
|
100
114
|
width: anchorRef.current?.clientWidth
|
|
@@ -110,10 +124,12 @@ const Panel = /*#__PURE__*/React.forwardRef(function Panel({
|
|
|
110
124
|
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
111
125
|
id: overlayId,
|
|
112
126
|
...rest,
|
|
113
|
-
ref:
|
|
127
|
+
ref: setPopperElement,
|
|
114
128
|
role: "dialog",
|
|
115
|
-
style:
|
|
116
|
-
|
|
129
|
+
style: {
|
|
130
|
+
...styles.popper
|
|
131
|
+
},
|
|
132
|
+
...attributes.popper,
|
|
117
133
|
className: clsx.clsx('np-panel', {
|
|
118
134
|
'np-panel--open': open
|
|
119
135
|
}, rest.className),
|
|
@@ -122,9 +138,9 @@ const Panel = /*#__PURE__*/React.forwardRef(function Panel({
|
|
|
122
138
|
style: contentStyle,
|
|
123
139
|
className: clsx.clsx('np-panel__content'),
|
|
124
140
|
children: [children, arrow && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
125
|
-
ref:
|
|
141
|
+
ref: setArrowElement,
|
|
126
142
|
className: clsx.clsx('np-panel__arrow'),
|
|
127
|
-
style:
|
|
143
|
+
style: styles.arrow
|
|
128
144
|
})]
|
|
129
145
|
})
|
|
130
146
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.js","sources":["../../../src/common/panel/Panel.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Panel.js","sources":["../../../src/common/panel/Panel.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport {\n CSSProperties,\n HTMLAttributes,\n MutableRefObject,\n PropsWithChildren,\n SyntheticEvent,\n forwardRef,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport { usePopper } from 'react-popper';\n\nimport { Position, PositionBottom, PositionLeft, PositionRight, PositionTop } from '..';\nimport Dimmer from '../../dimmer';\nimport { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider';\n\nconst POPOVER_OFFSET = [0, 16];\n\n// By default the flip positioning explores only the opposite alternative. So if left is passed and there's no enough space\n// the right one gets chosen. If there's no space on both sides popover goes back to the initially chosen one left.\n// This mapping forces popover to try the four available positions before going back to the initial chosen one.\nconst fallbackPlacements = {\n [Position.TOP]: [Position.BOTTOM, Position.RIGHT, Position.LEFT],\n [Position.BOTTOM]: [Position.TOP, Position.RIGHT, Position.LEFT],\n [Position.LEFT]: [Position.RIGHT, Position.TOP, Position.BOTTOM],\n [Position.RIGHT]: [Position.LEFT, Position.TOP, Position.BOTTOM],\n};\n\nexport type PanelProps = PropsWithChildren<{\n arrow?: boolean;\n flip?: boolean;\n altAxis?: boolean;\n open?: boolean;\n onClose?: (event: Event | SyntheticEvent) => void;\n position?: PositionBottom | PositionLeft | PositionRight | PositionTop;\n anchorRef: MutableRefObject<Element | null>;\n anchorWidth?: boolean;\n considerHeight?: boolean;\n}> &\n HTMLAttributes<HTMLDivElement>;\n\nconst Panel = forwardRef<HTMLDivElement, PanelProps>(function Panel(\n {\n arrow = false,\n flip = true,\n altAxis = false,\n children,\n open = false,\n onClose,\n position = Position.BOTTOM,\n anchorRef,\n anchorWidth = false,\n considerHeight = false,\n ...rest\n }: PanelProps,\n reference,\n) {\n const [arrowElement, setArrowElement] = useState<HTMLDivElement | null>(null);\n const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);\n\n const modifiers = [];\n\n if (altAxis) {\n modifiers.push({\n // https://popper.js.org/docs/v2/modifiers/prevent-overflow\n name: 'preventOverflow',\n options: {\n altAxis: true,\n tether: false,\n },\n });\n }\n\n if (arrow) {\n modifiers.push({\n name: 'arrow',\n options: {\n element: arrowElement,\n options: {\n padding: 8, // 8px from the edges of the popper\n },\n },\n });\n // This lets you displace a popper element from its reference element.\n modifiers.push({ name: 'offset', options: { offset: POPOVER_OFFSET } });\n }\n if (flip && fallbackPlacements[position]) {\n modifiers.push({\n name: 'flip',\n options: {\n fallbackPlacements: fallbackPlacements[position],\n },\n });\n }\n\n const { styles, attributes, forceUpdate } = usePopper(anchorRef.current, popperElement, {\n placement: position,\n modifiers,\n });\n\n // If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),\n // it is most simple just to always position before opening\n useEffect(() => {\n if (open && forceUpdate) {\n forceUpdate();\n }\n }, [open]);\n\n const contentStyle: CSSProperties = {\n ...(anchorWidth ? { width: anchorRef.current?.clientWidth } : undefined),\n };\n\n const overlayId = useContext(OverlayIdContext);\n\n return (\n <Dimmer open={open} transparent fadeContentOnEnter fadeContentOnExit onClose={onClose}>\n <div\n id={overlayId}\n {...rest}\n ref={setPopperElement}\n role=\"dialog\"\n style={{ ...styles.popper }}\n {...attributes.popper}\n className={clsx('np-panel', { 'np-panel--open': open }, rest.className)}\n >\n <div ref={reference} style={contentStyle} className={clsx('np-panel__content')}>\n {children}\n {/* Arrow has to stay inside content to get the same animations as the \"dialog\" and to get hidden when panel is closed. */}\n {arrow && (\n <div ref={setArrowElement} className={clsx('np-panel__arrow')} style={styles.arrow} />\n )}\n </div>\n </div>\n </Dimmer>\n );\n});\n\nexport default Panel;\n"],"names":["POPOVER_OFFSET","fallbackPlacements","Position","TOP","BOTTOM","RIGHT","LEFT","Panel","forwardRef","arrow","flip","altAxis","children","open","onClose","position","anchorRef","anchorWidth","considerHeight","rest","reference","arrowElement","setArrowElement","useState","popperElement","setPopperElement","modifiers","push","name","options","tether","element","padding","offset","styles","attributes","forceUpdate","usePopper","current","placement","useEffect","contentStyle","width","clientWidth","undefined","overlayId","useContext","OverlayIdContext","_jsx","Dimmer","transparent","fadeContentOnEnter","fadeContentOnExit","id","ref","role","style","popper","className","clsx","_jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAMA,cAAc,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC;AAE9B;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG;AACzB,EAAA,CAACC,iBAAQ,CAACC,GAAG,GAAG,CAACD,iBAAQ,CAACE,MAAM,EAAEF,iBAAQ,CAACG,KAAK,EAAEH,iBAAQ,CAACI,IAAI,CAAC;AAChE,EAAA,CAACJ,iBAAQ,CAACE,MAAM,GAAG,CAACF,iBAAQ,CAACC,GAAG,EAAED,iBAAQ,CAACG,KAAK,EAAEH,iBAAQ,CAACI,IAAI,CAAC;AAChE,EAAA,CAACJ,iBAAQ,CAACI,IAAI,GAAG,CAACJ,iBAAQ,CAACG,KAAK,EAAEH,iBAAQ,CAACC,GAAG,EAAED,iBAAQ,CAACE,MAAM,CAAC;AAChE,EAAA,CAACF,iBAAQ,CAACG,KAAK,GAAG,CAACH,iBAAQ,CAACI,IAAI,EAAEJ,iBAAQ,CAACC,GAAG,EAAED,iBAAQ,CAACE,MAAM;CAChE;AAeD,MAAMG,KAAK,gBAAGC,gBAAU,CAA6B,SAASD,KAAKA,CACjE;AACEE,EAAAA,KAAK,GAAG,KAAK;AACbC,EAAAA,IAAI,G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,QAAA,eAExEgD,eAAA,CAAA,KAAA,EAAA;AAAKN,QAAAA,GAAG,EAAElC,SAAU;AAACoC,QAAAA,KAAK,EAAEf,YAAa;AAACiB,QAAAA,SAAS,EAAEC,SAAI,CAAC,mBAAmB,CAAE;AAAA/C,QAAAA,QAAA,EAAA,CAC5EA,QAAQ,EAERH,KAAK,iBACJuC,cAAA,CAAA,KAAA,EAAA;AAAKM,UAAAA,GAAG,EAAEhC,eAAgB;AAACoC,UAAAA,SAAS,EAAEC,SAAI,CAAC,iBAAiB,CAAE;UAACH,KAAK,EAAEtB,MAAM,CAACzB;AAAM,SAAA,CACpF;OACE;KACF;AACP,GAAQ,CAAC;AAEb,CAAC;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { offset, flip, shift, arrow, useFloating, autoUpdate } from '@floating-ui/react';
|
|
2
1
|
import { clsx } from 'clsx';
|
|
3
|
-
import { forwardRef,
|
|
2
|
+
import { forwardRef, useState, useEffect, useContext } from 'react';
|
|
3
|
+
import { usePopper } from 'react-popper';
|
|
4
4
|
import '../theme.mjs';
|
|
5
5
|
import '../direction.mjs';
|
|
6
6
|
import '../propsValues/control.mjs';
|
|
@@ -28,7 +28,7 @@ import { jsx, jsxs } from 'react/jsx-runtime';
|
|
|
28
28
|
import Dimmer from '../../dimmer/Dimmer.mjs';
|
|
29
29
|
import { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider.mjs';
|
|
30
30
|
|
|
31
|
-
const POPOVER_OFFSET = 16;
|
|
31
|
+
const POPOVER_OFFSET = [0, 16];
|
|
32
32
|
// By default the flip positioning explores only the opposite alternative. So if left is passed and there's no enough space
|
|
33
33
|
// the right one gets chosen. If there's no space on both sides popover goes back to the initially chosen one left.
|
|
34
34
|
// This mapping forces popover to try the four available positions before going back to the initial chosen one.
|
|
@@ -39,8 +39,8 @@ const fallbackPlacements = {
|
|
|
39
39
|
[Position.RIGHT]: [Position.LEFT, Position.TOP, Position.BOTTOM]
|
|
40
40
|
};
|
|
41
41
|
const Panel = /*#__PURE__*/forwardRef(function Panel({
|
|
42
|
-
arrow
|
|
43
|
-
flip
|
|
42
|
+
arrow = false,
|
|
43
|
+
flip = true,
|
|
44
44
|
altAxis = false,
|
|
45
45
|
children,
|
|
46
46
|
open = false,
|
|
@@ -51,46 +51,60 @@ const Panel = /*#__PURE__*/forwardRef(function Panel({
|
|
|
51
51
|
considerHeight = false,
|
|
52
52
|
...rest
|
|
53
53
|
}, reference) {
|
|
54
|
-
const
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
middleware.push(offset(POPOVER_OFFSET));
|
|
58
|
-
}
|
|
59
|
-
if (flip$1 && fallbackPlacements[position]) {
|
|
60
|
-
middleware.push(flip({
|
|
61
|
-
fallbackPlacements: fallbackPlacements[position]
|
|
62
|
-
}));
|
|
63
|
-
}
|
|
54
|
+
const [arrowElement, setArrowElement] = useState(null);
|
|
55
|
+
const [popperElement, setPopperElement] = useState(null);
|
|
56
|
+
const modifiers = [];
|
|
64
57
|
if (altAxis) {
|
|
65
|
-
|
|
58
|
+
modifiers.push({
|
|
59
|
+
// https://popper.js.org/docs/v2/modifiers/prevent-overflow
|
|
60
|
+
name: 'preventOverflow',
|
|
61
|
+
options: {
|
|
62
|
+
altAxis: true,
|
|
63
|
+
tether: false
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
66
|
}
|
|
67
|
-
if (arrow
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
67
|
+
if (arrow) {
|
|
68
|
+
modifiers.push({
|
|
69
|
+
name: 'arrow',
|
|
70
|
+
options: {
|
|
71
|
+
element: arrowElement,
|
|
72
|
+
options: {
|
|
73
|
+
padding: 8 // 8px from the edges of the popper
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
// This lets you displace a popper element from its reference element.
|
|
78
|
+
modifiers.push({
|
|
79
|
+
name: 'offset',
|
|
80
|
+
options: {
|
|
81
|
+
offset: POPOVER_OFFSET
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
if (flip && fallbackPlacements[position]) {
|
|
86
|
+
modifiers.push({
|
|
87
|
+
name: 'flip',
|
|
88
|
+
options: {
|
|
89
|
+
fallbackPlacements: fallbackPlacements[position]
|
|
90
|
+
}
|
|
91
|
+
});
|
|
72
92
|
}
|
|
73
93
|
const {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
} = useFloating({
|
|
94
|
+
styles,
|
|
95
|
+
attributes,
|
|
96
|
+
forceUpdate
|
|
97
|
+
} = usePopper(anchorRef.current, popperElement, {
|
|
79
98
|
placement: position,
|
|
80
|
-
|
|
81
|
-
elements: {
|
|
82
|
-
reference: anchorRef.current
|
|
83
|
-
},
|
|
84
|
-
whileElementsMounted: open ? autoUpdate : undefined
|
|
99
|
+
modifiers
|
|
85
100
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
};
|
|
101
|
+
// If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),
|
|
102
|
+
// it is most simple just to always position before opening
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (open && forceUpdate) {
|
|
105
|
+
forceUpdate();
|
|
106
|
+
}
|
|
107
|
+
}, [open]);
|
|
94
108
|
const contentStyle = {
|
|
95
109
|
...(anchorWidth ? {
|
|
96
110
|
width: anchorRef.current?.clientWidth
|
|
@@ -106,10 +120,12 @@ const Panel = /*#__PURE__*/forwardRef(function Panel({
|
|
|
106
120
|
children: /*#__PURE__*/jsx("div", {
|
|
107
121
|
id: overlayId,
|
|
108
122
|
...rest,
|
|
109
|
-
ref:
|
|
123
|
+
ref: setPopperElement,
|
|
110
124
|
role: "dialog",
|
|
111
|
-
style:
|
|
112
|
-
|
|
125
|
+
style: {
|
|
126
|
+
...styles.popper
|
|
127
|
+
},
|
|
128
|
+
...attributes.popper,
|
|
113
129
|
className: clsx('np-panel', {
|
|
114
130
|
'np-panel--open': open
|
|
115
131
|
}, rest.className),
|
|
@@ -117,10 +133,10 @@ const Panel = /*#__PURE__*/forwardRef(function Panel({
|
|
|
117
133
|
ref: reference,
|
|
118
134
|
style: contentStyle,
|
|
119
135
|
className: clsx('np-panel__content'),
|
|
120
|
-
children: [children, arrow
|
|
121
|
-
ref:
|
|
136
|
+
children: [children, arrow && /*#__PURE__*/jsx("div", {
|
|
137
|
+
ref: setArrowElement,
|
|
122
138
|
className: clsx('np-panel__arrow'),
|
|
123
|
-
style:
|
|
139
|
+
style: styles.arrow
|
|
124
140
|
})]
|
|
125
141
|
})
|
|
126
142
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.mjs","sources":["../../../src/common/panel/Panel.tsx"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"Panel.mjs","sources":["../../../src/common/panel/Panel.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport {\n CSSProperties,\n HTMLAttributes,\n MutableRefObject,\n PropsWithChildren,\n SyntheticEvent,\n forwardRef,\n useContext,\n useEffect,\n useState,\n} from 'react';\nimport { usePopper } from 'react-popper';\n\nimport { Position, PositionBottom, PositionLeft, PositionRight, PositionTop } from '..';\nimport Dimmer from '../../dimmer';\nimport { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider';\n\nconst POPOVER_OFFSET = [0, 16];\n\n// By default the flip positioning explores only the opposite alternative. So if left is passed and there's no enough space\n// the right one gets chosen. If there's no space on both sides popover goes back to the initially chosen one left.\n// This mapping forces popover to try the four available positions before going back to the initial chosen one.\nconst fallbackPlacements = {\n [Position.TOP]: [Position.BOTTOM, Position.RIGHT, Position.LEFT],\n [Position.BOTTOM]: [Position.TOP, Position.RIGHT, Position.LEFT],\n [Position.LEFT]: [Position.RIGHT, Position.TOP, Position.BOTTOM],\n [Position.RIGHT]: [Position.LEFT, Position.TOP, Position.BOTTOM],\n};\n\nexport type PanelProps = PropsWithChildren<{\n arrow?: boolean;\n flip?: boolean;\n altAxis?: boolean;\n open?: boolean;\n onClose?: (event: Event | SyntheticEvent) => void;\n position?: PositionBottom | PositionLeft | PositionRight | PositionTop;\n anchorRef: MutableRefObject<Element | null>;\n anchorWidth?: boolean;\n considerHeight?: boolean;\n}> &\n HTMLAttributes<HTMLDivElement>;\n\nconst Panel = forwardRef<HTMLDivElement, PanelProps>(function Panel(\n {\n arrow = false,\n flip = true,\n altAxis = false,\n children,\n open = false,\n onClose,\n position = Position.BOTTOM,\n anchorRef,\n anchorWidth = false,\n considerHeight = false,\n ...rest\n }: PanelProps,\n reference,\n) {\n const [arrowElement, setArrowElement] = useState<HTMLDivElement | null>(null);\n const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);\n\n const modifiers = [];\n\n if (altAxis) {\n modifiers.push({\n // https://popper.js.org/docs/v2/modifiers/prevent-overflow\n name: 'preventOverflow',\n options: {\n altAxis: true,\n tether: false,\n },\n });\n }\n\n if (arrow) {\n modifiers.push({\n name: 'arrow',\n options: {\n element: arrowElement,\n options: {\n padding: 8, // 8px from the edges of the popper\n },\n },\n });\n // This lets you displace a popper element from its reference element.\n modifiers.push({ name: 'offset', options: { offset: POPOVER_OFFSET } });\n }\n if (flip && fallbackPlacements[position]) {\n modifiers.push({\n name: 'flip',\n options: {\n fallbackPlacements: fallbackPlacements[position],\n },\n });\n }\n\n const { styles, attributes, forceUpdate } = usePopper(anchorRef.current, popperElement, {\n placement: position,\n modifiers,\n });\n\n // If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),\n // it is most simple just to always position before opening\n useEffect(() => {\n if (open && forceUpdate) {\n forceUpdate();\n }\n }, [open]);\n\n const contentStyle: CSSProperties = {\n ...(anchorWidth ? { width: anchorRef.current?.clientWidth } : undefined),\n };\n\n const overlayId = useContext(OverlayIdContext);\n\n return (\n <Dimmer open={open} transparent fadeContentOnEnter fadeContentOnExit onClose={onClose}>\n <div\n id={overlayId}\n {...rest}\n ref={setPopperElement}\n role=\"dialog\"\n style={{ ...styles.popper }}\n {...attributes.popper}\n className={clsx('np-panel', { 'np-panel--open': open }, rest.className)}\n >\n <div ref={reference} style={contentStyle} className={clsx('np-panel__content')}>\n {children}\n {/* Arrow has to stay inside content to get the same animations as the \"dialog\" and to get hidden when panel is closed. */}\n {arrow && (\n <div ref={setArrowElement} className={clsx('np-panel__arrow')} style={styles.arrow} />\n )}\n </div>\n </div>\n </Dimmer>\n );\n});\n\nexport default Panel;\n"],"names":["POPOVER_OFFSET","fallbackPlacements","Position","TOP","BOTTOM","RIGHT","LEFT","Panel","forwardRef","arrow","flip","altAxis","children","open","onClose","position","anchorRef","anchorWidth","considerHeight","rest","reference","arrowElement","setArrowElement","useState","popperElement","setPopperElement","modifiers","push","name","options","tether","element","padding","offset","styles","attributes","forceUpdate","usePopper","current","placement","useEffect","contentStyle","width","clientWidth","undefined","overlayId","useContext","OverlayIdContext","_jsx","Dimmer","transparent","fadeContentOnEnter","fadeContentOnExit","id","ref","role","style","popper","className","clsx","_jsxs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBA,MAAMA,cAAc,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC;AAE9B;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG;AACzB,EAAA,CAACC,QAAQ,CAACC,GAAG,GAAG,CAACD,QAAQ,CAACE,MAAM,EAAEF,QAAQ,CAACG,KAAK,EAAEH,QAAQ,CAACI,IAAI,CAAC;AAChE,EAAA,CAACJ,QAAQ,CAACE,MAAM,GAAG,CAACF,QAAQ,CAACC,GAAG,EAAED,QAAQ,CAACG,KAAK,EAAEH,QAAQ,CAACI,IAAI,CAAC;AAChE,EAAA,CAACJ,QAAQ,CAACI,IAAI,GAAG,CAACJ,QAAQ,CAACG,KAAK,EAAEH,QAAQ,CAACC,GAAG,EAAED,QAAQ,CAACE,MAAM,CAAC;AAChE,EAAA,CAACF,QAAQ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AAE,QAAA,GAAGtB,MAAM,CAACuB;OAAS;MAAA,GACxBtB,UAAU,CAACsB,MAAM;AACrBC,MAAAA,SAAS,EAAEC,IAAI,CAAC,UAAU,EAAE;AAAE,QAAA,gBAAgB,EAAE9C;AAAI,OAAE,EAAEM,IAAI,CAACuC,SAAS,CAAE;AAAA9C,MAAAA,QAAA,eAExEgD,IAAA,CAAA,KAAA,EAAA;AAAKN,QAAAA,GAAG,EAAElC,SAAU;AAACoC,QAAAA,KAAK,EAAEf,YAAa;AAACiB,QAAAA,SAAS,EAAEC,IAAI,CAAC,mBAAmB,CAAE;AAAA/C,QAAAA,QAAA,EAAA,CAC5EA,QAAQ,EAERH,KAAK,iBACJuC,GAAA,CAAA,KAAA,EAAA;AAAKM,UAAAA,GAAG,EAAEhC,eAAgB;AAACoC,UAAAA,SAAS,EAAEC,IAAI,CAAC,iBAAiB,CAAE;UAACH,KAAK,EAAEtB,MAAM,CAACzB;AAAM,SAAA,CACpF;OACE;KACF;AACP,GAAQ,CAAC;AAEb,CAAC;;;;"}
|
package/build/tooltip/Tooltip.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var react = require('@floating-ui/react');
|
|
6
5
|
var clsx = require('clsx');
|
|
7
6
|
var React = require('react');
|
|
7
|
+
var reactPopper = require('react-popper');
|
|
8
8
|
require('../common/theme.js');
|
|
9
9
|
require('../common/direction.js');
|
|
10
10
|
require('../common/propsValues/control.js');
|
|
@@ -30,6 +30,7 @@ require('react-intl');
|
|
|
30
30
|
require('../common/closeButton/CloseButton.messages.js');
|
|
31
31
|
var jsxRuntime = require('react/jsx-runtime');
|
|
32
32
|
|
|
33
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
33
34
|
const Tooltip = ({
|
|
34
35
|
position: position$1 = position.Position.TOP,
|
|
35
36
|
children = undefined,
|
|
@@ -38,35 +39,51 @@ const Tooltip = ({
|
|
|
38
39
|
className
|
|
39
40
|
}) => {
|
|
40
41
|
const [open, setOpen] = React.useState(false);
|
|
41
|
-
const
|
|
42
|
+
const anchorReference = React.useRef(null);
|
|
43
|
+
const [arrowElement, setArrowElement] = React.useState(null);
|
|
44
|
+
const [popperElement, setPopperElement] = React.useState(null);
|
|
42
45
|
const fallbackId = React.useId();
|
|
43
46
|
const tooltipId = id ?? fallbackId;
|
|
47
|
+
const modifiers = [];
|
|
48
|
+
modifiers.push({
|
|
49
|
+
name: 'arrow',
|
|
50
|
+
options: {
|
|
51
|
+
element: arrowElement,
|
|
52
|
+
options: {
|
|
53
|
+
padding: 8 // 8px from the edges of the popper
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
// This lets you displace a popper element from its reference element.
|
|
58
|
+
modifiers.push({
|
|
59
|
+
name: 'offset',
|
|
60
|
+
options: {
|
|
61
|
+
offset: [0, 16]
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
modifiers.push({
|
|
65
|
+
name: 'flip',
|
|
66
|
+
options: {
|
|
67
|
+
fallbackPlacements: position.Position.TOP
|
|
68
|
+
}
|
|
69
|
+
});
|
|
44
70
|
const {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
} = react.useFloating({
|
|
71
|
+
styles,
|
|
72
|
+
attributes,
|
|
73
|
+
forceUpdate
|
|
74
|
+
} = reactPopper.usePopper(anchorReference.current, popperElement, {
|
|
50
75
|
placement: position$1,
|
|
51
|
-
|
|
52
|
-
fallbackPlacements: [position.Position.TOP]
|
|
53
|
-
}), react.arrow({
|
|
54
|
-
element: arrowRef,
|
|
55
|
-
padding: 8
|
|
56
|
-
})],
|
|
57
|
-
whileElementsMounted: open ? react.autoUpdate : undefined,
|
|
58
|
-
open
|
|
76
|
+
modifiers
|
|
59
77
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
};
|
|
78
|
+
// If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),
|
|
79
|
+
// it is most simple just to always position before opening
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
if (open && forceUpdate) {
|
|
82
|
+
forceUpdate();
|
|
83
|
+
}
|
|
84
|
+
}, [open]);
|
|
68
85
|
return /*#__PURE__*/jsxRuntime.jsxs("span", {
|
|
69
|
-
ref:
|
|
86
|
+
ref: anchorReference,
|
|
70
87
|
className: "tw-tooltip-container",
|
|
71
88
|
onMouseOver: () => setOpen(true),
|
|
72
89
|
onFocus: () => setOpen(true),
|
|
@@ -75,19 +92,23 @@ const Tooltip = ({
|
|
|
75
92
|
children: [children ? /*#__PURE__*/React.cloneElement(children, {
|
|
76
93
|
'aria-describedby': `${tooltipId}-tooltip`
|
|
77
94
|
}) : null, /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
78
|
-
|
|
95
|
+
// @ts-expect-error
|
|
96
|
+
ref: setPopperElement,
|
|
79
97
|
className: clsx.clsx('np-tooltip', 'np-panel', open ? `np-panel--open np-tooltip--open` : null, className),
|
|
80
|
-
style:
|
|
81
|
-
|
|
98
|
+
style: {
|
|
99
|
+
...styles.popper
|
|
100
|
+
},
|
|
101
|
+
...attributes.popper,
|
|
82
102
|
"aria-hidden": !open,
|
|
83
103
|
role: "tooltip",
|
|
84
104
|
id: `${tooltipId}-tooltip`,
|
|
85
105
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
86
106
|
className: "np-panel__content tooltip-inner",
|
|
87
107
|
children: [label, /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
88
|
-
|
|
108
|
+
// @ts-expect-error
|
|
109
|
+
ref: setArrowElement,
|
|
89
110
|
className: clsx.clsx('np-panel__arrow'),
|
|
90
|
-
style:
|
|
111
|
+
style: styles.arrow
|
|
91
112
|
})]
|
|
92
113
|
})
|
|
93
114
|
})]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.js","sources":["../../src/tooltip/Tooltip.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"Tooltip.js","sources":["../../src/tooltip/Tooltip.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { clsx } from 'clsx';\nimport {\n AriaAttributes,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n cloneElement,\n useEffect,\n useId,\n useRef,\n useState,\n} from 'react';\nimport { usePopper } from 'react-popper';\n\nimport { CommonProps, Position } from '../common';\nimport {\n PositionBottom,\n PositionLeft,\n PositionRight,\n PositionTop,\n} from '../common/propsValues/position';\n\nexport type TooltipProps = PropsWithChildren<{\n position?: PositionTop | PositionRight | PositionBottom | PositionLeft;\n label: ReactNode;\n id?: string;\n}> &\n CommonProps;\n\nconst Tooltip = ({\n position = Position.TOP,\n children = undefined,\n label,\n id,\n className,\n}: TooltipProps) => {\n const [open, setOpen] = useState(false);\n const anchorReference = useRef(null);\n const [arrowElement, setArrowElement] = useState(null);\n const [popperElement, setPopperElement] = useState(null);\n\n const fallbackId = useId();\n const tooltipId = id ?? fallbackId;\n const modifiers = [];\n\n modifiers.push({\n name: 'arrow',\n options: {\n element: arrowElement,\n options: {\n padding: 8, // 8px from the edges of the popper\n },\n },\n });\n // This lets you displace a popper element from its reference element.\n modifiers.push({ name: 'offset', options: { offset: [0, 16] } });\n modifiers.push({\n name: 'flip',\n options: {\n fallbackPlacements: Position.TOP,\n },\n });\n\n const { styles, attributes, forceUpdate } = usePopper(anchorReference.current, popperElement, {\n placement: position,\n modifiers,\n });\n\n // If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),\n // it is most simple just to always position before opening\n useEffect(() => {\n if (open && forceUpdate) {\n forceUpdate();\n }\n }, [open]);\n\n return (\n <span\n ref={anchorReference}\n className=\"tw-tooltip-container\"\n onMouseOver={() => setOpen(true)}\n onFocus={() => setOpen(true)}\n onMouseOut={() => setOpen(false)}\n onBlur={() => setOpen(false)}\n >\n {children\n ? cloneElement(children as ReactElement<Pick<AriaAttributes, 'aria-describedby'>>, {\n 'aria-describedby': `${tooltipId}-tooltip`,\n })\n : null}\n <div\n // @ts-expect-error\n ref={setPopperElement}\n className={clsx(\n 'np-tooltip',\n 'np-panel',\n open ? `np-panel--open np-tooltip--open` : null,\n className,\n )}\n style={{ ...styles.popper }}\n {...attributes.popper}\n aria-hidden={!open}\n role=\"tooltip\"\n id={`${tooltipId}-tooltip`}\n >\n <div className=\"np-panel__content tooltip-inner\">\n {label}\n <div\n // @ts-expect-error\n ref={setArrowElement}\n className={clsx('np-panel__arrow')}\n style={styles.arrow}\n />\n </div>\n </div>\n </span>\n );\n};\n\nexport default Tooltip;\n"],"names":["Tooltip","position","Position","TOP","children","undefined","label","id","className","open","setOpen","useState","anchorReference","useRef","arrowElement","setArrowElement","popperElement","setPopperElement","fallbackId","useId","tooltipId","modifiers","push","name","options","element","padding","offset","fallbackPlacements","styles","attributes","forceUpdate","usePopper","current","placement","useEffect","_jsxs","ref","onMouseOver","onFocus","onMouseOut","onBlur","cloneElement","_jsx","clsx","style","popper","role","arrow"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AA8BA,MAAMA,OAAO,GAAGA,CAAC;YACfC,UAAQ,GAAGC,iBAAQ,CAACC,GAAG;AACvBC,EAAAA,QAAQ,GAAGC,SAAS;EACpBC,KAAK;EACLC,EAAE;AACFC,EAAAA;AAAS,CACI,KAAI;EACjB,MAAM,CAACC,IAAI,EAAEC,OAAO,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;AACvC,EAAA,MAAMC,eAAe,GAAGC,YAAM,CAAC,IAAI,CAAC;EACpC,MAAM,CAACC,YAAY,EAAEC,eAAe,CAAC,GAAGJ,cAAQ,CAAC,IAAI,CAAC;EACtD,MAAM,CAACK,aAAa,EAAEC,gBAAgB,CAAC,GAAGN,cAAQ,CAAC,IAAI,CAAC;AAExD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,CAAE;AAC7B8B,IAAAA,UAAU,EAAEA,MAAM9B,OAAO,CAAC,KAAK,CAAE;AACjC+B,IAAAA,MAAM,EAAEA,MAAM/B,OAAO,CAAC,KAAK,CAAE;AAAAN,IAAAA,QAAA,GAE5BA,QAAQ,gBACLsC,kBAAY,CAACtC,QAAkE,EAAE;MAC/E,kBAAkB,EAAE,GAAGgB,SAAS,CAAA,QAAA;KACjC,CAAC,GACF,IAAI,eACRuB,cAAA,CAAA,KAAA,EAAA;AACE;AACAN,MAAAA,GAAG,EAAEpB,gBAAiB;AACtBT,MAAAA,SAAS,EAAEoC,SAAI,CACb,YAAY,EACZ,UAAU,EACVnC,IAAI,GAAG,CAAA,+BAAA,CAAiC,GAAG,IAAI,EAC/CD,SAAS,CACT;AACFqC,MAAAA,KAAK,EAAE;AAAE,QAAA,GAAGhB,MAAM,CAACiB;OAAS;MAAA,GACxBhB,UAAU,CAACgB,MAAM;AACrB,MAAA,aAAA,EAAa,CAACrC,IAAK;AACnBsC,MAAAA,IAAI,EAAC,SAAS;MACdxC,EAAE,EAAE,CAAA,EAAGa,SAAS,CAAA,QAAA,CAAW;AAAAhB,MAAAA,QAAA,eAE3BgC,eAAA,CAAA,KAAA,EAAA;AAAK5B,QAAAA,SAAS,EAAC,iCAAiC;QAAAJ,QAAA,EAAA,CAC7CE,KAAK,eACNqC,cAAA,CAAA,KAAA,EAAA;AACE;AACAN,UAAAA,GAAG,EAAEtB,eAAgB;AACrBP,UAAAA,SAAS,EAAEoC,SAAI,CAAC,iBAAiB,CAAE;UACnCC,KAAK,EAAEhB,MAAM,CAACmB;AAAM,SAAA,CAExB;OAAK;AACP,KAAK,CACP;AAAA,GAAM,CAAC;AAEX;;;;"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useFloating, autoUpdate, offset, flip, arrow } from '@floating-ui/react';
|
|
2
1
|
import { clsx } from 'clsx';
|
|
3
|
-
import { useState, useRef, useId, cloneElement } from 'react';
|
|
2
|
+
import { useState, useRef, useId, useEffect, cloneElement } from 'react';
|
|
3
|
+
import { usePopper } from 'react-popper';
|
|
4
4
|
import '../common/theme.mjs';
|
|
5
5
|
import '../common/direction.mjs';
|
|
6
6
|
import '../common/propsValues/control.mjs';
|
|
@@ -26,6 +26,7 @@ import 'react-intl';
|
|
|
26
26
|
import '../common/closeButton/CloseButton.messages.mjs';
|
|
27
27
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
28
28
|
|
|
29
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
29
30
|
const Tooltip = ({
|
|
30
31
|
position = Position.TOP,
|
|
31
32
|
children = undefined,
|
|
@@ -34,35 +35,51 @@ const Tooltip = ({
|
|
|
34
35
|
className
|
|
35
36
|
}) => {
|
|
36
37
|
const [open, setOpen] = useState(false);
|
|
37
|
-
const
|
|
38
|
+
const anchorReference = useRef(null);
|
|
39
|
+
const [arrowElement, setArrowElement] = useState(null);
|
|
40
|
+
const [popperElement, setPopperElement] = useState(null);
|
|
38
41
|
const fallbackId = useId();
|
|
39
42
|
const tooltipId = id ?? fallbackId;
|
|
43
|
+
const modifiers = [];
|
|
44
|
+
modifiers.push({
|
|
45
|
+
name: 'arrow',
|
|
46
|
+
options: {
|
|
47
|
+
element: arrowElement,
|
|
48
|
+
options: {
|
|
49
|
+
padding: 8 // 8px from the edges of the popper
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
// This lets you displace a popper element from its reference element.
|
|
54
|
+
modifiers.push({
|
|
55
|
+
name: 'offset',
|
|
56
|
+
options: {
|
|
57
|
+
offset: [0, 16]
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
modifiers.push({
|
|
61
|
+
name: 'flip',
|
|
62
|
+
options: {
|
|
63
|
+
fallbackPlacements: Position.TOP
|
|
64
|
+
}
|
|
65
|
+
});
|
|
40
66
|
const {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
} = useFloating({
|
|
67
|
+
styles,
|
|
68
|
+
attributes,
|
|
69
|
+
forceUpdate
|
|
70
|
+
} = usePopper(anchorReference.current, popperElement, {
|
|
46
71
|
placement: position,
|
|
47
|
-
|
|
48
|
-
fallbackPlacements: [Position.TOP]
|
|
49
|
-
}), arrow({
|
|
50
|
-
element: arrowRef,
|
|
51
|
-
padding: 8
|
|
52
|
-
})],
|
|
53
|
-
whileElementsMounted: open ? autoUpdate : undefined,
|
|
54
|
-
open
|
|
72
|
+
modifiers
|
|
55
73
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
74
|
+
// If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),
|
|
75
|
+
// it is most simple just to always position before opening
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (open && forceUpdate) {
|
|
78
|
+
forceUpdate();
|
|
79
|
+
}
|
|
80
|
+
}, [open]);
|
|
64
81
|
return /*#__PURE__*/jsxs("span", {
|
|
65
|
-
ref:
|
|
82
|
+
ref: anchorReference,
|
|
66
83
|
className: "tw-tooltip-container",
|
|
67
84
|
onMouseOver: () => setOpen(true),
|
|
68
85
|
onFocus: () => setOpen(true),
|
|
@@ -71,19 +88,23 @@ const Tooltip = ({
|
|
|
71
88
|
children: [children ? /*#__PURE__*/cloneElement(children, {
|
|
72
89
|
'aria-describedby': `${tooltipId}-tooltip`
|
|
73
90
|
}) : null, /*#__PURE__*/jsx("div", {
|
|
74
|
-
|
|
91
|
+
// @ts-expect-error
|
|
92
|
+
ref: setPopperElement,
|
|
75
93
|
className: clsx('np-tooltip', 'np-panel', open ? `np-panel--open np-tooltip--open` : null, className),
|
|
76
|
-
style:
|
|
77
|
-
|
|
94
|
+
style: {
|
|
95
|
+
...styles.popper
|
|
96
|
+
},
|
|
97
|
+
...attributes.popper,
|
|
78
98
|
"aria-hidden": !open,
|
|
79
99
|
role: "tooltip",
|
|
80
100
|
id: `${tooltipId}-tooltip`,
|
|
81
101
|
children: /*#__PURE__*/jsxs("div", {
|
|
82
102
|
className: "np-panel__content tooltip-inner",
|
|
83
103
|
children: [label, /*#__PURE__*/jsx("div", {
|
|
84
|
-
|
|
104
|
+
// @ts-expect-error
|
|
105
|
+
ref: setArrowElement,
|
|
85
106
|
className: clsx('np-panel__arrow'),
|
|
86
|
-
style:
|
|
107
|
+
style: styles.arrow
|
|
87
108
|
})]
|
|
88
109
|
})
|
|
89
110
|
})]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.mjs","sources":["../../src/tooltip/Tooltip.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"Tooltip.mjs","sources":["../../src/tooltip/Tooltip.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/ban-ts-comment */\nimport { clsx } from 'clsx';\nimport {\n AriaAttributes,\n PropsWithChildren,\n ReactElement,\n ReactNode,\n cloneElement,\n useEffect,\n useId,\n useRef,\n useState,\n} from 'react';\nimport { usePopper } from 'react-popper';\n\nimport { CommonProps, Position } from '../common';\nimport {\n PositionBottom,\n PositionLeft,\n PositionRight,\n PositionTop,\n} from '../common/propsValues/position';\n\nexport type TooltipProps = PropsWithChildren<{\n position?: PositionTop | PositionRight | PositionBottom | PositionLeft;\n label: ReactNode;\n id?: string;\n}> &\n CommonProps;\n\nconst Tooltip = ({\n position = Position.TOP,\n children = undefined,\n label,\n id,\n className,\n}: TooltipProps) => {\n const [open, setOpen] = useState(false);\n const anchorReference = useRef(null);\n const [arrowElement, setArrowElement] = useState(null);\n const [popperElement, setPopperElement] = useState(null);\n\n const fallbackId = useId();\n const tooltipId = id ?? fallbackId;\n const modifiers = [];\n\n modifiers.push({\n name: 'arrow',\n options: {\n element: arrowElement,\n options: {\n padding: 8, // 8px from the edges of the popper\n },\n },\n });\n // This lets you displace a popper element from its reference element.\n modifiers.push({ name: 'offset', options: { offset: [0, 16] } });\n modifiers.push({\n name: 'flip',\n options: {\n fallbackPlacements: Position.TOP,\n },\n });\n\n const { styles, attributes, forceUpdate } = usePopper(anchorReference.current, popperElement, {\n placement: position,\n modifiers,\n });\n\n // If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),\n // it is most simple just to always position before opening\n useEffect(() => {\n if (open && forceUpdate) {\n forceUpdate();\n }\n }, [open]);\n\n return (\n <span\n ref={anchorReference}\n className=\"tw-tooltip-container\"\n onMouseOver={() => setOpen(true)}\n onFocus={() => setOpen(true)}\n onMouseOut={() => setOpen(false)}\n onBlur={() => setOpen(false)}\n >\n {children\n ? cloneElement(children as ReactElement<Pick<AriaAttributes, 'aria-describedby'>>, {\n 'aria-describedby': `${tooltipId}-tooltip`,\n })\n : null}\n <div\n // @ts-expect-error\n ref={setPopperElement}\n className={clsx(\n 'np-tooltip',\n 'np-panel',\n open ? `np-panel--open np-tooltip--open` : null,\n className,\n )}\n style={{ ...styles.popper }}\n {...attributes.popper}\n aria-hidden={!open}\n role=\"tooltip\"\n id={`${tooltipId}-tooltip`}\n >\n <div className=\"np-panel__content tooltip-inner\">\n {label}\n <div\n // @ts-expect-error\n ref={setArrowElement}\n className={clsx('np-panel__arrow')}\n style={styles.arrow}\n />\n </div>\n </div>\n </span>\n );\n};\n\nexport default Tooltip;\n"],"names":["Tooltip","position","Position","TOP","children","undefined","label","id","className","open","setOpen","useState","anchorReference","useRef","arrowElement","setArrowElement","popperElement","setPopperElement","fallbackId","useId","tooltipId","modifiers","push","name","options","element","padding","offset","fallbackPlacements","styles","attributes","forceUpdate","usePopper","current","placement","useEffect","_jsxs","ref","onMouseOver","onFocus","onMouseOut","onBlur","cloneElement","_jsx","clsx","style","popper","role","arrow"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AA8BA,MAAMA,OAAO,GAAGA,CAAC;EACfC,QAAQ,GAAGC,QAAQ,CAACC,GAAG;AACvBC,EAAAA,QAAQ,GAAGC,SAAS;EACpBC,KAAK;EAC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BP,UAAAA,SAAS,EAAEoC,IAAI,CAAC,iBAAiB,CAAE;UACnCC,KAAK,EAAEhB,MAAM,CAACmB;AAAM,SAAA,CAExB;OAAK;AACP,KAAK,CACP;AAAA,GAAM,CAAC;AAEX;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../../src/common/panel/Panel.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../../src/common/panel/Panel.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EAKf,MAAM,OAAO,CAAC;AAGf,OAAO,EAAY,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,IAAI,CAAC;AAgBxF,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC;IACzC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,KAAK,IAAI,CAAC;IAClD,QAAQ,CAAC,EAAE,cAAc,GAAG,YAAY,GAAG,aAAa,GAAG,WAAW,CAAC;IACvE,SAAS,EAAE,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;IAC5C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC,GACA,cAAc,CAAC,cAAc,CAAC,CAAC;AAEjC,QAAA,MAAM,KAAK;YAZD,OAAO;WACR,OAAO;cACJ,OAAO;WACV,OAAO;cACJ,CAAC,KAAK,EAAE,KAAK,GAAG,cAAc,KAAK,IAAI;eACtC,cAAc,GAAG,YAAY,GAAG,aAAa,GAAG,WAAW;eAC3D,gBAAgB,CAAC,OAAO,GAAG,IAAI,CAAC;kBAC7B,OAAO;qBACJ,OAAO;;;mFAkGxB,CAAC;AAEH,eAAe,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../../src/tooltip/Tooltip.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Tooltip.d.ts","sourceRoot":"","sources":["../../../src/tooltip/Tooltip.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,iBAAiB,EAEjB,SAAS,EAMV,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,WAAW,EAAY,MAAM,WAAW,CAAC;AAClD,OAAO,EACL,cAAc,EACd,YAAY,EACZ,aAAa,EACb,WAAW,EACZ,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,YAAY,GAAG,iBAAiB,CAAC;IAC3C,QAAQ,CAAC,EAAE,WAAW,GAAG,aAAa,GAAG,cAAc,GAAG,YAAY,CAAC;IACvE,KAAK,EAAE,SAAS,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC,GACA,WAAW,CAAC;AAEd,QAAA,MAAM,OAAO,GAAI,+CAMd,YAAY,gCAkFd,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@transferwise/components",
|
|
3
|
-
"version": "0.0.0-experimental-
|
|
3
|
+
"version": "0.0.0-experimental-1b9f42b",
|
|
4
4
|
"description": "Neptune React components",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -104,6 +104,7 @@
|
|
|
104
104
|
"@babel/runtime": "^7.29.2",
|
|
105
105
|
"@floating-ui/react": "^0.27.19",
|
|
106
106
|
"@headlessui/react": "^2.2.9",
|
|
107
|
+
"@popperjs/core": "^2.11.8",
|
|
107
108
|
"@react-aria/focus": "^3.21.5",
|
|
108
109
|
"@react-aria/overlays": "^3.31.2",
|
|
109
110
|
"@transferwise/formatting": "^2.14.0",
|
|
@@ -115,6 +116,7 @@
|
|
|
115
116
|
"lodash.clamp": "^4.0.3",
|
|
116
117
|
"lodash.debounce": "^4.0.8",
|
|
117
118
|
"merge-props": "^6.0.0",
|
|
119
|
+
"react-popper": "^2.3.0",
|
|
118
120
|
"react-transition-group": "^4.4.5",
|
|
119
121
|
"virtua": "^0.48.8",
|
|
120
122
|
"@transferwise/neptune-tokens": "^8.20.3"
|
|
@@ -1,12 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
arrow as arrowMiddleware,
|
|
3
|
-
autoUpdate,
|
|
4
|
-
flip as flipMiddleware,
|
|
5
|
-
offset,
|
|
6
|
-
type Placement,
|
|
7
|
-
shift,
|
|
8
|
-
useFloating,
|
|
9
|
-
} from '@floating-ui/react';
|
|
10
1
|
import { clsx } from 'clsx';
|
|
11
2
|
import {
|
|
12
3
|
CSSProperties,
|
|
@@ -16,19 +7,21 @@ import {
|
|
|
16
7
|
SyntheticEvent,
|
|
17
8
|
forwardRef,
|
|
18
9
|
useContext,
|
|
19
|
-
|
|
10
|
+
useEffect,
|
|
11
|
+
useState,
|
|
20
12
|
} from 'react';
|
|
13
|
+
import { usePopper } from 'react-popper';
|
|
21
14
|
|
|
22
15
|
import { Position, PositionBottom, PositionLeft, PositionRight, PositionTop } from '..';
|
|
23
16
|
import Dimmer from '../../dimmer';
|
|
24
17
|
import { OverlayIdContext } from '../../provider/overlay/OverlayIdProvider';
|
|
25
18
|
|
|
26
|
-
const POPOVER_OFFSET = 16;
|
|
19
|
+
const POPOVER_OFFSET = [0, 16];
|
|
27
20
|
|
|
28
21
|
// By default the flip positioning explores only the opposite alternative. So if left is passed and there's no enough space
|
|
29
22
|
// the right one gets chosen. If there's no space on both sides popover goes back to the initially chosen one left.
|
|
30
23
|
// This mapping forces popover to try the four available positions before going back to the initial chosen one.
|
|
31
|
-
const fallbackPlacements
|
|
24
|
+
const fallbackPlacements = {
|
|
32
25
|
[Position.TOP]: [Position.BOTTOM, Position.RIGHT, Position.LEFT],
|
|
33
26
|
[Position.BOTTOM]: [Position.TOP, Position.RIGHT, Position.LEFT],
|
|
34
27
|
[Position.LEFT]: [Position.RIGHT, Position.TOP, Position.BOTTOM],
|
|
@@ -64,43 +57,56 @@ const Panel = forwardRef<HTMLDivElement, PanelProps>(function Panel(
|
|
|
64
57
|
}: PanelProps,
|
|
65
58
|
reference,
|
|
66
59
|
) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
const middleware = [];
|
|
70
|
-
|
|
71
|
-
if (arrow) {
|
|
72
|
-
middleware.push(offset(POPOVER_OFFSET));
|
|
73
|
-
}
|
|
60
|
+
const [arrowElement, setArrowElement] = useState<HTMLDivElement | null>(null);
|
|
61
|
+
const [popperElement, setPopperElement] = useState<HTMLDivElement | null>(null);
|
|
74
62
|
|
|
75
|
-
|
|
76
|
-
middleware.push(
|
|
77
|
-
flipMiddleware({
|
|
78
|
-
fallbackPlacements: fallbackPlacements[position],
|
|
79
|
-
}),
|
|
80
|
-
);
|
|
81
|
-
}
|
|
63
|
+
const modifiers = [];
|
|
82
64
|
|
|
83
65
|
if (altAxis) {
|
|
84
|
-
|
|
66
|
+
modifiers.push({
|
|
67
|
+
// https://popper.js.org/docs/v2/modifiers/prevent-overflow
|
|
68
|
+
name: 'preventOverflow',
|
|
69
|
+
options: {
|
|
70
|
+
altAxis: true,
|
|
71
|
+
tether: false,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
85
74
|
}
|
|
86
75
|
|
|
87
76
|
if (arrow) {
|
|
88
|
-
|
|
77
|
+
modifiers.push({
|
|
78
|
+
name: 'arrow',
|
|
79
|
+
options: {
|
|
80
|
+
element: arrowElement,
|
|
81
|
+
options: {
|
|
82
|
+
padding: 8, // 8px from the edges of the popper
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
// This lets you displace a popper element from its reference element.
|
|
87
|
+
modifiers.push({ name: 'offset', options: { offset: POPOVER_OFFSET } });
|
|
88
|
+
}
|
|
89
|
+
if (flip && fallbackPlacements[position]) {
|
|
90
|
+
modifiers.push({
|
|
91
|
+
name: 'flip',
|
|
92
|
+
options: {
|
|
93
|
+
fallbackPlacements: fallbackPlacements[position],
|
|
94
|
+
},
|
|
95
|
+
});
|
|
89
96
|
}
|
|
90
97
|
|
|
91
|
-
const {
|
|
98
|
+
const { styles, attributes, forceUpdate } = usePopper(anchorRef.current, popperElement, {
|
|
92
99
|
placement: position,
|
|
93
|
-
|
|
94
|
-
elements: {
|
|
95
|
-
reference: anchorRef.current,
|
|
96
|
-
},
|
|
97
|
-
whileElementsMounted: open ? autoUpdate : undefined,
|
|
100
|
+
modifiers,
|
|
98
101
|
});
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
// If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),
|
|
104
|
+
// it is most simple just to always position before opening
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (open && forceUpdate) {
|
|
107
|
+
forceUpdate();
|
|
108
|
+
}
|
|
109
|
+
}, [open]);
|
|
104
110
|
|
|
105
111
|
const contentStyle: CSSProperties = {
|
|
106
112
|
...(anchorWidth ? { width: anchorRef.current?.clientWidth } : undefined),
|
|
@@ -113,16 +119,18 @@ const Panel = forwardRef<HTMLDivElement, PanelProps>(function Panel(
|
|
|
113
119
|
<div
|
|
114
120
|
id={overlayId}
|
|
115
121
|
{...rest}
|
|
116
|
-
ref={
|
|
122
|
+
ref={setPopperElement}
|
|
117
123
|
role="dialog"
|
|
118
|
-
style={
|
|
119
|
-
|
|
124
|
+
style={{ ...styles.popper }}
|
|
125
|
+
{...attributes.popper}
|
|
120
126
|
className={clsx('np-panel', { 'np-panel--open': open }, rest.className)}
|
|
121
127
|
>
|
|
122
128
|
<div ref={reference} style={contentStyle} className={clsx('np-panel__content')}>
|
|
123
129
|
{children}
|
|
124
130
|
{/* Arrow has to stay inside content to get the same animations as the "dialog" and to get hidden when panel is closed. */}
|
|
125
|
-
{arrow &&
|
|
131
|
+
{arrow && (
|
|
132
|
+
<div ref={setArrowElement} className={clsx('np-panel__arrow')} style={styles.arrow} />
|
|
133
|
+
)}
|
|
126
134
|
</div>
|
|
127
135
|
</div>
|
|
128
136
|
</Dimmer>
|
package/src/tooltip/Tooltip.tsx
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
arrow as arrowMiddleware,
|
|
3
|
-
autoUpdate,
|
|
4
|
-
flip,
|
|
5
|
-
offset,
|
|
6
|
-
useFloating,
|
|
7
|
-
} from '@floating-ui/react';
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
8
2
|
import { clsx } from 'clsx';
|
|
9
3
|
import {
|
|
10
4
|
AriaAttributes,
|
|
11
|
-
CSSProperties,
|
|
12
5
|
PropsWithChildren,
|
|
13
6
|
ReactElement,
|
|
14
7
|
ReactNode,
|
|
15
8
|
cloneElement,
|
|
9
|
+
useEffect,
|
|
16
10
|
useId,
|
|
17
11
|
useRef,
|
|
18
12
|
useState,
|
|
19
13
|
} from 'react';
|
|
14
|
+
import { usePopper } from 'react-popper';
|
|
20
15
|
|
|
21
16
|
import { CommonProps, Position } from '../common';
|
|
22
17
|
import {
|
|
@@ -41,30 +36,48 @@ const Tooltip = ({
|
|
|
41
36
|
className,
|
|
42
37
|
}: TooltipProps) => {
|
|
43
38
|
const [open, setOpen] = useState(false);
|
|
44
|
-
const
|
|
39
|
+
const anchorReference = useRef(null);
|
|
40
|
+
const [arrowElement, setArrowElement] = useState(null);
|
|
41
|
+
const [popperElement, setPopperElement] = useState(null);
|
|
45
42
|
|
|
46
43
|
const fallbackId = useId();
|
|
47
44
|
const tooltipId = id ?? fallbackId;
|
|
45
|
+
const modifiers = [];
|
|
46
|
+
|
|
47
|
+
modifiers.push({
|
|
48
|
+
name: 'arrow',
|
|
49
|
+
options: {
|
|
50
|
+
element: arrowElement,
|
|
51
|
+
options: {
|
|
52
|
+
padding: 8, // 8px from the edges of the popper
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
// This lets you displace a popper element from its reference element.
|
|
57
|
+
modifiers.push({ name: 'offset', options: { offset: [0, 16] } });
|
|
58
|
+
modifiers.push({
|
|
59
|
+
name: 'flip',
|
|
60
|
+
options: {
|
|
61
|
+
fallbackPlacements: Position.TOP,
|
|
62
|
+
},
|
|
63
|
+
});
|
|
48
64
|
|
|
49
|
-
const {
|
|
65
|
+
const { styles, attributes, forceUpdate } = usePopper(anchorReference.current, popperElement, {
|
|
50
66
|
placement: position,
|
|
51
|
-
|
|
52
|
-
offset(16),
|
|
53
|
-
flip({ fallbackPlacements: [Position.TOP] }),
|
|
54
|
-
arrowMiddleware({ element: arrowRef, padding: 8 }),
|
|
55
|
-
],
|
|
56
|
-
whileElementsMounted: open ? autoUpdate : undefined,
|
|
57
|
-
open,
|
|
67
|
+
modifiers,
|
|
58
68
|
});
|
|
59
69
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
// If the trigger is not visible when the position is calculated, it will be incorrect. Because this can happen repeatedly (on resize for example),
|
|
71
|
+
// it is most simple just to always position before opening
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
if (open && forceUpdate) {
|
|
74
|
+
forceUpdate();
|
|
75
|
+
}
|
|
76
|
+
}, [open]);
|
|
64
77
|
|
|
65
78
|
return (
|
|
66
79
|
<span
|
|
67
|
-
ref={
|
|
80
|
+
ref={anchorReference}
|
|
68
81
|
className="tw-tooltip-container"
|
|
69
82
|
onMouseOver={() => setOpen(true)}
|
|
70
83
|
onFocus={() => setOpen(true)}
|
|
@@ -77,22 +90,28 @@ const Tooltip = ({
|
|
|
77
90
|
})
|
|
78
91
|
: null}
|
|
79
92
|
<div
|
|
80
|
-
|
|
93
|
+
// @ts-expect-error
|
|
94
|
+
ref={setPopperElement}
|
|
81
95
|
className={clsx(
|
|
82
96
|
'np-tooltip',
|
|
83
97
|
'np-panel',
|
|
84
98
|
open ? `np-panel--open np-tooltip--open` : null,
|
|
85
99
|
className,
|
|
86
100
|
)}
|
|
87
|
-
style={
|
|
88
|
-
|
|
101
|
+
style={{ ...styles.popper }}
|
|
102
|
+
{...attributes.popper}
|
|
89
103
|
aria-hidden={!open}
|
|
90
104
|
role="tooltip"
|
|
91
105
|
id={`${tooltipId}-tooltip`}
|
|
92
106
|
>
|
|
93
107
|
<div className="np-panel__content tooltip-inner">
|
|
94
108
|
{label}
|
|
95
|
-
<div
|
|
109
|
+
<div
|
|
110
|
+
// @ts-expect-error
|
|
111
|
+
ref={setArrowElement}
|
|
112
|
+
className={clsx('np-panel__arrow')}
|
|
113
|
+
style={styles.arrow}
|
|
114
|
+
/>
|
|
96
115
|
</div>
|
|
97
116
|
</div>
|
|
98
117
|
</span>
|