import * as React from 'react'; import { DefaultButton, PrimaryButton } from 'office-ui-fabric-react/lib/Button'; import { Dialog, DialogFooter, DialogType } from 'office-ui-fabric-react/lib/Dialog'; import { Panel } from 'office-ui-fabric-react/lib/Panel'; import { useConstCallback } from '@uifabric/react-hooks'; const explanation = 'When this panel is closed, a confirmation dialog will appear.'; const dialogContentProps = { type: DialogType.normal, title: 'Are you sure you want to close the panel?', }; const dialogModalProps = { isBlocking: true, styles: { main: { maxWidth: 450 } }, }; export const PanelConfirmDismissExample: React.FunctionComponent = () => { const [isPanelOpen, setIsPanelOpen] = React.useState(false); const [isDialogVisible, setIsDialogVisible] = React.useState(false); const openPanel = useConstCallback(() => setIsPanelOpen(true)); const onDismiss = useConstCallback((ev?: React.SyntheticEvent) => { if (ev) { // Instead of closing the panel immediately, cancel that action and show a dialog ev.preventDefault(); setIsDialogVisible(true); } }); const hideDialog = useConstCallback(() => setIsDialogVisible(false)); const hideDialogAndPanel = useConstCallback(() => { setIsPanelOpen(false); setIsDialogVisible(false); }); return (
{explanation}