-
Notifications
You must be signed in to change notification settings - Fork 1
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
4 changed files
with
54 additions
and
23 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { useState } from 'react'; | ||
import InteractiveEmotionIconCard from '@/components/Emotion/card/InteractiveEmotionIconCard'; | ||
|
||
// EmotionSelector 컴포넌트 함수 선언 | ||
function EmotionSelector() { | ||
// 감정 카드 상태 관리 | ||
const [states, setStates] = useState({ | ||
감동: 'Default' as 'Default' | 'Unclicked' | 'Clicked', | ||
기쁨: 'Default' as 'Default' | 'Unclicked' | 'Clicked', | ||
고민: 'Default' as 'Default' | 'Unclicked' | 'Clicked', | ||
슬픔: 'Default' as 'Default' | 'Unclicked' | 'Clicked', | ||
분노: 'Default' as 'Default' | 'Unclicked' | 'Clicked', | ||
}); | ||
|
||
// 감정 카드 클릭 핸들러 | ||
const handleCardClick = (iconType: '감동' | '기쁨' | '고민' | '슬픔' | '분노') => { | ||
setStates((prevStates) => { | ||
const newStates = { ...prevStates }; | ||
|
||
if (prevStates[iconType] === 'Clicked') { | ||
// 현재 클릭된 카드가 다시 클릭되면 모두 Default로 설정 | ||
Object.keys(newStates).forEach((key) => { | ||
newStates[key as '감동' | '기쁨' | '고민' | '슬픔' | '분노'] = 'Default'; | ||
}); | ||
} else { | ||
// 하나의 카드가 클릭되면 그 카드만 Clicked, 나머지는 Unclicked로 설정 | ||
Object.keys(newStates).forEach((key) => { | ||
newStates[key as '감동' | '기쁨' | '고민' | '슬픔' | '분노'] = key === iconType ? 'Clicked' : 'Unclicked'; | ||
}); | ||
} | ||
|
||
return newStates; | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className='w-[544px] h-[136px] justify-start items-start gap-4 inline-flex'> | ||
{(['감동', '기쁨', '고민', '슬픔', '분노'] as const).map((iconType) => ( | ||
<InteractiveEmotionIconCard key={iconType} iconType={iconType} size='lg' state={states[iconType]} onClick={() => handleCardClick(iconType)} /> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
export default EmotionSelector; |
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