@canonical/react-components 0.47.0 → 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 +45 -40
- 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 +55 -74
- 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 +56 -49
- 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,50 +8,53 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
9
8
|
var _react = _interopRequireWildcard(require("react"));
|
|
10
9
|
var _Field = _interopRequireDefault(require("../Field"));
|
|
11
10
|
var _hooks = require("../../hooks");
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
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; }
|
|
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; }
|
|
15
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
14
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
17
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
20
|
-
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
21
|
-
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
22
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
23
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
24
15
|
/**
|
|
25
16
|
* The props for the Textarea component.
|
|
26
17
|
*/
|
|
27
18
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
grow =
|
|
34
|
-
help
|
|
35
|
-
id
|
|
36
|
-
label
|
|
37
|
-
labelClassName
|
|
38
|
-
|
|
39
|
-
required
|
|
40
|
-
stacked
|
|
41
|
-
style
|
|
42
|
-
success
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
(0, _react.
|
|
19
|
+
const Textarea = _ref => {
|
|
20
|
+
let {
|
|
21
|
+
caution,
|
|
22
|
+
className,
|
|
23
|
+
error,
|
|
24
|
+
grow = false,
|
|
25
|
+
help,
|
|
26
|
+
id,
|
|
27
|
+
label,
|
|
28
|
+
labelClassName,
|
|
29
|
+
onKeyUp,
|
|
30
|
+
required,
|
|
31
|
+
stacked,
|
|
32
|
+
style,
|
|
33
|
+
success,
|
|
34
|
+
takeFocus = false,
|
|
35
|
+
wrapperClassName,
|
|
36
|
+
...props
|
|
37
|
+
} = _ref;
|
|
38
|
+
const textareaRef = (0, _react.useRef)(null);
|
|
39
|
+
const validationId = (0, _hooks.useId)();
|
|
40
|
+
const helpId = (0, _hooks.useId)();
|
|
41
|
+
const hasError = !!error;
|
|
42
|
+
const [innerValue, setInnervalue] = (0, _react.useState)(props.defaultValue);
|
|
43
|
+
(0, _react.useEffect)(() => {
|
|
52
44
|
if (takeFocus) {
|
|
53
45
|
textareaRef.current.focus();
|
|
54
46
|
}
|
|
55
47
|
}, [takeFocus]);
|
|
48
|
+
(0, _react.useLayoutEffect)(() => {
|
|
49
|
+
if (grow) {
|
|
50
|
+
const textArea = textareaRef.current;
|
|
51
|
+
if (textArea) {
|
|
52
|
+
textArea.style.height = "0px";
|
|
53
|
+
const scrollHeight = textArea.scrollHeight;
|
|
54
|
+
textArea.style.height = "".concat(scrollHeight, "px");
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}, [textareaRef, grow, innerValue, props.value]);
|
|
56
58
|
return /*#__PURE__*/_react.default.createElement(_Field.default, {
|
|
57
59
|
caution: caution,
|
|
58
60
|
className: wrapperClassName,
|
|
@@ -72,20 +74,24 @@ var Textarea = function Textarea(_ref) {
|
|
|
72
74
|
"aria-invalid": hasError,
|
|
73
75
|
className: (0, _classnames.default)("p-form-validation__input", className),
|
|
74
76
|
id: id,
|
|
75
|
-
onKeyUp:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
77
|
+
onKeyUp: evt => {
|
|
78
|
+
onKeyUp && onKeyUp(evt);
|
|
79
|
+
},
|
|
80
|
+
onChange: evt => {
|
|
81
|
+
if (!props.value) {
|
|
82
|
+
setInnervalue(evt.target.value);
|
|
79
83
|
}
|
|
80
84
|
},
|
|
81
85
|
ref: textareaRef,
|
|
82
|
-
style: grow &&
|
|
86
|
+
style: grow && {
|
|
83
87
|
minHeight: "5rem",
|
|
84
88
|
resize: "none",
|
|
85
89
|
overflow: "hidden",
|
|
86
|
-
boxSizing: "border-box"
|
|
87
|
-
|
|
88
|
-
|
|
90
|
+
boxSizing: "border-box",
|
|
91
|
+
...style
|
|
92
|
+
} || style
|
|
93
|
+
}, props, {
|
|
94
|
+
value: props.value || innerValue
|
|
95
|
+
})));
|
|
89
96
|
};
|
|
90
|
-
var _default = Textarea;
|
|
91
|
-
exports.default = _default;
|
|
97
|
+
var _default = exports.default = Textarea;
|
|
@@ -56,6 +56,10 @@ export type Props = {
|
|
|
56
56
|
* The z-index value of the tooltip message element.
|
|
57
57
|
*/
|
|
58
58
|
zIndex?: number;
|
|
59
|
+
/**
|
|
60
|
+
* Delay in ms after which Tooltip will appear (defaults to 350ms).
|
|
61
|
+
*/
|
|
62
|
+
delay?: number;
|
|
59
63
|
};
|
|
60
64
|
export declare const adjustForWindow: (position: Position, fitsWindow: WindowFitment) => Position;
|
|
61
65
|
/**
|
|
@@ -70,5 +74,5 @@ export declare const adjustForWindow: (position: Position, fitsWindow: WindowFit
|
|
|
70
74
|
* @param tooltipClassName An optional class to apply to the tooltip message element.
|
|
71
75
|
* @param zIndex The z-index value of the tooltip message element.
|
|
72
76
|
*/
|
|
73
|
-
declare const Tooltip: ({ autoAdjust, children, className, followMouse, message, position, positionElementClassName, tooltipClassName, zIndex, }: Props) => JSX.Element;
|
|
77
|
+
declare const Tooltip: ({ autoAdjust, children, className, followMouse, message, position, positionElementClassName, tooltipClassName, zIndex, delay, }: Props) => JSX.Element;
|
|
74
78
|
export default Tooltip;
|
|
@@ -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;
|