All files / src/pages/flowsheet-page/flowsheet ResizableHandle.tsx

80% Statements 24/30
50% Branches 7/14
16.66% Functions 1/6
95% Lines 19/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50      103x             3090x 3090x     12360x 3090x   3090x 132x   1x 1x     1x     1x     6313x     3090x   133x   3090x 3223x 131x 6180x       12360x          
import React, { useEffect, useState } from "react";
import { cn } from "@/lib/utils";
 
let activeResizeHandles = 0;
 
interface ResizableHandleProps extends React.HTMLAttributes<HTMLDivElement> {
  id?: string;
  isDragging: boolean;
}
 
function ResizableHandle({
  id = "drag-bar",
  isDragging,
  ...props
}: ResizableHandleProps) {
  const [isFocused, setIsFocused] = useState(false);
 
  useEffect(() => {
    Iif (!isDragging) return;
 
    activeResizeHandles += 1;
    document.documentElement.classList.add("sidebar-resize-active");
 
    return () => {
      activeResizeHandles = Math.max(0, activeResizeHandles - 1);
 
      if (activeResizeHandles === 0) {
        document.documentElement.classList.remove("sidebar-resize-active");
      }
    };
  }, [isDragging]);
 
  return (
    <div
      tabIndex={0}
      className={cn(
        "sample-drag-bar",
        (isDragging || isFocused) && "sample-drag-bar--dragging",
      )}
      onFocus={() => setIsFocused(true)}
      onBlur={() => setIsFocused(false)}
      {...props}
      id={id}
      data-testid={id}
    />
  );
}
 
export default ResizableHandle;