diff --git a/src/components/calendar/CalendarCell.tsx b/src/components/calendar/CalendarCell.tsx index d5d8657..ee2e3d7 100644 --- a/src/components/calendar/CalendarCell.tsx +++ b/src/components/calendar/CalendarCell.tsx @@ -4,12 +4,21 @@ import { cn } from '@/lib/utils'; interface CalendarCellProps { date: number; + isCurrentMonth?: boolean; + isToday?: boolean; goals?: Goal[]; onClick?: (date: number, goals: Goal[], event: React.MouseEvent) => void; className?: string; } -const CalendarCell = ({ date, goals = [], onClick, className }: CalendarCellProps) => { +const CalendarCell = ({ + date, + isCurrentMonth = true, + isToday = false, + goals = [], + onClick, + className, +}: CalendarCellProps) => { const hasGoals = goals.length > 0; const firstGoal = goals[0]; const goalColorName = firstGoal ? getGoalBackgroundColorClass(firstGoal.color) : null; @@ -26,10 +35,19 @@ const CalendarCell = ({ date, goals = [], onClick, className }: CalendarCellProp className={cn( 'rounded-4 flex h-40 w-full min-w-40 cursor-pointer flex-col items-center p-1 transition md:max-h-44 md:max-w-84 lg:h-40 lg:max-w-85 lg:min-w-71', hasGoals && 'hover:bg-tertiary-01', + !isCurrentMonth && 'opacity-40', className, )} > - {date} + + {date} + {hasGoals && (
(({ data, onCellClick }, ref) => { const { firstDay, daysInMonth, groupedGoals } = useCalendarData(data); const calendarCells = []; + const TOTAL_CELLS = 42; + + // 이전 달의 날짜 계산 + const today = new Date(); + const [currentYear, currentMonth] = data.month.split('-').map(Number); + + const prevMonth = new Date(currentYear, currentMonth - 1, 0); + const prevMonthDays = prevMonth.getDate(); - // 빈 셀 채우기 (월 시작 전 빈 공간) for (let i = 0; i < firstDay; i++) { - calendarCells.push(
); + const date = prevMonthDays - firstDay + i + 1; + calendarCells.push(); } - // 날짜 셀 채우기 for (let date = 1; date <= daysInMonth; date++) { const goalsOfTheDay = groupedGoals[date] || []; + const isToday = + today.getDate() === date && + today.getMonth() + 1 === currentMonth && + today.getFullYear() === currentYear; + + calendarCells.push( + , + ); + } + // 다음 달의 날짜 계산 + let nextMonthDate = 1; + const remainingCells = TOTAL_CELLS - (firstDay + daysInMonth); + for (let i = 0; i < remainingCells; i++) { calendarCells.push( - , + , ); }