12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import React from 'react';
- import { Button } from 'components/common/Button/Button';
- import { ConfirmationModalWrapper } from './ConfirmationModal.styled';
- export interface ConfirmationModalProps {
- isOpen?: boolean;
- title?: React.ReactNode;
- onConfirm(): void;
- onCancel(): void;
- isConfirming?: boolean;
- submitBtnText?: string;
- }
- const ConfirmationModal: React.FC<ConfirmationModalProps> = ({
- isOpen,
- children,
- title = 'Confirm the action',
- onCancel,
- onConfirm,
- isConfirming = false,
- submitBtnText = 'Submit',
- }) => {
- const cancelHandler = React.useCallback(() => {
- if (!isConfirming) {
- onCancel();
- }
- }, [isConfirming, onCancel]);
- return isOpen ? (
- <ConfirmationModalWrapper>
- <div onClick={cancelHandler} aria-hidden="true" />
- <div>
- <header>
- <p>{title}</p>
- </header>
- <section>{children}</section>
- <footer>
- <Button
- buttonType="secondary"
- buttonSize="M"
- onClick={cancelHandler}
- type="button"
- disabled={isConfirming}
- >
- Cancel
- </Button>
- <Button
- buttonType="primary"
- buttonSize="M"
- onClick={onConfirm}
- type="button"
- disabled={isConfirming}
- >
- {submitBtnText}
- </Button>
- </footer>
- </div>
- </ConfirmationModalWrapper>
- ) : null;
- };
- export default ConfirmationModal;
|