Skip to content

Instantly share code, notes, and snippets.

@esamattis
Last active February 6, 2017 19:05
Show Gist options
  • Save esamattis/9887246 to your computer and use it in GitHub Desktop.
Save esamattis/9887246 to your computer and use it in GitHub Desktop.
Lightbox.displayComponent(
<div>
<h1>hello</h1>
<button onClick={Lightbox.removeCurrentComponent}>close</button>
</div>
);
/** @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