From b394b3dda6ccedf4573a6ef4760cd961ba2df1e1 Mon Sep 17 00:00:00 2001 From: Pavel Klibani Date: Mon, 23 Oct 2023 12:29:50 +0200 Subject: [PATCH] Feat(web-react): Attachment image preview object fit #DS-1005 - Now accepts cover/contain value for objectFit prop to `FileUploaderAttachment` component --- .../FileUploader/AttachmentImagePreview.tsx | 16 ++++++++++---- .../FileUploader/FileUploaderAttachment.tsx | 5 +++-- .../src/components/FileUploader/README.md | 1 + .../FileUploader/useFileUploaderStyleProps.ts | 22 +++++++++++++++---- packages/web-react/src/types/fileUploader.ts | 1 + 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx b/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx index 919150aa41..f69312c869 100644 --- a/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx +++ b/packages/web-react/src/components/FileUploader/AttachmentImagePreview.tsx @@ -7,21 +7,29 @@ type AttachmentImagePreviewProps = { imagePreview: string; label: string; meta?: FileMetadata; + objectFit?: 'contain' | 'cover'; }; -const AttachmentImagePreview = ({ label, imagePreview, meta }: AttachmentImagePreviewProps) => { - const { classProps } = useFileUploaderStyleProps({ meta }); - const { imageCropStyles } = classProps; +const AttachmentImagePreview = ({ label, imagePreview, meta, objectFit }: AttachmentImagePreviewProps) => { + const { classProps } = useFileUploaderStyleProps({ meta, objectFit }); + const { imageCropStyles, attachmentStyles } = classProps; return ( - {label} + {label} ); }; AttachmentImagePreview.defaultProps = { meta: undefined, + objectFit: 'contain', }; export default AttachmentImagePreview; diff --git a/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx b/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx index 4996905982..faeaaea671 100644 --- a/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx +++ b/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx @@ -23,12 +23,13 @@ const FileUploaderAttachment = (props: SpiritFileUploaderAttachmentProps) => { iconName = DEFAULT_ICON_NAME, id, label, + meta, name, + objectFit, onDismiss, onEdit, onError, removeText, - meta, ...restProps } = props; const [imagePreview, setImagePreview] = useState(''); @@ -83,7 +84,7 @@ const FileUploaderAttachment = (props: SpiritFileUploaderAttachmentProps) => { className={classNames(classProps.attachment.root, styleProps.className)} > {hasImagePreview && imagePreview ? ( - + ) : (