From bc8dc792951b975c92fffc6b281d8831433a260b Mon Sep 17 00:00:00 2001 From: root Date: Wed, 25 Mar 2026 22:08:55 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=EC=9D=B8?= =?UTF-8?q?=ED=92=8B=EB=B0=95=EC=8A=A4=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/components/ImgInputForm.module.css | 97 ++++++++++++++-------- src/app/components/ImgInputForm.tsx | 39 ++++----- 2 files changed, 79 insertions(+), 57 deletions(-) diff --git a/src/app/components/ImgInputForm.module.css b/src/app/components/ImgInputForm.module.css index b1a3ad3..a81437c 100644 --- a/src/app/components/ImgInputForm.module.css +++ b/src/app/components/ImgInputForm.module.css @@ -1,59 +1,88 @@ .wrapper { - @apply w-full max-w-md mx-auto p-4; -} - -.dropzone { - @apply border-2 rounded-lg p-4 flex flex-col items-center justify-center transition-colors duration-150; -} - -.normal { - @apply border-dashed border-gray-300 bg-white; -} - -.dragging { - @apply border-indigo-400 bg-indigo-50; + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + min-height: 100vh; + width: 100%; + padding: 1rem; } .fileInput { - @apply hidden; -} - -.previewBox { - @apply w-32 h-32 rounded-md overflow-hidden bg-gray-100 flex items-center justify-center mb-3; -} - -.previewImg { - @apply object-cover w-full h-full cursor-pointer; -} - -.placeholder { - @apply text-gray-400 text-center text-sm px-2; + display: none; } .row { - @apply w-full flex gap-2 items-center; + width: 100%; + max-width: 520px; + display: flex; + gap: 0.5rem; + align-items: center; } .textInput { - @apply flex-1 px-3 py-2 border rounded h-10 cursor-pointer bg-white text-gray-700 focus:outline-none focus:ring-2 focus:ring-indigo-500; + flex: 1; + height: 2.75rem; + padding: 0.65rem 0.75rem; + border: 1px solid #cbd5e1; + border-radius: 0.55rem; + background-color: white; + color: #334155; + font-size: 0.95rem; + outline: none; +} + +.textInput:focus { + box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15); + border-color: #2563eb; } .btn { - @apply px-4 py-2 rounded text-white; + height: 2.75rem; + padding: 0.6rem 1rem; + border-radius: 0.55rem; + background-color: #6366F1; + color: #ffffff; + font-weight: 700; + cursor: pointer; +} + +.btn:hover { + background-color: #4F46E5; } .btnLoading { - @apply bg-indigo-300; + background-color: #A5B4FC; + cursor: wait; } -.btnPrimary { - @apply bg-indigo-600 hover:bg-indigo-700; +.messageArea { + width: 100%; + max-width: 520px; + margin-top: 0.75rem; + text-align: left; } .errorMsg { - @apply mt-3 text-sm text-red-600; + margin: 0.25rem 0 0; + color: #dc2626; } .successMsg { - @apply mt-3 text-sm text-green-600; + margin: 0.25rem 0 0; + color: #16a34a; +} + +.previewContainer { + margin-bottom: 1.5rem; + display: flex; + justify-content: center; +} + +.previewImage { + width: 200px; + height: 120px; + border-radius: 0.55rem; + box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); + object-fit: cover; } diff --git a/src/app/components/ImgInputForm.tsx b/src/app/components/ImgInputForm.tsx index 628e03a..449b74e 100644 --- a/src/app/components/ImgInputForm.tsx +++ b/src/app/components/ImgInputForm.tsx @@ -9,12 +9,14 @@ const ImgInputForm = () => { const fileRef = useRef(null) const [fileName, setFileName] = useState('') const [preview, setPreview] = useState(null) + const [showPreview, setShowPreview] = useState(false) const [isDragging, setIsDragging] = useState(false) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) const [success, setSuccess] = useState(null) - const API_BASE = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:9001' + //process.env.NEXT_PUBLIC_API_URL || + const API_BASE = 'http://localhost:9001' const handleFile = useCallback((file: File) => { setError(null) @@ -30,6 +32,7 @@ const ImgInputForm = () => { setFileName(file.name) setPreview(URL.createObjectURL(file)) + setShowPreview(false) // keep the selected file in the hidden input if (fileRef.current) { const dataTransfer = new DataTransfer() @@ -75,6 +78,7 @@ const ImgInputForm = () => { return } setLoading(true) + setShowPreview(false) try { const fd = new FormData() fd.append('image', file) @@ -85,6 +89,7 @@ const ImgInputForm = () => { }) if (!res.ok) throw new Error('업로드 실패') setSuccess('업로드 성공') + setShowPreview(true) } catch (err) { setError((err as Error).message || '업로드 중 오류가 발생했습니다') } finally { @@ -93,13 +98,8 @@ const ImgInputForm = () => { } return ( -
-
+ <> +
{ onChange={onChange} /> -
- {preview ? ( - // preview kept modest in size - // eslint-disable-next-line @next/next/no-img-element - preview - ) : ( -
- 이미지를 끌어다 놓거나
- 클릭해 선택하세요 -
- )} -
+ {preview && ( +
+ selected preview +
+ )}
{ />
- {error &&

{error}

} + {error &&

{error}

} {success &&

{success}

}
-
+ ) }