Last active
January 9, 2021 16:12
-
-
Save ryanflorence/ac5174cf97dd596e949c to your computer and use it in GitHub Desktop.
React Portal.js
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
var Dialog = React.createClass({ | |
mixins: [Portal], | |
createPortal: function() { | |
this.dialog = $(this.portalNode).dialog({ | |
autoOpen: false, | |
title: this.props.title, | |
close: this.props.onClose | |
}).data('ui-dialog'); | |
}, | |
portalWillReceiveProps: function(props) { | |
if (props.open) | |
this.dialog.open(); | |
else | |
this.dialog.close(); | |
}, | |
componentWillUnmount: function() { | |
this.dialog.destroy(); | |
} | |
}); |
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
var Portal = { | |
render: function() { | |
return React.DOM.div(); | |
}, | |
componentDidMount: function() { | |
this.portalNode = this.getDOMNode(); | |
this.createPortal(); | |
this._renderPortal(this.props); | |
}, | |
componentWillReceiveProps: function(newProps) { | |
this._renderPortal(newProps); | |
}, | |
_renderPortal: function(props) { | |
React.renderComponent(React.DOM.div({}, props.children), this.portalNode); | |
this.portalWillReceiveProps(props); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment