@canonical/react-components 0.41.0 → 0.43.0
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/dist/__mocks__/nanoid.js +0 -2
- package/dist/components/Accordion/Accordion.js +13 -37
- package/dist/components/Accordion/AccordionSection/AccordionSection.js +8 -14
- package/dist/components/Accordion/AccordionSection/index.js +0 -2
- package/dist/components/Accordion/index.js +0 -2
- package/dist/components/ActionButton/ActionButton.js +36 -65
- package/dist/components/ActionButton/index.js +0 -2
- package/dist/components/ArticlePagination/ArticlePagination.js +5 -15
- package/dist/components/ArticlePagination/index.js +0 -2
- package/dist/components/Badge/Badge.js +10 -28
- package/dist/components/Badge/index.js +0 -2
- package/dist/components/Button/Button.js +12 -25
- package/dist/components/Button/index.js +0 -4
- package/dist/components/Card/Card.js +7 -18
- package/dist/components/Card/index.js +0 -2
- package/dist/components/CheckboxInput/CheckableInput/CheckableInput.js +6 -20
- package/dist/components/CheckboxInput/CheckableInput/index.js +0 -2
- package/dist/components/CheckboxInput/CheckboxInput.js +3 -13
- package/dist/components/CheckboxInput/index.js +0 -2
- package/dist/components/Chip/Chip.js +14 -30
- package/dist/components/Chip/index.js +0 -2
- package/dist/components/Code/Code.js +5 -23
- package/dist/components/Code/index.js +0 -2
- package/dist/components/CodeSnippet/CodeSnippet.js +2 -12
- package/dist/components/CodeSnippet/CodeSnippetBlock.js +10 -18
- package/dist/components/CodeSnippet/CodeSnippetDropdown.js +5 -14
- package/dist/components/CodeSnippet/index.js +0 -3
- package/dist/components/Col/Col.js +15 -25
- package/dist/components/Col/index.js +0 -4
- package/dist/components/ConfirmationButton/ConfirmationButton.d.ts +25 -0
- package/dist/components/ConfirmationButton/ConfirmationButton.js +59 -0
- package/dist/components/ConfirmationButton/index.d.ts +2 -0
- package/dist/components/ConfirmationButton/index.js +13 -0
- package/dist/components/ConfirmationModal/ConfirmationModal.d.ts +33 -0
- package/dist/components/ConfirmationModal/ConfirmationModal.js +38 -0
- package/dist/components/ConfirmationModal/index.d.ts +2 -0
- package/dist/components/ConfirmationModal/index.js +13 -0
- package/dist/components/ContextualMenu/ContextualMenu.d.ts +3 -3
- package/dist/components/ContextualMenu/ContextualMenu.js +66 -101
- package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +2 -1
- package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +48 -85
- package/dist/components/ContextualMenu/ContextualMenuDropdown/index.js +0 -2
- package/dist/components/ContextualMenu/index.js +0 -2
- package/dist/components/EmptyState/EmptyState.d.ts +22 -0
- package/dist/components/EmptyState/EmptyState.js +27 -0
- package/dist/components/EmptyState/index.d.ts +2 -0
- package/dist/components/EmptyState/index.js +13 -0
- package/dist/components/Field/Field.js +35 -51
- package/dist/components/Field/index.js +0 -2
- package/dist/components/Form/Form.js +4 -14
- package/dist/components/Form/index.js +0 -2
- package/dist/components/Icon/Icon.js +3 -14
- package/dist/components/Icon/Icon.stories.scss +1 -0
- package/dist/components/Icon/index.js +0 -4
- package/dist/components/Input/Input.js +21 -39
- package/dist/components/Input/index.js +0 -2
- package/dist/components/Label/Label.js +7 -13
- package/dist/components/Label/index.js +0 -2
- package/dist/components/Link/Link.js +10 -22
- package/dist/components/Link/index.js +0 -2
- package/dist/components/List/List.d.ts +5 -5
- package/dist/components/List/List.js +17 -32
- package/dist/components/List/index.js +0 -2
- package/dist/components/Loader/Loader.js +0 -7
- package/dist/components/Loader/index.js +0 -2
- package/dist/components/MainTable/MainTable.js +59 -111
- package/dist/components/MainTable/index.js +0 -2
- package/dist/components/Modal/Modal.js +7 -34
- package/dist/components/Modal/index.js +0 -2
- package/dist/components/ModularTable/ModularTable.d.ts +9 -1
- package/dist/components/ModularTable/ModularTable.js +39 -46
- package/dist/components/ModularTable/index.js +0 -2
- package/dist/components/Navigation/Navigation.js +46 -82
- package/dist/components/Navigation/NavigationLink/NavigationLink.js +15 -30
- package/dist/components/Navigation/NavigationLink/index.js +0 -2
- package/dist/components/Navigation/NavigationMenu/NavigationMenu.js +12 -35
- package/dist/components/Navigation/NavigationMenu/index.js +0 -2
- package/dist/components/Navigation/index.js +0 -2
- package/dist/components/Notification/Notification.d.ts +6 -0
- package/dist/components/Notification/Notification.js +29 -42
- package/dist/components/Notification/index.js +0 -4
- package/dist/components/NotificationProvider/NotificationProvider.d.ts +5 -0
- package/dist/components/NotificationProvider/NotificationProvider.js +119 -0
- package/dist/components/NotificationProvider/index.d.ts +3 -0
- package/dist/components/NotificationProvider/index.js +49 -0
- package/dist/components/NotificationProvider/messageBuilder.d.ts +6 -0
- package/dist/components/NotificationProvider/messageBuilder.js +41 -0
- package/dist/components/NotificationProvider/types.d.ts +30 -0
- package/dist/components/NotificationProvider/types.js +5 -0
- package/dist/components/Pagination/Pagination.js +14 -44
- package/dist/components/Pagination/PaginationButton/PaginationButton.js +3 -10
- package/dist/components/Pagination/PaginationButton/index.js +0 -2
- package/dist/components/Pagination/PaginationItem/PaginationItem.js +3 -8
- package/dist/components/Pagination/PaginationItem/index.js +0 -2
- package/dist/components/Pagination/index.js +0 -2
- package/dist/components/PasswordToggle/PasswordToggle.js +16 -45
- package/dist/components/PasswordToggle/index.js +0 -2
- package/dist/components/RadioInput/RadioInput.js +1 -11
- package/dist/components/RadioInput/index.js +0 -2
- package/dist/components/Row/Row.js +2 -12
- package/dist/components/Row/index.js +0 -2
- package/dist/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.js +27 -49
- package/dist/components/SearchAndFilter/FilterPanelSection/index.js +0 -2
- package/dist/components/SearchAndFilter/SearchAndFilter.d.ts +9 -1
- package/dist/components/SearchAndFilter/SearchAndFilter.js +68 -104
- package/dist/components/SearchAndFilter/index.js +0 -2
- package/dist/components/SearchAndFilter/utils.js +1 -7
- package/dist/components/SearchBox/SearchBox.js +14 -34
- package/dist/components/SearchBox/index.js +0 -2
- package/dist/components/Select/Select.js +20 -33
- package/dist/components/Select/index.js +0 -2
- package/dist/components/Slider/Slider.js +16 -32
- package/dist/components/Slider/index.js +0 -2
- package/dist/components/Spinner/Spinner.js +8 -19
- package/dist/components/Spinner/index.js +0 -2
- package/dist/components/StatusLabel/StatusLabel.js +4 -15
- package/dist/components/StatusLabel/index.js +0 -4
- package/dist/components/Strip/Strip.js +25 -36
- package/dist/components/Strip/index.js +0 -2
- package/dist/components/SummaryButton/SummaryButton.js +4 -10
- package/dist/components/SummaryButton/index.js +0 -2
- package/dist/components/Switch/Switch.js +3 -12
- package/dist/components/Switch/index.js +0 -2
- package/dist/components/Table/Table.js +6 -16
- package/dist/components/Table/index.js +0 -2
- package/dist/components/TableCell/TableCell.js +10 -20
- package/dist/components/TableCell/index.js +0 -2
- package/dist/components/TableHeader/TableHeader.js +2 -11
- package/dist/components/TableHeader/index.js +0 -2
- package/dist/components/TableRow/TableRow.js +1 -10
- package/dist/components/TableRow/index.js +0 -2
- package/dist/components/Tabs/Tabs.js +7 -17
- package/dist/components/Tabs/index.js +0 -2
- package/dist/components/Textarea/Textarea.js +23 -36
- package/dist/components/Textarea/index.js +0 -2
- package/dist/components/Tooltip/Tooltip.js +38 -88
- package/dist/components/Tooltip/index.js +0 -4
- package/dist/enums.js +0 -2
- package/dist/hooks/index.js +0 -8
- package/dist/hooks/useClickOutside.js +2 -7
- package/dist/hooks/useId.js +0 -4
- package/dist/hooks/useListener.js +0 -8
- package/dist/hooks/useOnEscapePressed.js +0 -3
- package/dist/hooks/usePagination.js +13 -25
- package/dist/hooks/usePrevious.js +0 -3
- package/dist/hooks/useThrottle.js +1 -15
- package/dist/hooks/useWindowFitment.js +6 -13
- package/dist/index.d.ts +8 -0
- package/dist/index.js +64 -52
- package/dist/utils.js +3 -10
- package/package.json +31 -28
|
@@ -1,38 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.position = exports.default = exports.adjustForWindow = void 0;
|
|
9
|
-
|
|
10
8
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
|
-
|
|
12
9
|
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
-
|
|
14
10
|
var _reactUseportal = _interopRequireDefault(require("react-useportal"));
|
|
15
|
-
|
|
16
11
|
var _hooks = require("../../hooks");
|
|
17
|
-
|
|
18
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
15
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
25
|
-
|
|
26
16
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
27
|
-
|
|
28
17
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
29
|
-
|
|
30
|
-
function
|
|
31
|
-
|
|
32
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
33
|
-
|
|
18
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
19
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
34
20
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
35
|
-
|
|
36
21
|
var position = {
|
|
37
22
|
btmCenter: "btm-center",
|
|
38
23
|
btmLeft: "btm-left",
|
|
@@ -44,109 +29,87 @@ var position = {
|
|
|
44
29
|
topRight: "top-right"
|
|
45
30
|
};
|
|
46
31
|
exports.position = position;
|
|
47
|
-
|
|
48
32
|
var getPositionStyle = function getPositionStyle(pos, wrapperNode) {
|
|
49
33
|
if (!wrapperNode) {
|
|
50
34
|
return null;
|
|
51
35
|
}
|
|
52
|
-
|
|
53
36
|
var dimensions = wrapperNode.getBoundingClientRect();
|
|
54
37
|
var x = dimensions.x,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
38
|
+
y = dimensions.y,
|
|
39
|
+
height = dimensions.height,
|
|
40
|
+
width = dimensions.width;
|
|
58
41
|
var left = x + window.scrollX || 0;
|
|
59
42
|
var top = y + window.scrollY || 0;
|
|
60
|
-
|
|
61
43
|
switch (pos) {
|
|
62
44
|
case "btm-center":
|
|
63
45
|
left += width / 2;
|
|
64
46
|
top += height;
|
|
65
47
|
break;
|
|
66
|
-
|
|
67
48
|
case "btm-left":
|
|
68
49
|
top += height;
|
|
69
50
|
break;
|
|
70
|
-
|
|
71
51
|
case "btm-right":
|
|
72
52
|
left += width;
|
|
73
53
|
top += height;
|
|
74
54
|
break;
|
|
75
|
-
|
|
76
55
|
case "left":
|
|
77
56
|
top += height / 2;
|
|
78
57
|
break;
|
|
79
|
-
|
|
80
58
|
case "right":
|
|
81
59
|
left += width;
|
|
82
60
|
top += height / 2;
|
|
83
61
|
break;
|
|
84
|
-
|
|
85
62
|
case "top-center":
|
|
86
63
|
left += width / 2;
|
|
87
64
|
break;
|
|
88
|
-
|
|
89
65
|
case "top-left":
|
|
90
66
|
break;
|
|
91
|
-
|
|
92
67
|
case "top-right":
|
|
93
68
|
left += width;
|
|
94
69
|
break;
|
|
95
|
-
|
|
96
70
|
default:
|
|
97
71
|
break;
|
|
98
72
|
}
|
|
99
|
-
|
|
100
73
|
return {
|
|
101
74
|
position: "absolute",
|
|
102
75
|
left: left,
|
|
103
76
|
top: top
|
|
104
77
|
};
|
|
105
78
|
};
|
|
106
|
-
|
|
107
79
|
var adjustForWindow = function adjustForWindow(position, fitsWindow) {
|
|
108
80
|
var newPosition = position;
|
|
109
|
-
|
|
110
81
|
if (!fitsWindow.fromLeft.fitsLeft && newPosition === "left") {
|
|
111
82
|
newPosition = "top-right";
|
|
112
83
|
}
|
|
113
|
-
|
|
114
84
|
if (!fitsWindow.fromRight.fitsRight && newPosition === "right") {
|
|
115
85
|
newPosition = "top-left";
|
|
116
86
|
}
|
|
117
|
-
|
|
118
87
|
if (!fitsWindow.fromRight.fitsLeft && newPosition.endsWith("-right")) {
|
|
119
88
|
newPosition = newPosition.replace("right", "left");
|
|
120
89
|
}
|
|
121
|
-
|
|
122
90
|
if (!fitsWindow.fromLeft.fitsRight && newPosition.endsWith("-left")) {
|
|
123
91
|
newPosition = newPosition.replace("left", "right");
|
|
124
92
|
}
|
|
125
|
-
|
|
126
93
|
if (!fitsWindow.fromTop.fitsAbove && newPosition.startsWith("top")) {
|
|
127
94
|
newPosition = newPosition.replace("top", "btm");
|
|
128
95
|
}
|
|
129
|
-
|
|
130
96
|
if (!fitsWindow.fromBottom.fitsBelow && newPosition.startsWith("btm")) {
|
|
131
97
|
newPosition = newPosition.replace("btm", "top");
|
|
132
98
|
}
|
|
133
|
-
|
|
134
99
|
if (!fitsWindow.fromLeft.fitsRight && !fitsWindow.fromRight.fitsLeft && (newPosition.endsWith("-left") || newPosition.endsWith("-right"))) {
|
|
135
100
|
newPosition = newPosition.replace("left", "center").replace("right", "center");
|
|
136
101
|
}
|
|
137
|
-
|
|
138
102
|
if (newPosition.endsWith("center") && (fitsWindow.fromCenter.fitsCentered.fitsRight || fitsWindow.fromCenter.fitsCentered.fitsLeft)) {
|
|
139
103
|
if (!fitsWindow.fromCenter.fitsCentered.fitsRight) {
|
|
140
104
|
newPosition = newPosition.replace("center", "right");
|
|
141
105
|
}
|
|
142
|
-
|
|
143
106
|
if (!fitsWindow.fromCenter.fitsCentered.fitsLeft) {
|
|
144
107
|
newPosition = newPosition.replace("center", "left");
|
|
145
108
|
}
|
|
146
109
|
}
|
|
147
|
-
|
|
148
110
|
return newPosition;
|
|
149
111
|
};
|
|
112
|
+
|
|
150
113
|
/**
|
|
151
114
|
* A React component for Vanilla tooltips.
|
|
152
115
|
* @param [autoAdjust=true] Whether the tooltip should adjust to fit in the screen.
|
|
@@ -159,48 +122,41 @@ var adjustForWindow = function adjustForWindow(position, fitsWindow) {
|
|
|
159
122
|
* @param tooltipClassName An optional class to apply to the tooltip message element.
|
|
160
123
|
* @param zIndex The z-index value of the tooltip message element.
|
|
161
124
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
125
|
exports.adjustForWindow = adjustForWindow;
|
|
165
|
-
|
|
166
126
|
var Tooltip = function Tooltip(_ref) {
|
|
167
127
|
var _ref$autoAdjust = _ref.autoAdjust,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
128
|
+
autoAdjust = _ref$autoAdjust === void 0 ? true : _ref$autoAdjust,
|
|
129
|
+
children = _ref.children,
|
|
130
|
+
className = _ref.className,
|
|
131
|
+
_ref$followMouse = _ref.followMouse,
|
|
132
|
+
followMouse = _ref$followMouse === void 0 ? false : _ref$followMouse,
|
|
133
|
+
message = _ref.message,
|
|
134
|
+
_ref$position = _ref.position,
|
|
135
|
+
position = _ref$position === void 0 ? "top-left" : _ref$position,
|
|
136
|
+
positionElementClassName = _ref.positionElementClassName,
|
|
137
|
+
tooltipClassName = _ref.tooltipClassName,
|
|
138
|
+
zIndex = _ref.zIndex;
|
|
179
139
|
var wrapperRef = (0, _react.useRef)(null);
|
|
180
140
|
var messageRef = (0, _react.useRef)(null);
|
|
181
|
-
|
|
182
141
|
var _useState = (0, _react.useState)(position),
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
142
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
143
|
+
adjustedPosition = _useState2[0],
|
|
144
|
+
setAdjustedPosition = _useState2[1];
|
|
187
145
|
var _useState3 = (0, _react.useState)({
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
146
|
+
position: "absolute",
|
|
147
|
+
// Initially position the tooltip of the screen in case it gets shown
|
|
148
|
+
// before setting the position.
|
|
149
|
+
left: -9999999,
|
|
150
|
+
top: -9999999
|
|
151
|
+
}),
|
|
152
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
153
|
+
positionStyle = _useState4[0],
|
|
154
|
+
setPositionStyle = _useState4[1];
|
|
198
155
|
var _usePortal = (0, _reactUseportal.default)(),
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
156
|
+
openPortal = _usePortal.openPortal,
|
|
157
|
+
closePortal = _usePortal.closePortal,
|
|
158
|
+
isOpen = _usePortal.isOpen,
|
|
159
|
+
Portal = _usePortal.Portal;
|
|
204
160
|
var tooltipId = (0, _hooks.useId)();
|
|
205
161
|
(0, _react.useEffect)(function () {
|
|
206
162
|
if (isOpen && !followMouse && wrapperRef.current) {
|
|
@@ -220,10 +176,12 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
220
176
|
}, []);
|
|
221
177
|
var onUpdateWindowFitment = (0, _react.useCallback)(function (fitsWindow) {
|
|
222
178
|
setAdjustedPosition(adjustForWindow(position, fitsWindow));
|
|
223
|
-
}, [setAdjustedPosition, position]);
|
|
179
|
+
}, [setAdjustedPosition, position]);
|
|
224
180
|
|
|
225
|
-
|
|
181
|
+
// Handle mouse events.
|
|
182
|
+
(0, _hooks.useListener)(wrapperRef.current, mouseHandler, "mousemove", true, followMouse && isOpen);
|
|
226
183
|
|
|
184
|
+
// Handle adjusting the position of the tooltip so that it remains on screen.
|
|
227
185
|
(0, _hooks.useWindowFitment)(messageRef.current, wrapperRef.current, onUpdateWindowFitment, 20, isOpen, autoAdjust && followMouse);
|
|
228
186
|
var handleKeyPress = (0, _react.useCallback)(function (event) {
|
|
229
187
|
if (event.key === "Escape") {
|
|
@@ -236,32 +194,25 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
236
194
|
window.removeEventListener("keypress", handleKeyPress);
|
|
237
195
|
};
|
|
238
196
|
}, [handleKeyPress]);
|
|
239
|
-
|
|
240
197
|
var handleBlur = function handleBlur(e) {
|
|
241
198
|
var _wrapperRef$current, _messageRef$current;
|
|
242
|
-
|
|
243
199
|
// do not close if the focus is within the tooltip wrapper
|
|
244
200
|
if (wrapperRef !== null && wrapperRef !== void 0 && (_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(document.activeElement)) {
|
|
245
201
|
return;
|
|
246
202
|
}
|
|
247
|
-
|
|
248
203
|
if (e.relatedTarget ? !((_messageRef$current = messageRef.current) !== null && _messageRef$current !== void 0 && _messageRef$current.contains(e.relatedTarget)) : e.target !== messageRef.current) {
|
|
249
204
|
closePortal();
|
|
250
205
|
}
|
|
251
206
|
};
|
|
252
|
-
|
|
253
207
|
var handleClick = function handleClick(e) {
|
|
254
208
|
var _messageRef$current2;
|
|
255
|
-
|
|
256
209
|
// ignore clicks within the tooltip message
|
|
257
210
|
if ((_messageRef$current2 = messageRef.current) !== null && _messageRef$current2 !== void 0 && _messageRef$current2.contains(e.target)) {
|
|
258
211
|
return;
|
|
259
212
|
}
|
|
260
|
-
|
|
261
213
|
e.target.focus();
|
|
262
214
|
openPortal();
|
|
263
215
|
};
|
|
264
|
-
|
|
265
216
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, message ? /*#__PURE__*/_react.default.createElement("span", {
|
|
266
217
|
className: className,
|
|
267
218
|
onBlur: handleBlur,
|
|
@@ -277,7 +228,7 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
277
228
|
}
|
|
278
229
|
}, _react.default.Children.map(children, function (child) {
|
|
279
230
|
return child && /*#__PURE__*/_react.default.isValidElement(child) ? /*#__PURE__*/_react.default.cloneElement(child, {
|
|
280
|
-
"aria-describedby": tooltipId
|
|
231
|
+
"aria-describedby": isOpen ? tooltipId : undefined
|
|
281
232
|
}) : child;
|
|
282
233
|
})), isOpen ? /*#__PURE__*/_react.default.createElement(Portal, null, /*#__PURE__*/_react.default.createElement("span", {
|
|
283
234
|
className: (0, _classnames.default)("p-tooltip--".concat(adjustedPosition), "is-detached", tooltipClassName),
|
|
@@ -300,6 +251,5 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
300
251
|
className: className
|
|
301
252
|
}, children));
|
|
302
253
|
};
|
|
303
|
-
|
|
304
254
|
var _default = Tooltip;
|
|
305
255
|
exports.default = _default;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -17,9 +16,6 @@ Object.defineProperty(exports, "position", {
|
|
|
17
16
|
return _Tooltip.position;
|
|
18
17
|
}
|
|
19
18
|
});
|
|
20
|
-
|
|
21
19
|
var _Tooltip = _interopRequireWildcard(require("./Tooltip"));
|
|
22
|
-
|
|
23
20
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
24
|
-
|
|
25
21
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
package/dist/enums.js
CHANGED
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Theme = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* The Vanilla theme types.
|
|
10
9
|
*/
|
|
@@ -13,5 +12,4 @@ var Theme = /*#__PURE__*/function (Theme) {
|
|
|
13
12
|
Theme["LIGHT"] = "light";
|
|
14
13
|
return Theme;
|
|
15
14
|
}({});
|
|
16
|
-
|
|
17
15
|
exports.Theme = Theme;
|
package/dist/hooks/index.js
CHANGED
|
@@ -51,19 +51,11 @@ Object.defineProperty(exports, "useWindowFitment", {
|
|
|
51
51
|
return _useWindowFitment.useWindowFitment;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
-
|
|
55
54
|
var _useClickOutside = require("./useClickOutside");
|
|
56
|
-
|
|
57
55
|
var _useId = require("./useId");
|
|
58
|
-
|
|
59
56
|
var _useListener = require("./useListener");
|
|
60
|
-
|
|
61
57
|
var _useOnEscapePressed = require("./useOnEscapePressed");
|
|
62
|
-
|
|
63
58
|
var _usePrevious = require("./usePrevious");
|
|
64
|
-
|
|
65
59
|
var _useThrottle = require("./useThrottle");
|
|
66
|
-
|
|
67
60
|
var _usePagination = require("./usePagination");
|
|
68
|
-
|
|
69
61
|
var _useWindowFitment = require("./useWindowFitment");
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useClickOutside = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Handle clicks outside an element.
|
|
12
10
|
* @returns A ref to pass to the element to handle clicks outside of.
|
|
@@ -15,12 +13,10 @@ var useClickOutside = function useClickOutside(onClickOutside) {
|
|
|
15
13
|
var ref = (0, _react.useRef)(null);
|
|
16
14
|
var handleClickOutside = (0, _react.useCallback)(function (evt) {
|
|
17
15
|
var _evt$target, _ref$current;
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
var target = evt.target;
|
|
17
|
+
// The target might be something like an SVG node which doesn't provide
|
|
20
18
|
// the class name as a string.
|
|
21
|
-
|
|
22
19
|
var isValidTarget = typeof (evt === null || evt === void 0 ? void 0 : (_evt$target = evt.target) === null || _evt$target === void 0 ? void 0 : _evt$target.className) === "string";
|
|
23
|
-
|
|
24
20
|
if (!isValidTarget || ref.current && !((_ref$current = ref.current) !== null && _ref$current !== void 0 && _ref$current.contains(target)) && ref.current !== target) {
|
|
25
21
|
onClickOutside();
|
|
26
22
|
}
|
|
@@ -33,5 +29,4 @@ var useClickOutside = function useClickOutside(onClickOutside) {
|
|
|
33
29
|
}, [handleClickOutside]);
|
|
34
30
|
return ref;
|
|
35
31
|
};
|
|
36
|
-
|
|
37
32
|
exports.useClickOutside = useClickOutside;
|
package/dist/hooks/useId.js
CHANGED
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useId = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _nanoid = require("nanoid");
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* A hook that returns the same random ID string on every render.
|
|
14
11
|
* Can be used as a value for HTML "id" attributes.
|
|
@@ -17,5 +14,4 @@ var _nanoid = require("nanoid");
|
|
|
17
14
|
var useId = function useId() {
|
|
18
15
|
return (0, _react.useRef)((0, _nanoid.nanoid)()).current;
|
|
19
16
|
};
|
|
20
|
-
|
|
21
17
|
exports.useId = useId;
|
|
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useListener = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _useThrottle = require("./useThrottle");
|
|
11
|
-
|
|
12
9
|
var _usePrevious = require("./usePrevious");
|
|
13
|
-
|
|
14
10
|
/**
|
|
15
11
|
* A hook that handles attaching/removing listeners and smartly reattaching if
|
|
16
12
|
* any of the attributes change.
|
|
@@ -34,17 +30,14 @@ var useListener = function useListener(targetNode, callback, eventType) {
|
|
|
34
30
|
// If any of the props related to the attached listener changed then the
|
|
35
31
|
// listener needs to be re-attached.
|
|
36
32
|
var listenerAttributesChanged = callback !== previousCallback || eventType !== previousEventType || shouldThrottle !== previousShouldThrottle || targetNode !== previousTargetNode;
|
|
37
|
-
|
|
38
33
|
if (isListening.current && (!shouldListen || listenerAttributesChanged)) {
|
|
39
34
|
previousTargetNode.removeEventListener(previousEventType, eventListener.current);
|
|
40
35
|
isListening.current = false;
|
|
41
36
|
}
|
|
42
|
-
|
|
43
37
|
if (shouldThrottle !== previousShouldThrottle || callback !== previousCallback) {
|
|
44
38
|
// Set the listener to the callback, or used the throttled callback.
|
|
45
39
|
eventListener.current = shouldThrottle ? throttle : callback;
|
|
46
40
|
}
|
|
47
|
-
|
|
48
41
|
if (targetNode && shouldListen && !isListening.current) {
|
|
49
42
|
targetNode.addEventListener(eventType, eventListener.current);
|
|
50
43
|
isListening.current = true;
|
|
@@ -60,5 +53,4 @@ var useListener = function useListener(targetNode, callback, eventType) {
|
|
|
60
53
|
};
|
|
61
54
|
}, [eventType, targetNode]);
|
|
62
55
|
};
|
|
63
|
-
|
|
64
56
|
exports.useListener = useListener;
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useOnEscapePressed = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Handle the escape key pressed.
|
|
12
10
|
*/
|
|
@@ -23,5 +21,4 @@ var useOnEscapePressed = function useOnEscapePressed(onEscape) {
|
|
|
23
21
|
};
|
|
24
22
|
}, [keyDown]);
|
|
25
23
|
};
|
|
26
|
-
|
|
27
24
|
exports.useOnEscapePressed = useOnEscapePressed;
|
|
@@ -4,21 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.usePagination = usePagination;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
11
|
-
|
|
12
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
-
|
|
14
10
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
-
|
|
16
|
-
function
|
|
17
|
-
|
|
18
|
-
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
19
|
-
|
|
11
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
12
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
20
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
-
|
|
22
14
|
/**
|
|
23
15
|
* A hook that handles pagination.
|
|
24
16
|
* @param data - The data array to paginate.
|
|
@@ -27,37 +19,33 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
27
19
|
* @param {number} [options.initialPage=1] - Initial page number. Defaults to 1.
|
|
28
20
|
* @param {boolean} [options.autoResetPage=false] - Whether to reset the page number to 1 when the data changes.
|
|
29
21
|
*/
|
|
22
|
+
|
|
30
23
|
function usePagination(data, options) {
|
|
31
24
|
var _data$length;
|
|
32
|
-
|
|
33
25
|
var defaultOptions = {
|
|
34
26
|
initialPage: 1,
|
|
35
27
|
autoResetPage: false
|
|
36
28
|
};
|
|
37
|
-
|
|
38
29
|
var _Object$assign = Object.assign(defaultOptions, options),
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
itemsPerPage = _Object$assign.itemsPerPage,
|
|
31
|
+
initialPage = _Object$assign.initialPage,
|
|
32
|
+
autoResetPage = _Object$assign.autoResetPage;
|
|
43
33
|
var totalItems = (_data$length = data === null || data === void 0 ? void 0 : data.length) !== null && _data$length !== void 0 ? _data$length : 0;
|
|
44
34
|
var initialPageIndex = initialPage > 0 ? initialPage - 1 : 0;
|
|
45
|
-
|
|
46
35
|
var _useState = (0, _react.useState)(initialPageIndex),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
36
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
37
|
+
pageIndex = _useState2[0],
|
|
38
|
+
setPageIndex = _useState2[1];
|
|
51
39
|
var startIndex = typeof itemsPerPage === "number" ? pageIndex * itemsPerPage : 0;
|
|
52
|
-
|
|
53
40
|
var paginate = function paginate(pageNumber) {
|
|
54
41
|
return setPageIndex(pageNumber - 1);
|
|
55
42
|
};
|
|
56
|
-
|
|
57
43
|
(0, _react.useEffect)(function () {
|
|
58
44
|
if (typeof itemsPerPage === "number" && startIndex >= totalItems) {
|
|
59
|
-
!autoResetPage && Math.floor(totalItems / itemsPerPage) > 0 ?
|
|
60
|
-
|
|
45
|
+
!autoResetPage && Math.floor(totalItems / itemsPerPage) > 0 ?
|
|
46
|
+
// go to the last available page if the current page is out of bounds
|
|
47
|
+
setPageIndex(Math.floor(totalItems / itemsPerPage) - 1) :
|
|
48
|
+
// go to the initial page if autoResetPage is true
|
|
61
49
|
setPageIndex(0);
|
|
62
50
|
}
|
|
63
51
|
}, [pageIndex, startIndex, setPageIndex, totalItems, itemsPerPage, autoResetPage]);
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.usePrevious = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* A hook to handle storing the previous value of anything.
|
|
12
10
|
* @param value - The value to watch.
|
|
@@ -21,5 +19,4 @@ var usePrevious = function usePrevious(value) {
|
|
|
21
19
|
}, [value]);
|
|
22
20
|
return ref.current;
|
|
23
21
|
};
|
|
24
|
-
|
|
25
22
|
exports.usePrevious = usePrevious;
|
|
@@ -4,24 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useThrottle = exports.THROTTLE_DELAY = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11
|
-
|
|
12
9
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
-
|
|
14
10
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
15
|
-
|
|
16
11
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
17
|
-
|
|
18
12
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
19
|
-
|
|
20
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
21
|
-
|
|
13
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
22
14
|
var THROTTLE_DELAY = 1000 / 60;
|
|
23
15
|
exports.THROTTLE_DELAY = THROTTLE_DELAY;
|
|
24
|
-
|
|
25
16
|
// eslint-disable-line @typescript-eslint/no-explicit-any
|
|
26
17
|
|
|
27
18
|
/**
|
|
@@ -39,22 +30,18 @@ var useThrottle = function useThrottle(callback) {
|
|
|
39
30
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
40
31
|
args[_key] = arguments[_key];
|
|
41
32
|
}
|
|
42
|
-
|
|
43
33
|
lastArgs.current = args;
|
|
44
|
-
|
|
45
34
|
var callCallback = function callCallback() {
|
|
46
35
|
callback.apply(void 0, _toConsumableArray(lastArgs.current));
|
|
47
36
|
lastCall.current = Date.now();
|
|
48
37
|
timeout.current = null;
|
|
49
38
|
};
|
|
50
|
-
|
|
51
39
|
var createTimeout = function createTimeout() {
|
|
52
40
|
timeout.current = window.setTimeout(function () {
|
|
53
41
|
callCallback();
|
|
54
42
|
timeout.current = null;
|
|
55
43
|
}, delay);
|
|
56
44
|
};
|
|
57
|
-
|
|
58
45
|
if (!lastCall.current) {
|
|
59
46
|
// Initially call the callback and start a timeout for the next call.
|
|
60
47
|
callCallback();
|
|
@@ -75,5 +62,4 @@ var useThrottle = function useThrottle(callback) {
|
|
|
75
62
|
}, []);
|
|
76
63
|
return throttle;
|
|
77
64
|
};
|
|
78
|
-
|
|
79
65
|
exports.useThrottle = useThrottle;
|
|
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useWindowFitment = void 0;
|
|
7
|
-
|
|
8
7
|
var _react = require("react");
|
|
9
|
-
|
|
10
8
|
var _useListener = require("./useListener");
|
|
11
|
-
|
|
12
9
|
/**
|
|
13
10
|
* A hook to determine if an element fits on the window.
|
|
14
11
|
* @param targetNode The element to try and fit on the window.
|
|
@@ -27,7 +24,6 @@ var useWindowFitment = function useWindowFitment(targetNode, referenceNode, call
|
|
|
27
24
|
var htmlRef = (0, _react.useRef)(document.querySelector("html"));
|
|
28
25
|
var update = (0, _react.useCallback)(function (evt) {
|
|
29
26
|
var referenceCoordinates;
|
|
30
|
-
|
|
31
27
|
if (fromMouse) {
|
|
32
28
|
if (evt) {
|
|
33
29
|
referenceCoordinates = {
|
|
@@ -41,17 +37,15 @@ var useWindowFitment = function useWindowFitment(targetNode, referenceNode, call
|
|
|
41
37
|
} else if (referenceNode) {
|
|
42
38
|
referenceCoordinates = referenceNode.getBoundingClientRect();
|
|
43
39
|
}
|
|
44
|
-
|
|
45
40
|
if (shouldCheck && targetNode && referenceCoordinates) {
|
|
46
41
|
var _targetNode$getBoundi = targetNode.getBoundingClientRect(),
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
42
|
+
targetHeight = _targetNode$getBoundi.height,
|
|
43
|
+
targetWidth = _targetNode$getBoundi.width;
|
|
50
44
|
var _referenceCoordinates = referenceCoordinates,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
referenceHeight = _referenceCoordinates.height,
|
|
46
|
+
referenceLeft = _referenceCoordinates.left,
|
|
47
|
+
referenceTop = _referenceCoordinates.top,
|
|
48
|
+
referenceWidth = _referenceCoordinates.width;
|
|
55
49
|
var referenceBottom = referenceTop + referenceHeight;
|
|
56
50
|
var referenceRight = referenceLeft + referenceWidth;
|
|
57
51
|
var referenceCenterX = referenceLeft + referenceWidth / 2;
|
|
@@ -117,5 +111,4 @@ var useWindowFitment = function useWindowFitment(targetNode, referenceNode, call
|
|
|
117
111
|
}
|
|
118
112
|
}, [fromMouse, update]);
|
|
119
113
|
};
|
|
120
|
-
|
|
121
114
|
exports.useWindowFitment = useWindowFitment;
|