-
Notifications
You must be signed in to change notification settings - Fork 1
✨Feat: 드롭다운 컴포넌트 구현 및 드롭다운 아이템 상수 옵션 추가 #26
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e1b8c42
🖼️ feat: dropdown.svg 아이콘 추가
minimo-9 747faa8
✨ feat: 주소 및 카테고리 옵션 추가
minimo-9 b0c4e1b
✨ feat: 드롭다운 컴포넌트 추가
minimo-9 0538051
🐛 fix: 아이템이 잘리는 현상 해결
minimo-9 2b880c6
🐛 fix: 피드백 적용 완료
minimo-9 b772d5a
Merge branch 'develop' into feat/dropdown
minimo-9 9f0085a
🐛 fix: px단위 수정
minimo-9 85d0dc0
🐛 fix: 주영님 피드백 반영 완료
minimo-9 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 그렇네요! 바로 바꿀게요
Moon-ju-young marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or 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,92 @@ | ||
| import { | ||
| useEffect, | ||
| useRef, | ||
| useState, | ||
| type Dispatch, | ||
| type SetStateAction, | ||
| } from 'react'; | ||
| import Down from '@/assets/icons/dropdown.svg'; | ||
|
|
||
| interface DropdownProps { | ||
| options: string[]; | ||
| selected: string; | ||
| setSelect: Dispatch<SetStateAction<string>>; // Dispatch<SetStateAction<string>>는 set함수 타입 | ||
| placeholder?: string; | ||
| variant: 'form' | 'filter'; | ||
| } | ||
|
|
||
| export default function Dropdown({ | ||
| options, | ||
| selected, | ||
| setSelect, | ||
| placeholder = '선택', | ||
| variant, | ||
| }: DropdownProps) { | ||
| const [isOpen, setIsOpen] = useState(false); | ||
| const dropdownRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| const toggleDropdown = () => { | ||
| setIsOpen((prev) => !prev); | ||
| }; | ||
|
|
||
| const closeDropdown = () => { | ||
| setIsOpen(false); | ||
| }; | ||
|
|
||
| const handleSelect = (options: string) => { | ||
| setSelect(options); | ||
| closeDropdown(); | ||
| }; | ||
|
|
||
| // 외부 클릭 시 닫힘 | ||
| useEffect(() => { | ||
| const handleClickOutside = (e: MouseEvent) => { | ||
| if (!dropdownRef.current?.contains(e.target as Node)) { | ||
| closeDropdown(); | ||
| } | ||
| }; | ||
| document.addEventListener('click', handleClickOutside); | ||
| return () => { | ||
| document.removeEventListener('click', handleClickOutside); | ||
| }; | ||
| }, []); | ||
|
|
||
| return ( | ||
| <div ref={dropdownRef} className="relative"> | ||
| <button | ||
| type="button" | ||
| onClick={toggleDropdown} | ||
| className={`flex items-center justify-between rounded-md ${variant === 'form' ? 'h-58 w-full border border-gray-30 bg-white px-20 py-16 text-body1 font-regular' : 'rounded-5 h-30 w-105 justify-center gap-6 bg-gray-10 px-12 text-body2 font-bold'}`} | ||
| > | ||
| <span className={selected ? 'text-black' : 'text-gray-40'}> | ||
| {selected || placeholder} | ||
| </span> | ||
| <img | ||
| src={Down} | ||
| alt="arrow down" | ||
| className={`${isOpen ? '' : 'rotate-180'} ${variant === 'form' ? 'h-16 w-16' : 'h-10 w-10'}`} | ||
| /> | ||
| </button> | ||
|
|
||
| {isOpen && ( | ||
| <div | ||
| className={`absolute right-0 left-0 mt-8 flex cursor-pointer flex-col rounded-md border border-gray-20 bg-white text-black ${variant === 'form' ? 'h-230 w-full overflow-y-auto' : 'h-160 w-105 justify-center py-12'}`} | ||
| > | ||
| <ul | ||
| className={`${variant === 'form' ? '' : 'flex h-136 flex-col gap-8'}`} | ||
| > | ||
| {options.map((option) => ( | ||
| <li | ||
| key={option} | ||
| onClick={() => handleSelect(option)} | ||
| className={`flex items-center justify-center border-b border-gray-20 text-body2 leading-22 font-regular text-black last:border-b-0 ${variant === 'form' ? 'pt-12 pb-11' : 'pb-8'}`} | ||
| > | ||
| {option} | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| </div> | ||
| )} | ||
| </div> | ||
| ); | ||
| } |
Empty file.
This file contains hidden or 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,45 @@ | ||
| export const ADDRESS_OPTIONS = [ | ||
| '서울시 종로구', | ||
| '서울시 중구', | ||
| '서울시 용산구', | ||
| '서울시 성동구', | ||
| '서울시 광진구', | ||
| '서울시 동대문구', | ||
| '서울시 중랑구', | ||
| '서울시 성북구', | ||
| '서울시 강북구', | ||
| '서울시 도봉구', | ||
| '서울시 노원구', | ||
| '서울시 은평구', | ||
| '서울시 서대문구', | ||
| '서울시 마포구', | ||
| '서울시 양천구', | ||
| '서울시 강서구', | ||
| '서울시 구로구', | ||
| '서울시 금천구', | ||
| '서울시 영등포구', | ||
| '서울시 동작구', | ||
| '서울시 관악구', | ||
| '서울시 서초구', | ||
| '서울시 강남구', | ||
| '서울시 송파구', | ||
| '서울시 강동구', | ||
| ]; | ||
|
|
||
| export const CATEGORY_OPTIONS = [ | ||
| '한식', | ||
| '중식', | ||
| '일식', | ||
| '양식', | ||
| '분식', | ||
| '카페', | ||
| '편의점', | ||
| '기타', | ||
| ]; | ||
|
|
||
| export const SORT_OPTIONS = [ | ||
| '마감임박순', | ||
| '시급많은순', | ||
| '시간적은순', | ||
| '가나다순', | ||
| ]; |
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.

Uh oh!
There was an error while loading. Please reload this page.