-
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
Changes from 4 commits
e1b8c42
747faa8
b0c4e1b
0538051
2b880c6
b772d5a
9f0085a
85d0dc0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
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
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||
| import { useEffect, useRef, useState } from 'react'; | ||||||
| import Down from '@/assets/icons/dropdown.svg'; | ||||||
|
|
||||||
| interface DropdownProps { | ||||||
| items: string[]; | ||||||
|
||||||
| selected: string; | ||||||
| onSelect: (value: string) => void; | ||||||
|
||||||
| placeholder?: string; | ||||||
| variant: 'form' | 'filter'; | ||||||
| } | ||||||
|
|
||||||
| export default function Dropdown({ | ||||||
| items, | ||||||
| selected, | ||||||
| onSelect, | ||||||
| placeholder = '선택', | ||||||
| variant, | ||||||
| }: DropdownProps) { | ||||||
| const [isOpen, setIsOpen] = useState(false); | ||||||
| const dropdownRef = useRef<HTMLDivElement>(null); | ||||||
|
|
||||||
| const toggleDropdown = () => { | ||||||
| setIsOpen((prev) => !prev); | ||||||
| }; | ||||||
|
|
||||||
| const closeDropdown = () => { | ||||||
| setIsOpen(false); | ||||||
| }; | ||||||
|
|
||||||
| const handleSelect = (item: string) => { | ||||||
| onSelect(item); | ||||||
| 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 cursor-pointer items-center justify-between rounded-md border border-gray-30 bg-white ${variant === 'form' ? 'w-full px-5 py-4 text-base' : 'bg-gray-10px-3 rounded-[5px]px-3 h-[30px] w-[105px] gap-[6px] px-2.5 text-sm'}`} | ||||||
|
||||||
| className={`flex cursor-pointer items-center justify-between rounded-md border border-gray-30 bg-white ${variant === 'form' ? 'w-full px-5 py-4 text-base' : 'bg-gray-10px-3 rounded-[5px]px-3 h-[30px] w-[105px] gap-[6px] px-2.5 text-sm'}`} | |
| className={`flex cursor-pointer items-center justify-between rounded-md border border-gray-30 bg-white ${variant === 'form' ? 'w-full px-5 py-4 text-base' : 'bg-gray-10px-3 rounded-[5px] px-3 h-[30px] w-[105px] gap-[6px] px-2.5 text-sm'}`} |
❗ 띄어쓰기가 빠진 거 같아요
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.
오 못봤는데 감사합니다!
Outdated
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.
text-sm 은 14px을 의미하는데, 저희는 스타일 변수로 text-body2를 14px로 지정해두었습니다.
저희가 프로젝트에서 사용할 텍스트 크기를 따로 변수로 지정해둔 것이기 때문에 웬만하면 그걸 사용하시는게 가독성 면에서도 좋고, 사용하기도 편하실거에요!😄
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.
오 감사합니다 몰랐는데 바로 적용해야겠네요
| 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 = [ | ||
| '마감임박순', | ||
| '시급많은순', | ||
| '시간적은순', | ||
| '가나다순', | ||
| ]; |

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