Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

89 rindas
4.3 KiB

  1. function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  2. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  3. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  4. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  5. function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  6. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  7. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  8. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  9. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  10. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  11. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  12. import React from 'react';
  13. import ReactDOM from 'react-dom';
  14. import PropTypes from 'prop-types';
  15. var Portal = /*#__PURE__*/function (_React$Component) {
  16. _inherits(Portal, _React$Component);
  17. var _super = _createSuper(Portal);
  18. function Portal() {
  19. _classCallCheck(this, Portal);
  20. return _super.apply(this, arguments);
  21. }
  22. _createClass(Portal, [{
  23. key: "componentDidMount",
  24. value: function componentDidMount() {
  25. this.createContainer();
  26. }
  27. }, {
  28. key: "componentDidUpdate",
  29. value: function componentDidUpdate(prevProps) {
  30. var didUpdate = this.props.didUpdate;
  31. if (didUpdate) {
  32. didUpdate(prevProps);
  33. }
  34. }
  35. }, {
  36. key: "componentWillUnmount",
  37. value: function componentWillUnmount() {
  38. this.removeContainer();
  39. }
  40. }, {
  41. key: "createContainer",
  42. value: function createContainer() {
  43. this._container = this.props.getContainer();
  44. this.forceUpdate();
  45. }
  46. }, {
  47. key: "removeContainer",
  48. value: function removeContainer() {
  49. if (this._container) {
  50. this._container.parentNode.removeChild(this._container);
  51. }
  52. }
  53. }, {
  54. key: "render",
  55. value: function render() {
  56. if (this._container) {
  57. return ReactDOM.createPortal(this.props.children, this._container);
  58. }
  59. return null;
  60. }
  61. }]);
  62. return Portal;
  63. }(React.Component);
  64. Portal.propTypes = {
  65. getContainer: PropTypes.func.isRequired,
  66. children: PropTypes.node.isRequired,
  67. didUpdate: PropTypes.func
  68. };
  69. export { Portal as default };