2021-05-24 17:11:46 +10:00
|
|
|
import React, { useState } from "react";
|
2021-05-28 13:13:21 +10:00
|
|
|
import { createPortal } from "react-dom";
|
2021-05-27 17:37:59 +10:00
|
|
|
import { Box, Close, Grid, useThemeUI } from "theme-ui";
|
2021-05-24 17:11:46 +10:00
|
|
|
import { useSpring, animated, config } from "react-spring";
|
|
|
|
|
import ReactResizeDetector from "react-resize-detector";
|
|
|
|
|
import SimpleBar from "simplebar-react";
|
2021-05-24 13:34:21 +10:00
|
|
|
|
|
|
|
|
import { useGroup } from "../../contexts/GroupContext";
|
2021-05-28 13:13:21 +10:00
|
|
|
import { UNGROUP_ID_PREFIX } from "../../contexts/TileDragContext";
|
|
|
|
|
|
|
|
|
|
import Droppable from "../drag/Droppable";
|
2021-05-24 13:34:21 +10:00
|
|
|
|
2021-05-27 17:19:36 +10:00
|
|
|
import useResponsiveLayout from "../../hooks/useResponsiveLayout";
|
|
|
|
|
|
|
|
|
|
function TilesOverlay({ children }) {
|
2021-05-24 17:11:46 +10:00
|
|
|
const { openGroupId, onGroupClose, onGroupSelect } = useGroup();
|
|
|
|
|
|
2021-05-27 17:37:59 +10:00
|
|
|
const { theme } = useThemeUI();
|
|
|
|
|
|
2021-05-27 17:19:36 +10:00
|
|
|
const layout = useResponsiveLayout();
|
|
|
|
|
|
2021-05-24 17:11:46 +10:00
|
|
|
const openAnimation = useSpring({
|
|
|
|
|
opacity: openGroupId ? 1 : 0,
|
2021-05-24 17:28:57 +10:00
|
|
|
transform: openGroupId ? "scale(1)" : "scale(0.99)",
|
2021-05-24 17:11:46 +10:00
|
|
|
config: config.gentle,
|
|
|
|
|
});
|
2021-05-24 13:34:21 +10:00
|
|
|
|
2021-05-24 17:11:46 +10:00
|
|
|
const [containerSize, setContinerSize] = useState(0);
|
|
|
|
|
function handleResize(width, height) {
|
|
|
|
|
const size = Math.min(width, height) - 16;
|
|
|
|
|
setContinerSize(size);
|
2021-05-24 13:34:21 +10:00
|
|
|
}
|
|
|
|
|
|
2021-05-28 13:13:21 +10:00
|
|
|
function renderUngroupBoxes() {
|
|
|
|
|
return createPortal(
|
|
|
|
|
<div>
|
|
|
|
|
<Droppable
|
|
|
|
|
id={`${UNGROUP_ID_PREFIX}-1`}
|
|
|
|
|
style={{
|
|
|
|
|
width: "100vw",
|
|
|
|
|
height: `calc(50vh - ${containerSize / 2}px)`,
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: 0,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Droppable
|
|
|
|
|
id={`${UNGROUP_ID_PREFIX}-2`}
|
|
|
|
|
style={{
|
|
|
|
|
width: "100vw",
|
|
|
|
|
height: `calc(50vh - ${containerSize / 2}px)`,
|
|
|
|
|
position: "absolute",
|
|
|
|
|
bottom: 0,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Droppable
|
|
|
|
|
id={`${UNGROUP_ID_PREFIX}-3`}
|
|
|
|
|
style={{
|
|
|
|
|
width: `calc(50vw - ${containerSize / 2}px)`,
|
|
|
|
|
height: "100vh",
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<Droppable
|
|
|
|
|
id={`${UNGROUP_ID_PREFIX}-4`}
|
|
|
|
|
style={{
|
|
|
|
|
width: `calc(50vw - ${containerSize / 2}px)`,
|
|
|
|
|
height: "100vh",
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>,
|
|
|
|
|
document.body
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-24 13:34:21 +10:00
|
|
|
return (
|
2021-05-24 17:11:46 +10:00
|
|
|
<>
|
2021-05-28 13:13:21 +10:00
|
|
|
{openGroupId && renderUngroupBoxes()}
|
2021-05-24 17:11:46 +10:00
|
|
|
{openGroupId && (
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
top: 0,
|
|
|
|
|
}}
|
|
|
|
|
bg="overlay"
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
<ReactResizeDetector handleWidth handleHeight onResize={handleResize}>
|
|
|
|
|
<animated.div
|
|
|
|
|
style={{
|
|
|
|
|
...openAnimation,
|
|
|
|
|
position: "absolute",
|
|
|
|
|
width: "100%",
|
|
|
|
|
height: "100%",
|
|
|
|
|
top: 0,
|
|
|
|
|
display: "flex",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
justifyContent: "center",
|
|
|
|
|
cursor: "pointer",
|
|
|
|
|
pointerEvents: openGroupId ? undefined : "none",
|
|
|
|
|
}}
|
|
|
|
|
onClick={() => openGroupId && onGroupClose()}
|
|
|
|
|
>
|
|
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
width: containerSize,
|
|
|
|
|
height: containerSize,
|
|
|
|
|
borderRadius: "8px",
|
|
|
|
|
border: "1px solid",
|
|
|
|
|
borderColor: "border",
|
|
|
|
|
cursor: "default",
|
|
|
|
|
display: "flex",
|
2021-05-27 17:37:59 +10:00
|
|
|
alignItems: "flex-end",
|
2021-05-24 17:11:46 +10:00
|
|
|
justifyContent: "center",
|
|
|
|
|
position: "relative",
|
|
|
|
|
}}
|
|
|
|
|
bg="background"
|
|
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
|
>
|
|
|
|
|
<SimpleBar
|
|
|
|
|
style={{
|
|
|
|
|
width: containerSize - 16,
|
|
|
|
|
height: containerSize - 48,
|
2021-05-27 17:37:59 +10:00
|
|
|
marginBottom: "8px",
|
|
|
|
|
backgroundColor: theme.colors.muted,
|
2021-05-24 17:11:46 +10:00
|
|
|
}}
|
2021-05-27 17:37:59 +10:00
|
|
|
onClick={() => onGroupSelect()}
|
2021-05-24 17:11:46 +10:00
|
|
|
>
|
|
|
|
|
<Grid
|
|
|
|
|
sx={{
|
|
|
|
|
borderRadius: "4px",
|
|
|
|
|
overflow: "hidden",
|
|
|
|
|
}}
|
|
|
|
|
gap={2}
|
2021-05-27 17:19:36 +10:00
|
|
|
columns={`repeat(${layout.groupGridColumns}, 1fr)`}
|
2021-05-27 17:37:59 +10:00
|
|
|
p={3}
|
2021-05-24 17:11:46 +10:00
|
|
|
>
|
|
|
|
|
{children}
|
|
|
|
|
</Grid>
|
|
|
|
|
</SimpleBar>
|
|
|
|
|
<Close
|
|
|
|
|
onClick={() => onGroupClose()}
|
|
|
|
|
sx={{ position: "absolute", top: 0, right: 0 }}
|
|
|
|
|
/>
|
|
|
|
|
</Box>
|
|
|
|
|
</animated.div>
|
|
|
|
|
</ReactResizeDetector>
|
|
|
|
|
</>
|
2021-05-24 13:34:21 +10:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default TilesOverlay;
|