import { 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"; import { Map, MapTool, MapToolId } from "../../types/Map"; import { MapState } from "../../types/MapState"; import { MapChangeEventHandler, MapResetEventHandler, } from "../../types/Events"; import { Settings } from "../../types/Settings"; type MapControlsProps = { onMapChange: MapChangeEventHandler; onMapReset: MapResetEventHandler; currentMap?: Map; currentMapState?: MapState; selectedToolId: MapToolId; onSelectedToolChange: (toolId: MapToolId) => void; toolSettings: Settings; onToolSettingChange: (change: Partial) => void; onToolAction: (actionId: string) => void; disabledControls: string[]; disabledSettings: Partial>; }; function MapContols({ onMapChange, onMapReset, currentMap, currentMapState, selectedToolId, onSelectedToolChange, toolSettings, onToolSettingChange, onToolAction, disabledControls, disabledSettings, }: MapControlsProps) { const [isExpanded, setIsExpanded] = useState(true); const [fullScreen, setFullScreen] = useSetting("map.fullScreen"); const toolsById: Record = { 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: MapToolId[] = [ "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 || selectedToolId === "move" || selectedToolId === "measure" || selectedToolId === "note" ) { return null; } return ( ) => onToolSettingChange({ [selectedToolId]: { ...toolSettings[selectedToolId], ...change, }, }) } onToolAction={onToolAction} disabledActions={disabledSettings[selectedToolId]} /> ); } 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;