import styled from '@emotion/styled'; import type { Integral } from '@zakodium/nmr-types'; import { useChartData } from '../../context/ChartContext.js'; import { useDispatch } from '../../context/DispatchContext.js'; import { useScaleChecked } from '../../context/ScaleContext.js'; import { ResizerWithScale } from '../../elements/ResizerWithScale.js'; import type { Position } from '../../elements/resizer/SVGResizer.js'; import { useHighlight } from '../../highlight/index.js'; import { useResizerStatus } from '../../hooks/useResizerStatus.js'; import useSpectrum from '../../hooks/useSpectrum.js'; import { IntegralIndicator } from './IntegralIndicator.js'; const Group = styled.g<{ isActive: boolean }>` rect { fill: ${(props) => (props.isActive ? '#ff6f0057' : 'transparent')}; } .target { visibility: ${(props) => (props.isActive ? 'visible' : 'hidden')}; } `; interface IntegralResizableProps { integralData: Integral; integralFormat: string; } function IntegralResizable({ integralData, integralFormat, }: IntegralResizableProps) { const { height, margin } = useChartData(); const spectrum = useSpectrum(); const { scaleX } = useScaleChecked(); const dispatch = useDispatch(); const { id, integral, to, from } = integralData; const highlight = useHighlight([id], { type: 'INTEGRAL', extra: { id, spectrumID: spectrum.id }, }); function handleOnStopResizing(position: Position) { dispatch({ type: 'RESIZE_INTEGRAL', payload: { integral: { ...integralData, from: scaleX().invert(position.x2), to: scaleX().invert(position.x1), }, spectrumKey: spectrum.id, }, }); } const bottom = height - margin.bottom; const isResizingActive = useResizerStatus('integral'); return ( highlight.show()} onMouseLeave={() => highlight.hide()} > {({ x1, x2 }, isActive) => { const width = x2 - x1; return ( ); }} ); } export default IntegralResizable;