splitPanel.tsx 984 B

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