@canonical/react-components 3.10.0 → 3.11.1

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.
@@ -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; }
@@ -40,6 +41,12 @@ const ConfirmationButton = _ref => {
40
41
  isOpen,
41
42
  Portal
42
43
  } = (0, _external.usePortal)();
44
+ const _ref2 = confirmationModalProps,
45
+ {
46
+ renderInPortal: _ignoredRenderInPortal,
47
+ portalRenderer: _ignoredPortalRenderer
48
+ } = _ref2,
49
+ safeConfirmationModalProps = _objectWithoutProperties(_ref2, _excluded2);
43
50
  const handleCancelModal = () => {
44
51
  closePortal();
45
52
  if (confirmationModalProps.close) {
@@ -64,13 +71,14 @@ const ConfirmationButton = _ref => {
64
71
  }
65
72
  shiftClickEnabled ? handleShiftClick(e) : openPortal(e);
66
73
  };
67
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isOpen && /*#__PURE__*/_react.default.createElement(Portal, null, /*#__PURE__*/_react.default.createElement(_ConfirmationModal.default, _extends({}, confirmationModalProps, {
74
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, isOpen && /*#__PURE__*/_react.default.createElement(_ConfirmationModal.default, _extends({}, safeConfirmationModalProps, {
68
75
  close: handleCancelModal,
69
76
  confirmButtonLabel: confirmationModalProps.confirmButtonLabel,
70
- onConfirm: handleConfirmModal
77
+ onConfirm: handleConfirmModal,
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
- }, "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, {
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, {
74
82
  onClick: handleClick,
75
83
  title: generateTitle(onHoverText !== null && onHoverText !== void 0 ? onHoverText : confirmationModalProps.confirmButtonLabel)
76
84
  }), actionButtonProps.children));
@@ -45,9 +45,20 @@ export type Props = PropsWithSpread<{
45
45
  * Whether the confirm button should be disabled.
46
46
  */
47
47
  confirmButtonDisabled?: boolean;
48
+ /**
49
+ * Whether to render the modal inside a Portal component.
50
+ */
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
+ }>;
48
59
  }, Omit<ModalProps, "buttonRow">>;
49
60
  /**
50
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.
51
62
  */
52
- export declare const ConfirmationModal: ({ cancelButtonLabel, cancelButtonProps, children, confirmButtonAppearance, confirmButtonLabel, confirmExtra, onConfirm, confirmButtonLoading, confirmButtonDisabled, confirmButtonProps, ...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;
53
64
  export default ConfirmationModal;
@@ -8,15 +8,26 @@ var _react = _interopRequireDefault(require("react"));
8
8
  var _Button = _interopRequireDefault(require("../Button"));
9
9
  var _Modal = _interopRequireDefault(require("../Modal"));
10
10
  var _ActionButton = _interopRequireDefault(require("../ActionButton"));
11
- const _excluded = ["cancelButtonLabel", "cancelButtonProps", "children", "confirmButtonAppearance", "confirmButtonLabel", "confirmExtra", "onConfirm", "confirmButtonLoading", "confirmButtonDisabled", "confirmButtonProps"];
11
+ var _external = require("../../external");
12
+ const _excluded = ["cancelButtonLabel", "cancelButtonProps", "children", "confirmButtonAppearance", "confirmButtonLabel", "confirmExtra", "onConfirm", "confirmButtonLoading", "confirmButtonDisabled", "confirmButtonProps", "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; }
15
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
+
16
27
  /**
17
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.
18
29
  */
19
- const ConfirmationModal = _ref => {
30
+ const ConfirmationModal = _ref2 => {
20
31
  var _cancelButtonProps$ty;
21
32
  let {
22
33
  cancelButtonLabel = "Cancel",
@@ -28,9 +39,11 @@ const ConfirmationModal = _ref => {
28
39
  onConfirm,
29
40
  confirmButtonLoading,
30
41
  confirmButtonDisabled,
31
- confirmButtonProps
32
- } = _ref,
33
- props = _objectWithoutProperties(_ref, _excluded);
42
+ confirmButtonProps,
43
+ renderInPortal = false,
44
+ portalRenderer: PortalRenderer
45
+ } = _ref2,
46
+ props = _objectWithoutProperties(_ref2, _excluded);
34
47
  const handleClick = action => event => {
35
48
  if (!props.shouldPropagateClickEvent) {
36
49
  event.stopPropagation();
@@ -39,7 +52,7 @@ const ConfirmationModal = _ref => {
39
52
  action(event);
40
53
  }
41
54
  };
42
- return /*#__PURE__*/_react.default.createElement(_Modal.default, _extends({
55
+ const ModalElement = /*#__PURE__*/_react.default.createElement(_Modal.default, _extends({
43
56
  buttonRow: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, confirmExtra, /*#__PURE__*/_react.default.createElement(_Button.default, _extends({}, cancelButtonProps, {
44
57
  type: (_cancelButtonProps$ty = cancelButtonProps === null || cancelButtonProps === void 0 ? void 0 : cancelButtonProps.type) !== null && _cancelButtonProps$ty !== void 0 ? _cancelButtonProps$ty : "button",
45
58
  className: "u-no-margin--bottom",
@@ -52,6 +65,13 @@ const ConfirmationModal = _ref => {
52
65
  disabled: confirmButtonDisabled
53
66
  }), confirmButtonLabel))
54
67
  }, props), children);
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
+ }
55
75
  };
56
76
  exports.ConfirmationModal = ConfirmationModal;
57
77
  var _default = exports.default = ConfirmationModal;
@@ -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; }
@@ -33,6 +34,12 @@ export var ConfirmationButton = _ref => {
33
34
  isOpen,
34
35
  Portal
35
36
  } = usePortal();
37
+ var _ref2 = confirmationModalProps,
38
+ {
39
+ renderInPortal: _ignoredRenderInPortal,
40
+ portalRenderer: _ignoredPortalRenderer
41
+ } = _ref2,
42
+ safeConfirmationModalProps = _objectWithoutProperties(_ref2, _excluded2);
36
43
  var handleCancelModal = () => {
37
44
  closePortal();
38
45
  if (confirmationModalProps.close) {
@@ -57,13 +64,14 @@ export var ConfirmationButton = _ref => {
57
64
  }
58
65
  shiftClickEnabled ? handleShiftClick(e) : openPortal(e);
59
66
  };
60
- return /*#__PURE__*/React.createElement(React.Fragment, null, isOpen && /*#__PURE__*/React.createElement(Portal, null, /*#__PURE__*/React.createElement(ConfirmationModal, _extends({}, confirmationModalProps, {
67
+ return /*#__PURE__*/React.createElement(React.Fragment, null, isOpen && /*#__PURE__*/React.createElement(ConfirmationModal, _extends({}, safeConfirmationModalProps, {
61
68
  close: handleCancelModal,
62
69
  confirmButtonLabel: confirmationModalProps.confirmButtonLabel,
63
- onConfirm: handleConfirmModal
70
+ onConfirm: handleConfirmModal,
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
- }, "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, {
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, {
67
75
  onClick: handleClick,
68
76
  title: generateTitle(onHoverText !== null && onHoverText !== void 0 ? onHoverText : confirmationModalProps.confirmButtonLabel)
69
77
  }), actionButtonProps.children));
@@ -45,9 +45,20 @@ export type Props = PropsWithSpread<{
45
45
  * Whether the confirm button should be disabled.
46
46
  */
47
47
  confirmButtonDisabled?: boolean;
48
+ /**
49
+ * Whether to render the modal inside a Portal component.
50
+ */
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
+ }>;
48
59
  }, Omit<ModalProps, "buttonRow">>;
49
60
  /**
50
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.
51
62
  */
52
- export declare const ConfirmationModal: ({ cancelButtonLabel, cancelButtonProps, children, confirmButtonAppearance, confirmButtonLabel, confirmExtra, onConfirm, confirmButtonLoading, confirmButtonDisabled, confirmButtonProps, ...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;
53
64
  export default ConfirmationModal;
@@ -1,4 +1,4 @@
1
- var _excluded = ["cancelButtonLabel", "cancelButtonProps", "children", "confirmButtonAppearance", "confirmButtonLabel", "confirmExtra", "onConfirm", "confirmButtonLoading", "confirmButtonDisabled", "confirmButtonProps"];
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; }
@@ -6,10 +6,21 @@ import React from "react";
6
6
  import Button from "../Button";
7
7
  import Modal from "../Modal";
8
8
  import ActionButton from "../ActionButton";
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
+
9
20
  /**
10
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.
11
22
  */
12
- export var ConfirmationModal = _ref => {
23
+ export var ConfirmationModal = _ref2 => {
13
24
  var _cancelButtonProps$ty;
14
25
  var {
15
26
  cancelButtonLabel = "Cancel",
@@ -21,9 +32,11 @@ export var ConfirmationModal = _ref => {
21
32
  onConfirm,
22
33
  confirmButtonLoading,
23
34
  confirmButtonDisabled,
24
- confirmButtonProps
25
- } = _ref,
26
- props = _objectWithoutProperties(_ref, _excluded);
35
+ confirmButtonProps,
36
+ renderInPortal = false,
37
+ portalRenderer: PortalRenderer
38
+ } = _ref2,
39
+ props = _objectWithoutProperties(_ref2, _excluded);
27
40
  var handleClick = action => event => {
28
41
  if (!props.shouldPropagateClickEvent) {
29
42
  event.stopPropagation();
@@ -32,7 +45,7 @@ export var ConfirmationModal = _ref => {
32
45
  action(event);
33
46
  }
34
47
  };
35
- return /*#__PURE__*/React.createElement(Modal, _extends({
48
+ var ModalElement = /*#__PURE__*/React.createElement(Modal, _extends({
36
49
  buttonRow: /*#__PURE__*/React.createElement(React.Fragment, null, confirmExtra, /*#__PURE__*/React.createElement(Button, _extends({}, cancelButtonProps, {
37
50
  type: (_cancelButtonProps$ty = cancelButtonProps === null || cancelButtonProps === void 0 ? void 0 : cancelButtonProps.type) !== null && _cancelButtonProps$ty !== void 0 ? _cancelButtonProps$ty : "button",
38
51
  className: "u-no-margin--bottom",
@@ -45,5 +58,12 @@ export var ConfirmationModal = _ref => {
45
58
  disabled: confirmButtonDisabled
46
59
  }), confirmButtonLabel))
47
60
  }, props), children);
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
+ }
48
68
  };
49
69
  export default ConfirmationModal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "3.10.0",
3
+ "version": "3.11.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {