From b2ff593dcd5ee00684707c0382f7ecf6eda4c376 Mon Sep 17 00:00:00 2001 From: Mohammad Khatib Date: Tue, 13 Dec 2022 16:58:38 -0800 Subject: [PATCH] [BulkEditPhotos] Add preview size controls (#57) --- src/BulkEditPhotos/BulkEditPhotos.tsx | 45 ++++++++++++++++++++++----- src/images/ImageCanvasEditor.tsx | 10 ++++-- src/images/PhotoCropper.tsx | 10 ++++-- 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/src/BulkEditPhotos/BulkEditPhotos.tsx b/src/BulkEditPhotos/BulkEditPhotos.tsx index 1045f67..cdd452e 100644 --- a/src/BulkEditPhotos/BulkEditPhotos.tsx +++ b/src/BulkEditPhotos/BulkEditPhotos.tsx @@ -1,3 +1,4 @@ +import { PhotoIcon } from '@heroicons/react/24/solid'; import JSZip from 'jszip'; import { doc } from 'prettier'; import { useCallback, useEffect, useRef, useState } from 'react'; @@ -39,6 +40,7 @@ const BulkEditPhotos = (): JSX.Element => { const [opacity, setOpacity] = useState(100); const [saturation, setSaturation] = useState(100); const [sepia, setSepia] = useState(0); + const [previewSize, setPreviewSize] = useState(250); const onCrop = useCallback(() => { const croppedCanvases = cropperRefs.current.map((cropper) => { @@ -130,14 +132,39 @@ const BulkEditPhotos = (): JSX.Element => {
{/* Sidebar */}
-
- - Add More Images - +
+
+ + Add More Images + +
+
+
+
+ +
{' '} +
+ +
{' '} +
{/* Crops */} @@ -545,6 +572,7 @@ const BulkEditPhotos = (): JSX.Element => { image={image} ref={(ref) => registerPhotoCropperRef(ref, index)} onCrop={onCrop} + previewSize={previewSize} />
); @@ -580,6 +608,7 @@ const BulkEditPhotos = (): JSX.Element => { sepia={sepia} opacity={opacity} blur={blur} + previewSize={previewSize} /> )}
diff --git a/src/images/ImageCanvasEditor.tsx b/src/images/ImageCanvasEditor.tsx index af86c4c..8d2fb8c 100644 --- a/src/images/ImageCanvasEditor.tsx +++ b/src/images/ImageCanvasEditor.tsx @@ -23,6 +23,7 @@ interface ImageCanvasEditorProps { sepia?: number; opacity?: number; blur?: number; + previewSize?: number; } export interface CanvasEditorRef { @@ -51,6 +52,7 @@ export const ImageCanvasEditor = forwardRef< sepia = 0, opacity = 100, blur = 0, + previewSize = 100, }, ref ): JSX.Element { @@ -102,10 +104,14 @@ export const ImageCanvasEditor = forwardRef< {srcCanvas ? ( ) : ( -
+
void; + previewSize?: number; } function centerAspectCrop( @@ -43,7 +44,7 @@ export interface PhotoCropperRef { } const PhotoCropper = forwardRef(function ( - { image, onCrop, aspect }, + { image, onCrop, aspect, previewSize = 250 }, ref ): JSX.Element { const [crop, setCrop] = useState(); @@ -154,8 +155,11 @@ const PhotoCropper = forwardRef(function ( ref={imgRef} alt="Crop me" src={image.url} - style={{ transform: `scale(${scale}) rotate(${rotate}deg)` }} - className="h-40 block pointer-events-none" + style={{ + transform: `scale(${scale}) rotate(${rotate}deg)`, + height: previewSize, + }} + className="block pointer-events-none" /> {/* Toolbar */}