From 76c4c03c403d364f39a599376be13cfaf4aa10d0 Mon Sep 17 00:00:00 2001 From: jiminyee Date: Sun, 15 Dec 2024 19:38:33 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8=20=EA=B2=80=EC=83=89=EC=B0=BD=20?= =?UTF-8?q?=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/SearchInput.tsx | 84 +++++++++++++++++++++++++++++++++++++ pages/test/index.tsx | 7 ++++ public/icon/icon-search.svg | 3 ++ 3 files changed, 94 insertions(+) create mode 100644 components/SearchInput.tsx create mode 100644 public/icon/icon-search.svg diff --git a/components/SearchInput.tsx b/components/SearchInput.tsx new file mode 100644 index 0000000..1f2a5bc --- /dev/null +++ b/components/SearchInput.tsx @@ -0,0 +1,84 @@ +import React, { useState } from 'react'; + +interface SearchInputProps { + size: 'large' | 'medium'; + value?: string; + onSubmit?: (value: string) => void; + placeholder?: string; +} + +function SearchInput({ + size = 'large', + value = '', + onSubmit = () => {}, + placeholder, +}: SearchInputProps) { + const [inputValue, setInputValue] = useState(value); + const [isFocused, setIsFocused] = useState(false); + + const defaultPlaceholder = + size === 'large' ? '이름으로 위키 검색' : '제목을 검색해 주세요.'; + + // 크기별 스타일 + const sizeStyles = { + large: { + container: 'w-[860px] h-[45px] ', + padding: 'p-[8px] pl-[56px] pr-[128px]', + }, + medium: { + container: 'w-[800px] h-[40px] ', + padding: 'p-[8px] pl-[56px] pr-[128px]', + }, + }; + + const currentSize = sizeStyles[size]; + + const inputStyles = [ + currentSize.container, + currentSize.padding, + 'rounded-lg', + 'border-none', + 'bg-gray-100', + 'text-gray-500', + 'text-16', + 'placeholder:text-gray-400', + isFocused + ? 'outline outline-2 outline-green-100' + : 'focus:outline-green-100', + ].join(' '); + + function handleInputChange(e: React.ChangeEvent) { + setInputValue(e.target.value); + } + + function handleSubmit(e: React.FormEvent) { + e.preventDefault(); + onSubmit(inputValue); + } + + return ( +
+
+
+ 검색 아이콘 +
+ + setIsFocused(true)} + onBlur={() => setIsFocused(false)} + /> +
+
+ ); +} + +export default SearchInput; diff --git a/pages/test/index.tsx b/pages/test/index.tsx index 79585f4..fb76771 100644 --- a/pages/test/index.tsx +++ b/pages/test/index.tsx @@ -1,5 +1,6 @@ import Button from '@/components/Button'; import LinkBar from '@/components/LinkBar'; +import SearchInput from '@/components/SearchInput'; export default function Test() { const commonCellClass = 'border-r border-gray-300'; @@ -39,6 +40,12 @@ export default function Test() { + + SearchInput + + + + diff --git a/public/icon/icon-search.svg b/public/icon/icon-search.svg new file mode 100644 index 0000000..343e3af --- /dev/null +++ b/public/icon/icon-search.svg @@ -0,0 +1,3 @@ + + + From 7ace855b6e80ea3e1b593a97e84929b10ca89f3c Mon Sep 17 00:00:00 2001 From: jiminyee Date: Sun, 15 Dec 2024 23:39:11 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=94=A7=EB=82=B4=EB=B6=80=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EA=B4=80=EB=A6=AC=20=EC=A0=9C=EA=B1=B0,=EC=95=84?= =?UTF-8?q?=EC=9D=B4=EC=BD=98=20=EC=A0=95=EB=A0=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/SearchInput.tsx | 54 ++++++++++++++++++-------------------- pages/test/index.tsx | 2 +- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/components/SearchInput.tsx b/components/SearchInput.tsx index 1f2a5bc..f39ee98 100644 --- a/components/SearchInput.tsx +++ b/components/SearchInput.tsx @@ -4,30 +4,28 @@ interface SearchInputProps { size: 'large' | 'medium'; value?: string; onSubmit?: (value: string) => void; + onChange: (value: string) => void; placeholder?: string; } function SearchInput({ size = 'large', + onChange, value = '', onSubmit = () => {}, - placeholder, + placeholder = '검색어를 입력해 주세요', }: SearchInputProps) { - const [inputValue, setInputValue] = useState(value); const [isFocused, setIsFocused] = useState(false); - const defaultPlaceholder = - size === 'large' ? '이름으로 위키 검색' : '제목을 검색해 주세요.'; - // 크기별 스타일 const sizeStyles = { large: { container: 'w-[860px] h-[45px] ', - padding: 'p-[8px] pl-[56px] pr-[128px]', + padding: 'p-[20px] pl-[15px]', }, medium: { container: 'w-[800px] h-[40px] ', - padding: 'p-[8px] pl-[56px] pr-[128px]', + padding: 'p-[20px] pl-[15px]', }, }; @@ -48,35 +46,33 @@ function SearchInput({ ].join(' '); function handleInputChange(e: React.ChangeEvent) { - setInputValue(e.target.value); + onChange(e.target.value); // 부모 컴포넌트에 값 전달 } function handleSubmit(e: React.FormEvent) { e.preventDefault(); - onSubmit(inputValue); + onSubmit(value); // 부모 컴포넌트에서 관리하는 value 전달 } return ( -
-
-
- 검색 아이콘 -
- - setIsFocused(true)} - onBlur={() => setIsFocused(false)} - /> -
+ + 검색 아이콘 + setIsFocused(true)} + onBlur={() => setIsFocused(false)} + />
); } diff --git a/pages/test/index.tsx b/pages/test/index.tsx index fb76771..168cb59 100644 --- a/pages/test/index.tsx +++ b/pages/test/index.tsx @@ -43,7 +43,7 @@ export default function Test() { SearchInput - + {}} /> From 8cc14d80a5cb1385db5d2f1db0b278db8a96a9f2 Mon Sep 17 00:00:00 2001 From: jy <105865068+crazyupinc-design@users.noreply.github.com> Date: Mon, 16 Dec 2024 16:09:16 +0900 Subject: [PATCH 3/5] =?UTF-8?q?SearchInput.tsx=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=ED=96=88=EC=8A=B5=EB=8B=88=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 이미지를 라벨로 감싸고 처리함 --- components/SearchInput.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/components/SearchInput.tsx b/components/SearchInput.tsx index f39ee98..be14a82 100644 --- a/components/SearchInput.tsx +++ b/components/SearchInput.tsx @@ -59,11 +59,13 @@ function SearchInput({ onSubmit={handleSubmit} className="flex items-center rounded-lg bg-gray-100 px-[20px]" > + Date: Mon, 16 Dec 2024 16:19:49 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=EC=9D=B4=EB=AF=B8=EC=A7=80=20=ED=83=9C?= =?UTF-8?q?=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/SearchInput.tsx | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/components/SearchInput.tsx b/components/SearchInput.tsx index be14a82..f9b6098 100644 --- a/components/SearchInput.tsx +++ b/components/SearchInput.tsx @@ -60,13 +60,10 @@ function SearchInput({ className="flex items-center rounded-lg bg-gray-100 px-[20px]" > + 검색 + Date: Mon, 16 Dec 2024 18:52:38 +0900 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=9A=A8Resolve=20lint=20and=20prettier?= =?UTF-8?q?=20issues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/SearchInput.tsx | 6 +++--- pages/test/index.tsx | 1 - tsconfig.json | 24 +++++------------------- 3 files changed, 8 insertions(+), 23 deletions(-) diff --git a/components/SearchInput.tsx b/components/SearchInput.tsx index f9b6098..71cbfe0 100644 --- a/components/SearchInput.tsx +++ b/components/SearchInput.tsx @@ -59,9 +59,9 @@ function SearchInput({ onSubmit={handleSubmit} className="flex items-center rounded-lg bg-gray-100 px-[20px]" > - +