2019-10-21 11:40:24 +00:00
|
|
|
import React, { useRef, useEffect } from "react";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
import { createPortal } from "react-dom";
|
|
|
|
|
import PopperJS from "popper.js";
|
2019-11-25 05:07:27 +00:00
|
|
|
import PaneWrapper from "pages/common/PaneWrapper";
|
2019-10-21 11:40:24 +00:00
|
|
|
|
|
|
|
|
type PopperProps = {
|
|
|
|
|
isOpen: boolean;
|
2020-01-02 12:42:02 +00:00
|
|
|
targetNode?: Element;
|
2019-10-21 11:40:24 +00:00
|
|
|
children: JSX.Element;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const PopperWrapper = styled(PaneWrapper)`
|
|
|
|
|
position: absolute;
|
|
|
|
|
z-index: 1;
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
max-height: ${props => props.theme.propertyPane.height}px;
|
2019-10-21 11:40:24 +00:00
|
|
|
width: ${props => props.theme.propertyPane.width}px;
|
|
|
|
|
margin: ${props => props.theme.spaces[6]}px;
|
2019-12-10 13:30:16 +00:00
|
|
|
overflow-y: auto;
|
2019-10-21 11:40:24 +00:00
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
/* eslint-disable react/display-name */
|
|
|
|
|
export default (props: PopperProps) => {
|
|
|
|
|
const contentRef = useRef(null);
|
|
|
|
|
useEffect(() => {
|
2020-01-02 12:42:02 +00:00
|
|
|
const parentElement = props.targetNode && props.targetNode.parentElement;
|
2019-12-27 10:10:04 +00:00
|
|
|
if (
|
|
|
|
|
parentElement &&
|
|
|
|
|
parentElement.parentElement &&
|
2020-01-02 12:42:02 +00:00
|
|
|
props.targetNode &&
|
2019-12-27 10:10:04 +00:00
|
|
|
props.isOpen
|
|
|
|
|
) {
|
2020-01-07 12:28:58 +00:00
|
|
|
const _popper = new PopperJS(
|
2020-01-02 12:42:02 +00:00
|
|
|
props.targetNode,
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
(contentRef.current as unknown) as Element,
|
|
|
|
|
{
|
|
|
|
|
placement: "right-start",
|
|
|
|
|
modifiers: {
|
|
|
|
|
flip: {
|
|
|
|
|
behavior: ["right", "left", "bottom", "top"],
|
|
|
|
|
},
|
|
|
|
|
keepTogether: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
|
|
|
|
arrow: {
|
|
|
|
|
enabled: false,
|
|
|
|
|
},
|
2019-10-21 11:40:24 +00:00
|
|
|
},
|
|
|
|
|
},
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
);
|
2020-01-07 12:28:58 +00:00
|
|
|
_popper.disableEventListeners();
|
|
|
|
|
return () => {
|
|
|
|
|
_popper.destroy();
|
|
|
|
|
};
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
}
|
2020-01-02 12:42:02 +00:00
|
|
|
}, [props.targetNode, props.isOpen]);
|
2019-10-21 11:40:24 +00:00
|
|
|
return createPortal(
|
|
|
|
|
<PopperWrapper ref={contentRef}>{props.children}</PopperWrapper>,
|
|
|
|
|
document.body,
|
|
|
|
|
);
|
|
|
|
|
};
|