Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Portal.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  2. import PropTypes from 'prop-types';
  3. import componentOrElement from 'prop-types-extra/lib/componentOrElement';
  4. import React from 'react';
  5. import ReactDOM from 'react-dom';
  6. import WaitForContainer from './WaitForContainer';
  7. /**
  8. * The `<Portal/>` component renders its children into a new "subtree" outside of current component hierarchy.
  9. * You can think of it as a declarative `appendChild()`, or jQuery's `$.fn.appendTo()`.
  10. * The children of `<Portal/>` component will be appended to the `container` specified.
  11. */
  12. var Portal =
  13. /*#__PURE__*/
  14. function (_React$Component) {
  15. _inheritsLoose(Portal, _React$Component);
  16. function Portal() {
  17. return _React$Component.apply(this, arguments) || this;
  18. }
  19. var _proto = Portal.prototype;
  20. _proto.render = function render() {
  21. var _this = this;
  22. return this.props.children ? React.createElement(WaitForContainer, {
  23. container: this.props.container,
  24. onContainerResolved: this.props.onRendered
  25. }, function (container) {
  26. return ReactDOM.createPortal(_this.props.children, container);
  27. }) : null;
  28. };
  29. return Portal;
  30. }(React.Component);
  31. Portal.displayName = 'Portal';
  32. Portal.propTypes = {
  33. /**
  34. * A Node, Component instance, or function that returns either. The `container` will have the Portal children
  35. * appended to it.
  36. */
  37. container: PropTypes.oneOfType([componentOrElement, PropTypes.func]),
  38. onRendered: PropTypes.func
  39. };
  40. export default Portal;