import React from "react"; import { Menu, Flex, Input, Text } from "@mantine/core"; import { getHotkeyHandler, useHotkeys } from "@mantine/hooks"; import { CgChevronDown } from "react-icons/cg"; import useGraph from "src/store/useGraph"; import * as Styles from "./styles"; export const ZoomMenu = () => { const zoomIn = useGraph(state => state.zoomIn); const zoomOut = useGraph(state => state.zoomOut); const centerView = useGraph(state => state.centerView); const setZoomFactor = useGraph(state => state.setZoomFactor); const zoomFactor = useGraph(state => state.viewPort?.zoomFactor || 1); const [tempZoomValue, setTempZoomValue] = React.useState(zoomFactor); React.useEffect(() => { if (!Number.isNaN(zoomFactor)) setTempZoomValue(zoomFactor); }, [zoomFactor]); useHotkeys([ ["shift+Digit0", () => setZoomFactor(100 / 100)], ["shift+Digit1", centerView], ]); return ( {Math.round(zoomFactor * 100)}% setTempZoomValue(e.currentTarget.valueAsNumber / 100)} onKeyDown={getHotkeyHandler([["Enter", () => setZoomFactor(tempZoomValue)]])} size="xs" rightSection="%" /> Zoom in Zoom out Zoom to fit setZoomFactor(50 / 100)}> Zoom to %50 setZoomFactor(100 / 100)}> Zoom to %100 setZoomFactor(200 / 100)}> Zoom to %200 ); };