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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | 33x 33x 3761x 3761x 7522x 2x 1x 1x 1x 33x 3761x 3761x 3761x 3761x 3761x 20x 1x | import { Button } from "@/ahuora-design-system/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuGroup,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuShortcut,
DropdownMenuTrigger,
} from "@/ahuora-design-system/ui/dropdown-menu";
import { Separator } from "@/ahuora-design-system/ui/separator";
import { ToolTipCover } from "@/ahuora-design-system/ui/tooltip";
import { useCommand } from "just-search-it";
import {
ChevronDown,
Eye,
EyeOff,
Fullscreen,
Minus,
Plus,
} from "lucide-react";
import React, { forwardRef } from "react";
import { ZoomToFit, ZoomReset } from "./FlowsheetCommands";
import SolveButton from "../SolveButton";
import { useSearchParam } from "../../../../hooks/searchParams";
import { DefinedStatusButton } from "./DefinedStatus";
{
/* <ToolTipCover asChild content={`${indicatorsVisible ? 'Hide' : 'Show'} Status Indicators`}>
<Button
variant="secondary"
size="icon"
onClick={() => setIndicatorsVisible(!indicatorsVisible)}
className="h-9 w-9"
>
{indicatorsVisible ? <Eye size={18} /> : <EyeOff size={18} />}
</Button>
</ToolTipCover> */
}
type CanvasControlsProps = {
canvasWidth: number;
canvasHeight: number;
canvasScale: number;
viewStatusData: {
visibilitySetter: (visible: boolean) => void;
visibility: boolean;
};
solveButton: React.ReactNode;
canvasChangeZoom: (x: number, y: number, scaleBy: number) => void;
};
interface ResetDropDownProps {
canvasScale: number;
canvasChangeZoom: () => void;
}
//Add advance canvas functionalities here
const MenuDetails = {
zoomReset: {
label: "Zoom Reset (100%)",
Shortcut: "CTRL + 0",
},
zoomToFit: {
label: "Zoom to fit",
Shortcut: "F",
},
};
/**
* Reset DropDown
* @param canvasScale
* @returns DropDown box
*/
const ResetDropDown = forwardRef<HTMLDivElement, ResetDropDownProps>(
({ canvasScale, canvasChangeZoom }, ref) => {
const zoomToFit = useCommand(ZoomToFit);
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
{/* Tooltip wrapped button with asChild */}
<Button
variant="tertiary"
className="w-15 h-full p-1"
size={null}
aria-label="flowsheet-zoom-reset"
>
{Math.round((canvasScale) * 100)}%
<ChevronDown size="16px" color="hsl(var(--foreground))" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent ref={ref} className="w-60">
<DropdownMenuLabel>Zoom options</DropdownMenuLabel>
<DropdownMenuGroup>
{Object.keys(MenuDetails).map((key) => (
<DropdownMenuItem
key={key}
onSelect={() => {
if (key === "zoomReset") {
canvasChangeZoom();
} else if (key === "zoomToFit") {
zoomToFit();
}
}}
>
<span>
{MenuDetails[key as keyof typeof MenuDetails].label}
</span>
<DropdownMenuShortcut>
{MenuDetails[key as keyof typeof MenuDetails].Shortcut}
</DropdownMenuShortcut>
</DropdownMenuItem>
))}
</DropdownMenuGroup>
</DropdownMenuContent>
</DropdownMenu>
);
},
);
const CanvasControls = ({
canvasWidth,
canvasHeight,
canvasScale,
canvasChangeZoom,
viewStatusData,
}: CanvasControlsProps) => {
const [scenario, setScenario] = useSearchParam("scenario");
const zoomBy = 1.125;
const zoomCommand = useCommand(ZoomToFit);
const resetCommmand = useCommand(ZoomReset);
return (
<div className="flex flex-row justify-between items-center h-10 shadow gap-1">
<SolveButton scenarioNumber={+scenario} className="h-full" />
<div className="h-10 bg-card shadow border-border border-2 rounded-md flex flex-row justify-center items-center">
<ToolTipCover
asChild
content={`${viewStatusData?.visibility ? "Hide" : "Show"} Status Indicators`}
>
<Button
variant="ghost"
size="icon"
onClick={() =>
viewStatusData?.visibilitySetter(!viewStatusData.visibility)
}
className=""
>
{viewStatusData.visibility ? <Eye /> : <EyeOff />}
</Button>
</ToolTipCover>
<Separator orientation="vertical" />
{/* Zoom out */}
<ToolTipCover content="Zoom out: ctrl + scroll / ctrl -" asChild>
<Button
disabled = {canvasScale<=0.25}
aria-label="flowsheet-zoom-out"
className="p-2"
variant="ghost"
onClick={() =>
canvasChangeZoom(canvasWidth / 2, canvasHeight / 2, 1 / zoomBy)
}
>
<Minus size="16px" />
</Button>
</ToolTipCover>
{/* Reset zoom */}
<ToolTipCover content="Click for more zooming options" asChild>
<div>
<ResetDropDown
canvasScale={canvasScale}
canvasChangeZoom={resetCommmand}
/>
</div>
</ToolTipCover>
{/* Zoom in */}
<ToolTipCover content="Zoom in: ctrl + scroll / ctrl +" asChild>
<Button
disabled = {canvasScale>=4.5}
aria-label="flowsheet-zoom-in"
className="p-2"
variant="ghost"
onClick={() =>
canvasChangeZoom(canvasWidth / 2, canvasHeight / 2, zoomBy)
}
>
<Plus size="16px" />
</Button>
</ToolTipCover>
{/* Zoom to fit */}
<ToolTipCover content="Zoom to fit: F" asChild>
<Button
aria-label="flowsheet-zoom-fit"
className="p-2"
variant="ghost"
onClick={zoomCommand}
>
<Fullscreen size="16px" />
</Button>
</ToolTipCover>
</div>
</div>
);
};
export default CanvasControls;
|