UNPKG

1.08 kBJSXView Raw
1/*
2 * <Alert
3 * className=string
4 * alertType=required string ["default", "success", "warning", "error"]
5 * alertText=required string
6 * boldText=string
7 * >
8 */
9
10var React = require("react");
11var PropTypes = React.PropTypes;
12
13var Alert = React.createClass({
14
15 propTypes: {
16 alertType: PropTypes.string.isRequired,
17 alertText: PropTypes.string.isRequired,
18 className: PropTypes.string,
19 boldText: PropTypes.string,
20 onClick: PropTypes.func
21 },
22
23 getDefaultProps: function() {
24 return {
25 altertType: "default",
26 boldText: "",
27 alertText: "Hello!"
28 };
29 },
30
31 render: function() {
32 var alertTypeClass = "cb-alert-" + this.props.alertType;
33 var boldText;
34 if (this.props.boldText) {
35 boldText = <strong>{this.props.boldText + " "}</strong>;
36 }
37
38 if( typeof(this.props.onClick) === 'undefined' ){
39 this.props.onClick = null;
40 }
41
42 return (
43 <div className={["cb-alert", alertTypeClass].join(" ")} onClick={this.props.onClick} >
44 <p className="cb-alert-text">
45 {boldText}
46 {this.props.alertText}
47 </p>
48 </div>
49 );
50 }
51});
52
53module.exports = Alert;