@activecollab/components
Version:
ActiveCollab Components
75 lines (74 loc) • 4.01 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.ConfirmDialog = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _Button = require("../Button/Button");
var _Dialog = require("../Dialog");
var _Body = require("../Typography/Variants/Body2");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var ConfirmDialog = exports.ConfirmDialog = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
var _ref$open = _ref.open,
open = _ref$open === void 0 ? false : _ref$open,
onCancel = _ref.onCancel,
onConfirm = _ref.onConfirm,
className = _ref.className,
_ref$dialogTitle = _ref.dialogTitle,
dialogTitle = _ref$dialogTitle === void 0 ? "Discard changes?" : _ref$dialogTitle,
_ref$dialogContent = _ref.dialogContent,
dialogContent = _ref$dialogContent === void 0 ? "All unsaved changes will be lost." : _ref$dialogContent,
_ref$confirmBtnText = _ref.confirmBtnText,
confirmBtnText = _ref$confirmBtnText === void 0 ? "OK" : _ref$confirmBtnText,
_ref$cancelBtnText = _ref.cancelBtnText,
cancelBtnText = _ref$cancelBtnText === void 0 ? "Cancel" : _ref$cancelBtnText,
_ref$shouldShowCancel = _ref.shouldShowCancelButton,
shouldShowCancelButton = _ref$shouldShowCancel === void 0 ? true : _ref$shouldShowCancel,
_ref$isLoading = _ref.isLoading,
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
_ref$fullWidth = _ref.fullWidth,
fullWidth = _ref$fullWidth === void 0 ? false : _ref$fullWidth;
(0, _react.useEffect)(function () {
var handleKeyDown = function handleKeyDown(event) {
if (event.key === "Enter" && onConfirm) {
event.preventDefault();
onConfirm();
}
};
if (open) {
window.addEventListener("keydown", handleKeyDown);
}
return function () {
window.removeEventListener("keydown", handleKeyDown);
};
}, [open, onConfirm]);
return /*#__PURE__*/_react.default.createElement(_Dialog.Dialog, {
ref: ref,
open: open,
onClose: onCancel,
className: (0, _classnames.default)("c-confirm-dialog", className),
disableCloseOnEsc: isLoading,
fullWidth: fullWidth
}, /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.Title, null, dialogTitle), /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.ContentDivider, null), /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.Content, null, /*#__PURE__*/_react.default.createElement(_Body.Body2, {
lineHeight: "loose",
color: "secondary",
whitespace: "pre-line"
}, dialogContent)), /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.ContentDivider, null), /*#__PURE__*/_react.default.createElement(_Dialog.Dialog.Actions, null, /*#__PURE__*/_react.default.createElement(_Button.Button, {
variant: "primary",
style: {
marginRight: "12px"
},
onClick: onConfirm,
disabled: isLoading
}, confirmBtnText), shouldShowCancelButton ? /*#__PURE__*/_react.default.createElement(_Button.Button, {
variant: "secondary",
"data-action": "cancel",
onClick: onCancel,
type: "button",
disabled: isLoading
}, cancelBtnText) : null));
});
ConfirmDialog.displayName = "ConfirmDialog";
//# sourceMappingURL=ConfirmDialog.js.map