import React, { useState, Fragment } from "react"; import { IconButton, Flex, Box } from "theme-ui"; import RadioIconButton from "../RadioIconButton"; import Divider from "../Divider"; import SelectMapButton from "./SelectMapButton"; import FogToolSettings from "./controls/FogToolSettings"; import DrawingToolSettings from "./controls/DrawingToolSettings"; import PointerToolSettings from "./controls/PointerToolSettings"; import MoveToolIcon from "../../icons/MoveToolIcon"; import FogToolIcon from "../../icons/FogToolIcon"; import BrushToolIcon from "../../icons/BrushToolIcon"; import MeasureToolIcon from "../../icons/MeasureToolIcon"; import ExpandMoreIcon from "../../icons/ExpandMoreIcon"; import PointerToolIcon from "../../icons/PointerToolIcon"; import FullScreenIcon from "../../icons/FullScreenIcon"; import FullScreenExitIcon from "../../icons/FullScreenExitIcon"; import NoteToolIcon from "../../icons/NoteToolIcon"; import useSetting from "../../hooks/useSetting"; function MapContols({ onMapChange, onMapReset, currentMap, currentMapState, selectedToolId, onSelectedToolChange, toolSettings, onToolSettingChange, onToolAction, disabledControls, disabledSettings, }) { const [isExpanded, setIsExpanded] = useState(true); const [fullScreen, setFullScreen] = useSetting("map.fullScreen"); const toolsById = { move: { id: "move", icon: , title: "Move Tool (W)", }, fog: { id: "fog", icon: , title: "Fog Tool (F)", SettingsComponent: FogToolSettings, }, drawing: { id: "drawing", icon: , title: "Drawing Tool (D)", SettingsComponent: DrawingToolSettings, }, measure: { id: "measure", icon: , title: "Measure Tool (M)", }, pointer: { id: "pointer", icon: , title: "Pointer Tool (Q)", SettingsComponent: PointerToolSettings, }, note: { id: "note", icon: , title: "Note Tool (N)", }, }; const tools = ["move", "fog", "drawing", "measure", "pointer", "note"]; const sections = [ { id: "map", component: ( ), }, { id: "tools", component: tools.map((tool) => ( onSelectedToolChange(tool)} isSelected={selectedToolId === tool} disabled={disabledControls.includes(tool)} > {toolsById[tool].icon} )), }, ]; let controls = null; if (sections.length === 1 && sections[0].id === "map") { controls = ( {sections[0].component} ); } else if (sections.length > 0) { controls = ( <> setIsExpanded(!isExpanded)} sx={{ transform: `rotate(${isExpanded ? "0" : "180deg"})`, display: "block", backgroundColor: "overlay", borderRadius: "50%", }} m={2} > {sections.map((section, index) => ( {section.component} {index !== sections.length - 1 && } ))} ); } function getToolSettings() { const Settings = toolsById[selectedToolId].SettingsComponent; if (Settings) { return ( onToolSettingChange(selectedToolId, change) } onToolAction={onToolAction} disabledActions={disabledSettings[selectedToolId]} /> ); } else { return null; } } return ( <> {controls} {getToolSettings()} setFullScreen(!fullScreen)} aria-label={fullScreen ? "Exit Full Screen" : "Enter Full Screen"} title={fullScreen ? "Exit Full Screen" : "Enter Full Screen"} > {fullScreen ? : } ); } export default MapContols;