|
| 1 | +import styled from "styled-components"; |
| 2 | +import { ResizableBox, ResizeCallbackData } from "react-resizable"; |
| 3 | +import { Layers } from "../../constants/Layers"; |
| 4 | +import { BottomResComp } from "../../types/bottomRes"; |
| 5 | +import * as React from "react"; |
| 6 | +import { useState } from "react"; |
| 7 | +import { HeaderWrapper, useResultPanel } from "./index"; |
| 8 | + |
| 9 | +const StyledResizableBox = styled(ResizableBox)` |
| 10 | + position: absolute; |
| 11 | + box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1); |
| 12 | + border-top: 1px solid #e1e3eb; |
| 13 | + z-index: ${Layers.queryResultPanel}; |
| 14 | + width: 100%; |
| 15 | + bottom: 0; |
| 16 | + left: 0; |
| 17 | + border-top-left-radius: 8px; |
| 18 | + border-top-right-radius: 8px; |
| 19 | +
|
| 20 | + .react-resizable-handle { |
| 21 | + position: absolute; |
| 22 | + border-top: transparent solid 3px; |
| 23 | + width: 100%; |
| 24 | + padding: 0 3px 3px 0; |
| 25 | + top: 0; |
| 26 | + cursor: row-resize; |
| 27 | + } |
| 28 | +`; |
| 29 | +const QueryLibraryResultWrapper = styled.div` |
| 30 | + display: flex; |
| 31 | + flex-direction: column; |
| 32 | + height: 100%; |
| 33 | + width: 100%; |
| 34 | + border-top-left-radius: 8px; |
| 35 | + border-top-right-radius: 8px; |
| 36 | +`; |
| 37 | +const preventDefault = (e: any) => { |
| 38 | + e.preventDefault(); |
| 39 | +}; |
| 40 | +const addListener = () => { |
| 41 | + window.addEventListener("mousedown", preventDefault); |
| 42 | +}; |
| 43 | +const removeListener = () => { |
| 44 | + window.removeEventListener("mousedown", preventDefault); |
| 45 | +}; |
| 46 | +export const QueryLibraryResultPanel = (props: { comp: BottomResComp; onClose: () => void }) => { |
| 47 | + const result = props.comp?.result(); |
| 48 | + const [bottomHeight, setBottomHeight] = useState(360); |
| 49 | + |
| 50 | + const { header, body } = useResultPanel({ |
| 51 | + ...(result ?? { data: "", dataType: "default", success: true }), |
| 52 | + onClose: props.onClose, |
| 53 | + }); |
| 54 | + |
| 55 | + if (!result) { |
| 56 | + return null; |
| 57 | + } |
| 58 | + |
| 59 | + const clientHeight = document.documentElement.clientHeight; |
| 60 | + const resizeStop = (e: React.SyntheticEvent, data: ResizeCallbackData) => { |
| 61 | + setBottomHeight(data.size.height); |
| 62 | + removeListener(); |
| 63 | + }; |
| 64 | + |
| 65 | + return ( |
| 66 | + <StyledResizableBox |
| 67 | + width={Infinity} |
| 68 | + height={bottomHeight} |
| 69 | + resizeHandles={["n"]} |
| 70 | + minConstraints={[680, 285]} |
| 71 | + maxConstraints={[Infinity, clientHeight - 48 - 95]} |
| 72 | + onResizeStart={addListener} |
| 73 | + onResizeStop={resizeStop} |
| 74 | + > |
| 75 | + <QueryLibraryResultWrapper> |
| 76 | + <HeaderWrapper style={{ cursor: "default" }}>{header}</HeaderWrapper> |
| 77 | + {body} |
| 78 | + </QueryLibraryResultWrapper> |
| 79 | + </StyledResizableBox> |
| 80 | + ); |
| 81 | +}; |
0 commit comments