Skip to content

Commit f23606e

Browse files
committed
doest render if hidden, fixes #1
1 parent 8a07276 commit f23606e

5 files changed

Lines changed: 37 additions & 34 deletions

File tree

build/simple-modal.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@ var _react = require('react');
2020

2121
var _react2 = _interopRequireDefault(_react);
2222

23-
var Slug = (function (_React$Component) {
24-
_inherits(Slug, _React$Component);
23+
var Modal = (function (_React$Component) {
24+
_inherits(Modal, _React$Component);
2525

26-
function Slug(props) {
27-
_classCallCheck(this, Slug);
26+
function Modal(props) {
27+
_classCallCheck(this, Modal);
2828

29-
_get(Object.getPrototypeOf(Slug.prototype), 'constructor', this).call(this);
29+
_get(Object.getPrototypeOf(Modal.prototype), 'constructor', this).call(this);
3030
var closeOnOuterClick = true;
3131
if (props.closeOnOuterClick === false) closeOnOuterClick = false;
3232

3333
this.state = {
34-
display: 'none',
34+
display: false,
3535
closeOnOuterClick: closeOnOuterClick
3636
};
3737
this.hide = this.hide.bind(this);
3838
this.hideOnOuterClick = this.hideOnOuterClick.bind(this);
3939
}
4040

41-
_createClass(Slug, [{
41+
_createClass(Modal, [{
4242
key: 'hideOnOuterClick',
4343
value: function hideOnOuterClick(event) {
4444
if (!this.state.closeOnOuterClick) return;
@@ -48,30 +48,31 @@ var Slug = (function (_React$Component) {
4848
}, {
4949
key: 'hide',
5050
value: function hide() {
51-
this.setState({ display: 'none' });
51+
this.setState({ display: false });
5252
}
5353
}, {
5454
key: 'show',
5555
value: function show() {
56-
this.setState({ display: 'block' });
56+
this.setState({ display: true });
5757
}
5858
}, {
5959
key: 'render',
6060
value: function render() {
61+
if (!this.state.display) return null;
6162
return _react2['default'].createElement(
6263
'div',
63-
_extends({ style: this.state }, this.props, { onClick: this.hideOnOuterClick, 'data-modal': "true" }),
64+
_extends({}, this.props, { onClick: this.hideOnOuterClick, 'data-modal': "true" }),
6465
_react2['default'].createElement(
6566
'div',
66-
{ style: this.state },
67+
null,
6768
this.props.children
6869
)
6970
);
7071
}
7172
}]);
7273

73-
return Slug;
74+
return Modal;
7475
})(_react2['default'].Component);
7576

76-
exports['default'] = Slug;
77+
exports['default'] = Modal;
7778
module.exports = exports['default'];

dist/simple-react-modal.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,25 +22,25 @@ var _react = (typeof window !== "undefined" ? window['React'] : typeof global !=
2222

2323
var _react2 = _interopRequireDefault(_react);
2424

25-
var Slug = (function (_React$Component) {
26-
_inherits(Slug, _React$Component);
25+
var Modal = (function (_React$Component) {
26+
_inherits(Modal, _React$Component);
2727

28-
function Slug(props) {
29-
_classCallCheck(this, Slug);
28+
function Modal(props) {
29+
_classCallCheck(this, Modal);
3030

31-
_get(Object.getPrototypeOf(Slug.prototype), 'constructor', this).call(this);
31+
_get(Object.getPrototypeOf(Modal.prototype), 'constructor', this).call(this);
3232
var closeOnOuterClick = true;
3333
if (props.closeOnOuterClick === false) closeOnOuterClick = false;
3434

3535
this.state = {
36-
display: 'none',
36+
display: false,
3737
closeOnOuterClick: closeOnOuterClick
3838
};
3939
this.hide = this.hide.bind(this);
4040
this.hideOnOuterClick = this.hideOnOuterClick.bind(this);
4141
}
4242

43-
_createClass(Slug, [{
43+
_createClass(Modal, [{
4444
key: 'hideOnOuterClick',
4545
value: function hideOnOuterClick(event) {
4646
if (!this.state.closeOnOuterClick) return;
@@ -50,32 +50,33 @@ var Slug = (function (_React$Component) {
5050
}, {
5151
key: 'hide',
5252
value: function hide() {
53-
this.setState({ display: 'none' });
53+
this.setState({ display: false });
5454
}
5555
}, {
5656
key: 'show',
5757
value: function show() {
58-
this.setState({ display: 'block' });
58+
this.setState({ display: true });
5959
}
6060
}, {
6161
key: 'render',
6262
value: function render() {
63+
if (!this.state.display) return null;
6364
return _react2['default'].createElement(
6465
'div',
65-
_extends({ style: this.state }, this.props, { onClick: this.hideOnOuterClick, 'data-modal': "true" }),
66+
_extends({}, this.props, { onClick: this.hideOnOuterClick, 'data-modal': "true" }),
6667
_react2['default'].createElement(
6768
'div',
68-
{ style: this.state },
69+
null,
6970
this.props.children
7071
)
7172
);
7273
}
7374
}]);
7475

75-
return Slug;
76+
return Modal;
7677
})(_react2['default'].Component);
7778

78-
exports['default'] = Slug;
79+
exports['default'] = Modal;
7980
module.exports = exports['default'];
8081

8182
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})

dist/simple-react-modal.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "simple-react-modal",
33
"description": "The simplest modal",
4-
"version": "0.0.1",
4+
"version": "0.0.2",
55
"main": "./build/simple-modal.js",
66
"directories": {
77
"example": "example"

src/simple-modal.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import React from 'react'
22

3-
export default class Slug extends React.Component{
3+
export default class Modal extends React.Component{
44

55
constructor(props){
66
super()
77
let closeOnOuterClick = true
88
if(props.closeOnOuterClick === false) closeOnOuterClick = false
99

1010
this.state = {
11-
display: 'none',
11+
display: false,
1212
closeOnOuterClick
1313
}
1414
this.hide = this.hide.bind(this)
@@ -22,17 +22,18 @@ export default class Slug extends React.Component{
2222
}
2323

2424
hide(){
25-
this.setState({display: 'none'})
25+
this.setState({display: false})
2626
}
2727

2828
show(){
29-
this.setState({display: 'block'})
29+
this.setState({display: true})
3030
}
3131

3232
render(){
33+
if(!this.state.display) return null
3334
return (
34-
<div style={this.state} {...this.props} onClick={this.hideOnOuterClick} data-modal="true">
35-
<div style={this.state}>
35+
<div {...this.props} onClick={this.hideOnOuterClick} data-modal="true">
36+
<div>
3637
{this.props.children}
3738
</div>
3839
</div>

0 commit comments

Comments
 (0)