-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a371d4
commit 4f3c8c8
Showing
2 changed files
with
77 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { Button, IconButton, Popover, Typography } from '@mui/material'; | ||
import DeleteIcon from '@mui/icons-material/Delete'; | ||
|
||
type ErasingAllConfirmationButtonProps = { | ||
handleEraseAll: () => void; | ||
}; | ||
|
||
const ErasingAllConfirmationButton: React.FC<ErasingAllConfirmationButtonProps> = (props) => { | ||
|
||
const { handleEraseAll } = props; | ||
|
||
const [ anchorEl, setAnchorEl ] = useState<HTMLButtonElement | null>(null); | ||
const [ confirmed, setConfirmed ] = useState<boolean>(false); | ||
|
||
const handleConfirm = (event: React.MouseEvent<HTMLButtonElement>) => { | ||
setAnchorEl(event.currentTarget); | ||
}; | ||
|
||
const handleConfirmed = () => { | ||
setConfirmed(true); | ||
setAnchorEl(null); | ||
}; | ||
|
||
useEffect(() => { | ||
if (confirmed) { | ||
handleEraseAll(); | ||
setConfirmed(false); | ||
} | ||
}, [ confirmed ]); | ||
|
||
const handleClose = () => { | ||
setAnchorEl(null); | ||
}; | ||
|
||
const open = Boolean(anchorEl); | ||
const id = open ? 'simple-popover' : undefined; | ||
|
||
return ( | ||
<div style={{ display: 'inline-block' }}> | ||
<IconButton onClick={handleConfirm} aria-describedby={id}> | ||
<DeleteIcon /> | ||
</IconButton> | ||
<Popover | ||
id={id} | ||
open={open} | ||
anchorEl={anchorEl} | ||
onClose={handleClose} | ||
anchorOrigin={{ | ||
vertical: 'top', | ||
horizontal: 'center', | ||
}} | ||
transformOrigin={{ | ||
vertical: 'bottom', | ||
horizontal: 'right', | ||
}} | ||
> | ||
<Typography sx={{ p: 1 }}> | ||
<Button | ||
variant="contained" | ||
color="warning" | ||
onClick={handleConfirmed} | ||
> | ||
Confirm | ||
</Button> | ||
</Typography> | ||
</Popover> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ErasingAllConfirmationButton; |