Skip to content

[recover] selectbox #24

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 3 commits into from
Jun 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/components/Home.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import RecommendPlaceList from '@/components/selectbox/RecommendPlaceList';
import Selectbox from '@/components/selectbox/Selectbox';
import type { RecommendPlaceResponse } from '@/components/selectbox/types/type';
import { useCallback, useEffect, useRef, useState } from 'react';
Expand All @@ -7,6 +6,7 @@ import SearchBar from '@/components/searchbar/SearchBar';
import Carousel from '@/components/carousel/Carousel';
import RankingMovie from '@/components/movie/RankingMovie';
import { movies } from '@/mock/data';
import RecommendPlace from '@/components/selectbox/RecommendPlace';
import { searchbarElements } from '@/components/searchbar/mocks/searchbar';

export default function Home() {
Expand Down Expand Up @@ -44,7 +44,17 @@ export default function Home() {
임시 selectbox
</span>
<Selectbox isOpen={isOpen} setIsOpen={setIsOpen} excludeClickRef={ref}>
<RecommendPlaceList data={data} />
{data.map(({ title, items }, idx) => {
return (
<Selectbox.Group title={title}>
{items.map((item) => (
<Selectbox.option key={idx} value={item}>
<RecommendPlace {...item} />
</Selectbox.option>
))}
</Selectbox.Group>
);
})}
</Selectbox>

<SearchBar elements={searchbarElements} />
Expand Down
13 changes: 10 additions & 3 deletions src/components/selectbox/Selectbox.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import SelectboxOption from '@/components/selectbox/components/SelectBoxOption';
import useOutsideClick from '@/components/selectbox/hooks/useOutsideClick';
import SelectboxGroup from '@/components/selectbox/SelectboxGroup';
import { useRef, type SetStateAction } from 'react';

type SelectboxProps = {
Expand All @@ -10,14 +12,14 @@ type SelectboxProps = {
excludeClickRef: React.RefObject<HTMLElement | null>;
};

export default function Selectbox({
const Selectbox = ({
children,
isCloseOnClickOutside = true,
isCloseOnPressedESC = true,
isOpen,
setIsOpen,
excludeClickRef,
}: SelectboxProps) {
}: SelectboxProps) => {
const ref = useRef<HTMLDivElement>(null);

useOutsideClick({
Expand All @@ -38,4 +40,9 @@ export default function Selectbox({
</div>
)
);
}
};

Selectbox.Group = SelectboxGroup;
Selectbox.option = SelectboxOption;

export default Selectbox;
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { RecommendPlaceResponse } from '@/components/selectbox/types/type';

type SelectBoxItemProps = {
type SelectBoxOptionProps = {
children: React.ReactNode;
value: RecommendPlaceResponse['items'][number];
};

export default function SelectBoxItem({ children, value }: SelectBoxItemProps) {
export default function SelectboxOption({ children, value }: SelectBoxOptionProps) {
const { itemId, itemTitle } = value;

const handleClickItem = () => {
Expand Down
Loading