colibri-ui 0.8.47 → 0.8.50
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/ClickOutside/index.d.ts +3 -2
- package/ClickOutside/index.js +7 -10
- package/Dropdown/Dropdown.module.css +8 -0
- package/Dropdown/index.d.ts +1 -1
- package/Dropdown/index.js +48 -96
- package/Dropdown/index.props.d.ts +2 -4
- package/Tooltip/Tooltip.module.css +19 -113
- package/Tooltip/index.d.ts +3 -3
- package/Tooltip/index.js +50 -81
- package/Tooltip/index.props.d.ts +5 -6
- package/esm/ClickOutside/index.d.ts +3 -2
- package/esm/ClickOutside/index.js +8 -10
- package/esm/Dropdown/Dropdown.module.css +8 -0
- package/esm/Dropdown/index.d.ts +1 -1
- package/esm/Dropdown/index.js +46 -95
- package/esm/Dropdown/index.props.d.ts +2 -4
- package/esm/Tooltip/Tooltip.module.css +19 -113
- package/esm/Tooltip/index.d.ts +3 -3
- package/esm/Tooltip/index.js +51 -82
- package/esm/Tooltip/index.props.d.ts +5 -6
- package/esm/hooks/useOnClickOutside/index.d.ts +9 -2
- package/esm/hooks/useOnClickOutside/index.js +5 -4
- package/esm/index.d.ts +0 -2
- package/esm/index.js +0 -2
- package/hooks/useOnClickOutside/index.d.ts +9 -2
- package/hooks/useOnClickOutside/index.js +5 -4
- package/index.d.ts +0 -2
- package/index.js +57 -61
- package/package.json +4 -3
- package/esm/helpers/on.js +0 -10
- package/helpers/on.js +0 -12
package/ClickOutside/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FC, PropsWithChildren } from "react";
|
|
2
|
-
|
|
2
|
+
type ClickOutsideProps = {
|
|
3
3
|
onClick: (e: MouseEvent | TouchEvent) => void;
|
|
4
|
-
}
|
|
4
|
+
};
|
|
5
|
+
declare const ClickOutside: FC<PropsWithChildren<ClickOutsideProps>>;
|
|
5
6
|
export default ClickOutside;
|
package/ClickOutside/index.js
CHANGED
|
@@ -9,23 +9,20 @@ var index = require('../hooks/useOnClickOutside/index.js');
|
|
|
9
9
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
10
|
|
|
11
11
|
var _typeof__default = /*#__PURE__*/_interopDefault(_typeof);
|
|
12
|
-
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
13
12
|
|
|
14
13
|
var ClickOutside = function ClickOutside(_ref) {
|
|
15
14
|
var children = _ref.children,
|
|
16
15
|
onClick = _ref.onClick;
|
|
17
|
-
var childRef = React.useRef();
|
|
16
|
+
var childRef = React.useRef(null);
|
|
18
17
|
index.default(childRef, onClick);
|
|
19
|
-
if (! /*#__PURE__*/
|
|
18
|
+
if (! /*#__PURE__*/React.isValidElement(children)) return null;
|
|
20
19
|
var combinedRef = function combinedRef(node) {
|
|
21
20
|
childRef.current = node;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
childRefProp.current = node;
|
|
28
|
-
}
|
|
21
|
+
var childRefProp = children.ref;
|
|
22
|
+
if (typeof childRefProp === "function") {
|
|
23
|
+
childRefProp(node);
|
|
24
|
+
} else if (childRefProp && _typeof__default.default(childRefProp) === "object" && "current" in childRefProp) {
|
|
25
|
+
childRefProp.current = node;
|
|
29
26
|
}
|
|
30
27
|
};
|
|
31
28
|
return /*#__PURE__*/React.cloneElement(children, {
|
|
@@ -4,6 +4,14 @@
|
|
|
4
4
|
z-index: 1001;
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
+
.popper-container.placement-top {
|
|
8
|
+
transform-origin: bottom center;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.popper-container.placement-bottom {
|
|
12
|
+
transform-origin: top center;
|
|
13
|
+
}
|
|
14
|
+
|
|
7
15
|
.overlay-container {
|
|
8
16
|
background-color: var(--palette-white);
|
|
9
17
|
border-color: var(--palette-bg-2);
|
package/Dropdown/index.d.ts
CHANGED
package/Dropdown/index.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
5
6
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
6
7
|
var React = require('react');
|
|
7
8
|
var classNames = require('classnames/bind');
|
|
8
|
-
var
|
|
9
|
-
var index = require('../
|
|
10
|
-
var on = require('../helpers/on.js');
|
|
11
|
-
var index$1 = require('../ClickOutside/index.js');
|
|
9
|
+
var react = require('@floating-ui/react');
|
|
10
|
+
var index = require('../ClickOutside/index.js');
|
|
12
11
|
var styles = require('./Dropdown.module.css');
|
|
13
12
|
|
|
14
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
14
|
|
|
15
|
+
var _toConsumableArray__default = /*#__PURE__*/_interopDefault(_toConsumableArray);
|
|
16
16
|
var _slicedToArray__default = /*#__PURE__*/_interopDefault(_slicedToArray);
|
|
17
17
|
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
18
18
|
var classNames__default = /*#__PURE__*/_interopDefault(classNames);
|
|
@@ -27,7 +27,7 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
27
27
|
onVisibleChange = _ref.onVisibleChange,
|
|
28
28
|
overlay = _ref.overlay,
|
|
29
29
|
_ref$placement = _ref.placement,
|
|
30
|
-
placement = _ref$placement === void 0 ? "bottom-
|
|
30
|
+
placement = _ref$placement === void 0 ? "bottom-center" : _ref$placement,
|
|
31
31
|
_ref$strategy = _ref.strategy,
|
|
32
32
|
strategy = _ref$strategy === void 0 ? "absolute" : _ref$strategy,
|
|
33
33
|
_ref$trigger = _ref.trigger,
|
|
@@ -39,102 +39,55 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
39
39
|
_ref$preventAutoClose = _ref.preventAutoClose,
|
|
40
40
|
preventAutoClose = _ref$preventAutoClose === void 0 ? false : _ref$preventAutoClose,
|
|
41
41
|
_ref$flip = _ref.flip,
|
|
42
|
-
|
|
42
|
+
flipEnabled = _ref$flip === void 0 ? true : _ref$flip,
|
|
43
43
|
_ref$samewidth = _ref.samewidth,
|
|
44
44
|
samewidth = _ref$samewidth === void 0 ? false : _ref$samewidth;
|
|
45
|
-
var
|
|
45
|
+
var _a;
|
|
46
|
+
var _useState = React.useState(false),
|
|
46
47
|
_useState2 = _slicedToArray__default.default(_useState, 2),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
var _useState3 = React.useState(null),
|
|
50
|
-
_useState4 = _slicedToArray__default.default(_useState3, 2),
|
|
51
|
-
popperElement = _useState4[0],
|
|
52
|
-
setPopperElement = _useState4[1];
|
|
53
|
-
var _useState5 = React.useState(false),
|
|
54
|
-
_useState6 = _slicedToArray__default.default(_useState5, 2),
|
|
55
|
-
visible = _useState6[0],
|
|
56
|
-
setVisible = _useState6[1];
|
|
48
|
+
visible = _useState2[0],
|
|
49
|
+
setVisible = _useState2[1];
|
|
57
50
|
var isVisible = visibleProp && visible && !disabled;
|
|
58
|
-
var
|
|
51
|
+
var _useFloating = react.useFloating({
|
|
52
|
+
open: isVisible,
|
|
53
|
+
onOpenChange: setVisible,
|
|
59
54
|
placement: placement,
|
|
60
55
|
strategy: strategy,
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
enabled: flip,
|
|
64
|
-
options: {
|
|
65
|
-
fallbackPlacements: ["top"]
|
|
66
|
-
}
|
|
67
|
-
}, {
|
|
68
|
-
name: "preventOverflow",
|
|
69
|
-
enabled: preventOverflow
|
|
70
|
-
}]
|
|
56
|
+
whileElementsMounted: react.autoUpdate,
|
|
57
|
+
middleware: [react.offset(6)].concat(_toConsumableArray__default.default(flipEnabled ? [react.flip()] : []), _toConsumableArray__default.default(preventOverflow ? [react.shift()] : []))
|
|
71
58
|
}),
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
59
|
+
refs = _useFloating.refs,
|
|
60
|
+
floatingStyles = _useFloating.floatingStyles,
|
|
61
|
+
context = _useFloating.context,
|
|
62
|
+
update = _useFloating.update,
|
|
63
|
+
finalPlacement = _useFloating.placement;
|
|
64
|
+
var hover = react.useHover(context, {
|
|
65
|
+
enabled: trigger.includes("hover")
|
|
66
|
+
});
|
|
67
|
+
var click = react.useClick(context, {
|
|
68
|
+
enabled: trigger.includes("click")
|
|
69
|
+
});
|
|
70
|
+
var focus = react.useFocus(context, {
|
|
71
|
+
enabled: trigger.includes("focus")
|
|
72
|
+
});
|
|
73
|
+
var dismiss = react.useDismiss(context);
|
|
74
|
+
var role = react.useRole(context, {
|
|
75
|
+
role: "menu"
|
|
76
|
+
});
|
|
77
|
+
var _useInteractions = react.useInteractions([hover, click, focus, dismiss, role]),
|
|
78
|
+
getReferenceProps = _useInteractions.getReferenceProps,
|
|
79
|
+
getFloatingProps = _useInteractions.getFloatingProps;
|
|
75
80
|
var isNotComponent = typeof children === "string";
|
|
76
81
|
var reference = React.useMemo(function () {
|
|
77
82
|
if (!children) return null;
|
|
78
83
|
return React.Children.only(isNotComponent ? /*#__PURE__*/React__default.default.createElement("button", null, children) : children);
|
|
79
84
|
}, [children, isNotComponent]);
|
|
80
|
-
var onToggle = function onToggle(event) {
|
|
81
|
-
var _a;
|
|
82
|
-
if ((_a = event.target) === null || _a === void 0 ? void 0 : _a.closest('[data-ignore-click="true"]')) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
setVisible(function (state) {
|
|
86
|
-
return !state;
|
|
87
|
-
});
|
|
88
|
-
};
|
|
89
|
-
var handleShow = function handleShow() {
|
|
90
|
-
return setVisible(true);
|
|
91
|
-
};
|
|
92
|
-
var handleHide = React.useCallback(function () {
|
|
93
|
-
setVisible(false);
|
|
94
|
-
}, []);
|
|
95
|
-
var onClickOutside = React.useCallback(function (event) {
|
|
96
|
-
if (controlElement === null || controlElement === void 0 ? void 0 : controlElement.contains(event.target)) return;
|
|
97
|
-
handleHide();
|
|
98
|
-
}, [handleHide, controlElement]);
|
|
99
85
|
var onClickOverlay = React.useCallback(function (event) {
|
|
100
86
|
event.stopPropagation();
|
|
101
87
|
if (!preventAutoClose) {
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
106
|
-
[handleHide]);
|
|
107
|
-
React.useEffect(function () {
|
|
108
|
-
var unsubscribes = [];
|
|
109
|
-
if (trigger.includes("click")) {
|
|
110
|
-
unsubscribes.push(on.on(controlElement, "click", onToggle, false));
|
|
88
|
+
setVisible(false);
|
|
111
89
|
}
|
|
112
|
-
|
|
113
|
-
unsubscribes.push(on.on(controlElement, "mouseenter", handleShow, false));
|
|
114
|
-
unsubscribes.push(on.on(controlElement, "mouseleave", handleHide, false));
|
|
115
|
-
unsubscribes.push(on.on(popperElement, "mouseenter", handleShow, false));
|
|
116
|
-
unsubscribes.push(on.on(popperElement, "mouseleave", handleHide, false));
|
|
117
|
-
}
|
|
118
|
-
if (trigger.includes("focus")) {
|
|
119
|
-
var onFocusOut = function onFocusOut() {
|
|
120
|
-
requestAnimationFrame(function () {
|
|
121
|
-
if (controlElement === null || controlElement === void 0 ? void 0 : controlElement.contains(document.activeElement)) return;
|
|
122
|
-
if (popperElement === null || popperElement === void 0 ? void 0 : popperElement.contains(document.activeElement)) return;
|
|
123
|
-
handleHide();
|
|
124
|
-
});
|
|
125
|
-
};
|
|
126
|
-
unsubscribes.push(on.on(controlElement, "focusin", handleShow, false));
|
|
127
|
-
unsubscribes.push(on.on(controlElement, "focusout", onFocusOut, false));
|
|
128
|
-
unsubscribes.push(on.on(popperElement, "focusin", handleShow, false));
|
|
129
|
-
unsubscribes.push(on.on(popperElement, "focusout", onFocusOut, false));
|
|
130
|
-
}
|
|
131
|
-
return function () {
|
|
132
|
-
return unsubscribes.forEach(function (un) {
|
|
133
|
-
return un();
|
|
134
|
-
});
|
|
135
|
-
};
|
|
136
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
137
|
-
}, [controlElement, popperElement, onToggle, handleShow, handleHide]);
|
|
90
|
+
}, [preventAutoClose]);
|
|
138
91
|
React.useEffect(function () {
|
|
139
92
|
if (onVisibleChange) onVisibleChange(visible);
|
|
140
93
|
}, [onVisibleChange, visible]);
|
|
@@ -142,24 +95,23 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
142
95
|
if (update) update();
|
|
143
96
|
}, [update, visible]);
|
|
144
97
|
return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, reference && (/*#__PURE__*/React__default.default.createElement(reference.type, Object.assign({
|
|
145
|
-
ref:
|
|
98
|
+
ref: refs.setReference,
|
|
146
99
|
tabIndex: 0
|
|
147
|
-
}, reference.props))), isVisible && (/*#__PURE__*/React__default.default.createElement(
|
|
148
|
-
onClick:
|
|
100
|
+
}, getReferenceProps(reference.props)))), isVisible && (/*#__PURE__*/React__default.default.createElement(react.FloatingPortal, null, /*#__PURE__*/React__default.default.createElement(index.default, {
|
|
101
|
+
onClick: function onClick() {
|
|
102
|
+
return setVisible(false);
|
|
103
|
+
}
|
|
149
104
|
}, /*#__PURE__*/React__default.default.createElement("div", Object.assign({
|
|
150
|
-
ref:
|
|
105
|
+
ref: refs.setFloating,
|
|
151
106
|
"data-testid": "popper-container",
|
|
152
|
-
className: clx("popper-container"),
|
|
153
|
-
style: Object.assign(Object.assign(
|
|
107
|
+
className: clx("popper-container", "placement-".concat(finalPlacement)),
|
|
108
|
+
style: Object.assign(Object.assign({}, floatingStyles), {
|
|
154
109
|
zIndex: zIndex,
|
|
155
|
-
minWidth:
|
|
156
|
-
}), samewidth && {
|
|
157
|
-
maxWidth: controlElement === null || controlElement === void 0 ? void 0 : controlElement.offsetWidth
|
|
158
|
-
}), {
|
|
110
|
+
minWidth: samewidth ? "".concat((_a = refs.reference.current) === null || _a === void 0 ? void 0 : _a.offsetWidth, "px") : undefined,
|
|
159
111
|
fontSize: "".concat(fontSize, "px")
|
|
160
112
|
}),
|
|
161
113
|
tabIndex: 0
|
|
162
|
-
},
|
|
114
|
+
}, getFloatingProps()), /*#__PURE__*/React__default.default.createElement("div", {
|
|
163
115
|
"data-testid": "overlay-container",
|
|
164
116
|
className: clx("overlay-container"),
|
|
165
117
|
onClick: onClickOverlay
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Placement as PopperPlacement } from "@popperjs/core";
|
|
4
|
-
export type Placement = Extract<PopperPlacement, "bottom-start" | "bottom" | "bottom-end">;
|
|
2
|
+
import type { Placement, Strategy } from "@floating-ui/react";
|
|
5
3
|
export type Trigger = "click" | "hover" | "focus";
|
|
6
4
|
export type DropdownProps = {
|
|
7
5
|
zIndex?: number;
|
|
@@ -10,7 +8,7 @@ export type DropdownProps = {
|
|
|
10
8
|
onVisibleChange?: (visible: boolean) => void;
|
|
11
9
|
overlay: ReactNode;
|
|
12
10
|
placement?: Placement;
|
|
13
|
-
strategy?:
|
|
11
|
+
strategy?: Strategy;
|
|
14
12
|
trigger?: [Trigger, ...Trigger[]];
|
|
15
13
|
visible?: boolean;
|
|
16
14
|
preventOverflow?: boolean;
|
|
@@ -1,122 +1,28 @@
|
|
|
1
|
-
.
|
|
2
|
-
padding-top: 4px;
|
|
3
|
-
}
|
|
4
|
-
.root[data-popper-placement=bottom-start]::before {
|
|
5
|
-
left: 6px;
|
|
6
|
-
top: 0;
|
|
7
|
-
}
|
|
8
|
-
.root[data-popper-placement=bottom-end] {
|
|
9
|
-
padding-top: 4px;
|
|
10
|
-
}
|
|
11
|
-
.root[data-popper-placement=bottom-end]::before {
|
|
12
|
-
right: 6px;
|
|
13
|
-
top: 0;
|
|
14
|
-
}
|
|
15
|
-
.root[data-popper-placement=bottom] {
|
|
16
|
-
padding-top: 4px;
|
|
17
|
-
}
|
|
18
|
-
.root[data-popper-placement=bottom]::before {
|
|
19
|
-
left: 50%;
|
|
20
|
-
top: 0;
|
|
21
|
-
transform: translate(-50%, 0);
|
|
22
|
-
}
|
|
23
|
-
.root[data-popper-placement=right] {
|
|
24
|
-
padding-left: 4px;
|
|
25
|
-
}
|
|
26
|
-
.root[data-popper-placement=right]::before {
|
|
27
|
-
left: -6px;
|
|
28
|
-
top: 50%;
|
|
29
|
-
transform: translate(0, -50%) rotate(-90deg);
|
|
30
|
-
}
|
|
31
|
-
.root[data-popper-placement=right-start] {
|
|
32
|
-
padding-left: 4px;
|
|
33
|
-
}
|
|
34
|
-
.root[data-popper-placement=right-start]::before {
|
|
35
|
-
left: -6px;
|
|
36
|
-
top: 6px;
|
|
37
|
-
transform: rotate(-90deg);
|
|
38
|
-
}
|
|
39
|
-
.root[data-popper-placement=right-end] {
|
|
40
|
-
padding-left: 4px;
|
|
41
|
-
}
|
|
42
|
-
.root[data-popper-placement=right-end]::before {
|
|
43
|
-
bottom: 6px;
|
|
44
|
-
left: -6px;
|
|
45
|
-
transform: rotate(-90deg);
|
|
46
|
-
}
|
|
47
|
-
.root[data-popper-placement=left] {
|
|
48
|
-
padding-right: 4px;
|
|
49
|
-
}
|
|
50
|
-
.root[data-popper-placement=left]::before {
|
|
51
|
-
right: -6px;
|
|
52
|
-
top: 50%;
|
|
53
|
-
transform: translate(0, -50%) rotate(90deg);
|
|
54
|
-
}
|
|
55
|
-
.root[data-popper-placement=left-start] {
|
|
56
|
-
padding-right: 4px;
|
|
57
|
-
}
|
|
58
|
-
.root[data-popper-placement=left-start]::before {
|
|
59
|
-
right: -6px;
|
|
60
|
-
top: 6px;
|
|
61
|
-
transform: rotate(90deg);
|
|
62
|
-
}
|
|
63
|
-
.root[data-popper-placement=left-end] {
|
|
64
|
-
padding-right: 4px;
|
|
65
|
-
}
|
|
66
|
-
.root[data-popper-placement=left-end]::before {
|
|
67
|
-
bottom: 6px;
|
|
68
|
-
right: -6px;
|
|
69
|
-
transform: rotate(90deg);
|
|
70
|
-
}
|
|
71
|
-
.root[data-popper-placement=top] {
|
|
72
|
-
padding-bottom: 4px;
|
|
73
|
-
}
|
|
74
|
-
.root[data-popper-placement=top]::before {
|
|
75
|
-
bottom: 0;
|
|
76
|
-
left: 50%;
|
|
77
|
-
transform: translate(-50%, 0) rotate(180deg);
|
|
78
|
-
}
|
|
79
|
-
.root[data-popper-placement=top-start] {
|
|
80
|
-
padding-bottom: 4px;
|
|
81
|
-
}
|
|
82
|
-
.root[data-popper-placement=top-start]::before {
|
|
83
|
-
bottom: 0;
|
|
84
|
-
left: 6px;
|
|
85
|
-
transform: rotate(180deg);
|
|
86
|
-
}
|
|
87
|
-
.root[data-popper-placement=top-end] {
|
|
88
|
-
padding-bottom: 4px;
|
|
89
|
-
}
|
|
90
|
-
.root[data-popper-placement=top-end]::before {
|
|
91
|
-
bottom: 0;
|
|
92
|
-
right: 6px;
|
|
93
|
-
transform: rotate(180deg);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
.tail {
|
|
97
|
-
position: relative;
|
|
98
|
-
}
|
|
99
|
-
.tail::before {
|
|
100
|
-
border-bottom: 5px solid var(--tooltip-bg);
|
|
101
|
-
border-left: 6px solid transparent;
|
|
102
|
-
border-right: 6px solid transparent;
|
|
103
|
-
content: "";
|
|
104
|
-
height: 0;
|
|
105
|
-
position: absolute;
|
|
106
|
-
width: 0;
|
|
107
|
-
z-index: 3000;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
.overlay {
|
|
1
|
+
.tooltip {
|
|
111
2
|
background-color: var(--tooltip-bg);
|
|
112
3
|
border-radius: 0.35rem;
|
|
113
|
-
|
|
4
|
+
padding: 4px 10px;
|
|
114
5
|
font-size: 14px;
|
|
115
|
-
font-style: normal;
|
|
116
6
|
font-weight: 400;
|
|
117
7
|
line-height: 18px;
|
|
8
|
+
color: var(--tooltip-color);
|
|
118
9
|
max-width: 200px;
|
|
10
|
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
|
11
|
+
z-index: 1000;
|
|
12
|
+
position: relative;
|
|
13
|
+
display: inline-block;
|
|
14
|
+
box-sizing: border-box;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.content {
|
|
18
|
+
background-color: inherit;
|
|
19
|
+
border-radius: inherit;
|
|
20
|
+
color: inherit;
|
|
21
|
+
font-size: inherit;
|
|
22
|
+
font-weight: inherit;
|
|
23
|
+
line-height: inherit;
|
|
24
|
+
padding: inherit;
|
|
25
|
+
max-width: inherit;
|
|
119
26
|
overflow: hidden;
|
|
120
|
-
padding: 4px 10px;
|
|
121
27
|
position: relative;
|
|
122
28
|
}
|
package/Tooltip/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type {
|
|
3
|
-
declare const Tooltip: FC<PropsWithChildren<
|
|
1
|
+
import { type FC, type PropsWithChildren } from "react";
|
|
2
|
+
import type { TooltipProps } from "./index.props";
|
|
3
|
+
declare const Tooltip: FC<PropsWithChildren<TooltipProps>>;
|
|
4
4
|
export default Tooltip;
|
package/Tooltip/index.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
6
6
|
var React = require('react');
|
|
7
|
-
var reactPopper = require('react-popper');
|
|
8
7
|
var classNames = require('classnames/bind');
|
|
9
|
-
var
|
|
10
|
-
var on = require('../helpers/on.js');
|
|
11
|
-
var index$1 = require('../ClickOutside/index.js');
|
|
8
|
+
var react = require('@floating-ui/react');
|
|
12
9
|
var styles = require('./Tooltip.module.css');
|
|
13
10
|
|
|
14
11
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -21,100 +18,72 @@ var styles__default = /*#__PURE__*/_interopDefault(styles);
|
|
|
21
18
|
var clx = classNames__default.default.bind(styles__default.default);
|
|
22
19
|
var Tooltip = function Tooltip(_ref) {
|
|
23
20
|
var children = _ref.children,
|
|
24
|
-
zIndex = _ref.zIndex,
|
|
25
21
|
content = _ref.content,
|
|
22
|
+
_ref$zIndex = _ref.zIndex,
|
|
23
|
+
zIndex = _ref$zIndex === void 0 ? 1000 : _ref$zIndex,
|
|
26
24
|
_ref$withTail = _ref.withTail,
|
|
27
25
|
withTail = _ref$withTail === void 0 ? false : _ref$withTail,
|
|
28
26
|
_ref$placement = _ref.placement,
|
|
29
27
|
placement = _ref$placement === void 0 ? "bottom" : _ref$placement,
|
|
30
28
|
_ref$strategy = _ref.strategy,
|
|
31
|
-
strategy = _ref$strategy === void 0 ? "absolute" : _ref$strategy
|
|
32
|
-
|
|
29
|
+
strategy = _ref$strategy === void 0 ? "absolute" : _ref$strategy,
|
|
30
|
+
className = _ref.className;
|
|
31
|
+
var _useState = React.useState(false),
|
|
33
32
|
_useState2 = _slicedToArray__default.default(_useState, 2),
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var
|
|
37
|
-
|
|
38
|
-
popperElement = _useState4[0],
|
|
39
|
-
setPopperElement = _useState4[1];
|
|
40
|
-
var _useState5 = React.useState(false),
|
|
41
|
-
_useState6 = _slicedToArray__default.default(_useState5, 2),
|
|
42
|
-
visible = _useState6[0],
|
|
43
|
-
setVisible = _useState6[1];
|
|
44
|
-
var _usePopper = reactPopper.usePopper(controlElement, popperElement, {
|
|
33
|
+
isOpen = _useState2[0],
|
|
34
|
+
setIsOpen = _useState2[1];
|
|
35
|
+
var arrowRef = React.useRef(null);
|
|
36
|
+
var _useFloating = react.useFloating({
|
|
45
37
|
placement: placement,
|
|
46
38
|
strategy: strategy,
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}]
|
|
39
|
+
open: isOpen,
|
|
40
|
+
onOpenChange: setIsOpen,
|
|
41
|
+
middleware: [react.offset(8), react.flip(), react.shift({
|
|
42
|
+
padding: 8
|
|
43
|
+
}), react.arrow({
|
|
44
|
+
element: arrowRef
|
|
45
|
+
})]
|
|
54
46
|
}),
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
refs = _useFloating.refs,
|
|
48
|
+
context = _useFloating.context,
|
|
49
|
+
floatingStyles = _useFloating.floatingStyles;
|
|
50
|
+
var hover = react.useHover(context, {
|
|
51
|
+
move: false,
|
|
52
|
+
delay: {
|
|
53
|
+
open: 100,
|
|
54
|
+
close: 100
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
var dismiss = react.useDismiss(context);
|
|
58
|
+
var role = react.useRole(context, {
|
|
59
|
+
role: "tooltip"
|
|
60
|
+
});
|
|
61
|
+
var _useInteractions = react.useInteractions([hover, dismiss, role]),
|
|
62
|
+
getReferenceProps = _useInteractions.getReferenceProps,
|
|
63
|
+
getFloatingProps = _useInteractions.getFloatingProps;
|
|
58
64
|
var reference = React.useMemo(function () {
|
|
59
65
|
if (!children) return null;
|
|
60
66
|
if (typeof children === "string") {
|
|
61
|
-
return /*#__PURE__*/React__default.default.createElement("
|
|
67
|
+
return /*#__PURE__*/React__default.default.createElement("span", null, children);
|
|
62
68
|
}
|
|
63
|
-
return
|
|
69
|
+
return children;
|
|
64
70
|
}, [children]);
|
|
65
|
-
var
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}, []);
|
|
74
|
-
var onHide = React.useCallback(function () {
|
|
75
|
-
setVisible(false);
|
|
76
|
-
}, []);
|
|
77
|
-
var onClickOutside = React.useCallback(function (event) {
|
|
78
|
-
if (controlElement === null || controlElement === void 0 ? void 0 : controlElement.contains(event.target)) return;
|
|
79
|
-
onHide();
|
|
80
|
-
}, [onHide, controlElement]);
|
|
81
|
-
var onClickOverlay = React.useCallback(function (event) {
|
|
82
|
-
event.stopPropagation();
|
|
83
|
-
onHide();
|
|
84
|
-
}, [onHide]);
|
|
85
|
-
React.useEffect(function () {
|
|
86
|
-
var unsubscribes = [];
|
|
87
|
-
unsubscribes.push(on.on(controlElement, "mouseenter", onShow, false));
|
|
88
|
-
unsubscribes.push(on.on(controlElement, "mouseleave", onHide, false));
|
|
89
|
-
unsubscribes.push(on.on(popperElement, "mouseenter", onShow, false));
|
|
90
|
-
unsubscribes.push(on.on(popperElement, "mouseleave", onHide, false));
|
|
91
|
-
return function () {
|
|
92
|
-
return unsubscribes.forEach(function (un) {
|
|
93
|
-
return un();
|
|
94
|
-
});
|
|
95
|
-
};
|
|
96
|
-
}, [controlElement, popperElement, onToggle, onShow, onHide]);
|
|
97
|
-
React.useEffect(function () {
|
|
98
|
-
if (update) update();
|
|
99
|
-
}, [update, visible]);
|
|
100
|
-
return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, reference && /*#__PURE__*/React__default.default.cloneElement(reference, {
|
|
101
|
-
ref: setControlElement
|
|
102
|
-
}), visible && (/*#__PURE__*/React__default.default.createElement(index.default, null, /*#__PURE__*/React__default.default.createElement(index$1.default, {
|
|
103
|
-
onClick: onClickOutside
|
|
104
|
-
}, /*#__PURE__*/React__default.default.createElement("div", Object.assign({
|
|
105
|
-
className: clx("root", {
|
|
106
|
-
tail: !!withTail
|
|
107
|
-
}),
|
|
108
|
-
ref: setPopperElement,
|
|
109
|
-
style: Object.assign(Object.assign({}, popperStyles.popper), {
|
|
71
|
+
var trigger = reference ? /*#__PURE__*/React.cloneElement(reference, Object.assign({
|
|
72
|
+
ref: refs.setReference
|
|
73
|
+
}, getReferenceProps())) : null;
|
|
74
|
+
return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, trigger, isOpen && (/*#__PURE__*/React__default.default.createElement(react.FloatingPortal, null, /*#__PURE__*/React__default.default.createElement("div", Object.assign({
|
|
75
|
+
ref: refs.setFloating
|
|
76
|
+
}, getFloatingProps(), {
|
|
77
|
+
className: clx("tooltip", className),
|
|
78
|
+
style: Object.assign(Object.assign({}, floatingStyles), {
|
|
110
79
|
zIndex: zIndex
|
|
111
80
|
})
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
81
|
+
}), /*#__PURE__*/React__default.default.createElement("div", {
|
|
82
|
+
className: clx("content")
|
|
83
|
+
}, content), withTail && (/*#__PURE__*/React__default.default.createElement(react.FloatingArrow, {
|
|
84
|
+
ref: arrowRef,
|
|
85
|
+
context: context
|
|
86
|
+
}))))));
|
|
118
87
|
};
|
|
119
88
|
|
|
120
89
|
exports.default = Tooltip;
|
package/Tooltip/index.props.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
export type Placement = Extract<PopperPlacement, "bottom-start" | "bottom" | "bottom-end" | "top-start" | "top" | "top-end" | "right-start" | "right" | "right-end" | "left-start" | "left" | "left-end">;
|
|
5
|
-
export interface ITooltipProps {
|
|
2
|
+
import { Placement, Strategy } from "@floating-ui/react";
|
|
3
|
+
export type TooltipProps = {
|
|
6
4
|
content: ReactNode;
|
|
7
5
|
zIndex?: number;
|
|
8
6
|
placement?: Placement;
|
|
9
|
-
strategy?:
|
|
7
|
+
strategy?: Strategy;
|
|
10
8
|
withTail?: boolean;
|
|
11
|
-
|
|
9
|
+
className?: string;
|
|
10
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { FC, PropsWithChildren } from "react";
|
|
2
|
-
|
|
2
|
+
type ClickOutsideProps = {
|
|
3
3
|
onClick: (e: MouseEvent | TouchEvent) => void;
|
|
4
|
-
}
|
|
4
|
+
};
|
|
5
|
+
declare const ClickOutside: FC<PropsWithChildren<ClickOutsideProps>>;
|
|
5
6
|
export default ClickOutside;
|
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
import _typeof from '@babel/runtime/helpers/typeof';
|
|
2
|
-
import
|
|
2
|
+
import { useRef, isValidElement, cloneElement } from 'react';
|
|
3
3
|
import useOnClickOutside from '../hooks/useOnClickOutside/index.js';
|
|
4
4
|
|
|
5
5
|
var ClickOutside = function ClickOutside(_ref) {
|
|
6
6
|
var children = _ref.children,
|
|
7
7
|
onClick = _ref.onClick;
|
|
8
|
-
var childRef = useRef();
|
|
8
|
+
var childRef = useRef(null);
|
|
9
9
|
useOnClickOutside(childRef, onClick);
|
|
10
|
-
if (! /*#__PURE__*/
|
|
10
|
+
if (! /*#__PURE__*/isValidElement(children)) return null;
|
|
11
11
|
var combinedRef = function combinedRef(node) {
|
|
12
12
|
childRef.current = node;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
childRefProp.current = node;
|
|
19
|
-
}
|
|
13
|
+
var childRefProp = children.ref;
|
|
14
|
+
if (typeof childRefProp === "function") {
|
|
15
|
+
childRefProp(node);
|
|
16
|
+
} else if (childRefProp && _typeof(childRefProp) === "object" && "current" in childRefProp) {
|
|
17
|
+
childRefProp.current = node;
|
|
20
18
|
}
|
|
21
19
|
};
|
|
22
20
|
return /*#__PURE__*/cloneElement(children, {
|