-
Notifications
You must be signed in to change notification settings - Fork 6
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
11 changed files
with
306 additions
and
9 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,85 @@ | ||
import * as RadioGroup from '@radix-ui/react-radio-group'; | ||
import { useState } from 'react'; | ||
|
||
interface RadioSelectProps { | ||
items: (string | number)[] | Record<string, string | number>; | ||
ariaLabel: string; | ||
onSelectionChange: (selectedValue: string | number) => void; | ||
gridCols?: number; | ||
} | ||
|
||
type gridColumnsType = { | ||
[key: number]: string; | ||
}; | ||
|
||
const gridColumns: gridColumnsType = { | ||
2: 'grid grid-cols-2', | ||
3: 'grid grid-cols-3', | ||
4: 'grid grid-cols-4', | ||
}; | ||
|
||
export const RadioSelect: React.FC<RadioSelectProps> = ({ | ||
items, | ||
ariaLabel, | ||
onSelectionChange, | ||
gridCols = 2, | ||
}) => { | ||
const [selectedValue, setSelectedValue] = useState<string | number | null>( | ||
null, | ||
); | ||
|
||
console.log('selected Radio value:', selectedValue); | ||
|
||
const handleRadioChange = (value: string | number) => { | ||
setSelectedValue(value); | ||
onSelectionChange(value); | ||
}; | ||
|
||
const gridClassName = gridColumns[gridCols] || gridColumns[2]; | ||
return ( | ||
<> | ||
<form> | ||
<RadioGroup.Root | ||
className={`RadioGroupRoot grid w-full gap-x-4 ${gridClassName}`} | ||
onValueChange={handleRadioChange} | ||
aria-label={ariaLabel}> | ||
{Array.isArray(items) | ||
? items.map((value) => ( | ||
<div key={value}> | ||
<RadioGroup.Item | ||
className="RadioGroupItem" | ||
value={value as string} | ||
id={`r${value}`}> | ||
<RadioGroup.Indicator className="RadioGroupIndicator absolute" /> | ||
</RadioGroup.Item> | ||
<label | ||
className={`Label block flex h-10 w-full cursor-pointer items-center justify-center rounded-lg bg-gray1 transition-colors ${ | ||
selectedValue === value ? 'bg-gray3' : '' | ||
}`} | ||
htmlFor={`r${value}`}> | ||
{String(value)} | ||
</label> | ||
</div> | ||
)) | ||
: Object.entries(items).map(([label, value]) => ( | ||
<div key={String(value)}> | ||
<RadioGroup.Item | ||
className="RadioGroupItem" | ||
value={String(value)} | ||
id={`r${value}`}> | ||
<RadioGroup.Indicator className="RadioGroupIndicator absolute" /> | ||
</RadioGroup.Item> | ||
<label | ||
className={`Label block flex h-10 w-full cursor-pointer items-center justify-center rounded-lg bg-gray1 transition-colors ${ | ||
selectedValue === String(value) ? 'bg-gray3' : '' | ||
}`} | ||
htmlFor={`r${value}`}> | ||
{label} | ||
</label> | ||
</div> | ||
))} | ||
</RadioGroup.Root> | ||
</form> | ||
</> | ||
); | ||
}; |
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,19 @@ | ||
import { AREA_CODE } from '@/constants'; | ||
import { RadioSelect } from '@components/common/radio/Radio'; | ||
|
||
interface RegionSelectProps { | ||
onRegionChange: (selectedRegion: string | number) => void; | ||
} | ||
|
||
export const RegionSelect: React.FC<RegionSelectProps> = ({ | ||
onRegionChange, | ||
}) => { | ||
return ( | ||
<RadioSelect | ||
items={AREA_CODE} | ||
ariaLabel="지역선택" | ||
onSelectionChange={onRegionChange} | ||
gridCols={3} | ||
/> | ||
); | ||
}; |
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,14 @@ | ||
export const SearchInput = () => { | ||
return ( | ||
<> | ||
<div className="relative flex items-center "> | ||
<button className=" backIcon bg-gray5 mr-2.5 h-[24px] w-[24px]" /> | ||
<div className="absolute left-[52px] top-1/2 h-[12px] w-[12px] -translate-y-1/2 transform bg-black" /> | ||
<input | ||
className="bg-gray1 body1 ml-2.5 h-[40px] w-full items-center rounded-lg pl-[32px] pr-2.5 focus:outline-none" | ||
onClick={() => {}} | ||
placeholder="어디로 떠나세요?"></input> | ||
</div> | ||
</> | ||
); | ||
}; |
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,18 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
export const StartSearchButton = () => { | ||
const navigate = useNavigate(); | ||
|
||
const goToSearch = () => { | ||
navigate('/search'); | ||
}; | ||
|
||
return ( | ||
<button | ||
className="flex h-[40px] w-full items-center border-b-2 border-solid px-1" | ||
onClick={goToSearch}> | ||
<div className=" searchIcon mr-2.5 h-[12px] w-[12px]" /> | ||
<span className="text-gray4 body1">어디로 떠나세요?</span> | ||
</button> | ||
); | ||
}; |
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,19 @@ | ||
export const AREA_CODE = { | ||
서울: '서울', | ||
부산: '부산', | ||
대구: '대구', | ||
인천: '인천', | ||
광주: '광주', | ||
대전: '대전', | ||
울산: '울산', | ||
세종: '세종', | ||
제주: '제주', | ||
경기: '경기', | ||
강원: '강원', | ||
충북: '충북', | ||
충남: '충남', | ||
경북: '경북', | ||
경남: '경남', | ||
전북: '전북', | ||
전남: '전남', | ||
}; |
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,15 @@ | ||
import { RegionSelect } from '@components/search/RegionSelect'; | ||
import { SearchInput } from '@components/search/SearchInput'; | ||
|
||
export const Search = () => { | ||
const handleRegionChange = (selectedRegion: string | number) => { | ||
console.log('선택한 지역:', selectedRegion); | ||
}; | ||
|
||
return ( | ||
<> | ||
<SearchInput /> | ||
<RegionSelect onRegionChange={handleRegionChange} /> | ||
</> | ||
); | ||
}; |
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