Skip to content

Commit

Permalink
feat: 태그 선택 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
sikkzz committed Feb 2, 2025
1 parent c275a61 commit f578e25
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/SelectTag/SelectTag.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { useState } from "react";

import styles from "@/components/SelectTag/SelectTag.module.scss";
import Button from "@/components/ui/Button/Button";
import Tag from "@/components/ui/Tag/Tag";
import Text from "@/components/ui/Text/Text";

// 임시 데이터
const TAG_LIST = [
"음식이 맛있어요",
"양이 많아요",
Expand All @@ -18,6 +21,18 @@ const TAG_LIST = [
];

const SelectTag = () => {
const [selectedTagList, setSelectedTagList] = useState<string[]>([]);

const handleTagClick = (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
const tag = e.currentTarget.textContent || "";

if (selectedTagList.includes(tag)) {
setSelectedTagList(selectedTagList.filter((selectedTag) => selectedTag !== tag));
} else {
setSelectedTagList([...selectedTagList, tag]);
}
};

return (
<div className={styles.SelectTag}>
<div className={styles.Top}>
Expand All @@ -31,7 +46,12 @@ const SelectTag = () => {
</div>
<div className={styles.TagList}>
{TAG_LIST.map((tag) => (
<Tag text={tag} key={tag} />
<Tag
text={tag}
key={tag}
onClick={handleTagClick}
isSelect={selectedTagList.includes(tag)}
/>
))}
<Tag variant="add" />
</div>
Expand Down

0 comments on commit f578e25

Please sign in to comment.