({
open,
close,
onConfirm,
title,
description,
confirm,
cancel,
}: Props)
| 15 | } |
| 16 | |
| 17 | export default function ConfirmationModal({ |
| 18 | open, |
| 19 | close, |
| 20 | onConfirm, |
| 21 | title, |
| 22 | description, |
| 23 | confirm, |
| 24 | cancel, |
| 25 | }: Props) { |
| 26 | useKeyboard( |
| 27 | { |
| 28 | onKeyUp(event) { |
| 29 | if (open) { |
| 30 | if (event.key === 'Escape') { |
| 31 | event.preventDefault(); |
| 32 | event.stopPropagation(); |
| 33 | close(); |
| 34 | } |
| 35 | |
| 36 | if (event.key === 'Enter') { |
| 37 | event.preventDefault(); |
| 38 | event.stopPropagation(); |
| 39 | onConfirm(); |
| 40 | } |
| 41 | } |
| 42 | }, |
| 43 | }, |
| 44 | [open] |
| 45 | ); |
| 46 | return ( |
| 47 | <Modal open={open} close={close}> |
| 48 | <h3 className={styles.header}>{title || 'Confirmation'}</h3> |
| 49 | <p className={styles.description}>{description || 'Are you sure?'}</p> |
| 50 | <div className={styles.buttons}> |
| 51 | <Button |
| 52 | color="blue" |
| 53 | onClick={(event) => { |
| 54 | event.preventDefault(); |
| 55 | event.stopPropagation(); |
| 56 | onConfirm(); |
| 57 | }} |
| 58 | type="button" |
| 59 | > |
| 60 | {confirm || 'Confirm'} |
| 61 | </Button> |
| 62 | <Button color="gray" onClick={close} type="button"> |
| 63 | {cancel || 'Cancel'} |
| 64 | </Button> |
| 65 | </div> |
| 66 | </Modal> |
| 67 | ); |
| 68 | } |
nothing calls this directly
no test coverage detected