-
Notifications
You must be signed in to change notification settings - Fork 86
Expand file tree
/
Copy pathNotification.js
More file actions
105 lines (90 loc) · 2.54 KB
/
Notification.js
File metadata and controls
105 lines (90 loc) · 2.54 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import Button from './Button';
import Icon from './Icon';
const NOTIFICATION_TYPES = ['alert', 'toast'];
const NOTIFICATION_LEVELS = [
'info',
'success',
'warning',
'error',
];
const Notification = (props) => {
const {
className, type, level, alt,
alertTexture = true,
icon, iconSize = 'small',
onClose, children, ...pprops
} = props;
const typeClassName = type && NOTIFICATION_TYPES.indexOf(type) >= 0 ?
`slds-notify--${type}` : null;
const levelClassName = type && NOTIFICATION_LEVELS.indexOf(level) >= 0 ?
`slds-theme--${level}` : null;
const alertClassNames = classnames(
className,
'slds-notify',
typeClassName,
levelClassName,
alertTexture ? 'slds-theme--alert-texture' : null
);
const iconEl = icon ? (
<Icon
className={type === 'toast' ? 'slds-m-right--small' : 'slds-m-right--x-small'}
icon={ icon }
size={ iconSize }
fillColor='none'
textColor={ level === 'warning' ? 'default' : null }
/>) :
undefined;
return (
<div className={ alertClassNames } role='alert' { ...pprops }>
{
alt ?
<span className='slds-assistive-text'>{ alt }</span> :
undefined
}
{
onClose ?
<Button
className='slds-notify__close'
type='icon-inverse'
icon='close'
iconSize={type === 'toast' ? 'large' : 'small'}
alt='Close'
onClick={ onClose }
/> :
undefined
}
{type === 'toast' ?
<div className='slds-notify__content slds-grid'>
{iconEl}
<div className='slds-col slds-align-middle'>
<h2 className='slds-text-heading--small'>{ children }</h2>
</div>
</div> :
<h2>
{iconEl}
{ children }
</h2>
}
</div>
);
};
Notification.propTypes = {
type: PropTypes.oneOf(NOTIFICATION_TYPES).isRequired,
className: PropTypes.string,
level: PropTypes.oneOf(NOTIFICATION_LEVELS),
alt: PropTypes.string,
icon: PropTypes.string,
iconSize: PropTypes.string,
children: PropTypes.node,
onClose: PropTypes.func,
};
export default Notification;
const propTypes = { ...Notification.propTypes };
delete propTypes.type;
export const Alert = props => <Notification { ...props } type='alert' />;
Alert.propTypes = propTypes;
export const Toast = props => <Notification { ...props } type='toast' />;
Toast.propTypes = propTypes;