2020-04-19 13:33:31 +10:00
|
|
|
import React, { useState } from "react";
|
2020-04-18 23:31:40 +10:00
|
|
|
import { Flex, Box, IconButton } from "theme-ui";
|
|
|
|
|
|
|
|
|
|
import AddMapButton from "./AddMapButton";
|
|
|
|
|
import ExpandMoreIcon from "../icons/ExpandMoreIcon";
|
|
|
|
|
import PanToolIcon from "../icons/PanToolIcon";
|
|
|
|
|
import BrushToolIcon from "../icons/BrushToolIcon";
|
|
|
|
|
import EraseToolIcon from "../icons/EraseToolIcon";
|
|
|
|
|
import UndoIcon from "../icons/UndoIcon";
|
|
|
|
|
import RedoIcon from "../icons/RedoIcon";
|
|
|
|
|
|
2020-04-19 00:24:06 +10:00
|
|
|
function MapControls({
|
|
|
|
|
onMapChange,
|
|
|
|
|
onToolChange,
|
|
|
|
|
selectedTool,
|
2020-04-19 13:33:31 +10:00
|
|
|
disabledTools,
|
2020-04-19 00:24:06 +10:00
|
|
|
onUndo,
|
|
|
|
|
onRedo,
|
2020-04-19 13:33:31 +10:00
|
|
|
undoDisabled,
|
|
|
|
|
redoDisabled,
|
2020-04-19 00:24:06 +10:00
|
|
|
}) {
|
2020-04-19 13:33:31 +10:00
|
|
|
const [isExpanded, setIsExpanded] = useState(false);
|
|
|
|
|
|
2020-04-18 23:31:40 +10:00
|
|
|
const divider = (
|
|
|
|
|
<Box
|
|
|
|
|
my={2}
|
|
|
|
|
bg="text"
|
|
|
|
|
sx={{ height: "2px", width: "24px", borderRadius: "2px", opacity: 0.5 }}
|
|
|
|
|
></Box>
|
|
|
|
|
);
|
|
|
|
|
return (
|
|
|
|
|
<Flex
|
|
|
|
|
p={2}
|
|
|
|
|
sx={{
|
|
|
|
|
position: "absolute",
|
|
|
|
|
top: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
}}
|
|
|
|
|
>
|
2020-04-19 00:24:06 +10:00
|
|
|
<IconButton
|
2020-04-19 13:33:31 +10:00
|
|
|
aria-label={isExpanded ? "Hide Map Controls" : "Show Map Controls"}
|
|
|
|
|
title={isExpanded ? "Hide Map Controls" : "Show Map Controls"}
|
|
|
|
|
onClick={() => setIsExpanded(!isExpanded)}
|
|
|
|
|
sx={{
|
|
|
|
|
transform: `rotate(${isExpanded ? "0" : "180deg"})`,
|
|
|
|
|
display: "block",
|
|
|
|
|
}}
|
2020-04-19 00:24:06 +10:00
|
|
|
>
|
2020-04-19 13:33:31 +10:00
|
|
|
<ExpandMoreIcon />
|
2020-04-18 23:31:40 +10:00
|
|
|
</IconButton>
|
2020-04-19 13:33:31 +10:00
|
|
|
<Box
|
|
|
|
|
sx={{
|
|
|
|
|
flexDirection: "column",
|
|
|
|
|
alignItems: "center",
|
|
|
|
|
display: isExpanded ? "flex" : "none",
|
|
|
|
|
}}
|
2020-04-19 00:24:06 +10:00
|
|
|
>
|
2020-04-19 13:33:31 +10:00
|
|
|
<AddMapButton onMapChange={onMapChange} />
|
|
|
|
|
{divider}
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="Pan Tool"
|
|
|
|
|
title="Pan Tool"
|
|
|
|
|
onClick={() => onToolChange("pan")}
|
|
|
|
|
sx={{ color: selectedTool === "pan" ? "primary" : "text" }}
|
|
|
|
|
disabled={disabledTools.includes("pan")}
|
|
|
|
|
>
|
|
|
|
|
<PanToolIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="Brush Tool"
|
|
|
|
|
title="Brush Tool"
|
|
|
|
|
onClick={() => onToolChange("brush")}
|
|
|
|
|
sx={{ color: selectedTool === "brush" ? "primary" : "text" }}
|
|
|
|
|
disabled={disabledTools.includes("brush")}
|
|
|
|
|
>
|
|
|
|
|
<BrushToolIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="Erase Tool"
|
|
|
|
|
title="Erase Tool"
|
|
|
|
|
onClick={() => onToolChange("erase")}
|
|
|
|
|
sx={{ color: selectedTool === "erase" ? "primary" : "text" }}
|
|
|
|
|
disabled={disabledTools.includes("erase")}
|
|
|
|
|
>
|
|
|
|
|
<EraseToolIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
{divider}
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="Undo"
|
|
|
|
|
title="Undo"
|
|
|
|
|
onClick={() => onUndo()}
|
|
|
|
|
disabled={undoDisabled}
|
|
|
|
|
>
|
|
|
|
|
<UndoIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
<IconButton
|
|
|
|
|
aria-label="Redo"
|
|
|
|
|
title="Redo"
|
|
|
|
|
onClick={() => onRedo()}
|
|
|
|
|
disabled={redoDisabled}
|
|
|
|
|
>
|
|
|
|
|
<RedoIcon />
|
|
|
|
|
</IconButton>
|
|
|
|
|
</Box>
|
2020-04-18 23:31:40 +10:00
|
|
|
</Flex>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default MapControls;
|