diff --git a/src/App.jsx b/src/App.jsx index 7dfeeebff..975768529 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -1,9 +1,9 @@ import React from "react"; import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; -import ItemsPage from "./pages/ItemsPage.jsx"; -import AddItem from "./pages/AddItem.jsx"; -import Nav from "./components/Nav.jsx"; -import ItemDetail from "./pages/ItemDetail.jsx"; +import ItemsPage from "./pages/ItemsPage.tsx"; +import AddItem from "./pages/AddItem.tsx"; +import Nav from "./components/Nav.tsx"; +import ItemDetail from "./pages/ItemDetail.tsx"; import "./style.css"; function App() { diff --git a/src/components/AddImgForm.jsx b/src/components/AddImgForm.jsx deleted file mode 100644 index 83b1516fb..000000000 --- a/src/components/AddImgForm.jsx +++ /dev/null @@ -1,67 +0,0 @@ -import React, { useState } from "react"; -import PlusIcon from "../asset/icon/ic_plus.png"; -import CloseIcon from "../asset/icon/ic_X.png"; -import "./AddImgForm.css"; - -function AddImgForm({ label }) { - const [imagePreviewUrl, setImagePreviewUrl] = useState(""); - const fileInputRef = React.useRef(null); - - const handleImageChange = (e) => { - const file = e.target.files[0]; - if (file) { - // 미리보기 주소 값(Object URL) 생성 - const imageUrl = URL.createObjectURL(file); - setImagePreviewUrl(imageUrl); - } - }; - - const handleClick = () => { - fileInputRef.current.click(); - }; - - const handleRemoveImage = () => { - setImagePreviewUrl(""); - fileInputRef.current.value = ""; - }; - - return ( -
- -
-
- 업로드 아이콘 -

이미지 등록

-
- - {imagePreviewUrl && ( -
- 미리보기 - 삭제 버튼 -
- )} -
- - -
- ); -} - -export default AddImgForm; diff --git a/src/components/AddImgForm.css b/src/components/AddImgForm.module.css similarity index 100% rename from src/components/AddImgForm.css rename to src/components/AddImgForm.module.css diff --git a/src/components/AddImgForm.tsx b/src/components/AddImgForm.tsx new file mode 100644 index 000000000..8c795d4b7 --- /dev/null +++ b/src/components/AddImgForm.tsx @@ -0,0 +1,80 @@ +import React, { useState, useRef, ChangeEvent } from "react"; +import PlusIcon from "../asset/icon/ic_plus.png"; +import CloseIcon from "../asset/icon/ic_X.png"; +import styles from "./AddImgForm.module.css"; + +interface AddImgFormProps { + label: string; +} + +function AddImgForm({ label }: AddImgFormProps) { + const [imagePreviewUrl, setImagePreviewUrl] = useState(""); + const fileInputRef = useRef(null); + + function handleImageChange(e: ChangeEvent) { + const file = e.target.files?.[0]; + if (file) { + const imageUrl = URL.createObjectURL(file); + setImagePreviewUrl(imageUrl); + } + } + + function handleClick() { + fileInputRef.current?.click(); + } + + function handleRemoveImage() { + setImagePreviewUrl(""); + if (fileInputRef.current) { + fileInputRef.current.value = ""; + } + } + + return ( +
+ +
+
+ 업로드 아이콘 +

이미지 등록

+
+ + {imagePreviewUrl && ( +
+ 미리보기 + 삭제 버튼 +
+ )} +
+ + +
+ ); +} + +export default AddImgForm; diff --git a/src/components/AddItemForm.css b/src/components/AddItemForm.module.css similarity index 100% rename from src/components/AddItemForm.css rename to src/components/AddItemForm.module.css diff --git a/src/components/AddItemForm.jsx b/src/components/AddItemForm.tsx similarity index 51% rename from src/components/AddItemForm.jsx rename to src/components/AddItemForm.tsx index 44dea6d83..139fd0abf 100644 --- a/src/components/AddItemForm.jsx +++ b/src/components/AddItemForm.tsx @@ -1,27 +1,42 @@ import React from "react"; -import "./AddItemForm.css"; +import styles from "./AddItemForm.module.css"; + +interface AddItemFormProps { + label: string; + type?: string; + placeholder: string; + id: string; + value: string; + onChange: ( + event: React.ChangeEvent + ) => void; + isTextArea?: boolean; + onKeyDown?: ( + event: React.KeyboardEvent + ) => void; +} function AddItemForm({ label, - type, + type = "text", placeholder, id, value, onChange, - isTextArea, + isTextArea = false, onKeyDown, -}) { +}: AddItemFormProps) { return ( -
+
{isTextArea ? (