diff --git a/src/configurator/components/led-strip-editor.tsx b/src/configurator/components/led-strip-editor.tsx index aed95a0..51b35ba 100644 --- a/src/configurator/components/led-strip-editor.tsx +++ b/src/configurator/components/led-strip-editor.tsx @@ -1,4 +1,4 @@ -import { HTMLAttributes, useCallback } from 'react'; +import { HTMLAttributes, MouseEventHandler, useCallback } from 'react'; import { FC } from 'react'; import { LedStripConfig } from '../models/led-strip-config'; import tw, { styled } from 'twin.macro'; @@ -26,36 +26,54 @@ export const LedStripEditor: FC = ({ onChange, ...htmlAttrs }) => { - const addLed = useCallback(() => { - if (config) { - if (config.global_start_position <= config.global_end_position) { - onChange?.({ ...config, global_end_position: config.global_end_position + 1 }); + const addLed: MouseEventHandler = useCallback( + (ev) => { + ev.preventDefault(); + const delta = ev.button === 2 ? 10 : 1; + if (config) { + if (config.global_start_position <= config.global_end_position) { + onChange?.({ + ...config, + global_end_position: config.global_end_position + delta, + }); + } else { + onChange?.({ + ...config, + global_start_position: config.global_start_position + delta, + }); + } } else { - onChange?.({ - ...config, - global_start_position: config.global_start_position + 1, - }); + onChange?.(new LedStripConfig(0, 0, 0)); } - } else { - onChange?.(new LedStripConfig(0, 0, 0)); - } - }, [config, onChange]); - const removeLed = useCallback(() => { - if (!config) { - onChange?.(null); - } else if (Math.abs(config.global_start_position - config.global_end_position) <= 1) { - onChange?.(null); - } else { - if (config.global_start_position <= config.global_end_position) { - onChange?.({ ...config, global_end_position: config.global_end_position - 1 }); + }, + [config, onChange], + ); + const removeLed: MouseEventHandler = useCallback( + (ev) => { + ev.preventDefault(); + const delta = ev.button === 2 ? 10 : 1; + if (!config) { + onChange?.(null); + } else if ( + Math.abs(config.global_start_position - config.global_end_position) <= delta + ) { + onChange?.(null); } else { - onChange?.({ - ...config, - global_start_position: config.global_start_position - 1, - }); + if (config.global_start_position <= config.global_end_position) { + onChange?.({ + ...config, + global_end_position: config.global_end_position - delta, + }); + } else { + onChange?.({ + ...config, + global_start_position: config.global_start_position - delta, + }); + } } - } - }, [config, onChange]); + }, + [config, onChange], + ); const reverse = useCallback(() => { if (!config) { return; @@ -69,10 +87,10 @@ export const LedStripEditor: FC = ({ return ( - + - +