Created
June 25, 2021 04:53
-
-
Save jack-hermanson/525a6153bd6ce472ad4e7b6b275589ec to your computer and use it in GitHub Desktop.
Generic Confirmation Modal
This file contains hidden or 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
import React from "react"; | |
import { Button, Modal, ModalBody, ModalFooter, ModalHeader } from "reactstrap"; | |
interface Props { | |
isOpen: boolean; | |
setIsOpen: React.Dispatch<React.SetStateAction<boolean>>; | |
title: string; | |
buttonColor?: string; | |
onConfirm: () => any; | |
buttonText?: string; | |
children?: React.ReactNode; | |
} | |
export const ConfirmationModal: React.FC<Props> = ({ | |
isOpen, | |
setIsOpen, | |
title, | |
buttonColor = "primary", | |
onConfirm, | |
buttonText = "Confirm", | |
children, | |
}: Props) => { | |
const toggle = React.useCallback(() => { | |
setIsOpen(o => !o); | |
}, [setIsOpen]); | |
return ( | |
<Modal isOpen={isOpen} toggle={toggle}> | |
<ModalHeader toggle={toggle} className="mb-0"> | |
{title} | |
</ModalHeader> | |
<ModalBody>{children}</ModalBody> | |
<ModalFooter> | |
<Button size="sm" color="secondary" onClick={toggle}> | |
Cancel | |
</Button> | |
<Button | |
size="sm" | |
color={buttonColor} | |
onClick={() => onConfirm()} | |
> | |
{buttonText} | |
</Button> | |
</ModalFooter> | |
</Modal> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment