@canonical/react-components 3.11.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; }
@@ -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({}, confirmationModalProps, {
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
- renderInPortal: true
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 = _ref => {
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
- } = _ref,
35
- props = _objectWithoutProperties(_ref, _excluded);
36
- const {
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
- return renderInPortal ? /*#__PURE__*/_react.default.createElement(Portal, null, ModalElement) : ModalElement;
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;
@@ -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({}, confirmationModalProps, {
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
- renderInPortal: true
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 = _ref => {
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
- } = _ref,
28
- props = _objectWithoutProperties(_ref, _excluded);
29
- var {
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
- return renderInPortal ? /*#__PURE__*/React.createElement(Portal, null, ModalElement) : ModalElement;
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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "3.11.0",
3
+ "version": "3.11.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {