@canonical/react-components 3.11.0 → 3.12.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/components/ConfirmationButton/ConfirmationButton.d.ts +2 -1
- package/dist/components/ConfirmationButton/ConfirmationButton.js +12 -4
- package/dist/components/ConfirmationModal/ConfirmationModal.d.ts +8 -1
- package/dist/components/ConfirmationModal/ConfirmationModal.js +23 -9
- package/dist/components/Tooltip/Tooltip.d.ts +1 -1
- package/dist/components/Tooltip/Tooltip.js +21 -6
- package/dist/esm/components/ConfirmationButton/ConfirmationButton.d.ts +2 -1
- package/dist/esm/components/ConfirmationButton/ConfirmationButton.js +12 -4
- package/dist/esm/components/ConfirmationModal/ConfirmationModal.d.ts +8 -1
- package/dist/esm/components/ConfirmationModal/ConfirmationModal.js +23 -9
- package/dist/esm/components/Tooltip/Tooltip.d.ts +1 -1
- package/dist/esm/components/Tooltip/Tooltip.js +21 -6
- package/package.json +1 -1
|
@@ -5,8 +5,9 @@ import { ConfirmationModalProps } from "../ConfirmationModal";
|
|
|
5
5
|
export type Props = PropsWithSpread<{
|
|
6
6
|
/**
|
|
7
7
|
* Additional props to pass to the confirmation modal.
|
|
8
|
+
* The `renderInPortal` and `portalRenderer` props are controlled internally by this component.
|
|
8
9
|
*/
|
|
9
|
-
confirmationModalProps: SubComponentProps<ConfirmationModalProps
|
|
10
|
+
confirmationModalProps: SubComponentProps<Omit<ConfirmationModalProps, "renderInPortal" | "portalRenderer">>;
|
|
10
11
|
/**
|
|
11
12
|
* An optional text to be shown when hovering over the button.<br/>
|
|
12
13
|
* Defaults to the label of the confirm button in the modal.
|
|
@@ -8,7 +8,8 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
8
8
|
var _ActionButton = _interopRequireDefault(require("../ActionButton"));
|
|
9
9
|
var _ConfirmationModal = _interopRequireDefault(require("../ConfirmationModal"));
|
|
10
10
|
var _external = require("../../external");
|
|
11
|
-
const _excluded = ["confirmationModalProps", "onHoverText", "shiftClickEnabled", "showShiftClickHint", "preModalOpenHook"]
|
|
11
|
+
const _excluded = ["confirmationModalProps", "onHoverText", "shiftClickEnabled", "showShiftClickHint", "preModalOpenHook"],
|
|
12
|
+
_excluded2 = ["renderInPortal", "portalRenderer"];
|
|
12
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
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); }
|
|
14
15
|
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; }
|
|
@@ -37,8 +38,15 @@ const ConfirmationButton = _ref => {
|
|
|
37
38
|
const {
|
|
38
39
|
openPortal,
|
|
39
40
|
closePortal,
|
|
40
|
-
isOpen
|
|
41
|
+
isOpen,
|
|
42
|
+
Portal
|
|
41
43
|
} = (0, _external.usePortal)();
|
|
44
|
+
const _ref2 = confirmationModalProps,
|
|
45
|
+
{
|
|
46
|
+
renderInPortal: _ignoredRenderInPortal,
|
|
47
|
+
portalRenderer: _ignoredPortalRenderer
|
|
48
|
+
} = _ref2,
|
|
49
|
+
safeConfirmationModalProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
42
50
|
const handleCancelModal = () => {
|
|
43
51
|
closePortal();
|
|
44
52
|
if (confirmationModalProps.close) {
|
|
@@ -63,11 +71,11 @@ const ConfirmationButton = _ref => {
|
|
|
63
71
|
}
|
|
64
72
|
shiftClickEnabled ? handleShiftClick(e) : openPortal(e);
|
|
65
73
|
};
|
|
66
|
-
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isOpen && /*#__PURE__*/_react.default.createElement(_ConfirmationModal.default, _extends({},
|
|
74
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isOpen && /*#__PURE__*/_react.default.createElement(_ConfirmationModal.default, _extends({}, safeConfirmationModalProps, {
|
|
67
75
|
close: handleCancelModal,
|
|
68
76
|
confirmButtonLabel: confirmationModalProps.confirmButtonLabel,
|
|
69
77
|
onConfirm: handleConfirmModal,
|
|
70
|
-
|
|
78
|
+
portalRenderer: Portal
|
|
71
79
|
}), confirmationModalProps.children, showShiftClickHint && /*#__PURE__*/_react.default.createElement("p", {
|
|
72
80
|
className: "p-text--small u-text--muted u-hide--small"
|
|
73
81
|
}, "Next time, you can skip this confirmation by holding", " ", /*#__PURE__*/_react.default.createElement("code", null, "SHIFT"), " and clicking the action.")), /*#__PURE__*/_react.default.createElement(_ActionButton.default, _extends({}, actionButtonProps, {
|
|
@@ -49,9 +49,16 @@ export type Props = PropsWithSpread<{
|
|
|
49
49
|
* Whether to render the modal inside a Portal component.
|
|
50
50
|
*/
|
|
51
51
|
renderInPortal?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Optional custom portal renderer. If provided, it takes precedence
|
|
54
|
+
* over `renderInPortal`.
|
|
55
|
+
*/
|
|
56
|
+
portalRenderer?: React.ComponentType<{
|
|
57
|
+
children: ReactNode;
|
|
58
|
+
}>;
|
|
52
59
|
}, Omit<ModalProps, "buttonRow">>;
|
|
53
60
|
/**
|
|
54
61
|
* `ConfirmationModal` is a specialised version of the [Modal](?path=/docs/modal--default-story) component to prompt a confirmation from the user before executing an action.
|
|
55
62
|
*/
|
|
56
|
-
export declare const ConfirmationModal: ({ cancelButtonLabel, cancelButtonProps, children, confirmButtonAppearance, confirmButtonLabel, confirmExtra, onConfirm, confirmButtonLoading, confirmButtonDisabled, confirmButtonProps, renderInPortal, ...props }: Props) => React.JSX.Element;
|
|
63
|
+
export declare const ConfirmationModal: ({ cancelButtonLabel, cancelButtonProps, children, confirmButtonAppearance, confirmButtonLabel, confirmExtra, onConfirm, confirmButtonLoading, confirmButtonDisabled, confirmButtonProps, renderInPortal, portalRenderer: PortalRenderer, ...props }: Props) => React.JSX.Element;
|
|
57
64
|
export default ConfirmationModal;
|
|
@@ -9,15 +9,25 @@ var _Button = _interopRequireDefault(require("../Button"));
|
|
|
9
9
|
var _Modal = _interopRequireDefault(require("../Modal"));
|
|
10
10
|
var _ActionButton = _interopRequireDefault(require("../ActionButton"));
|
|
11
11
|
var _external = require("../../external");
|
|
12
|
-
const _excluded = ["cancelButtonLabel", "cancelButtonProps", "children", "confirmButtonAppearance", "confirmButtonLabel", "confirmExtra", "onConfirm", "confirmButtonLoading", "confirmButtonDisabled", "confirmButtonProps", "renderInPortal"];
|
|
12
|
+
const _excluded = ["cancelButtonLabel", "cancelButtonProps", "children", "confirmButtonAppearance", "confirmButtonLabel", "confirmExtra", "onConfirm", "confirmButtonLoading", "confirmButtonDisabled", "confirmButtonProps", "renderInPortal", "portalRenderer"];
|
|
13
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
14
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); }
|
|
15
15
|
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; }
|
|
16
16
|
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; }
|
|
17
|
+
const InternalPortalRenderer = _ref => {
|
|
18
|
+
let {
|
|
19
|
+
children
|
|
20
|
+
} = _ref;
|
|
21
|
+
const {
|
|
22
|
+
Portal
|
|
23
|
+
} = (0, _external.usePortal)();
|
|
24
|
+
return /*#__PURE__*/_react.default.createElement(Portal, null, children);
|
|
25
|
+
};
|
|
26
|
+
|
|
17
27
|
/**
|
|
18
28
|
* `ConfirmationModal` is a specialised version of the [Modal](?path=/docs/modal--default-story) component to prompt a confirmation from the user before executing an action.
|
|
19
29
|
*/
|
|
20
|
-
const ConfirmationModal =
|
|
30
|
+
const ConfirmationModal = _ref2 => {
|
|
21
31
|
var _cancelButtonProps$ty;
|
|
22
32
|
let {
|
|
23
33
|
cancelButtonLabel = "Cancel",
|
|
@@ -30,12 +40,10 @@ const ConfirmationModal = _ref => {
|
|
|
30
40
|
confirmButtonLoading,
|
|
31
41
|
confirmButtonDisabled,
|
|
32
42
|
confirmButtonProps,
|
|
33
|
-
renderInPortal = false
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Portal
|
|
38
|
-
} = (0, _external.usePortal)();
|
|
43
|
+
renderInPortal = false,
|
|
44
|
+
portalRenderer: PortalRenderer
|
|
45
|
+
} = _ref2,
|
|
46
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
39
47
|
const handleClick = action => event => {
|
|
40
48
|
if (!props.shouldPropagateClickEvent) {
|
|
41
49
|
event.stopPropagation();
|
|
@@ -57,7 +65,13 @@ const ConfirmationModal = _ref => {
|
|
|
57
65
|
disabled: confirmButtonDisabled
|
|
58
66
|
}), confirmButtonLabel))
|
|
59
67
|
}, props), children);
|
|
60
|
-
|
|
68
|
+
if (PortalRenderer) {
|
|
69
|
+
return /*#__PURE__*/_react.default.createElement(PortalRenderer, null, ModalElement);
|
|
70
|
+
} else if (renderInPortal) {
|
|
71
|
+
return /*#__PURE__*/_react.default.createElement(InternalPortalRenderer, null, ModalElement);
|
|
72
|
+
} else {
|
|
73
|
+
return ModalElement;
|
|
74
|
+
}
|
|
61
75
|
};
|
|
62
76
|
exports.ConfirmationModal = ConfirmationModal;
|
|
63
77
|
var _default = exports.default = ConfirmationModal;
|
|
@@ -62,7 +62,7 @@ export type Props = {
|
|
|
62
62
|
*/
|
|
63
63
|
delay?: number;
|
|
64
64
|
};
|
|
65
|
-
export declare const adjustForWindow: (position: Position, fitsWindow: WindowFitment) => Position;
|
|
65
|
+
export declare const adjustForWindow: (position: Position, fitsWindow: WindowFitment, messageHeight?: number) => Position;
|
|
66
66
|
/**
|
|
67
67
|
* This is the [React](https://reactjs.org/) component for Vanilla [Tooltips](https://vanillaframework.io/docs/patterns/tooltips).
|
|
68
68
|
*
|
|
@@ -70,14 +70,27 @@ const getPositionStyle = (pos, wrapperNode) => {
|
|
|
70
70
|
top
|
|
71
71
|
};
|
|
72
72
|
};
|
|
73
|
-
const adjustForWindow = (position, fitsWindow)
|
|
73
|
+
const adjustForWindow = function (position, fitsWindow) {
|
|
74
|
+
let messageHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
74
75
|
let newPosition = position;
|
|
75
76
|
if (!fitsWindow.fromLeft.fitsLeft && newPosition === "left") {
|
|
76
77
|
newPosition = "top-right";
|
|
77
78
|
}
|
|
79
|
+
if (fitsWindow.fromTop.spaceAbove < messageHeight / 2 && newPosition === "left") {
|
|
80
|
+
newPosition = "btm-left";
|
|
81
|
+
}
|
|
82
|
+
if (fitsWindow.fromBottom.spaceBelow < messageHeight / 2 && newPosition === "left") {
|
|
83
|
+
newPosition = "top-left";
|
|
84
|
+
}
|
|
78
85
|
if (!fitsWindow.fromRight.fitsRight && newPosition === "right") {
|
|
79
86
|
newPosition = "top-left";
|
|
80
87
|
}
|
|
88
|
+
if (fitsWindow.fromTop.spaceAbove < messageHeight / 2 && newPosition === "right") {
|
|
89
|
+
newPosition = "btm-right";
|
|
90
|
+
}
|
|
91
|
+
if (fitsWindow.fromBottom.spaceBelow < messageHeight / 2 && newPosition === "right") {
|
|
92
|
+
newPosition = "top-right";
|
|
93
|
+
}
|
|
81
94
|
if (!fitsWindow.fromRight.fitsLeft && newPosition.endsWith("-right")) {
|
|
82
95
|
newPosition = newPosition.replace("right", "left");
|
|
83
96
|
}
|
|
@@ -168,7 +181,9 @@ const Tooltip = _ref => {
|
|
|
168
181
|
});
|
|
169
182
|
}, []);
|
|
170
183
|
const onUpdateWindowFitment = (0, _react.useCallback)(fitsWindow => {
|
|
171
|
-
|
|
184
|
+
var _messageRef$current$g, _messageRef$current;
|
|
185
|
+
const messageHeight = (_messageRef$current$g = (_messageRef$current = messageRef.current) === null || _messageRef$current === void 0 ? void 0 : _messageRef$current.getBoundingClientRect().height) !== null && _messageRef$current$g !== void 0 ? _messageRef$current$g : 0;
|
|
186
|
+
setAdjustedPosition(adjustForWindow(position, fitsWindow, messageHeight));
|
|
172
187
|
}, [setAdjustedPosition, position]);
|
|
173
188
|
|
|
174
189
|
// Handle mouse events.
|
|
@@ -188,19 +203,19 @@ const Tooltip = _ref => {
|
|
|
188
203
|
};
|
|
189
204
|
}, [handleKeyPress]);
|
|
190
205
|
const handleBlur = e => {
|
|
191
|
-
var _wrapperRef$current, _messageRef$
|
|
206
|
+
var _wrapperRef$current, _messageRef$current2, _wrapperRef$current2;
|
|
192
207
|
// do not close if the focus is within the tooltip wrapper
|
|
193
208
|
if (wrapperRef !== null && wrapperRef !== void 0 && (_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(document.activeElement)) {
|
|
194
209
|
return;
|
|
195
210
|
}
|
|
196
|
-
if (e.relatedTarget ? !((_messageRef$
|
|
211
|
+
if (e.relatedTarget ? !((_messageRef$current2 = messageRef.current) !== null && _messageRef$current2 !== void 0 && _messageRef$current2.contains(e.relatedTarget)) && !((_wrapperRef$current2 = wrapperRef.current) !== null && _wrapperRef$current2 !== void 0 && _wrapperRef$current2.contains(e.relatedTarget)) : e.target !== messageRef.current) {
|
|
197
212
|
cancelableClosePortal();
|
|
198
213
|
}
|
|
199
214
|
};
|
|
200
215
|
const handleClick = e => {
|
|
201
|
-
var _messageRef$
|
|
216
|
+
var _messageRef$current3;
|
|
202
217
|
// ignore clicks within the tooltip message
|
|
203
|
-
if ((_messageRef$
|
|
218
|
+
if ((_messageRef$current3 = messageRef.current) !== null && _messageRef$current3 !== void 0 && _messageRef$current3.contains(e.target)) {
|
|
204
219
|
return;
|
|
205
220
|
}
|
|
206
221
|
e.target.focus();
|
|
@@ -5,8 +5,9 @@ import { ConfirmationModalProps } from "../ConfirmationModal";
|
|
|
5
5
|
export type Props = PropsWithSpread<{
|
|
6
6
|
/**
|
|
7
7
|
* Additional props to pass to the confirmation modal.
|
|
8
|
+
* The `renderInPortal` and `portalRenderer` props are controlled internally by this component.
|
|
8
9
|
*/
|
|
9
|
-
confirmationModalProps: SubComponentProps<ConfirmationModalProps
|
|
10
|
+
confirmationModalProps: SubComponentProps<Omit<ConfirmationModalProps, "renderInPortal" | "portalRenderer">>;
|
|
10
11
|
/**
|
|
11
12
|
* An optional text to be shown when hovering over the button.<br/>
|
|
12
13
|
* Defaults to the label of the confirm button in the modal.
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
var _excluded = ["confirmationModalProps", "onHoverText", "shiftClickEnabled", "showShiftClickHint", "preModalOpenHook"]
|
|
1
|
+
var _excluded = ["confirmationModalProps", "onHoverText", "shiftClickEnabled", "showShiftClickHint", "preModalOpenHook"],
|
|
2
|
+
_excluded2 = ["renderInPortal", "portalRenderer"];
|
|
2
3
|
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); }
|
|
3
4
|
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; }
|
|
4
5
|
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; }
|
|
@@ -30,8 +31,15 @@ export var ConfirmationButton = _ref => {
|
|
|
30
31
|
var {
|
|
31
32
|
openPortal,
|
|
32
33
|
closePortal,
|
|
33
|
-
isOpen
|
|
34
|
+
isOpen,
|
|
35
|
+
Portal
|
|
34
36
|
} = usePortal();
|
|
37
|
+
var _ref2 = confirmationModalProps,
|
|
38
|
+
{
|
|
39
|
+
renderInPortal: _ignoredRenderInPortal,
|
|
40
|
+
portalRenderer: _ignoredPortalRenderer
|
|
41
|
+
} = _ref2,
|
|
42
|
+
safeConfirmationModalProps = _objectWithoutProperties(_ref2, _excluded2);
|
|
35
43
|
var handleCancelModal = () => {
|
|
36
44
|
closePortal();
|
|
37
45
|
if (confirmationModalProps.close) {
|
|
@@ -56,11 +64,11 @@ export var ConfirmationButton = _ref => {
|
|
|
56
64
|
}
|
|
57
65
|
shiftClickEnabled ? handleShiftClick(e) : openPortal(e);
|
|
58
66
|
};
|
|
59
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, isOpen && /*#__PURE__*/React.createElement(ConfirmationModal, _extends({},
|
|
67
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, isOpen && /*#__PURE__*/React.createElement(ConfirmationModal, _extends({}, safeConfirmationModalProps, {
|
|
60
68
|
close: handleCancelModal,
|
|
61
69
|
confirmButtonLabel: confirmationModalProps.confirmButtonLabel,
|
|
62
70
|
onConfirm: handleConfirmModal,
|
|
63
|
-
|
|
71
|
+
portalRenderer: Portal
|
|
64
72
|
}), confirmationModalProps.children, showShiftClickHint && /*#__PURE__*/React.createElement("p", {
|
|
65
73
|
className: "p-text--small u-text--muted u-hide--small"
|
|
66
74
|
}, "Next time, you can skip this confirmation by holding", " ", /*#__PURE__*/React.createElement("code", null, "SHIFT"), " and clicking the action.")), /*#__PURE__*/React.createElement(ActionButton, _extends({}, actionButtonProps, {
|
|
@@ -49,9 +49,16 @@ export type Props = PropsWithSpread<{
|
|
|
49
49
|
* Whether to render the modal inside a Portal component.
|
|
50
50
|
*/
|
|
51
51
|
renderInPortal?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Optional custom portal renderer. If provided, it takes precedence
|
|
54
|
+
* over `renderInPortal`.
|
|
55
|
+
*/
|
|
56
|
+
portalRenderer?: React.ComponentType<{
|
|
57
|
+
children: ReactNode;
|
|
58
|
+
}>;
|
|
52
59
|
}, Omit<ModalProps, "buttonRow">>;
|
|
53
60
|
/**
|
|
54
61
|
* `ConfirmationModal` is a specialised version of the [Modal](?path=/docs/modal--default-story) component to prompt a confirmation from the user before executing an action.
|
|
55
62
|
*/
|
|
56
|
-
export declare const ConfirmationModal: ({ cancelButtonLabel, cancelButtonProps, children, confirmButtonAppearance, confirmButtonLabel, confirmExtra, onConfirm, confirmButtonLoading, confirmButtonDisabled, confirmButtonProps, renderInPortal, ...props }: Props) => React.JSX.Element;
|
|
63
|
+
export declare const ConfirmationModal: ({ cancelButtonLabel, cancelButtonProps, children, confirmButtonAppearance, confirmButtonLabel, confirmExtra, onConfirm, confirmButtonLoading, confirmButtonDisabled, confirmButtonProps, renderInPortal, portalRenderer: PortalRenderer, ...props }: Props) => React.JSX.Element;
|
|
57
64
|
export default ConfirmationModal;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["cancelButtonLabel", "cancelButtonProps", "children", "confirmButtonAppearance", "confirmButtonLabel", "confirmExtra", "onConfirm", "confirmButtonLoading", "confirmButtonDisabled", "confirmButtonProps", "renderInPortal"];
|
|
1
|
+
var _excluded = ["cancelButtonLabel", "cancelButtonProps", "children", "confirmButtonAppearance", "confirmButtonLabel", "confirmExtra", "onConfirm", "confirmButtonLoading", "confirmButtonDisabled", "confirmButtonProps", "renderInPortal", "portalRenderer"];
|
|
2
2
|
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); }
|
|
3
3
|
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; }
|
|
4
4
|
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; }
|
|
@@ -7,10 +7,20 @@ import Button from "../Button";
|
|
|
7
7
|
import Modal from "../Modal";
|
|
8
8
|
import ActionButton from "../ActionButton";
|
|
9
9
|
import { usePortal } from "../../external";
|
|
10
|
+
var InternalPortalRenderer = _ref => {
|
|
11
|
+
var {
|
|
12
|
+
children
|
|
13
|
+
} = _ref;
|
|
14
|
+
var {
|
|
15
|
+
Portal
|
|
16
|
+
} = usePortal();
|
|
17
|
+
return /*#__PURE__*/React.createElement(Portal, null, children);
|
|
18
|
+
};
|
|
19
|
+
|
|
10
20
|
/**
|
|
11
21
|
* `ConfirmationModal` is a specialised version of the [Modal](?path=/docs/modal--default-story) component to prompt a confirmation from the user before executing an action.
|
|
12
22
|
*/
|
|
13
|
-
export var ConfirmationModal =
|
|
23
|
+
export var ConfirmationModal = _ref2 => {
|
|
14
24
|
var _cancelButtonProps$ty;
|
|
15
25
|
var {
|
|
16
26
|
cancelButtonLabel = "Cancel",
|
|
@@ -23,12 +33,10 @@ export var ConfirmationModal = _ref => {
|
|
|
23
33
|
confirmButtonLoading,
|
|
24
34
|
confirmButtonDisabled,
|
|
25
35
|
confirmButtonProps,
|
|
26
|
-
renderInPortal = false
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Portal
|
|
31
|
-
} = usePortal();
|
|
36
|
+
renderInPortal = false,
|
|
37
|
+
portalRenderer: PortalRenderer
|
|
38
|
+
} = _ref2,
|
|
39
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
32
40
|
var handleClick = action => event => {
|
|
33
41
|
if (!props.shouldPropagateClickEvent) {
|
|
34
42
|
event.stopPropagation();
|
|
@@ -50,6 +58,12 @@ export var ConfirmationModal = _ref => {
|
|
|
50
58
|
disabled: confirmButtonDisabled
|
|
51
59
|
}), confirmButtonLabel))
|
|
52
60
|
}, props), children);
|
|
53
|
-
|
|
61
|
+
if (PortalRenderer) {
|
|
62
|
+
return /*#__PURE__*/React.createElement(PortalRenderer, null, ModalElement);
|
|
63
|
+
} else if (renderInPortal) {
|
|
64
|
+
return /*#__PURE__*/React.createElement(InternalPortalRenderer, null, ModalElement);
|
|
65
|
+
} else {
|
|
66
|
+
return ModalElement;
|
|
67
|
+
}
|
|
54
68
|
};
|
|
55
69
|
export default ConfirmationModal;
|
|
@@ -62,7 +62,7 @@ export type Props = {
|
|
|
62
62
|
*/
|
|
63
63
|
delay?: number;
|
|
64
64
|
};
|
|
65
|
-
export declare const adjustForWindow: (position: Position, fitsWindow: WindowFitment) => Position;
|
|
65
|
+
export declare const adjustForWindow: (position: Position, fitsWindow: WindowFitment, messageHeight?: number) => Position;
|
|
66
66
|
/**
|
|
67
67
|
* This is the [React](https://reactjs.org/) component for Vanilla [Tooltips](https://vanillaframework.io/docs/patterns/tooltips).
|
|
68
68
|
*
|
|
@@ -61,14 +61,27 @@ var getPositionStyle = (pos, wrapperNode) => {
|
|
|
61
61
|
top
|
|
62
62
|
};
|
|
63
63
|
};
|
|
64
|
-
export var adjustForWindow = (position, fitsWindow)
|
|
64
|
+
export var adjustForWindow = function adjustForWindow(position, fitsWindow) {
|
|
65
|
+
var messageHeight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
65
66
|
var newPosition = position;
|
|
66
67
|
if (!fitsWindow.fromLeft.fitsLeft && newPosition === "left") {
|
|
67
68
|
newPosition = "top-right";
|
|
68
69
|
}
|
|
70
|
+
if (fitsWindow.fromTop.spaceAbove < messageHeight / 2 && newPosition === "left") {
|
|
71
|
+
newPosition = "btm-left";
|
|
72
|
+
}
|
|
73
|
+
if (fitsWindow.fromBottom.spaceBelow < messageHeight / 2 && newPosition === "left") {
|
|
74
|
+
newPosition = "top-left";
|
|
75
|
+
}
|
|
69
76
|
if (!fitsWindow.fromRight.fitsRight && newPosition === "right") {
|
|
70
77
|
newPosition = "top-left";
|
|
71
78
|
}
|
|
79
|
+
if (fitsWindow.fromTop.spaceAbove < messageHeight / 2 && newPosition === "right") {
|
|
80
|
+
newPosition = "btm-right";
|
|
81
|
+
}
|
|
82
|
+
if (fitsWindow.fromBottom.spaceBelow < messageHeight / 2 && newPosition === "right") {
|
|
83
|
+
newPosition = "top-right";
|
|
84
|
+
}
|
|
72
85
|
if (!fitsWindow.fromRight.fitsLeft && newPosition.endsWith("-right")) {
|
|
73
86
|
newPosition = newPosition.replace("right", "left");
|
|
74
87
|
}
|
|
@@ -158,7 +171,9 @@ var Tooltip = _ref => {
|
|
|
158
171
|
});
|
|
159
172
|
}, []);
|
|
160
173
|
var onUpdateWindowFitment = useCallback(fitsWindow => {
|
|
161
|
-
|
|
174
|
+
var _messageRef$current$g, _messageRef$current;
|
|
175
|
+
var messageHeight = (_messageRef$current$g = (_messageRef$current = messageRef.current) === null || _messageRef$current === void 0 ? void 0 : _messageRef$current.getBoundingClientRect().height) !== null && _messageRef$current$g !== void 0 ? _messageRef$current$g : 0;
|
|
176
|
+
setAdjustedPosition(adjustForWindow(position, fitsWindow, messageHeight));
|
|
162
177
|
}, [setAdjustedPosition, position]);
|
|
163
178
|
|
|
164
179
|
// Handle mouse events.
|
|
@@ -178,19 +193,19 @@ var Tooltip = _ref => {
|
|
|
178
193
|
};
|
|
179
194
|
}, [handleKeyPress]);
|
|
180
195
|
var handleBlur = e => {
|
|
181
|
-
var _wrapperRef$current, _messageRef$
|
|
196
|
+
var _wrapperRef$current, _messageRef$current2, _wrapperRef$current2;
|
|
182
197
|
// do not close if the focus is within the tooltip wrapper
|
|
183
198
|
if (wrapperRef !== null && wrapperRef !== void 0 && (_wrapperRef$current = wrapperRef.current) !== null && _wrapperRef$current !== void 0 && _wrapperRef$current.contains(document.activeElement)) {
|
|
184
199
|
return;
|
|
185
200
|
}
|
|
186
|
-
if (e.relatedTarget ? !((_messageRef$
|
|
201
|
+
if (e.relatedTarget ? !((_messageRef$current2 = messageRef.current) !== null && _messageRef$current2 !== void 0 && _messageRef$current2.contains(e.relatedTarget)) && !((_wrapperRef$current2 = wrapperRef.current) !== null && _wrapperRef$current2 !== void 0 && _wrapperRef$current2.contains(e.relatedTarget)) : e.target !== messageRef.current) {
|
|
187
202
|
cancelableClosePortal();
|
|
188
203
|
}
|
|
189
204
|
};
|
|
190
205
|
var handleClick = e => {
|
|
191
|
-
var _messageRef$
|
|
206
|
+
var _messageRef$current3;
|
|
192
207
|
// ignore clicks within the tooltip message
|
|
193
|
-
if ((_messageRef$
|
|
208
|
+
if ((_messageRef$current3 = messageRef.current) !== null && _messageRef$current3 !== void 0 && _messageRef$current3.contains(e.target)) {
|
|
194
209
|
return;
|
|
195
210
|
}
|
|
196
211
|
e.target.focus();
|