diff --git a/packages/web-react/docs/stories/examples/FileUploaderWithImagePreview.stories.tsx b/packages/web-react/docs/stories/examples/FileUploaderWithImagePreview.stories.tsx index 7dc31487ee..2c189c8c15 100644 --- a/packages/web-react/docs/stories/examples/FileUploaderWithImagePreview.stories.tsx +++ b/packages/web-react/docs/stories/examples/FileUploaderWithImagePreview.stories.tsx @@ -16,6 +16,7 @@ export const FileUploaderWithModalImagePreview = (args) => { const [base64File, setBase64File] = useState(''); const [fileToPreview, setFileToPreview] = useState(null); const { fileQueue, addToQueue, clearQueue, onDismiss, updateQueue } = useFileQueue(); + console.log('fileQueue:', fileQueue); const imagePreview = (key: string, file: File) => { if (file.type.includes('image')) { @@ -46,16 +47,18 @@ export const FileUploaderWithModalImagePreview = (args) => { }; const confirmPreview = () => { + const meta = { x: 10, y: 10, width: 50, height: 50 }; + setIsModalOpen(false); - addToQueue(fileToPreview?.name || '', fileToPreview as File); + addToQueue(fileToPreview?.name || '', fileToPreview as File, meta); }; const onEdit = (event: MouseEvent, file: File) => { imagePreview(file.name, file); }; - const attachmentComponent = ({ id, ...props }: SpiritFileUploaderAttachmentProps) => ( - + const attachmentComponent = ({ id, meta, ...props }: SpiritFileUploaderAttachmentProps) => ( + ); return ( diff --git a/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx b/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx index 438316f990..8c04497d56 100644 --- a/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx +++ b/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx @@ -1,20 +1,41 @@ import React from 'react'; +import { FileQueueValueMetaType } from '../../types/fileUploader'; import { useFileUploaderStyleProps } from './useFileUploaderStyleProps'; import { IMAGE_DIMENSION } from './constants'; type AttachmentImagePreviewProps = { label: string; imagePreview: string; + meta?: FileQueueValueMetaType; }; -const AttachmentImagePreview = ({ label, imagePreview }: AttachmentImagePreviewProps) => { +const AttachmentImagePreview = ({ label, imagePreview, meta }: AttachmentImagePreviewProps) => { const { classProps } = useFileUploaderStyleProps(); + // TODO: Add CSS styles for crop + const { x, y, width, height } = meta || {}; + console.log('x:', x, 'y:', y, 'width:', width, 'height:', height); + return ( - {label} + {label} ); }; +AttachmentImagePreview.defaultProps = { + meta: undefined, +}; + export default AttachmentImagePreview; diff --git a/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx b/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx index 96e78d51df..aaa6054304 100644 --- a/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx +++ b/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx @@ -28,6 +28,7 @@ const FileUploaderAttachment = (props: SpiritFileUploaderAttachmentProps) => { onEdit, onError, removeText, + meta, ...restProps } = props; const [imagePreview, setImagePreview] = useState(''); @@ -51,7 +52,7 @@ const FileUploaderAttachment = (props: SpiritFileUploaderAttachmentProps) => { image2Base64Preview(file, 100, (compressedDataURL) => setImagePreview(compressedDataURL)); } - useFileUploaderAttachment({ attachmentRef, file, name, onError }); + useFileUploaderAttachment({ attachmentRef, file, name, meta, onError }); useDeprecationMessage({ method: 'property', @@ -82,7 +83,7 @@ const FileUploaderAttachment = (props: SpiritFileUploaderAttachmentProps) => { className={classNames(classProps.attachment.root, styleProps.className)} > {hasImagePreview && imagePreview ? ( - + ) : (