splitPanel.tsx 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. import {useCallback} from 'react';
  2. import debounce from 'lodash/debounce';
  3. import type {SplitPanelProps} from 'sentry/components/splitPanel';
  4. import SplitPanel from 'sentry/components/splitPanel';
  5. import useSplitPanelTracking from 'sentry/utils/replays/hooks/useSplitPanelTracking';
  6. function ReplaySplitPanel(props: SplitPanelProps) {
  7. const {availableSize} = props;
  8. const isLeftRight = 'left' in props;
  9. const {setStartPosition, logEndPosition} = useSplitPanelTracking({
  10. slideDirection: isLeftRight ? 'leftright' : 'updown',
  11. });
  12. // eslint-disable-next-line react-hooks/exhaustive-deps
  13. const handleResize = useCallback(
  14. debounce(newSize => logEndPosition(`${(newSize / availableSize) * 100}%`), 750),
  15. [logEndPosition, availableSize]
  16. );
  17. const handleMouseDown = useCallback(
  18. (sizePct: `${number}%`) => {
  19. setStartPosition(sizePct);
  20. },
  21. [setStartPosition]
  22. );
  23. return <SplitPanel {...props} onMouseDown={handleMouseDown} onResize={handleResize} />;
  24. }
  25. export default ReplaySplitPanel;