-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
77 additions
and
46 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,55 @@ | ||
'use client'; | ||
|
||
import { ProjectSortOption } from '@/types'; | ||
import type { ProjectSortOption, ProjectSortOptionState } from '@/types'; | ||
import { Text } from '@jjoing/ui'; | ||
import { memo, useState } from 'react'; | ||
import { Dispatch, memo, SetStateAction, useState } from 'react'; | ||
import { IoIosArrowDown, IoIosArrowUp } from 'react-icons/io'; | ||
|
||
type ProjectSelectBoxProps = { | ||
options: ProjectSortOption[]; | ||
setSelectedSortOption: Dispatch<SetStateAction<ProjectSortOptionState>>; | ||
}; | ||
|
||
const ProjectSelectBox = memo(({ options }: ProjectSelectBoxProps) => { | ||
const [isClickButton, setIsClickButton] = useState(false); | ||
const [clickButtonOption, setClickButtonOption] = useState(options[0]); // 백엔드로 요청할때는 id를 넘겨야 하므로 객체를 기본값으로 가짐 | ||
const ProjectSelectBox = memo( | ||
({ options, setSelectedSortOption }: ProjectSelectBoxProps) => { | ||
const [isClickButton, setIsClickButton] = useState(false); | ||
const [clickButtonOption, setClickButtonOption] = useState(options[0]); | ||
|
||
const handleOpenAndCloseOptions = () => { | ||
setIsClickButton(!isClickButton); | ||
}; | ||
const handleOpenAndCloseOptions = () => { | ||
setIsClickButton(!isClickButton); | ||
}; | ||
|
||
const handleOptionClick = (option: ProjectSortOption) => { | ||
setClickButtonOption(option); | ||
setIsClickButton(false); | ||
}; | ||
const handleOptionClick = (option: ProjectSortOption) => { | ||
setClickButtonOption(option); | ||
setSelectedSortOption(option.state); | ||
setIsClickButton(false); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col gap-5 relative"> | ||
<button | ||
className="w-[150px] h-[40px] px-3 border border-gray-300 focus:border-gray-400 rounded-md bg-white flex items-center justify-between transition duration-30" | ||
onClick={handleOpenAndCloseOptions} | ||
> | ||
<Text type="body3">{clickButtonOption?.content}</Text> | ||
{isClickButton ? <IoIosArrowUp /> : <IoIosArrowDown />} | ||
</button> | ||
{isClickButton && ( | ||
<div className="absolute top-[45px] w-full border rounded-md border-gray-300 bg-white z-10"> | ||
{options.map((option) => ( | ||
<div | ||
className="w-full h-[40px] px-3 flex items-center cursor-p rounded-md hover:bg-gray-100 transition duration-30" | ||
onClick={() => handleOptionClick(option)} | ||
key={option.id} | ||
> | ||
<Text type="body3">{option.content}</Text> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}); | ||
return ( | ||
<div className="flex flex-col gap-5 relative"> | ||
<button | ||
className="w-[150px] h-[40px] px-3 border border-gray-300 focus:border-gray-400 rounded-md bg-white flex items-center justify-between transition duration-30" | ||
onClick={handleOpenAndCloseOptions} | ||
> | ||
<Text type="body3">{clickButtonOption?.content}</Text> | ||
{isClickButton ? <IoIosArrowUp /> : <IoIosArrowDown />} | ||
</button> | ||
{isClickButton && ( | ||
<div className="absolute top-[45px] w-full border rounded-md border-gray-300 bg-white z-10"> | ||
{options.map((option) => ( | ||
<div | ||
className="w-full h-[40px] px-3 flex items-center cursor-p rounded-md hover:bg-gray-100 transition duration-30" | ||
onClick={() => handleOptionClick(option)} | ||
key={option.id} | ||
> | ||
<Text type="body3">{option.content}</Text> | ||
</div> | ||
))} | ||
</div> | ||
)} | ||
</div> | ||
); | ||
} | ||
); | ||
|
||
export default ProjectSelectBox; |
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,17 +1,19 @@ | ||
export const ProjectRecruitOptions = [ | ||
import type { ProjectSortOption } from '@/types'; | ||
|
||
export const ProjectRecruitOptions: ProjectSortOption[] = [ | ||
{ | ||
id: 0, | ||
content: '최신순', | ||
criteria: '', | ||
state: '', | ||
}, | ||
{ | ||
id: 1, | ||
content: '조회수 많은 순', | ||
criteria: 'view', | ||
state: 'view', | ||
}, | ||
{ | ||
id: 2, | ||
content: '좋아요 많은 순', | ||
criteria: 'like', | ||
state: 'like', | ||
}, | ||
]; |
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 +1,2 @@ | ||
export * from './projectSortOption'; | ||
export * from './projectSortOptionState'; |
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,6 +1,7 @@ | ||
import type { ProjectSortOptionState } from './projectSortOptionState'; | ||
|
||
export type ProjectSortOption = { | ||
id: number; | ||
content: string; | ||
criteria?: string; | ||
state?: string; | ||
state?: ProjectSortOptionState; | ||
}; |
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,7 @@ | ||
export type ProjectSortOptionState = | ||
| '' | ||
| 'view' | ||
| 'like' | ||
| 'FINDING' | ||
| 'FOUND' | ||
| undefined; |