-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathConfirmationDialog.tsx
More file actions
78 lines (72 loc) · 1.93 KB
/
Copy pathConfirmationDialog.tsx
File metadata and controls
78 lines (72 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import type React from 'react'
import { useEffect, useRef } from 'react'
import { useTranslation } from 'react-i18next'
import {
DialogActionTrigger,
DialogBody,
DialogCloseTrigger,
DialogContent,
DialogFooter,
DialogHeader,
DialogRoot,
DialogTitle,
} from '../ui/dialog'
import { BlueButton, RedButton } from './Button'
interface ConfirmationProps {
isOpen: boolean
message: string
onClose: () => void
onConfirm: () => void
}
const ConfirmationDialog: React.FC<ConfirmationProps> = ({
isOpen,
message,
onClose,
onConfirm,
}: ConfirmationProps) => {
const { t } = useTranslation()
const closeButtonRef = useRef<HTMLButtonElement>(null)
const cancelButtonRef = useRef<HTMLButtonElement>(null)
useEffect(() => {
if (isOpen && cancelButtonRef.current) {
setTimeout(() => {
cancelButtonRef.current?.focus()
}, 50)
}
}, [isOpen])
if (!isOpen) return null
return (
<DialogRoot
key="delete-collection-confirmation-dialog"
placement="center"
motionPreset="slide-in-bottom"
open={isOpen}
onOpenChange={(detail) => {
if (!detail.open) {
onClose()
}
}}
>
<DialogContent bg={'bg.50'}>
<DialogHeader>
<DialogTitle color="fg.DEFAULT">{t('components.confirmationDialog.title')}</DialogTitle>
</DialogHeader>
<DialogBody>
<p>{message}</p>
</DialogBody>
<DialogFooter>
<DialogActionTrigger asChild>
<BlueButton onClick={onClose} ref={cancelButtonRef} tabIndex={0}>
{t('general.actions.cancel')}
</BlueButton>
</DialogActionTrigger>
<RedButton onClick={onConfirm} colorPalette="red">
{t('general.actions.delete')}
</RedButton>
</DialogFooter>
<DialogCloseTrigger ref={closeButtonRef} />
</DialogContent>
</DialogRoot>
)
}
export default ConfirmationDialog