import React, { useState, useEffect } from "react"; import { ActionIcon, Slider } from "@mantine/core"; import { useViewer } from "@app/contexts/ViewerContext"; import { useNavigationState } from "@app/contexts/NavigationContext"; import ZoomInIcon from "@mui/icons-material/ZoomIn"; import ZoomOutIcon from "@mui/icons-material/ZoomOut"; /** * Compact zoom controls rendered inline in the WorkbenchBar when the current workbench is "viewer". */ export function ViewerInlineControls() { const { workbench } = useNavigationState(); const viewer = useViewer(); const [zoomPercent, setZoomPercent] = useState(100); useEffect(() => { const zoomState = viewer.getZoomState(); setZoomPercent(zoomState.zoomPercent || 100); const unregister = viewer.registerImmediateZoomUpdate((pct) => { setZoomPercent(pct); }); return () => unregister?.(); }, [viewer.registerImmediateZoomUpdate]); if (workbench !== "viewer") return null; const sliderValue = Math.min(Math.max(zoomPercent, 20), 500); return (
{/* Divider */}
{/* Zoom controls */} viewer.zoomActions.zoomOut()} aria-label="Zoom out" >
{ viewer.zoomActions.setZoomLevel?.(val / 100); }} size="xs" styles={{ root: { width: "6rem" }, thumb: { width: 14, height: 14 }, track: { height: 3 }, }} label={null} />
viewer.zoomActions.zoomIn()} aria-label="Zoom in" > {Math.round(zoomPercent)}%
); }