-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Modal] Add destructive primary action example
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
polaris.shopify.com/pages/examples/modal-with-destructive-primary-action.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import {Button, Modal, Frame} from '@shopify/polaris'; | ||
import {useState, useCallback} from 'react'; | ||
import {withPolarisExample} from '../../src/components/PolarisExampleWrapper'; | ||
|
||
function ModalWithDestructivePrimaryActionExample() { | ||
const [active, setActive] = useState(true); | ||
|
||
const toggleModal = useCallback(() => setActive((active) => !active), []); | ||
|
||
const activator = <Button onClick={toggleModal}>Open</Button>; | ||
|
||
return ( | ||
<Frame> | ||
<div style={{height: '500px'}}> | ||
<Modal | ||
activator={activator} | ||
open={active} | ||
onClose={toggleModal} | ||
title="Discard all unsaved changes" | ||
primaryAction={{ | ||
destructive: true, | ||
content: 'Discard changes', | ||
onAction: toggleModal, | ||
}} | ||
secondaryActions={[ | ||
{ | ||
content: 'Continue editing', | ||
onAction: toggleModal, | ||
}, | ||
]} | ||
> | ||
<Modal.Section> | ||
If you discard changes, you’ll delete any edits you made since you | ||
last saved. | ||
</Modal.Section> | ||
</Modal> | ||
</div> | ||
</Frame> | ||
); | ||
} | ||
|
||
export default withPolarisExample(ModalWithDestructivePrimaryActionExample); |