diff --git a/src/app/globals.css b/src/app/globals.css index 752ecc7..203f024 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -28,6 +28,9 @@ body { .Text-gray { @apply text-[#787486] dark:text-[#BCBCBC]; } +.Text-white { + @apply text-[#FFFFFF] dark:text-[#333236]; +} .Border-btn { @apply border border-[#D9D9D9] dark:border-[#747474]; } diff --git a/src/app/shared/components/common/Profile.tsx b/src/app/shared/components/common/Profile.tsx new file mode 100644 index 0000000..f4e6d29 --- /dev/null +++ b/src/app/shared/components/common/Profile.tsx @@ -0,0 +1,80 @@ +'use client' + +import Image from 'next/image' + +type ProfileProps = { + nickname: string + imageUrl?: string + size?: number +} + +const customColors = [ + '#efaa8d', + '#FFC85A', + '#b9ef8d', + '#8eef8d', + '#8defd3', + '#8dcaef', + '#8d9def', + '#a58def', + '#e292e0', +] + +// 첫 글자로 사용자 프로필 생성하는 함수 +function getInitial(nickname: string): string { + const firstChar = nickname.trim().charAt(0) + + if (/[a-zA-Z]/.test(firstChar)) { + return firstChar.toUpperCase() // 영어: 대문자 + } + + if (/[가-힣]/.test(firstChar)) { + return firstChar // 한글은 그대로 반환 + } + + return '?' // 기타문자: 물음표 +} + +// 닉네임으로부터 배경색 생성 함수 +function getColor(nickname: string): string { + const hash = nickname + .split('') + .reduce((acc, char) => acc + char.charCodeAt(0), 0) + return customColors[hash % customColors.length] +} + +export function Profile({ nickname, imageUrl, size = 36 }: ProfileProps) { + const initial = getInitial(nickname) + const bgColor = getColor(nickname) + + return imageUrl ? ( + // 프로필 이미지가 있을 때 +