-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨feat: 공고 검색 페이지에서 dropdown 구현하기 #15
- Loading branch information
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,56 @@ | ||
import { useState } from 'react'; | ||
import DownArrowIcon from '@/assets/icons/PostSearch/DownArrowIcon.svg?react'; | ||
|
||
type DropdownProps = { | ||
options: string[]; | ||
value: string | undefined; | ||
onSelect: (option: string) => void; | ||
}; | ||
|
||
// DropdownModal 컴포넌트: 드롭다운 옵션을 표시하는 모달 | ||
const DropdownModal = ({ options, value, onSelect }: DropdownProps) => { | ||
return ( | ||
<div className="w-min absolute top-[1.7rem] right-0 shadow rounded-2xl bg-white border border-[#dcdcdc] flex flex-row items-start justify-start p-2 text-left text-sm text-[#656565]"> | ||
<div className="flex-1 flex flex-col items-start justify-start gap-[5px]"> | ||
{options.map((option, index) => ( | ||
<div | ||
key={index} | ||
className={`px-2 py-2 ${value == option && 'bg-[#f4f4f9] text-[#1e1926]'} rounded-lg caption-1-sb`} | ||
onClick={() => onSelect(option)} | ||
> | ||
{option} | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
const PostSearchSortDropdown = ({ | ||
options, | ||
value, | ||
onSelect, | ||
}: DropdownProps) => { | ||
const [isOpen, setIsOpen] = useState(false); | ||
return ( | ||
<div className="relative"> | ||
<button | ||
onClick={() => setIsOpen(!isOpen)} | ||
className="flex items-center gap-[0.25rem] py-[0.25rem] px-[0.5rem] rounded-[0.25rem] border-[0.031rem] border-[#1E1926] text-[#1E1926] caption-1-sb" | ||
> | ||
{value} | ||
<div | ||
className={`transition-transform duration-300 ${ | ||
isOpen && 'rotate-180' | ||
}`} | ||
> | ||
<DownArrowIcon /> | ||
</div> | ||
</button> | ||
{isOpen && ( | ||
<DropdownModal value={value} options={options} onSelect={onSelect} /> | ||
)} | ||
</div> | ||
); | ||
}; | ||
export default PostSearchSortDropdown; |
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