UNPKG

1.26 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5exports.__esModule = true;
6exports["default"] = void 0;
7
8var _propTypes = _interopRequireDefault(require("prop-types"));
9
10var _reactDom = _interopRequireDefault(require("react-dom"));
11
12var _react = _interopRequireDefault(require("react"));
13
14var _useWaitForDOMRef = _interopRequireDefault(require("./useWaitForDOMRef"));
15
16var propTypes = {
17 /**
18 * A DOM element, Ref to an element, or function that returns either. The `container` will have the Portal children
19 * appended to it.
20 */
21 container: _propTypes["default"].any,
22 onRendered: _propTypes["default"].func
23};
24
25/**
26 * @public
27 */
28var Portal = function Portal(_ref) {
29 var container = _ref.container,
30 children = _ref.children,
31 onRendered = _ref.onRendered;
32 var resolvedContainer = (0, _useWaitForDOMRef["default"])(container, onRendered);
33 return resolvedContainer ? /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_reactDom["default"].createPortal(children, resolvedContainer)) : null;
34};
35
36Portal.displayName = 'Portal';
37Portal.propTypes = propTypes;
38var _default = Portal;
39exports["default"] = _default;
40module.exports = exports.default;
\No newline at end of file