| 17 | } |
| 18 | |
| 19 | export function AlertDialog({ |
| 20 | title, |
| 21 | variant, |
| 22 | cancelLabel, |
| 23 | actionLabel, |
| 24 | onAction, |
| 25 | children, |
| 26 | ...props |
| 27 | }: AlertDialogProps) { |
| 28 | return ( |
| 29 | <Dialog role="alertdialog" {...props}> |
| 30 | {({close}) => ( |
| 31 | <> |
| 32 | <Heading slot="title" className="text-xl font-semibold leading-6 my-0"> |
| 33 | {title} |
| 34 | </Heading> |
| 35 | <div |
| 36 | className={`w-6 h-6 absolute right-6 top-6 stroke-2 ${variant === 'destructive' ? 'text-red-500' : 'text-blue-500'}`}> |
| 37 | {variant === 'destructive' ? <AlertCircleIcon aria-hidden /> : <InfoIcon aria-hidden />} |
| 38 | </div> |
| 39 | <p className="mt-3 text-neutral-500 dark:text-neutral-400">{children}</p> |
| 40 | <div className="mt-6 flex justify-end gap-2"> |
| 41 | <Button variant="secondary" onPress={close}> |
| 42 | {cancelLabel || 'Cancel'} |
| 43 | </Button> |
| 44 | <Button |
| 45 | variant={variant === 'destructive' ? 'destructive' : 'primary'} |
| 46 | autoFocus |
| 47 | onPress={chain(onAction, close)}> |
| 48 | {actionLabel} |
| 49 | </Button> |
| 50 | </div> |
| 51 | </> |
| 52 | )} |
| 53 | </Dialog> |
| 54 | ); |
| 55 | } |