import { Dispatch, FC } from 'react'; import { FaHandPaper, FaRedo, FaUndo } from 'react-icons/fa'; import { LocalizeText } from '../../../api'; import { Base, Flex, Text } from '../../../common'; import { FloorplanAction, FloorActionMode, FloorplanState } from '../state/types'; type Props = { state: FloorplanState; dispatch: Dispatch; canUndo?: boolean; canRedo?: boolean; onUndo?: () => void; onRedo?: () => void; panMode?: boolean; /** * Imperative setter for pan mode. Receiving the explicit * value (not a toggle) lets every tool button switch the * hand off on click without needing to know its current * state — the hand is part of the same exclusive tool group * as the brushes, so picking any brush has to clear it. */ setPanMode?: (next: boolean) => void; }; const BRUSH_BUTTONS: { id: string; mode: FloorActionMode; iconClass: string }[] = [ { id: 'tool-set', mode: 'SET', iconClass: 'icon-set-tile' }, { id: 'tool-unset', mode: 'UNSET', iconClass: 'icon-unset-tile' }, { id: 'tool-up', mode: 'UP', iconClass: 'icon-increase-height' }, { id: 'tool-down', mode: 'DOWN', iconClass: 'icon-decrease-height' }, { id: 'tool-door', mode: 'DOOR', iconClass: 'icon-set-door' } ]; export const FloorplanToolbar: FC = ({ state, dispatch, canUndo, canRedo, onUndo, onRedo, panMode, setPanMode }) => { // The hand and the brush buttons form a single exclusive tool // group. Picking ANY other tool clears pan mode so the user // never ends up in 'I clicked SET but the canvas still pans'. const exitPan = () => { if(panMode && setPanMode) setPanMode(false); }; return ( { setPanMode && ( setPanMode(!panMode) } > ) } { LocalizeText('floor.plan.editor.draw.mode') } { BRUSH_BUTTONS.map(b => { const active = state.brush.action === b.mode && !panMode; return ( { exitPan(); dispatch({ type: 'BRUSH_SET', action: b.mode }); } } /> ); }) } 0 ? 'icon-set-deselect' : 'icon-set-select' }` } onClick={ () => { exitPan(); dispatch({ type: 'SELECT_ALL' }); } } /> { exitPan(); dispatch({ type: 'SQUARE_SELECT_TOGGLE' }); } } /> { (onUndo || onRedo) && ( ) } ); };