From 9e7539a2650fd5b47c049769d4e95027968a14cd 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..a1612c62b0 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; + imageObjectFit?: 'contain' | 'cover'; }; -const AttachmentImagePreview = ({ label, imagePreview, meta }: AttachmentImagePreviewProps) => { - const { classProps } = useFileUploaderStyleProps({ meta }); - const { imageCropStyles } = classProps; +const AttachmentImagePreview = ({ label, imagePreview, meta, imageObjectFit }: AttachmentImagePreviewProps) => { + const { classProps } = useFileUploaderStyleProps({ meta, imageObjectFit }); + const { imageCropStyles, attachmentStyles } = classProps; return ( - {label} + {label} ); }; AttachmentImagePreview.defaultProps = { meta: undefined, + imageObjectFit: 'cover', }; 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..35e55c6160 100644 --- a/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx +++ b/packages/web-react/src/components/FileUploader/FileUploaderAttachment.tsx @@ -22,13 +22,14 @@ const FileUploaderAttachment = (props: SpiritFileUploaderAttachmentProps) => { hasImagePreview, iconName = DEFAULT_ICON_NAME, id, + imageObjectFit, label, + meta, name, 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 ? ( - + ) : (