-
Notifications
You must be signed in to change notification settings - Fork 246
/
Copy pathAlert.jsx
68 lines (61 loc) · 1.43 KB
/
Alert.jsx
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
import React from 'react';
import PropTypes from 'prop-types';
import { Alert as ParagonAlert } from '@openedx/paragon';
import { CheckCircle, Info, WarningFilled } from '@openedx/paragon/icons';
import { ALERT_TYPES } from './UserMessagesProvider';
function getAlertVariant(type) {
switch (type) {
case ALERT_TYPES.ERROR:
return 'warning';
case ALERT_TYPES.DANGER:
return 'danger';
case ALERT_TYPES.SUCCESS:
return 'success';
default:
return 'info';
}
}
function getAlertIcon(type) {
switch (type) {
case ALERT_TYPES.ERROR:
return WarningFilled;
case ALERT_TYPES.SUCCESS:
return CheckCircle;
default:
return Info;
}
}
const Alert = ({
type, dismissible, children, onDismiss, stacked,
}) => (
<ParagonAlert
data-testid={`alert-container-${type}`}
variant={getAlertVariant(type)}
icon={getAlertIcon(type)}
dismissible={dismissible}
onClose={onDismiss}
stacked={stacked}
className={`alert-container-${type}`}
>
{children}
</ParagonAlert>
);
Alert.propTypes = {
type: PropTypes.oneOf([
ALERT_TYPES.ERROR,
ALERT_TYPES.DANGER,
ALERT_TYPES.INFO,
ALERT_TYPES.SUCCESS,
]).isRequired,
dismissible: PropTypes.bool,
children: PropTypes.node,
onDismiss: PropTypes.func,
stacked: PropTypes.bool,
};
Alert.defaultProps = {
dismissible: false,
children: undefined,
onDismiss: null,
stacked: false,
};
export default Alert;