Parcourir la source

Rename BodyPortal to Portal and accept prop "root" which is where the portal should be placed

Johannes Schill il y a 7 ans
Parent
commit
7d6db12f34

+ 10 - 3
public/app/core/components/Portal/BodyPortal.tsx → public/app/core/components/Portal/Portal.tsx

@@ -3,18 +3,25 @@ import ReactDOM from 'react-dom';
 
 
 interface Props {
 interface Props {
   className?: string;
   className?: string;
+  root?: HTMLElement;
 }
 }
 
 
 export default class BodyPortal extends PureComponent<Props> {
 export default class BodyPortal extends PureComponent<Props> {
   node: HTMLElement = document.createElement('div');
   node: HTMLElement = document.createElement('div');
-  portalRoot = document.body;
+  portalRoot: HTMLElement;
 
 
   constructor(props) {
   constructor(props) {
     super(props);
     super(props);
-    const { className } = this.props;
+    const {
+      className,
+      root = document.body
+    } = this.props;
+
     if (className) {
     if (className) {
-      this.node.classList.add();
+      this.node.classList.add(className);
     }
     }
+
+    this.portalRoot = root;
     this.portalRoot.appendChild(this.node);
     this.portalRoot.appendChild(this.node);
   }
   }
 
 

+ 3 - 3
public/app/core/components/Tooltip/Popper.tsx

@@ -1,5 +1,5 @@
 import React, { PureComponent } from 'react';
 import React, { PureComponent } from 'react';
-import BodyPortal from 'app/core/components/Portal/BodyPortal';
+import Portal from 'app/core/components/Portal/Portal';
 import { Manager, Popper as ReactPopper, Reference } from 'react-popper';
 import { Manager, Popper as ReactPopper, Reference } from 'react-popper';
 import Transition from 'react-transition-group/Transition';
 import Transition from 'react-transition-group/Transition';
 
 
@@ -39,7 +39,7 @@ class Popper extends PureComponent<Props> {
         </Reference>
         </Reference>
         <Transition in={show} timeout={100} mountOnEnter={true} unmountOnExit={true}>
         <Transition in={show} timeout={100} mountOnEnter={true} unmountOnExit={true}>
           {transitionState => (
           {transitionState => (
-            <BodyPortal className="hej">
+            <Portal>
               <ReactPopper placement={placement}>
               <ReactPopper placement={placement}>
                 {({ ref, style, placement, arrowProps }) => {
                 {({ ref, style, placement, arrowProps }) => {
                   return (
                   return (
@@ -61,7 +61,7 @@ class Popper extends PureComponent<Props> {
                   );
                   );
                 }}
                 }}
               </ReactPopper>
               </ReactPopper>
-            </BodyPortal>
+            </Portal>
           )}
           )}
         </Transition>
         </Transition>
       </Manager>
       </Manager>