1 | var React = require('react');
|
2 |
|
3 | var SkyLight = React.createClass({
|
4 |
|
5 | propTypes: {
|
6 | title: React.PropTypes.string,
|
7 | showOverlay: React.PropTypes.bool,
|
8 | onShow: React.PropTypes.func,
|
9 | onClose: React.PropTypes.func,
|
10 | visible: React.PropTypes.bool
|
11 | },
|
12 |
|
13 |
|
14 | getDefaultProps: function() {
|
15 | return {
|
16 | title: '',
|
17 | showOverlay: true
|
18 | }
|
19 | },
|
20 |
|
21 | getInitialState: function(){
|
22 | return {
|
23 | isVisible: false
|
24 | };
|
25 | },
|
26 |
|
27 | show: function() {
|
28 | this.setState({ isVisible: true });
|
29 | if(this.props.onShow) {
|
30 | this.props.onShow();
|
31 | }
|
32 | },
|
33 |
|
34 | hide: function() {
|
35 | this.setState({ isVisible: false });
|
36 | if(this.props.onClose) {
|
37 | this.props.onClose();
|
38 | }
|
39 | },
|
40 |
|
41 | render: function(){
|
42 |
|
43 | var overlay;
|
44 | var displayStyle = this.state.isVisible ? {display: 'block'} : {display: 'none'};
|
45 |
|
46 | if(this.props.showOverlay) {
|
47 | overlay = (<div className="skylight-dialog__overlay" style={displayStyle}></div>);
|
48 | }
|
49 |
|
50 | return (
|
51 | <section className="skylight-wrapper">
|
52 | {overlay}
|
53 | <div className="skylight-dialog" style={displayStyle}>
|
54 | <a role="button" className="skylight-dialog--close" onClick={this.hide}>×</a>
|
55 | <h2>{this.props.title}</h2>
|
56 | {this.props.children}
|
57 | </div>
|
58 | </section>
|
59 | )
|
60 | }
|
61 | });
|
62 |
|
63 | module.exports = SkyLight;
|