-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAlert.tsx
More file actions
81 lines (78 loc) · 3.1 KB
/
Alert.tsx
File metadata and controls
81 lines (78 loc) · 3.1 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
79
80
81
import cx from 'classnames';
import Button from '../Button';
import { ButtonVariant } from '../Button/types';
import Icon from '../Icon';
import useCoreContext from '../../../core/Context/useCoreContext';
import { TypographyElement, TypographyVariant } from '../Typography/types';
import Typography from '../Typography/Typography';
import { AlertIcon } from './AlertIcon';
import { AlertProps, AlertVariantOption } from './types';
import './Alert.scss';
//TODO: Revisit the closeButton prop which is adopted from Bento component
export const Alert = ({
className,
description,
closeButton,
title,
type,
children,
onClose,
actions,
variant = AlertVariantOption.DEFAULT,
'data-testid': dataTestId,
}: AlertProps) => {
const { i18n } = useCoreContext();
const hasActions = !!actions?.length;
const shouldShowCloseButton = onClose && (variant !== AlertVariantOption.TIP || closeButton);
return (
<div
data-testid={dataTestId}
className={cx('adyen-pe-alert', `adyen-pe-alert--${type}`, `adyen-pe-alert--${variant}`, className)}
role="alert"
>
<AlertIcon type={type} className="adyen-pe-alert__icon" />
<div className="adyen-pe-alert__content-container">
<div className="adyen-pe-alert__content">
{title && variant !== AlertVariantOption.TIP && (
<Typography className={'adyen-pe-alert__title'} el={TypographyElement.DIV} variant={TypographyVariant.BODY} wide strongest>
{title}
</Typography>
)}
{description && (
<Typography
className={'adyen-pe-alert__description'}
el={TypographyElement.DIV}
variant={variant === AlertVariantOption.TIP ? TypographyVariant.CAPTION : TypographyVariant.BODY}
wide
>
{description}
</Typography>
)}
{children}
</div>
{hasActions && (
<div className="adyen-pe-alert__actions">
{actions?.map((action, index) => (
<Button key={index} onClick={action.onClick} variant={ButtonVariant.TERTIARY}>
{action.label}
</Button>
))}
</div>
)}
</div>
{shouldShowCloseButton && (
<div className="adyen-pe-alert__close-button">
<Button
iconButton
variant={ButtonVariant.TERTIARY}
onClick={onClose}
aria-label={i18n.get('common.actions.dismiss.labels.dismiss')}
>
<Icon name="cross" />
</Button>
</div>
)}
</div>
);
};
export default Alert;