ContinueCancelModal.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. function _extends() { _extends = Object.assign || 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); }
  2. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  3. /*
  4. * Copyright 2019 Red Hat, Inc. and/or its affiliates.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. import * as React from "../../../common/keycloak/web_modules/react.js";
  19. import { Modal, Button } from "../../../common/keycloak/web_modules/@patternfly/react-core.js";
  20. import { Msg } from "./Msg.js";
  21. /**
  22. * For any of these properties that are strings, you can
  23. * pass in a localization key instead of a static string.
  24. */
  25. /**
  26. * This class renders a button that provides a continue/cancel modal dialog when clicked. If the user selects 'Continue'
  27. * then the onContinue function is executed.
  28. *
  29. * @author Stan Silvert ssilvert@redhat.com (C) 2019 Red Hat Inc.
  30. */
  31. export class ContinueCancelModal extends React.Component {
  32. constructor(props) {
  33. super(props);
  34. _defineProperty(this, "handleModalToggle", () => {
  35. this.setState(({
  36. isModalOpen
  37. }) => ({
  38. isModalOpen: !isModalOpen
  39. }));
  40. if (this.props.onClose) this.props.onClose();
  41. });
  42. _defineProperty(this, "handleContinue", () => {
  43. this.handleModalToggle();
  44. this.props.onContinue();
  45. });
  46. this.state = {
  47. isModalOpen: false
  48. };
  49. }
  50. render() {
  51. const {
  52. isModalOpen
  53. } = this.state;
  54. return React.createElement(React.Fragment, null, !this.props.render && React.createElement(Button, {
  55. id: this.props.buttonId,
  56. variant: this.props.buttonVariant,
  57. onClick: this.handleModalToggle,
  58. isDisabled: this.props.isDisabled
  59. }, React.createElement(Msg, {
  60. msgKey: this.props.buttonTitle
  61. })), this.props.render && this.props.render(this.handleModalToggle), React.createElement(Modal, _extends({}, this.props, {
  62. title: Msg.localize(this.props.modalTitle),
  63. isOpen: isModalOpen,
  64. onClose: this.handleModalToggle,
  65. actions: [React.createElement(Button, {
  66. id: "modal-cancel",
  67. key: "cancel",
  68. variant: "secondary",
  69. onClick: this.handleModalToggle
  70. }, React.createElement(Msg, {
  71. msgKey: this.props.modalCancelButtonLabel
  72. })), React.createElement(Button, {
  73. id: "modal-confirm",
  74. key: "confirm",
  75. variant: "primary",
  76. onClick: this.handleContinue
  77. }, React.createElement(Msg, {
  78. msgKey: this.props.modalContinueButtonLabel
  79. }))]
  80. }), !this.props.modalMessage && this.props.children, this.props.modalMessage && React.createElement(Msg, {
  81. msgKey: this.props.modalMessage
  82. })));
  83. }
  84. }
  85. _defineProperty(ContinueCancelModal, "defaultProps", {
  86. buttonVariant: 'primary',
  87. modalContinueButtonLabel: 'continue',
  88. modalCancelButtonLabel: 'doCancel',
  89. isDisabled: false,
  90. isSmall: true
  91. });
  92. ;
  93. //# sourceMappingURL=ContinueCancelModal.js.map