Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#324 design: 업로드 박스 디자인 변경 #325

Merged
merged 2 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/components/UploadBox/UploadBox.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React, { useEffect, useState } from 'react';
import * as S from './UploadBox.style';
import FileButton from '../../pages/RegisterPage/RegisterComponents/Button/FileButton';

//미리보기 선택 시 전체 프리뷰 기능 미구현

// FileInfo 컴포넌트
const FileInfo = ({ uploadedInfo }) => {
Expand All @@ -15,17 +12,20 @@ const FileInfo = ({ uploadedInfo }) => {

return (
<S.PreviewWrapper>
<S.PreviewBox
style={{
backgroundImage: `url(${uploadedInfo.previewURL})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
}}
>
<S.PreviewLabel onClick={handlePreviewClick}>미리보기</S.PreviewLabel>
</S.PreviewBox>
{uploadedInfo.name !== null && (
<FileButton content={uploadedInfo.name} type={'white'} />
{uploadedInfo.previewURL ? (
<S.PreviewBox
style={{
backgroundImage: `url(${uploadedInfo.previewURL})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
}}
>
<S.PreviewLabel onClick={handlePreviewClick}>미리보기</S.PreviewLabel>
</S.PreviewBox>
) : (
<S.NoPreviewMsg>
엑셀 파일은 미리보기를 제공하지 않습니다.
</S.NoPreviewMsg>
)}
</S.PreviewWrapper>
);
Expand All @@ -43,9 +43,14 @@ const UploadBox = ({ defaultImageUrl, accept, onFileUpload }) => {
};

const setFileInfo = (file) => {
const name = file.name;
const previewURL = URL.createObjectURL(file);
setUploadedInfo({ name, previewURL });
let previewURL = null;

// 이미지 파일만 미리보기 URL 생성
if (file.type.startsWith('image/')) {
previewURL = URL.createObjectURL(file);
}

setUploadedInfo({ previewURL });
if (onFileUpload) {
onFileUpload(file);
}
Expand Down
7 changes: 6 additions & 1 deletion src/components/UploadBox/UploadBox.style.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ export const PreviewWrapper = styled.div`
height: 100%;
width: 100%;
align-items: end;
justify-content: space-between;
justify-content: center;
align-items: center;
`;

export const PreviewBox = styled.div`
Expand All @@ -58,6 +59,10 @@ export const PreviewBox = styled.div`
height: 100%;
`;

export const NoPreviewMsg = styled.div`
font-size: 18px;
`;

export const PreviewLabel = styled.button`
display: flex;
justify-content: center;
Expand Down