docs/developer_docs/components/ui/unsavedchangesmodal.mdx
import { StoryWithControls } from '../../../src/components/StorybookWrapper';
The UnsavedChangesModal component from Superset's UI library.
<StoryWithControls component="UnsavedChangesModal" props={{ showModal: false, title: "Unsaved Changes" }} controls={[ { name: "showModal", label: "Show Modal", type: "boolean", description: "Whether the modal is visible." }, { name: "title", label: "Title", type: "text", description: "Title text displayed in the modal header." } ]} triggerProp="showModal" onHideProp="onHide,handleSave,onConfirmNavigation" />
Edit the code below to experiment with the component:
function Demo() {
const [show, setShow] = React.useState(false);
return (
<div>
<Button onClick={() => setShow(true)}>
Navigate Away (Unsaved Changes)
</Button>
<UnsavedChangesModal
showModal={show}
onHide={() => setShow(false)}
handleSave={() => { alert('Saved!'); setShow(false); }}
onConfirmNavigation={() => { alert('Discarded changes'); setShow(false); }}
title="Unsaved Changes"
>
If you don't save, changes will be lost.
</UnsavedChangesModal>
</div>
);
}
function CustomTitle() {
const [show, setShow] = React.useState(false);
return (
<div>
<Button onClick={() => setShow(true)}>
Close Without Saving
</Button>
<UnsavedChangesModal
showModal={show}
onHide={() => setShow(false)}
handleSave={() => setShow(false)}
onConfirmNavigation={() => setShow(false)}
title="You have unsaved dashboard changes"
>
Your dashboard layout and filter changes have not been saved.
Do you want to save before leaving?
</UnsavedChangesModal>
</div>
);
}
| Prop | Type | Default | Description |
|---|---|---|---|
showModal | boolean | false | Whether the modal is visible. |
title | string | "Unsaved Changes" | Title text displayed in the modal header. |
import { UnsavedChangesModal } from '@superset/components';
:::tip[Improve this page] This documentation is auto-generated from the component's Storybook story. Help improve it by editing the story file. :::