| 1 |
import React from 'react' |
| 2 |
import { __ } from '@wordpress/i18n' |
| 3 |
import { Button, Flex, Modal } from '@wordpress/components' |
| 4 |
import type { ReactNode } from 'react' |
| 5 |
|
| 6 |
export interface ConfirmDialogProps { |
| 7 |
open?: boolean |
| 8 |
title: string |
| 9 |
onConfirm?: VoidFunction |
| 10 |
onCancel: VoidFunction |
| 11 |
confirmLabel?: string |
| 12 |
cancelLabel?: string |
| 13 |
children?: ReactNode, |
| 14 |
confirmButtonClassName?: string |
| 15 |
} |
| 16 |
|
| 17 |
export const ConfirmDialog: React.FC<ConfirmDialogProps> = ({ |
| 18 |
open, |
| 19 |
title, |
| 20 |
onConfirm, |
| 21 |
onCancel, |
| 22 |
children, |
| 23 |
confirmLabel = __('OK', 'code-snippets'), |
| 24 |
cancelLabel = __('Cancel', 'code-snippets'), |
| 25 |
confirmButtonClassName |
| 26 |
}) => |
| 27 |
open |
| 28 |
? <Modal |
| 29 |
title={title} |
| 30 |
onRequestClose={onCancel} |
| 31 |
closeButtonLabel={__('Close dialog', 'code-snippets')} |
| 32 |
isDismissible={true} |
| 33 |
> |
| 34 |
{children} |
| 35 |
<Flex direction="row" justify="flex-end"> |
| 36 |
<Button variant="tertiary" onClick={onCancel}> |
| 37 |
{cancelLabel} |
| 38 |
</Button> |
| 39 |
<Button variant="primary" onClick={onConfirm} className={confirmButtonClassName}> |
| 40 |
{confirmLabel} |
| 41 |
</Button> |
| 42 |
</Flex> |
| 43 |
</Modal> |
| 44 |
: null |
| 45 |
|