import * as Crop from "../../types/Crop"; import useImageCropperContext from "./useImageCropperContext"; export default function Toolbar() { const { state, dispatch } = useImageCropperContext(); const { cropping, image } = state; const aspectRatios: Array<[string, Crop.Ratio]> = [ ["Free", null], ["1:1", 1], ["3:2", 3 / 2], ["2:3", 2 / 3], ["4:3", 4 / 3], ["3:4", 3 / 4], ["5:4", 5 / 4], ["4:5", 4 / 5], ["16:9", 16 / 9] ]; const updateAspect = (ratio: Crop.Ratio) => (evt: React.MouseEvent) => { evt.preventDefault(); dispatch({ type: "setAspect", payload: ratio }); }; const toggleCrop = () => { if (state.cropping) { dispatch({ type: "completeCrop" }); } else { dispatch({ type: "startCrop" }); } }; const toggleFocal = () => { dispatch({ type: "toggleFocal" }); }; const width = Math.ceil(state.crop_width); const height = Math.ceil(state.crop_height); const format = image.content_type.split("/")[1].toUpperCase(); return (