|
| 1 | +// 태그 색상 변경용 태그 컬러칩 |
| 2 | +import clsx from "clsx"; |
| 3 | + |
| 4 | +const tagColors = [ |
| 5 | + { |
| 6 | + textColor: "text-[var(--sortTextBlue)]", |
| 7 | + bgColor: "bg-[var(--sortTextBgBlue)]", |
| 8 | + }, |
| 9 | + { |
| 10 | + textColor: "text-[var(--sortTextPink)]", |
| 11 | + bgColor: "bg-[var(--sortTextBgPink)]", |
| 12 | + }, |
| 13 | + { |
| 14 | + textColor: "text-[var(--sortTextGreen)]", |
| 15 | + bgColor: "bg-[var(--sortTextBgGreen)]", |
| 16 | + }, |
| 17 | + { |
| 18 | + textColor: "text-[var(--sortTextOrange)]", |
| 19 | + bgColor: "bg-[var(--sortTextBgOrange)]", |
| 20 | + }, |
| 21 | +]; |
| 22 | + |
| 23 | +interface Tag { |
| 24 | + text: string; |
| 25 | + textColor: string; |
| 26 | + bgColor: string; |
| 27 | +} |
| 28 | + |
| 29 | +interface TagColorChipProps { |
| 30 | + tags: Tag[]; |
| 31 | + selectedTagIndex: number | null; |
| 32 | + setTags: (tags: Tag[]) => void; |
| 33 | + onValueChange: (newTags: string[]) => void; |
| 34 | +} |
| 35 | + |
| 36 | +export function TagColorChip({ |
| 37 | + tags, |
| 38 | + selectedTagIndex, |
| 39 | + setTags, |
| 40 | + onValueChange, |
| 41 | +}: TagColorChipProps) { |
| 42 | + return ( |
| 43 | + <> |
| 44 | + {selectedTagIndex !== null && ( |
| 45 | + <div className="flex gap-2"> |
| 46 | + {tagColors.map((color, colorIdx) => ( |
| 47 | + <div |
| 48 | + key={colorIdx} |
| 49 | + onClick={() => { |
| 50 | + const updatedTags = [...tags]; |
| 51 | + updatedTags[selectedTagIndex] = { |
| 52 | + ...updatedTags[selectedTagIndex], |
| 53 | + textColor: color.textColor, |
| 54 | + bgColor: color.bgColor, |
| 55 | + }; |
| 56 | + setTags(updatedTags); |
| 57 | + onValueChange(updatedTags.map((tag) => tag.text)); |
| 58 | + }} |
| 59 | + className={clsx( |
| 60 | + "w-5 h-5 rounded-full cursor-pointer", |
| 61 | + color.bgColor, |
| 62 | + selectedTagIndex !== null && |
| 63 | + tags[selectedTagIndex]?.bgColor === color.bgColor && |
| 64 | + "ring-[1.5px] ring-[var(--primary)]" |
| 65 | + )} |
| 66 | + /> |
| 67 | + ))} |
| 68 | + </div> |
| 69 | + )} |
| 70 | + </> |
| 71 | + ); |
| 72 | +} |
0 commit comments