-
Notifications
You must be signed in to change notification settings - Fork 0
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
검색 모달 컴포넌트 구현 #62
Merged
Merged
검색 모달 컴포넌트 구현 #62
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
89ff8d1
chore: #57 - trend mock data 추가
eeseung 62a9475
refactor: #57 - DropdownProps onChange 타입 수정
eeseung 16c2cf5
feat: #57 - Dropdown 컴포넌트 영문 옵션 추가
eeseung 0feea67
feat: #57 - DropdownItemProps value 추가
eeseung 42d57b7
style: #57 - Tab 컴포넌트 z-index 추가
eeseung f630c50
feat: #57 - SearchModal 컴포넌트 구현
eeseung cbbdafa
feat: #57 - 헤더 & 검색 모달 연결
eeseung 46144d2
fix: #57 - 드롭다운 옵션 오타 수정
eeseung d255f8d
Merge branch 'develop' into feature/#57/search-modal
eeseung File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
export const TYPES = { | ||
space: ['최신순', '즐겨찾기순'], | ||
link: ['최신순', '좋아요순'], | ||
search: ['스페이스', '유저'], | ||
user_edit: ['편집 허용', '읽기 허용', '제거'], | ||
user_invite: ['편집 허용', '읽기 허용'], | ||
} | ||
export const DROPDOWN_OPTIONS = { | ||
space: { 최신순: 'recent', 즐겨찾기순: 'scrap' }, | ||
link: { 최신순: 'recent', 좋아요순: 'favorite' }, | ||
search: { 스페이스: 'space', 유저: 'user' }, | ||
user_edit: { '편집 혀용': 'edit', '읽기 허용': 'view', 제거: 'remove' }, | ||
user_invite: { '편집 허용': 'eidt', '읽기 허용': 'view' }, | ||
} as const | ||
|
||
export const VERTICAL_PADDING = { | ||
large: 'py-2.5', | ||
medium: 'py-1.5', | ||
small: 'py-0.5', | ||
} | ||
} as const | ||
|
||
export const PLACEMENTS = { | ||
left: 'left-0', | ||
right: 'right-0', | ||
} | ||
} as const |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
'use client' | ||
|
||
import { useRef } from 'react' | ||
import { useForm } from 'react-hook-form' | ||
import { Dropdown } from '@/components' | ||
import Input from '../Input/Input' | ||
import { SEARCH_MODAL_TITLE } from './constants' | ||
import useSearchModal from './hooks/useSearchModal' | ||
|
||
export interface SearchModalProps { | ||
onClose: () => void | ||
} | ||
|
||
export interface SearchFormValues { | ||
search: string | ||
target: string | ||
} | ||
|
||
const SearchModal = ({ onClose }: SearchModalProps) => { | ||
const { register, setValue, setFocus, handleSubmit } = | ||
useForm<SearchFormValues>({ | ||
defaultValues: { | ||
search: '', | ||
target: 'space', | ||
}, | ||
}) | ||
const searchModalRef = useRef<HTMLDivElement>(null) | ||
const { | ||
trends, | ||
handleOverlayClick, | ||
handleTargetChange, | ||
handleKeywordClick, | ||
onSubmit, | ||
} = useSearchModal({ | ||
searchModalRef, | ||
setValue, | ||
setFocus, | ||
onClose, | ||
}) | ||
|
||
return ( | ||
<div | ||
ref={searchModalRef} | ||
onClick={handleOverlayClick} | ||
className="fixed left-0 right-0 top-0 z-50 mx-auto flex h-screen w-full max-w-[500px] flex-col justify-center bg-black/40 shadow-xl"> | ||
<div className="max-h-content absolute top-0 flex w-full flex-col rounded-b-xl bg-bgColor px-4 pb-4"> | ||
<form | ||
className="flex gap-x-1.5 py-1.5" | ||
onSubmit={handleSubmit(onSubmit)}> | ||
<div className="shrink-0"> | ||
<Dropdown | ||
type="search" | ||
size="large" | ||
onChange={handleTargetChange} | ||
/> | ||
</div> | ||
<div className="grow"> | ||
<Input | ||
{...register('search', { required: true })} | ||
placeholder="검색어를 입력하세요." | ||
inputButton={true} | ||
buttonText="검색" | ||
/> | ||
</div> | ||
</form> | ||
<h2 className="py-4 font-bold text-gray9">{SEARCH_MODAL_TITLE}</h2> | ||
<ul> | ||
{trends.map((trend) => ( | ||
<li | ||
className="border-b border-gray3 px-3 py-2.5 text-sm font-medium text-gray9 last:border-none" | ||
onClick={handleKeywordClick} | ||
key={trend.keyword}> | ||
{trend.keyword} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default SearchModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const SEARCH_MODAL_TITLE = '인기 검색어' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useEffect } from 'react' | ||
import { | ||
SubmitHandler, | ||
UseFormSetFocus, | ||
UseFormSetValue, | ||
} from 'react-hook-form' | ||
import { mock_trendData } from '@/data' | ||
import { useRouter } from 'next/navigation' | ||
import { SearchFormValues } from '../SearchModal' | ||
|
||
export interface useSearchModalProps { | ||
searchModalRef: React.RefObject<HTMLDivElement> | ||
setValue: UseFormSetValue<SearchFormValues> | ||
setFocus: UseFormSetFocus<SearchFormValues> | ||
onClose: () => void | ||
} | ||
|
||
const useSearchModal = ({ | ||
searchModalRef, | ||
setValue, | ||
setFocus, | ||
onClose, | ||
}: useSearchModalProps) => { | ||
const router = useRouter() | ||
const trends = mock_trendData | ||
|
||
useEffect(() => { | ||
setFocus('search') | ||
}, [setFocus]) | ||
|
||
const handleTargetChange = (e: React.MouseEvent<HTMLButtonElement>) => { | ||
setValue('target', e.currentTarget.value) | ||
} | ||
|
||
const handleKeywordClick = (e: React.MouseEvent<HTMLLIElement>) => { | ||
router.push(`/search?target=space&keyword=${e.currentTarget.innerText}`) | ||
} | ||
|
||
const handleOverlayClick = (e: React.MouseEvent<HTMLDivElement>) => { | ||
if (e.target === searchModalRef.current) { | ||
onClose() | ||
} | ||
} | ||
|
||
const onSubmit: SubmitHandler<SearchFormValues> = (data) => { | ||
router.push(`/search?target=${data.target}&keyword=${data.search}`) | ||
} | ||
|
||
return { | ||
trends, | ||
handleTargetChange, | ||
handleKeywordClick, | ||
handleOverlayClick, | ||
onSubmit, | ||
} | ||
} | ||
|
||
export default useSearchModal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
편집 혀용..?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
앗 수정했습니다! 🙈