Skip to content

Automate browser based workflows with AI

1.7 KB
Raw Blame
import { ControlButton, useReactFlow } from "@xyflow/react";

import {
  Tooltip,
  TooltipContent,
  TooltipProvider,
  TooltipTrigger,
} from "@/components/ui/tooltip";

export function FitViewControl({ onClick }: { onClick?: () => void }) {
  const { fitView } = useReactFlow();
  const label = "Fit view";

  const handleClick = () => {
    // Optional override lets the parent route the call through a
    // suspend-constrainPan wrapper (see FlowRenderer.runFitView). Without
    // it, the default fitView still fires for canvases that do not pin the
    // viewport.
    if (onClick) {
      onClick();
      return;
    }
    fitView({ maxZoom: 1, duration: 300 });
  };

  return (
    <TooltipProvider delayDuration={100}>
      <Tooltip>
        <TooltipTrigger asChild>
          <div>
            <ControlButton onClick={handleClick} aria-label={label}>
              <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 30">
                <path d="M3.692 4.63c0-.53.4-.938.939-.938h5.215V0H4.708C2.13 0 0 2.054 0 4.63v5.216h3.692V4.631zM27.354 0h-5.2v3.692h5.17c.53 0 .984.4.984.939v5.215H32V4.631A4.624 4.624 0 0027.354 0zm.954 24.83c0 .532-.4.94-.939.94h-5.215v3.768h5.215c2.577 0 4.631-2.13 4.631-4.707v-5.139h-3.692v5.139zm-23.677.94c-.531 0-.939-.4-.939-.94v-5.138H0v5.139c0 2.577 2.13 4.707 4.708 4.707h5.138V25.77H4.631z" />
              </svg>
            </ControlButton>
          </div>
        </TooltipTrigger>
        <TooltipContent side="right" className="z-[9999]">
          <div className="flex flex-col">
            <span>{label}</span>
            <span className="text-[0.65rem] opacity-70">
              Shift+1 - max 100%
            </span>
          </div>
        </TooltipContent>
      </Tooltip>
    </TooltipProvider>
  );
}