office-ui-fabric-react
Version:
Reusable React components for building experiences for Office 365.
42 lines • 2.6 kB
JavaScript
define(["require", "exports", "react", "office-ui-fabric-react/lib/Button", "office-ui-fabric-react/lib/Dialog", "office-ui-fabric-react/lib/Panel", "@uifabric/react-hooks"], function (require, exports, React, Button_1, Dialog_1, Panel_1, react_hooks_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var explanation = 'When this panel is closed, a confirmation dialog will appear.';
var dialogContentProps = {
type: Dialog_1.DialogType.normal,
title: 'Are you sure you want to close the panel?'
};
var dialogModalProps = {
isBlocking: true,
styles: { main: { maxWidth: 450 } }
};
exports.PanelConfirmDismissExample = function () {
var _a = React.useState(false), isPanelOpen = _a[0], setIsPanelOpen = _a[1];
var _b = React.useState(false), isDialogVisible = _b[0], setIsDialogVisible = _b[1];
var openPanel = react_hooks_1.useConstCallback(function () { return setIsPanelOpen(true); });
var onDismiss = react_hooks_1.useConstCallback(function (ev) {
if (ev) {
// Instead of closing the panel immediately, cancel that action and show a dialog
ev.preventDefault();
setIsDialogVisible(true);
}
});
var hideDialog = react_hooks_1.useConstCallback(function () { return setIsDialogVisible(false); });
var hideDialogAndPanel = react_hooks_1.useConstCallback(function () {
setIsPanelOpen(false);
setIsDialogVisible(false);
});
return (React.createElement("div", null,
explanation,
React.createElement("br", null),
React.createElement("br", null),
React.createElement(Button_1.DefaultButton, { text: "Open panel", onClick: openPanel }),
React.createElement(Panel_1.Panel, { headerText: "Panel with custom close behavior", isOpen: isPanelOpen, onDismiss: onDismiss, closeButtonAriaLabel: "Close" },
React.createElement("span", null, explanation)),
React.createElement(Dialog_1.Dialog, { hidden: !isDialogVisible, onDismiss: hideDialog, dialogContentProps: dialogContentProps, modalProps: dialogModalProps },
React.createElement(Dialog_1.DialogFooter, null,
React.createElement(Button_1.PrimaryButton, { onClick: hideDialogAndPanel, text: "Yes" }),
React.createElement(Button_1.DefaultButton, { onClick: hideDialog, text: "No" })))));
};
});
//# sourceMappingURL=Panel.ConfirmDismiss.Example.js.map