-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathalert-dialog.tsx
53 lines (49 loc) · 1.6 KB
/
alert-dialog.tsx
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
import React, { FC, useRef } from 'react'
import classNames from 'classnames'
import { DialogBaseProps, DialogBaseWithState, EbayDialogFooter } from '../ebay-dialog-base'
import { EbayButton } from '../ebay-button'
const classPrefix = 'alert-dialog'
export interface Props<T = any> extends DialogBaseProps<T> {
open?: boolean;
confirmText: string;
onConfirm?: () => void;
}
const EbayAlertDialog: FC<Props> = ({
a11yCloseText = 'Close Dialog',
confirmText,
onConfirm = () => {},
...rest
}) => {
const confirmBtnRef = useRef(null)
const confirmId = 'alert-dialog-confirm'
const mainId = 'alert-dialog-main'
return (
<DialogBaseWithState
focus={confirmBtnRef}
{...rest}
a11yCloseText={a11yCloseText}
role="alertdialog"
classPrefix={classPrefix}
ignoreEscape
mainId={mainId}
buttonPosition="hidden"
className={classNames(rest.className, `${classPrefix}--mask-fade`)}
windowClass={`${classPrefix}__window ${classPrefix}__window--fade`}
>
{rest.children}
<EbayDialogFooter>
<EbayButton
priority="primary"
aria-describedby={mainId}
onClick={onConfirm}
ref={confirmBtnRef}
id={confirmId}
className="alert-dialog__acknowledge"
>
{confirmText}
</EbayButton>
</EbayDialogFooter>
</DialogBaseWithState>
)
}
export default EbayAlertDialog