Last active
February 6, 2017 19:05
-
-
Save esamattis/9887246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Lightbox.displayComponent( | |
<div> | |
<h1>hello</h1> | |
<button onClick={Lightbox.removeCurrentComponent}>close</button> | |
</div> | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @jsx React.DOM */ | |
var React = require("react"); | |
var Lightbox = React.createClass({ | |
render: function() { | |
return ( | |
<div> | |
<div className="lightbox-bg"></div> | |
<div className="lightbox"> | |
<div className="lightbox-wrap"> | |
{this.props.children} | |
</div> | |
</div> | |
</div> | |
); | |
} | |
}); | |
Lightbox.currentComponent = null; | |
// TODO: create if missing | |
Lightbox.container = document.getElementById("lightbox-container"); | |
Lightbox.displayComponent = function (component) { | |
if (Lightbox.currentComponent) Lightbox.removeCurrentComponent(); | |
Lightbox.currentComponent = component; | |
React.renderComponent( | |
<Lightbox>{component}</Lightbox>, | |
Lightbox.container | |
); | |
}; | |
Lightbox.removeCurrentComponent = function() { | |
if (!Lightbox.currentComponent) return; | |
React.unmountComponentAtNode(Lightbox.container); | |
Lightbox.currentComponent = null; | |
}; | |
module.exports = Lightbox; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment