-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathAlert.js
More file actions
55 lines (47 loc) · 1.16 KB
/
Alert.js
File metadata and controls
55 lines (47 loc) · 1.16 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
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import {
bsClass,
bsStyles,
getClassSet,
prefix,
splitBsProps
} from './utils/bootstrapUtils';
import { State } from './utils/StyleConfig';
import CloseButton from './CloseButton';
const propTypes = {
onDismiss: PropTypes.func,
closeLabel: PropTypes.string
};
const defaultProps = {
closeLabel: 'Close alert'
};
class Alert extends React.Component {
render() {
const { onDismiss, closeLabel, className, children, ...props } = this.props;
const [bsProps, elementProps] = splitBsProps(props);
const dismissable = !!onDismiss;
const classes = {
...getClassSet(bsProps),
[prefix(bsProps, 'dismissable')]: dismissable
};
return (
<div
{...elementProps}
role="alert"
className={classNames(className, classes)}
>
{dismissable && <CloseButton onClick={onDismiss} label={closeLabel} />}
{children}
</div>
);
}
}
Alert.propTypes = propTypes;
Alert.defaultProps = defaultProps;
export default bsStyles(
Object.values(State),
State.INFO,
bsClass('alert', Alert)
);