@canonical/react-components 0.59.1 → 0.60.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.
@@ -10,6 +10,15 @@ var _ConfirmationModal = _interopRequireDefault(require("../ConfirmationModal"))
10
10
  var _reactUseportal = _interopRequireDefault(require("react-useportal"));
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
12
  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); }
13
+ const generateTitle = title => {
14
+ if (typeof title === "string") {
15
+ return title;
16
+ }
17
+ if (typeof title === "number") {
18
+ return title.toString();
19
+ }
20
+ return null;
21
+ };
13
22
  /**
14
23
  * `ConfirmationButton` is a specialised version of the [ActionButton](?path=/docs/actionbutton--default-story) component that uses a [ConfirmationModal](?path=/docs/confirmationmodal--default-story) to prompt a confirmation from the user before executing an action.
15
24
  */
@@ -52,7 +61,7 @@ const ConfirmationButton = _ref => {
52
61
  className: "p-text--small u-text--muted u-hide--small"
53
62
  }, "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, {
54
63
  onClick: shiftClickEnabled ? handleShiftClick : openPortal,
55
- title: onHoverText !== null && onHoverText !== void 0 ? onHoverText : confirmationModalProps.confirmButtonLabel
64
+ title: generateTitle(onHoverText !== null && onHoverText !== void 0 ? onHoverText : confirmationModalProps.confirmButtonLabel)
56
65
  }), actionButtonProps.children));
57
66
  };
58
67
  exports.ConfirmationButton = ConfirmationButton;
@@ -1,13 +1,18 @@
1
1
  import { MouseEvent, ReactElement } from "react";
2
2
  import type { ReactNode } from "react";
3
3
  import { PropsWithSpread, ValueOf } from "../../types";
4
- import { ButtonAppearance } from "../Button";
4
+ import { ButtonAppearance, ButtonProps } from "../Button";
5
5
  import { ModalProps } from "../Modal";
6
+ import { ActionButtonProps } from "../ActionButton";
6
7
  export type Props = PropsWithSpread<{
7
8
  /**
8
9
  * Label for the cancel button.
9
10
  */
10
- cancelButtonLabel?: string;
11
+ cancelButtonLabel?: ReactNode;
12
+ /**
13
+ * Additional props to be spread on the cancel button.
14
+ */
15
+ cancelButtonProps?: Partial<ButtonProps>;
11
16
  /**
12
17
  * The content of the modal.
13
18
  */
@@ -19,7 +24,11 @@ export type Props = PropsWithSpread<{
19
24
  /**
20
25
  * Label for the confirm button.
21
26
  */
22
- confirmButtonLabel: string;
27
+ confirmButtonLabel: ReactNode;
28
+ /**
29
+ * Additional props to be spread on the confirm button.
30
+ */
31
+ confirmButtonProps?: Partial<ActionButtonProps>;
23
32
  /**
24
33
  * Extra elements to be placed in the button row of the modal.
25
34
  */
@@ -40,5 +49,5 @@ export type Props = PropsWithSpread<{
40
49
  /**
41
50
  * `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.
42
51
  */
43
- export declare const ConfirmationModal: ({ cancelButtonLabel, children, confirmButtonAppearance, confirmButtonLabel, confirmExtra, onConfirm, confirmButtonLoading, confirmButtonDisabled, ...props }: Props) => ReactElement;
52
+ export declare const ConfirmationModal: ({ cancelButtonLabel, cancelButtonProps, children, confirmButtonAppearance, confirmButtonLabel, confirmExtra, onConfirm, confirmButtonLoading, confirmButtonDisabled, confirmButtonProps, ...props }: Props) => ReactElement;
44
53
  export default ConfirmationModal;
@@ -16,6 +16,7 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
16
16
  const ConfirmationModal = _ref => {
17
17
  let {
18
18
  cancelButtonLabel = "Cancel",
19
+ cancelButtonProps,
19
20
  children,
20
21
  confirmButtonAppearance = "negative",
21
22
  confirmButtonLabel,
@@ -23,6 +24,7 @@ const ConfirmationModal = _ref => {
23
24
  onConfirm,
24
25
  confirmButtonLoading,
25
26
  confirmButtonDisabled,
27
+ confirmButtonProps,
26
28
  ...props
27
29
  } = _ref;
28
30
  const handleClick = action => event => {
@@ -34,16 +36,16 @@ const ConfirmationModal = _ref => {
34
36
  }
35
37
  };
36
38
  return /*#__PURE__*/_react.default.createElement(_Modal.default, _extends({
37
- buttonRow: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, confirmExtra, /*#__PURE__*/_react.default.createElement(_Button.default, {
39
+ buttonRow: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, confirmExtra, /*#__PURE__*/_react.default.createElement(_Button.default, _extends({}, cancelButtonProps, {
38
40
  className: "u-no-margin--bottom",
39
41
  onClick: handleClick(props.close)
40
- }, cancelButtonLabel), /*#__PURE__*/_react.default.createElement(_ActionButton.default, {
42
+ }), cancelButtonLabel), /*#__PURE__*/_react.default.createElement(_ActionButton.default, _extends({}, confirmButtonProps, {
41
43
  appearance: confirmButtonAppearance,
42
44
  className: "u-no-margin--bottom",
43
45
  onClick: handleClick(onConfirm),
44
46
  loading: confirmButtonLoading,
45
47
  disabled: confirmButtonDisabled
46
- }, confirmButtonLabel))
48
+ }), confirmButtonLabel))
47
49
  }, props), children);
48
50
  };
49
51
  exports.ConfirmationModal = ConfirmationModal;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "0.59.1",
3
+ "version": "0.60.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {