Skip to content

Instantly share code, notes, and snippets.

@jack-hermanson
Created June 25, 2021 04:53
Show Gist options
  • Save jack-hermanson/525a6153bd6ce472ad4e7b6b275589ec to your computer and use it in GitHub Desktop.
Save jack-hermanson/525a6153bd6ce472ad4e7b6b275589ec to your computer and use it in GitHub Desktop.
Generic Confirmation Modal
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