-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathAlert.jsx
More file actions
41 lines (33 loc) · 1.07 KB
/
Alert.jsx
File metadata and controls
41 lines (33 loc) · 1.07 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
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));