forked from react-bootstrap/react-bootstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlert.js
More file actions
74 lines (64 loc) · 1.61 KB
/
Copy pathAlert.js
File metadata and controls
74 lines (64 loc) · 1.61 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
import classNames from 'classnames';
import React from 'react';
import { bsClass, bsStyles, getClassSet, prefix, splitBsProps }
from './utils/bootstrapUtils';
import { State } from './utils/StyleConfig';
const propTypes = {
onDismiss: React.PropTypes.func,
closeLabel: React.PropTypes.string,
};
const defaultProps = {
closeLabel: 'Close alert',
};
class Alert extends React.Component {
renderDismissButton(onDismiss) {
return (
<button
type="button"
className="close"
onClick={onDismiss}
aria-hidden="true"
tabIndex="-1"
>
<span>×</span>
</button>
);
}
renderSrOnlyDismissButton(onDismiss, closeLabel) {
return (
<button
type="button"
className="close sr-only"
onClick={onDismiss}
>
{closeLabel}
</button>
);
}
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 && this.renderDismissButton(onDismiss)}
{children}
{dismissable && this.renderSrOnlyDismissButton(onDismiss, closeLabel)}
</div>
);
}
}
Alert.propTypes = propTypes;
Alert.defaultProps = defaultProps;
export default bsStyles(Object.values(State), State.INFO,
bsClass('alert', Alert)
);