1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | var React = require("react");
|
11 | var PropTypes = React.PropTypes;
|
12 |
|
13 | var 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 |
|
53 | module.exports = Alert;
|