diff --git a/src/component/elements/toggle/ToggleButton.tsx b/src/component/elements/toggle/ToggleButton.tsx deleted file mode 100644 index c6182848cf..0000000000 --- a/src/component/elements/toggle/ToggleButton.tsx +++ /dev/null @@ -1,51 +0,0 @@ -import { useCallback, useState, useEffect, ReactElement } from 'react'; -import { Toolbar } from 'react-science/ui'; - -interface ToggleButtonProps { - isActive?: boolean; - value?: any; - onChange?: (value: any) => null; - children: ReactElement; - isVisible?: boolean; -} - -export default function ToggleButton( - props: ToggleButtonProps & { title: string; id: string }, -) { - const { - children, - value = null, - isActive = false, - onChange = () => null, - isVisible = true, - id, - title, - } = props; - - const [active, setActive] = useState(props.isActive); - - const toggleButton = useCallback(() => { - const _isActive = !active; - setActive(_isActive); - - if (_isActive) { - onChange(value); - } else { - onChange(null); - } - }, [active, onChange, value]); - - useEffect(() => { - setActive(isActive); - }, [isActive]); - - if (!isVisible) { - return null; - } - - return ( - - {children} - - ); -} diff --git a/src/component/elements/toggle/ToggleButtonGroup.tsx b/src/component/elements/toggle/ToggleButtonGroup.tsx deleted file mode 100644 index 04d7410058..0000000000 --- a/src/component/elements/toggle/ToggleButtonGroup.tsx +++ /dev/null @@ -1,73 +0,0 @@ -import { - useCallback, - useState, - useMemo, - useEffect, - Children, - cloneElement, - ReactNode, -} from 'react'; - -import ToggleButton from './ToggleButton'; - -interface ToggleButtonGroupProps { - children: ReactNode; - value: string; - onChange?: (value: any) => void; -} - -export default function ToggleButtonGroup({ - children, - value, - onChange = () => null, -}: ToggleButtonGroupProps) { - const [toggleButtons, setToggleButtons] = useState([]); - const handleOnChange = useCallback( - (val) => { - const _toggles: any[] = [...toggleButtons]; - const toggles = _toggles.map((toggle) => { - return { - value: toggle.value, - isActive: toggle.value === val, - }; - }); - - setToggleButtons(toggles); - onChange(val); - }, - [onChange, toggleButtons], - ); - - const mappedChildren = useMemo(() => { - let index = 0; - return Children.map(children, (child: any) => { - if (child) { - if (child.type === ToggleButton) { - const _child = cloneElement(child, { - onChange: handleOnChange, - isActive: toggleButtons[index]?.isActive, - index, - }); - index++; - return _child; - } else { - return cloneElement(child); - } - } - }); - }, [children, handleOnChange, toggleButtons]); - - useEffect(() => { - const val = Children.map(children, (child: any) => { - if (child && child.type === ToggleButton) { - return { - value: child.props.value, - isActive: child.props.value === value, - }; - } - }); - setToggleButtons(val); - }, [children, value]); - - return <>{mappedChildren}; -} diff --git a/src/component/toolbar/FunctionToolBar.tsx b/src/component/toolbar/FunctionToolBar.tsx index b5d52f8cf1..153bb495ea 100644 --- a/src/component/toolbar/FunctionToolBar.tsx +++ b/src/component/toolbar/FunctionToolBar.tsx @@ -15,8 +15,6 @@ import { Toolbar } from 'react-science/ui'; import { useChartData } from '../context/ChartContext'; import { useDispatch } from '../context/DispatchContext'; -import ToggleButton from '../elements/toggle/ToggleButton'; -import ToggleButtonGroup from '../elements/toggle/ToggleButtonGroup'; import { useCheckToolsVisibility } from '../hooks/useCheckToolsVisibility'; import useDatumWithSpectraStatistics from '../hooks/useDatumWithSpectraStatistics'; import useToolsFunctions from '../hooks/useToolsFunctions'; @@ -71,157 +69,140 @@ function FunctionToolBarInner({ return ( <> - - {isButtonVisible('zoom') && ( - - - - )} + {isButtonVisible('zoom') && ( + handleChange(options.zoom.id)} + title={options.zoom.label} + id={options.zoom.id} + active={option === options.zoom.id} + icon={} + /> + )} - {isButtonVisible('zoomOut') && ( + {isButtonVisible('zoomOut') && ( + } + /> + )} + + {isButtonVisible('peakPicking') && ( + handleChange(options.peakPicking.id)} + title={`${options.peakPicking.label} ( Press p )`} + id={options.peakPicking.id} + active={option === options.peakPicking.id} + icon={} + /> + )} + {isButtonVisible('integral') && ( + handleChange(options.integral.id)} + title={`${options.integral.label} ( Press i )`} + id={options.integral.id} + active={option === options.integral.id} + icon={} + /> + )} + {isButtonVisible('zonePicking') && ( + handleChange(options.zonePicking.id)} + title={`${options.zonePicking.label} ( Press r )`} + id={options.zonePicking.id} + active={option === options.zonePicking.id} + icon={} + /> + )} + {isButtonVisible('slicing') && ( + handleChange(options.slicing.id)} + title={options.slicing.label} + id={options.slicing.id} + active={option === options.slicing.id} + icon={

Slic

} + /> + )} + {isButtonVisible('rangePicking') && ( + handleChange(options.rangePicking.id)} + title={`${options.rangePicking.label} ( Press r )`} + id={options.rangePicking.id} + active={option === options.rangePicking.id} + icon={} + /> + )} + {isButtonVisible('multipleSpectraAnalysis', { + checkSpectrumType: false, + }) && + ftCounter > 1 && ( } + onClick={() => handleChange(options.multipleSpectraAnalysis.id)} + title={options.multipleSpectraAnalysis.label} + id={options.multipleSpectraAnalysis.id} + active={option === options.multipleSpectraAnalysis.id} + icon={} /> )} + {isButtonVisible('apodization') && ( + handleChange(options.apodization.id)} + title={`${options.apodization.label} (Press a)`} + id={options.apodization.id} + active={option === options.apodization.id} + icon={} + /> + )} + {isButtonVisible('zeroFilling') && ( + handleChange(options.zeroFilling.id)} + title={`${options.zeroFilling.label} ( Press z )`} + id={options.zeroFilling.id} + active={option === options.zeroFilling.id} + icon={} + /> + )} + {isButtonVisible('phaseCorrection') && ( + handleChange(options.phaseCorrection.id)} + title={`${options.phaseCorrection.label} ( Press a )`} + id={options.phaseCorrection.id} + active={option === options.phaseCorrection.id} + icon={} + /> + )} + {isButtonVisible('phaseCorrectionTwoDimensions') && ( + handleChange(options.phaseCorrectionTwoDimensions.id)} + title={`${options.phaseCorrectionTwoDimensions.label} ( Press a )`} + id={options.phaseCorrectionTwoDimensions.id} + active={option === options.phaseCorrectionTwoDimensions.id} + icon={} + /> + )} - {isButtonVisible('peakPicking') && ( - - - - )} - {isButtonVisible('integral') && ( - - - - )} - {isButtonVisible('zonePicking') && ( - - - - )} - {isButtonVisible('slicing') && ( - -

Slic

-
- )} - {isButtonVisible('rangePicking') && ( - - - - )} - {isButtonVisible('multipleSpectraAnalysis', { - checkSpectrumType: false, - }) && - ftCounter > 1 && ( - - - - )} - {isButtonVisible('apodization') && ( - - - - )} - {isButtonVisible('zeroFilling') && ( - - - - )} - {isButtonVisible('phaseCorrection') && ( - - - - )} - {isButtonVisible('phaseCorrectionTwoDimensions') && ( - - - - )} + {isButtonVisible('baselineCorrection') && ( + handleChange(options.baselineCorrection.id)} + title={`${options.baselineCorrection.label} ( Press b )`} + id={options.baselineCorrection.id} + active={option === options.baselineCorrection.id} + icon={} + /> + )} - {isButtonVisible('baselineCorrection') && ( - - - + {isButtonVisible('exclusionZones', { checkSpectrumType: false }) && + ftCounter > 0 && ( + handleChange(options.exclusionZones.id)} + title={`${options.exclusionZones.label} ( Press e )`} + id={options.exclusionZones.id} + active={option === options.exclusionZones.id} + icon={} + /> )} - {isButtonVisible('exclusionZones', { checkSpectrumType: false }) && - ftCounter > 0 && ( - -
- -
-
- )} -
- {isButtonVisible('fft') && (