/** * Options bar of the modify tools (Revit's options bar): copy toggles, the * rotate centre / typed angle, mirror pick-or-draw, array count / spacing / * radial angle / group, offset distance. Bottom centre, like the drawing bar. */ import { useTranslation } from 'react-i18next'; import { useEditorDispatch, useEditorState } from '../state/EditorContext.tsx'; import { useModifyOptions, setModifyOptions } from '../tools/modifyOptions.ts'; import { pickRotateCenter } from '../tools/modifyTools.ts'; import { NumberInput } from './NumberInput.tsx'; import { Separator } from './ui/separator'; import { cn } from '../lib/utils.ts'; const fieldClass = 'h-7 w-16 rounded-lg border-input bg-transparent px-2 text-[11px] tabular-nums'; const chip = 'flex h-7 items-center rounded-md px-2 text-[11px] transition-colors cursor-pointer border-none'; const on = 'bg-[var(--accent-dim)] text-[var(--color-accent)]'; const off = 'bg-transparent text-muted-foreground hover:bg-accent hover:text-foreground'; const TOOLS = new Set(['rotate', 'mirror', 'array', 'align', 'offset', 'paste']); function Toggle({ checked, onChange, label, testId }: { checked: boolean; onChange: (v: boolean) => void; label: string; testId?: string }) { return ( ); } export default function ModifyOptionsBar() { const { t } = useTranslation(); const state = useEditorState(); const dispatch = useEditorDispatch(); const o = useModifyOptions(); const tool = state.activeTool; if (!TOOLS.has(tool) || state.viewMode !== '2d') return null; const ds = state.drawingState; const typed = ds?.typed?.length; return (
e.stopPropagation()} > {t(`modify.${tool}`)} {tool === 'rotate' && ( <> {t('modify.angle')} {typed ? `${typed}°` : ds?.modify?.angle !== undefined ? `${ds.modify.angle}°` : '—'} setModifyOptions({ rotateCopy: v })} label={t('modify.copy')} testId="rotate-copy" /> {o.rotateCopy && setModifyOptions({ renumberCopies: v })} label={t('modify.renumber')} testId="renumber-copies" />} )} {tool === 'mirror' && ( <> setModifyOptions({ mirrorCopy: v })} label={t('modify.copy')} testId="mirror-copy" /> {o.mirrorCopy && setModifyOptions({ renumberCopies: v })} label={t('modify.renumber')} testId="renumber-copies" />} )} {tool === 'array' && ( <> {t('modify.count')} { const n = parseInt(v, 10); if (n >= 2) setModifyOptions({ arrayCount: n }); }} /> {o.arrayMode === 'linear' ? ( <> ) : ( <> {t('modify.angle')} { const n = parseFloat(v); if (Number.isFinite(n) && n !== 0) setModifyOptions({ arrayAngle: n }); }} /> )} setModifyOptions({ arrayGroup: v })} label={t('modify.groupCopies')} testId="array-group" /> {!o.arrayGroup && setModifyOptions({ renumberCopies: v })} label={t('modify.renumber')} testId="renumber-copies" />} {typed && {t('modify.distance')} {typed}} )} {tool === 'offset' && ( <> {t('modify.distance')} { const n = parseFloat(v); if (n > 0) setModifyOptions({ offsetDistance: n }); }} /> setModifyOptions({ offsetCopy: v })} label={t('modify.copy')} testId="offset-copy" /> )} {(tool === 'align' || tool === 'paste') && ( {t(tool === 'align' ? (ds?.pick ? 'hint.align2' : 'hint.align') : 'hint.paste')} )} {tool === 'paste' && setModifyOptions({ renumberCopies: v })} label={t('modify.renumber')} testId="renumber-copies" />}
); }