From 47e96a027bdb86f0dbe533c98d17e5585f549e5c Mon Sep 17 00:00:00 2001 From: naweiss Date: Mon, 11 May 2026 09:35:46 +0300 Subject: [PATCH 1/2] Add color pallete for changing wire color --- .../simulator/SelectionActionBar.tsx | 96 +++++++++++++++++++ .../components/simulator/SimulatorCanvas.tsx | 5 + 2 files changed, 101 insertions(+) diff --git a/frontend/src/components/simulator/SelectionActionBar.tsx b/frontend/src/components/simulator/SelectionActionBar.tsx index 52c33b49..43e196e3 100644 --- a/frontend/src/components/simulator/SelectionActionBar.tsx +++ b/frontend/src/components/simulator/SelectionActionBar.tsx @@ -18,6 +18,7 @@ import React, { useEffect, useRef } from 'react'; import { useTranslation } from 'react-i18next'; +import { WIRE_KEY_COLORS } from '../../utils/wireUtils'; export type SelectionKind = 'wire' | 'component' | 'board'; @@ -30,6 +31,8 @@ interface SelectionActionBarProps { onDelete: () => void; onRotate?: () => void; onDeselect: () => void; + onColorChange?: (color: string) => void; + currentColor?: string; } const ICON_SIZE = 16; @@ -126,12 +129,16 @@ export const SelectionActionBar: React.FC = ({ onDelete, onRotate, onDeselect, + onColorChange, + currentColor, }) => { const { t } = useTranslation(); + const [showPalette, setShowPalette] = React.useState(false); const containerRef = useRef(null); const deleteRef = useRef(null); const rotateRef = useRef(null); const deselectRef = useRef(null); + const colorToggleRef = useRef(null); // Stop native touch events from reaching the canvas listener so it can't // call preventDefault on touchend (which would kill the synthetic click). @@ -154,6 +161,7 @@ export const SelectionActionBar: React.FC = ({ useTouchSafeAction(deleteRef, onDelete); useTouchSafeAction(rotateRef, onRotate ?? noop); useTouchSafeAction(deselectRef, onDeselect); + useTouchSafeAction(colorToggleRef, () => setShowPalette(!showPalette)); if (!kind) return null; @@ -163,6 +171,8 @@ export const SelectionActionBar: React.FC = ({ role="toolbar" aria-label={t('editor.selectionBar.label')} className="selection-action-bar" + onMouseDown={(e) => e.stopPropagation()} + onClick={(e) => e.stopPropagation()} style={{ position: 'absolute', top: 12, @@ -196,6 +206,63 @@ export const SelectionActionBar: React.FC = ({ {label} + {kind === 'wire' && onColorChange && ( +
+ + + {showPalette && ( +
+ {Object.values(WIRE_KEY_COLORS).map((color) => ( + { + onColorChange(color); + setShowPalette(false); + }} + /> + ))} +
+ )} +
+ )} + {canRotate && onRotate && (