@canonical/react-components 0.47.1 → 0.47.2
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 +3 -3
- package/dist/components/Accordion/Accordion.js +28 -41
- package/dist/components/Accordion/AccordionSection/AccordionSection.js +18 -18
- package/dist/components/Accordion/AccordionSection/index.js +1 -1
- package/dist/components/Accordion/index.js +1 -1
- package/dist/components/ActionButton/ActionButton.js +34 -66
- package/dist/components/ActionButton/index.js +1 -1
- package/dist/components/ArticlePagination/ArticlePagination.js +10 -12
- package/dist/components/ArticlePagination/index.js +1 -1
- package/dist/components/Badge/Badge.js +24 -29
- package/dist/components/Badge/index.js +1 -1
- package/dist/components/Button/Button.js +21 -26
- package/dist/components/Button/index.js +4 -5
- package/dist/components/Card/Card.js +12 -14
- package/dist/components/Card/index.js +1 -1
- package/dist/components/CheckboxInput/CheckableInput/CheckableInput.js +15 -19
- package/dist/components/CheckboxInput/CheckableInput/index.js +1 -1
- package/dist/components/CheckboxInput/CheckboxInput.js +7 -10
- package/dist/components/CheckboxInput/index.js +1 -1
- package/dist/components/Chip/Chip.js +23 -33
- package/dist/components/Chip/index.js +1 -1
- package/dist/components/Code/Code.js +14 -17
- package/dist/components/Code/index.js +1 -1
- package/dist/components/CodeSnippet/CodeSnippet.js +9 -14
- package/dist/components/CodeSnippet/CodeSnippetBlock.js +24 -29
- package/dist/components/CodeSnippet/CodeSnippetDropdown.js +11 -11
- package/dist/components/CodeSnippet/index.js +2 -2
- package/dist/components/Col/Col.js +24 -26
- package/dist/components/Col/index.js +4 -5
- package/dist/components/ConfirmationButton/ConfirmationButton.js +18 -21
- package/dist/components/ConfirmationButton/index.js +1 -1
- package/dist/components/ConfirmationModal/ConfirmationModal.js +11 -15
- package/dist/components/ConfirmationModal/index.js +1 -1
- package/dist/components/ContextualMenu/ContextualMenu.js +89 -107
- package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.d.ts +4 -4
- package/dist/components/ContextualMenu/ContextualMenuDropdown/ContextualMenuDropdown.js +97 -107
- package/dist/components/ContextualMenu/ContextualMenuDropdown/index.js +1 -1
- package/dist/components/ContextualMenu/index.js +1 -1
- package/dist/components/EmptyState/EmptyState.js +9 -11
- package/dist/components/EmptyState/index.js +1 -1
- package/dist/components/Field/Field.js +66 -65
- package/dist/components/Field/index.js +1 -1
- package/dist/components/Form/Form.js +9 -11
- package/dist/components/Form/index.js +1 -1
- package/dist/components/Icon/Icon.js +9 -12
- package/dist/components/Icon/index.js +4 -5
- package/dist/components/Input/Input.js +38 -45
- package/dist/components/Input/index.js +1 -1
- package/dist/components/Label/Label.js +9 -11
- package/dist/components/Label/index.js +1 -1
- package/dist/components/Link/Link.js +12 -18
- package/dist/components/Link/index.js +1 -1
- package/dist/components/List/List.js +50 -54
- package/dist/components/List/index.js +1 -1
- package/dist/components/Loader/Loader.js +2 -3
- package/dist/components/Loader/index.js +1 -1
- package/dist/components/MainTable/MainTable.js +87 -104
- package/dist/components/MainTable/index.js +1 -1
- package/dist/components/Modal/Modal.js +37 -38
- package/dist/components/Modal/index.js +1 -1
- package/dist/components/ModularTable/ModularTable.js +63 -77
- package/dist/components/ModularTable/index.js +1 -1
- package/dist/components/Navigation/Navigation.js +63 -97
- package/dist/components/Navigation/NavigationLink/NavigationLink.js +32 -35
- package/dist/components/Navigation/NavigationLink/index.js +1 -1
- package/dist/components/Navigation/NavigationMenu/NavigationMenu.js +26 -45
- package/dist/components/Navigation/NavigationMenu/index.js +1 -1
- package/dist/components/Navigation/index.js +1 -1
- package/dist/components/Notification/Notification.js +49 -59
- package/dist/components/Notification/index.js +4 -5
- package/dist/components/NotificationProvider/NotificationProvider.js +47 -68
- package/dist/components/NotificationProvider/index.js +7 -7
- package/dist/components/NotificationProvider/messageBuilder.js +9 -9
- package/dist/components/NotificationProvider/types.d.ts +1 -0
- package/dist/components/Pagination/Pagination.js +50 -69
- package/dist/components/Pagination/PaginationButton/PaginationButton.js +11 -12
- package/dist/components/Pagination/PaginationButton/index.js +1 -1
- package/dist/components/Pagination/PaginationItem/PaginationItem.js +7 -7
- package/dist/components/Pagination/PaginationItem/index.js +1 -1
- package/dist/components/Pagination/index.js +1 -1
- package/dist/components/PasswordToggle/PasswordToggle.d.ts +1 -1
- package/dist/components/PasswordToggle/PasswordToggle.js +25 -40
- package/dist/components/PasswordToggle/index.js +1 -1
- package/dist/components/RadioInput/RadioInput.js +6 -8
- package/dist/components/RadioInput/index.js +1 -1
- package/dist/components/Row/Row.js +7 -9
- package/dist/components/Row/index.js +1 -1
- package/dist/components/SearchAndFilter/FilterPanelSection/FilterPanelSection.js +38 -51
- package/dist/components/SearchAndFilter/FilterPanelSection/index.js +1 -1
- package/dist/components/SearchAndFilter/SearchAndFilter.js +75 -135
- package/dist/components/SearchAndFilter/index.js +1 -1
- package/dist/components/SearchAndFilter/utils.js +4 -8
- package/dist/components/SearchBox/SearchBox.js +25 -33
- package/dist/components/SearchBox/index.js +1 -1
- package/dist/components/Select/Select.js +38 -44
- package/dist/components/Select/index.js +1 -1
- package/dist/components/Slider/Slider.js +27 -35
- package/dist/components/Slider/index.js +1 -1
- package/dist/components/Spinner/Spinner.js +10 -15
- package/dist/components/Spinner/index.js +1 -1
- package/dist/components/StatusLabel/StatusLabel.js +11 -13
- package/dist/components/StatusLabel/index.js +4 -5
- package/dist/components/Strip/Strip.js +27 -34
- package/dist/components/Strip/index.js +1 -1
- package/dist/components/SummaryButton/SummaryButton.js +9 -8
- package/dist/components/SummaryButton/index.js +1 -1
- package/dist/components/Switch/Switch.js +7 -10
- package/dist/components/Switch/index.js +1 -1
- package/dist/components/Table/Table.js +9 -13
- package/dist/components/Table/index.js +1 -1
- package/dist/components/TableCell/TableCell.js +11 -17
- package/dist/components/TableCell/index.js +1 -1
- package/dist/components/TableHeader/TableHeader.js +7 -9
- package/dist/components/TableHeader/index.js +1 -1
- package/dist/components/TablePagination/TablePagination.d.ts +37 -0
- package/dist/components/TablePagination/TablePagination.js +125 -0
- package/dist/components/TablePagination/TablePagination.scss +40 -0
- package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.d.ts +16 -0
- package/dist/components/TablePagination/TablePaginationControls/TablePaginationControls.js +66 -0
- package/dist/components/TablePagination/TablePaginationControls/index.d.ts +2 -0
- package/dist/components/TablePagination/TablePaginationControls/index.js +13 -0
- package/dist/components/TablePagination/index.d.ts +2 -0
- package/dist/components/TablePagination/index.js +13 -0
- package/dist/components/TableRow/TableRow.js +6 -8
- package/dist/components/TableRow/index.js +1 -1
- package/dist/components/Tabs/Tabs.js +17 -17
- package/dist/components/Tabs/index.js +1 -1
- package/dist/components/Textarea/Textarea.js +51 -45
- package/dist/components/Textarea/index.js +1 -1
- package/dist/components/Tooltip/Tooltip.d.ts +5 -1
- package/dist/components/Tooltip/Tooltip.js +76 -79
- package/dist/components/Tooltip/index.js +4 -5
- package/dist/enums.js +2 -3
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +16 -10
- package/dist/hooks/useId.js +1 -3
- package/dist/hooks/useListener.d.ts +2 -1
- package/dist/hooks/useListener.js +25 -24
- package/dist/hooks/useOnClickOutside.d.ts +12 -0
- package/dist/hooks/useOnClickOutside.js +45 -0
- package/dist/hooks/useOnEscapePressed.d.ts +3 -1
- package/dist/hooks/useOnEscapePressed.js +13 -6
- package/dist/hooks/usePagination.js +17 -29
- package/dist/hooks/usePrevious.js +4 -4
- package/dist/hooks/useThrottle.js +16 -25
- package/dist/hooks/useWindowFitment.js +30 -28
- package/dist/index.d.ts +3 -1
- package/dist/index.js +86 -74
- package/dist/utils.js +6 -13
- package/package.json +42 -35
- package/dist/hooks/useClickOutside.d.ts +0 -6
- package/dist/hooks/useClickOutside.js +0 -32
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
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
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -9,16 +8,10 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
9
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
9
|
var _reactUseportal = _interopRequireDefault(require("react-useportal"));
|
|
11
10
|
var _hooks = require("../../hooks");
|
|
12
|
-
function _getRequireWildcardCache(
|
|
13
|
-
function _interopRequireWildcard(
|
|
11
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
14
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
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."); }
|
|
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); }
|
|
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; } }
|
|
20
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
21
|
-
var position = {
|
|
14
|
+
const position = exports.position = {
|
|
22
15
|
btmCenter: "btm-center",
|
|
23
16
|
btmLeft: "btm-left",
|
|
24
17
|
btmRight: "btm-right",
|
|
@@ -28,18 +21,19 @@ var position = {
|
|
|
28
21
|
topLeft: "top-left",
|
|
29
22
|
topRight: "top-right"
|
|
30
23
|
};
|
|
31
|
-
|
|
32
|
-
var getPositionStyle = function getPositionStyle(pos, wrapperNode) {
|
|
24
|
+
const getPositionStyle = (pos, wrapperNode) => {
|
|
33
25
|
if (!wrapperNode) {
|
|
34
26
|
return null;
|
|
35
27
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
const dimensions = wrapperNode.getBoundingClientRect();
|
|
29
|
+
const {
|
|
30
|
+
x,
|
|
31
|
+
y,
|
|
32
|
+
height,
|
|
33
|
+
width
|
|
34
|
+
} = dimensions;
|
|
35
|
+
let left = x + window.scrollX || 0;
|
|
36
|
+
let top = y + window.scrollY || 0;
|
|
43
37
|
switch (pos) {
|
|
44
38
|
case "btm-center":
|
|
45
39
|
left += width / 2;
|
|
@@ -72,12 +66,12 @@ var getPositionStyle = function getPositionStyle(pos, wrapperNode) {
|
|
|
72
66
|
}
|
|
73
67
|
return {
|
|
74
68
|
position: "absolute",
|
|
75
|
-
left
|
|
76
|
-
top
|
|
69
|
+
left,
|
|
70
|
+
top
|
|
77
71
|
};
|
|
78
72
|
};
|
|
79
|
-
|
|
80
|
-
|
|
73
|
+
const adjustForWindow = (position, fitsWindow) => {
|
|
74
|
+
let newPosition = position;
|
|
81
75
|
if (!fitsWindow.fromLeft.fitsLeft && newPosition === "left") {
|
|
82
76
|
newPosition = "top-right";
|
|
83
77
|
}
|
|
@@ -123,48 +117,50 @@ var adjustForWindow = function adjustForWindow(position, fitsWindow) {
|
|
|
123
117
|
* @param zIndex The z-index value of the tooltip message element.
|
|
124
118
|
*/
|
|
125
119
|
exports.adjustForWindow = adjustForWindow;
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
autoAdjust =
|
|
129
|
-
children
|
|
130
|
-
className
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
120
|
+
const Tooltip = _ref => {
|
|
121
|
+
let {
|
|
122
|
+
autoAdjust = true,
|
|
123
|
+
children,
|
|
124
|
+
className,
|
|
125
|
+
followMouse = false,
|
|
126
|
+
message,
|
|
127
|
+
position = "top-left",
|
|
128
|
+
positionElementClassName,
|
|
129
|
+
tooltipClassName,
|
|
130
|
+
zIndex,
|
|
131
|
+
delay = 350
|
|
132
|
+
} = _ref;
|
|
133
|
+
const wrapperRef = (0, _react.useRef)(null);
|
|
134
|
+
const messageRef = (0, _react.useRef)(null);
|
|
135
|
+
const [adjustedPosition, setAdjustedPosition] = (0, _react.useState)(position);
|
|
136
|
+
const [positionStyle, setPositionStyle] = (0, _react.useState)({
|
|
137
|
+
position: "absolute",
|
|
138
|
+
// Initially position the tooltip of the screen in case it gets shown
|
|
139
|
+
// before setting the position.
|
|
140
|
+
left: -9999999,
|
|
141
|
+
top: -9999999
|
|
142
|
+
});
|
|
143
|
+
const {
|
|
144
|
+
openPortal,
|
|
145
|
+
closePortal,
|
|
146
|
+
isOpen,
|
|
147
|
+
Portal
|
|
148
|
+
} = (0, _reactUseportal.default)({
|
|
149
|
+
programmaticallyOpen: true
|
|
150
|
+
});
|
|
151
|
+
const tooltipId = (0, _hooks.useId)();
|
|
152
|
+
const [timer, setTimer] = (0, _react.useState)(null);
|
|
153
|
+
const cancelableClosePortal = (0, _react.useCallback)(() => {
|
|
154
|
+
clearTimeout(timer);
|
|
155
|
+
closePortal();
|
|
156
|
+
}, [timer, closePortal]);
|
|
157
|
+
(0, _react.useEffect)(() => {
|
|
162
158
|
if (isOpen && !followMouse && wrapperRef.current) {
|
|
163
159
|
// Position the tooltip when it becomes visible.
|
|
164
160
|
setPositionStyle(getPositionStyle(adjustedPosition, wrapperRef.current));
|
|
165
161
|
}
|
|
166
162
|
}, [adjustedPosition, isOpen, followMouse]);
|
|
167
|
-
|
|
163
|
+
const mouseHandler = (0, _react.useCallback)(evt => {
|
|
168
164
|
// Set the position of the tooltip next to the mouse.
|
|
169
165
|
setPositionStyle({
|
|
170
166
|
// Don't allow the tooltip to block the mouse events.
|
|
@@ -174,7 +170,7 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
174
170
|
top: evt.pageY
|
|
175
171
|
});
|
|
176
172
|
}, []);
|
|
177
|
-
|
|
173
|
+
const onUpdateWindowFitment = (0, _react.useCallback)(fitsWindow => {
|
|
178
174
|
setAdjustedPosition(adjustForWindow(position, fitsWindow));
|
|
179
175
|
}, [setAdjustedPosition, position]);
|
|
180
176
|
|
|
@@ -183,61 +179,63 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
183
179
|
|
|
184
180
|
// Handle adjusting the position of the tooltip so that it remains on screen.
|
|
185
181
|
(0, _hooks.useWindowFitment)(messageRef.current, wrapperRef.current, onUpdateWindowFitment, 20, isOpen, autoAdjust && followMouse);
|
|
186
|
-
|
|
182
|
+
const handleKeyPress = (0, _react.useCallback)(event => {
|
|
187
183
|
if (event.key === "Escape") {
|
|
188
|
-
|
|
184
|
+
cancelableClosePortal();
|
|
189
185
|
}
|
|
190
|
-
}, [
|
|
191
|
-
(0, _react.useEffect)(
|
|
186
|
+
}, [cancelableClosePortal]);
|
|
187
|
+
(0, _react.useEffect)(() => {
|
|
192
188
|
window.addEventListener("keypress", handleKeyPress);
|
|
193
|
-
return
|
|
189
|
+
return () => {
|
|
194
190
|
window.removeEventListener("keypress", handleKeyPress);
|
|
195
191
|
};
|
|
196
192
|
}, [handleKeyPress]);
|
|
197
|
-
|
|
193
|
+
const handleBlur = e => {
|
|
198
194
|
var _wrapperRef$current, _messageRef$current;
|
|
199
195
|
// do not close if the focus is within the tooltip wrapper
|
|
200
196
|
if (wrapperRef !== null && wrapperRef !== void 0 && (_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(document.activeElement)) {
|
|
201
197
|
return;
|
|
202
198
|
}
|
|
203
199
|
if (e.relatedTarget ? !((_messageRef$current = messageRef.current) !== null && _messageRef$current !== void 0 && _messageRef$current.contains(e.relatedTarget)) : e.target !== messageRef.current) {
|
|
204
|
-
|
|
200
|
+
cancelableClosePortal();
|
|
205
201
|
}
|
|
206
202
|
};
|
|
207
|
-
|
|
203
|
+
const handleClick = e => {
|
|
208
204
|
var _messageRef$current2;
|
|
209
205
|
// ignore clicks within the tooltip message
|
|
210
206
|
if ((_messageRef$current2 = messageRef.current) !== null && _messageRef$current2 !== void 0 && _messageRef$current2.contains(e.target)) {
|
|
211
207
|
return;
|
|
212
208
|
}
|
|
213
209
|
e.target.focus();
|
|
214
|
-
openPortal();
|
|
210
|
+
openPortal(e);
|
|
215
211
|
};
|
|
212
|
+
const delayedOpenPortal = (0, _react.useCallback)(() => {
|
|
213
|
+
const timeout = setTimeout(() => openPortal(), delay);
|
|
214
|
+
setTimer(timeout);
|
|
215
|
+
}, [delay, openPortal]);
|
|
216
216
|
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, message ? /*#__PURE__*/_react.default.createElement("span", {
|
|
217
217
|
className: className,
|
|
218
218
|
onBlur: handleBlur,
|
|
219
219
|
onClick: handleClick,
|
|
220
220
|
onFocus: openPortal,
|
|
221
221
|
onMouseOut: handleBlur,
|
|
222
|
-
onMouseOver:
|
|
222
|
+
onMouseOver: delayedOpenPortal
|
|
223
223
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
224
224
|
className: positionElementClassName,
|
|
225
225
|
ref: wrapperRef,
|
|
226
226
|
style: {
|
|
227
227
|
display: "inline-block"
|
|
228
228
|
}
|
|
229
|
-
}, _react.default.Children.map(children,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}) : child;
|
|
233
|
-
})), isOpen ? /*#__PURE__*/_react.default.createElement(Portal, null, /*#__PURE__*/_react.default.createElement("span", {
|
|
229
|
+
}, _react.default.Children.map(children, child => child && /*#__PURE__*/_react.default.isValidElement(child) ? /*#__PURE__*/_react.default.cloneElement(child, {
|
|
230
|
+
"aria-describedby": isOpen ? tooltipId : undefined
|
|
231
|
+
}) : child)), isOpen ? /*#__PURE__*/_react.default.createElement(Portal, null, /*#__PURE__*/_react.default.createElement("span", {
|
|
234
232
|
className: (0, _classnames.default)("p-tooltip--".concat(adjustedPosition), "is-detached", tooltipClassName),
|
|
235
233
|
"data-testid": "tooltip-portal",
|
|
236
234
|
style: positionStyle
|
|
237
235
|
}, /*#__PURE__*/_react.default.createElement("span", {
|
|
238
236
|
role: "tooltip",
|
|
239
237
|
className: "p-tooltip__message",
|
|
240
|
-
onClick:
|
|
238
|
+
onClick: event => {
|
|
241
239
|
// Prevent clicks inside the message from bubbling to parent
|
|
242
240
|
// click handlers.
|
|
243
241
|
event.stopPropagation();
|
|
@@ -251,5 +249,4 @@ var Tooltip = function Tooltip(_ref) {
|
|
|
251
249
|
className: className
|
|
252
250
|
}, children));
|
|
253
251
|
};
|
|
254
|
-
var _default = Tooltip;
|
|
255
|
-
exports.default = _default;
|
|
252
|
+
var _default = exports.default = Tooltip;
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
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
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
Object.defineProperty(exports, "default", {
|
|
8
7
|
enumerable: true,
|
|
9
|
-
get: function
|
|
8
|
+
get: function () {
|
|
10
9
|
return _Tooltip.default;
|
|
11
10
|
}
|
|
12
11
|
});
|
|
13
12
|
Object.defineProperty(exports, "position", {
|
|
14
13
|
enumerable: true,
|
|
15
|
-
get: function
|
|
14
|
+
get: function () {
|
|
16
15
|
return _Tooltip.position;
|
|
17
16
|
}
|
|
18
17
|
});
|
|
19
18
|
var _Tooltip = _interopRequireWildcard(require("./Tooltip"));
|
|
20
|
-
function _getRequireWildcardCache(
|
|
21
|
-
function _interopRequireWildcard(
|
|
19
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
20
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
package/dist/enums.js
CHANGED
|
@@ -7,9 +7,8 @@ exports.Theme = void 0;
|
|
|
7
7
|
/**
|
|
8
8
|
* The Vanilla theme types.
|
|
9
9
|
*/
|
|
10
|
-
|
|
10
|
+
let Theme = exports.Theme = /*#__PURE__*/function (Theme) {
|
|
11
11
|
Theme["DARK"] = "dark";
|
|
12
12
|
Theme["LIGHT"] = "light";
|
|
13
13
|
return Theme;
|
|
14
|
-
}({});
|
|
15
|
-
exports.Theme = Theme;
|
|
14
|
+
}({});
|
package/dist/hooks/index.d.ts
CHANGED
package/dist/hooks/index.js
CHANGED
|
@@ -5,53 +5,59 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, "useClickOutside", {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function
|
|
9
|
-
return
|
|
8
|
+
get: function () {
|
|
9
|
+
return _useOnClickOutside.useClickOutside;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "useId", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function
|
|
14
|
+
get: function () {
|
|
15
15
|
return _useId.useId;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "useListener", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function
|
|
20
|
+
get: function () {
|
|
21
21
|
return _useListener.useListener;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
+
Object.defineProperty(exports, "useOnClickOutside", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _useOnClickOutside.useOnClickOutside;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
24
30
|
Object.defineProperty(exports, "useOnEscapePressed", {
|
|
25
31
|
enumerable: true,
|
|
26
|
-
get: function
|
|
32
|
+
get: function () {
|
|
27
33
|
return _useOnEscapePressed.useOnEscapePressed;
|
|
28
34
|
}
|
|
29
35
|
});
|
|
30
36
|
Object.defineProperty(exports, "usePagination", {
|
|
31
37
|
enumerable: true,
|
|
32
|
-
get: function
|
|
38
|
+
get: function () {
|
|
33
39
|
return _usePagination.usePagination;
|
|
34
40
|
}
|
|
35
41
|
});
|
|
36
42
|
Object.defineProperty(exports, "usePrevious", {
|
|
37
43
|
enumerable: true,
|
|
38
|
-
get: function
|
|
44
|
+
get: function () {
|
|
39
45
|
return _usePrevious.usePrevious;
|
|
40
46
|
}
|
|
41
47
|
});
|
|
42
48
|
Object.defineProperty(exports, "useThrottle", {
|
|
43
49
|
enumerable: true,
|
|
44
|
-
get: function
|
|
50
|
+
get: function () {
|
|
45
51
|
return _useThrottle.useThrottle;
|
|
46
52
|
}
|
|
47
53
|
});
|
|
48
54
|
Object.defineProperty(exports, "useWindowFitment", {
|
|
49
55
|
enumerable: true,
|
|
50
|
-
get: function
|
|
56
|
+
get: function () {
|
|
51
57
|
return _useWindowFitment.useWindowFitment;
|
|
52
58
|
}
|
|
53
59
|
});
|
|
54
|
-
var
|
|
60
|
+
var _useOnClickOutside = require("./useOnClickOutside");
|
|
55
61
|
var _useId = require("./useId");
|
|
56
62
|
var _useListener = require("./useListener");
|
|
57
63
|
var _useOnEscapePressed = require("./useOnEscapePressed");
|
package/dist/hooks/useId.js
CHANGED
|
@@ -11,7 +11,5 @@ var _nanoid = require("nanoid");
|
|
|
11
11
|
* Can be used as a value for HTML "id" attributes.
|
|
12
12
|
* @returns random ID string
|
|
13
13
|
*/
|
|
14
|
-
|
|
15
|
-
return (0, _react.useRef)((0, _nanoid.nanoid)()).current;
|
|
16
|
-
};
|
|
14
|
+
const useId = () => (0, _react.useRef)((0, _nanoid.nanoid)()).current;
|
|
17
15
|
exports.useId = useId;
|
|
@@ -6,5 +6,6 @@
|
|
|
6
6
|
* @param eventType The event name.
|
|
7
7
|
* @param shouldThrottle Whether the callback calls should be throttled.
|
|
8
8
|
* @param shouldListen When the listener should be active.
|
|
9
|
+
* @param options Native event listener options.
|
|
9
10
|
*/
|
|
10
|
-
export declare const useListener: (targetNode: Window | HTMLElement, callback: (...args: any[]) => any, eventType: string, shouldThrottle?: boolean, shouldListen?: boolean) => void;
|
|
11
|
+
export declare const useListener: (targetNode: Window | HTMLElement, callback: (...args: any[]) => any, eventType: string, shouldThrottle?: boolean, shouldListen?: boolean, options?: boolean | AddEventListenerOptions) => void;
|
|
@@ -15,23 +15,26 @@ var _usePrevious = require("./usePrevious");
|
|
|
15
15
|
* @param eventType The event name.
|
|
16
16
|
* @param shouldThrottle Whether the callback calls should be throttled.
|
|
17
17
|
* @param shouldListen When the listener should be active.
|
|
18
|
+
* @param options Native event listener options.
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
(0,
|
|
20
|
+
const useListener = function (targetNode, callback, eventType) {
|
|
21
|
+
let shouldThrottle = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
22
|
+
let shouldListen = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : true;
|
|
23
|
+
let options = arguments.length > 5 ? arguments[5] : undefined;
|
|
24
|
+
const isListening = (0, _react.useRef)(false);
|
|
25
|
+
const throttle = (0, _useThrottle.useThrottle)(callback);
|
|
26
|
+
const eventListener = (0, _react.useRef)(shouldThrottle ? throttle : callback);
|
|
27
|
+
const previousEventType = (0, _usePrevious.usePrevious)(eventType);
|
|
28
|
+
const previousShouldThrottle = (0, _usePrevious.usePrevious)(shouldThrottle);
|
|
29
|
+
const previousTargetNode = (0, _usePrevious.usePrevious)(targetNode);
|
|
30
|
+
const previousCallback = (0, _usePrevious.usePrevious)(callback);
|
|
31
|
+
const previousOptions = (0, _usePrevious.usePrevious)(options);
|
|
32
|
+
(0, _react.useEffect)(() => {
|
|
30
33
|
// If any of the props related to the attached listener changed then the
|
|
31
34
|
// listener needs to be re-attached.
|
|
32
|
-
|
|
35
|
+
const listenerAttributesChanged = callback !== previousCallback || eventType !== previousEventType || shouldThrottle !== previousShouldThrottle || targetNode !== previousTargetNode || options !== previousOptions;
|
|
33
36
|
if (isListening.current && (!shouldListen || listenerAttributesChanged)) {
|
|
34
|
-
previousTargetNode.removeEventListener(previousEventType, eventListener.current);
|
|
37
|
+
previousTargetNode.removeEventListener(previousEventType, eventListener.current, previousOptions);
|
|
35
38
|
isListening.current = false;
|
|
36
39
|
}
|
|
37
40
|
if (shouldThrottle !== previousShouldThrottle || callback !== previousCallback) {
|
|
@@ -39,18 +42,16 @@ var useListener = function useListener(targetNode, callback, eventType) {
|
|
|
39
42
|
eventListener.current = shouldThrottle ? throttle : callback;
|
|
40
43
|
}
|
|
41
44
|
if (targetNode && shouldListen && !isListening.current) {
|
|
42
|
-
targetNode.addEventListener(eventType, eventListener.current);
|
|
45
|
+
targetNode.addEventListener(eventType, eventListener.current, options);
|
|
43
46
|
isListening.current = true;
|
|
44
47
|
}
|
|
45
|
-
}, [callback, eventType, previousCallback, previousEventType, previousShouldThrottle, previousTargetNode, shouldListen, shouldThrottle, targetNode, throttle]);
|
|
46
|
-
(0, _react.useEffect)(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
}, [eventType, targetNode]);
|
|
48
|
+
}, [callback, eventType, options, previousCallback, previousEventType, previousOptions, previousShouldThrottle, previousTargetNode, shouldListen, shouldThrottle, targetNode, throttle]);
|
|
49
|
+
(0, _react.useEffect)(() => () => {
|
|
50
|
+
// Unattach the listener if the component gets unmounted while
|
|
51
|
+
// listening.
|
|
52
|
+
if (targetNode && isListening.current) {
|
|
53
|
+
targetNode.removeEventListener(eventType, eventListener.current, options);
|
|
54
|
+
}
|
|
55
|
+
}, [eventType, targetNode, options]);
|
|
55
56
|
};
|
|
56
57
|
exports.useListener = useListener;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { MutableRefObject, useRef } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Handle clicks outside an element.
|
|
4
|
+
*/
|
|
5
|
+
export declare const useOnClickOutside: <E extends HTMLElement>(elementRef: MutableRefObject<E>, onClickOutside: () => void, { isEnabled }?: {
|
|
6
|
+
isEnabled: boolean;
|
|
7
|
+
}) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Handle clicks outside an element.
|
|
10
|
+
* @returns A ref to pass to the element to handle clicks outside of.
|
|
11
|
+
*/
|
|
12
|
+
export declare const useClickOutside: <E extends HTMLElement>(onClickOutside: () => void) => MutableRefObject<E>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useOnClickOutside = exports.useClickOutside = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
/**
|
|
9
|
+
* Handle clicks outside an element.
|
|
10
|
+
*/
|
|
11
|
+
const useOnClickOutside = function (elementRef, onClickOutside) {
|
|
12
|
+
let {
|
|
13
|
+
isEnabled
|
|
14
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
|
|
15
|
+
isEnabled: true
|
|
16
|
+
};
|
|
17
|
+
const handleClickOutside = (0, _react.useCallback)(evt => {
|
|
18
|
+
var _evt$target, _elementRef$current;
|
|
19
|
+
const target = evt.target;
|
|
20
|
+
// The target might be something like an SVG node which doesn't provide
|
|
21
|
+
// the class name as a string.
|
|
22
|
+
const isValidTarget = typeof (evt === null || evt === void 0 || (_evt$target = evt.target) === null || _evt$target === void 0 ? void 0 : _evt$target.className) === "string";
|
|
23
|
+
if (!isValidTarget || elementRef !== null && elementRef !== void 0 && elementRef.current && !((_elementRef$current = elementRef.current) !== null && _elementRef$current !== void 0 && _elementRef$current.contains(target)) && elementRef.current !== target) {
|
|
24
|
+
onClickOutside();
|
|
25
|
+
}
|
|
26
|
+
}, [elementRef, onClickOutside]);
|
|
27
|
+
(0, _react.useEffect)(() => {
|
|
28
|
+
if (isEnabled) {
|
|
29
|
+
document.addEventListener("click", handleClickOutside, false);
|
|
30
|
+
}
|
|
31
|
+
return () => document.removeEventListener("click", handleClickOutside, false);
|
|
32
|
+
}, [handleClickOutside, isEnabled]);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Handle clicks outside an element.
|
|
37
|
+
* @returns A ref to pass to the element to handle clicks outside of.
|
|
38
|
+
*/
|
|
39
|
+
exports.useOnClickOutside = useOnClickOutside;
|
|
40
|
+
const useClickOutside = onClickOutside => {
|
|
41
|
+
const ref = (0, _react.useRef)(null);
|
|
42
|
+
useOnClickOutside(ref, onClickOutside);
|
|
43
|
+
return ref;
|
|
44
|
+
};
|
|
45
|
+
exports.useClickOutside = useClickOutside;
|
|
@@ -8,17 +8,24 @@ var _react = require("react");
|
|
|
8
8
|
/**
|
|
9
9
|
* Handle the escape key pressed.
|
|
10
10
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const useOnEscapePressed = function (onEscape) {
|
|
12
|
+
let {
|
|
13
|
+
isEnabled
|
|
14
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
|
15
|
+
isEnabled: true
|
|
16
|
+
};
|
|
17
|
+
const keyDown = (0, _react.useCallback)(evt => {
|
|
13
18
|
if (evt.code === "Escape") {
|
|
14
19
|
onEscape();
|
|
15
20
|
}
|
|
16
21
|
}, [onEscape]);
|
|
17
|
-
(0, _react.useEffect)(
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
(0, _react.useEffect)(() => {
|
|
23
|
+
if (isEnabled) {
|
|
24
|
+
document.addEventListener("keydown", keyDown);
|
|
25
|
+
}
|
|
26
|
+
return () => {
|
|
20
27
|
document.removeEventListener("keydown", keyDown);
|
|
21
28
|
};
|
|
22
|
-
}, [keyDown]);
|
|
29
|
+
}, [keyDown, isEnabled]);
|
|
23
30
|
};
|
|
24
31
|
exports.useOnEscapePressed = useOnEscapePressed;
|