1+ // src/app/page.tsx
12"use client" ;
23import React , { useState } from "react" ;
3- import { format , startOfMonth , endOfMonth , addMonths , subMonths , addDays } from "date-fns" ;
4+ import { format , addMonths , subMonths } from "date-fns" ;
5+ import CalendarGrid from "./components/CalendarGrid" ;
46
57export default function CalendarPage ( ) {
6- // State for the current date
78 const [ currentDate , setCurrentDate ] = useState ( new Date ( ) ) ;
89
9- // Functions to navigate months
1010 const handlePrevMonth = ( ) => setCurrentDate ( subMonths ( currentDate , 1 ) ) ;
1111 const handleNextMonth = ( ) => setCurrentDate ( addMonths ( currentDate , 1 ) ) ;
1212
1313 return (
1414 < main className = "flex flex-col items-center p-6 bg-gray-100 min-h-screen" >
1515 < header className = "flex justify-between items-center w-full max-w-2xl mb-8" >
16- < button
17- onClick = { handlePrevMonth }
18- className = "px-4 py-2 text-white bg-blue-600 rounded-md shadow-md hover:bg-blue-700 transition-all duration-300"
19- >
16+ < button onClick = { handlePrevMonth } className = "px-4 py-2 text-white bg-blue-600 rounded-md shadow-md hover:bg-blue-700 transition-all duration-300" >
2017 Previous
2118 </ button >
2219 < h2 className = "text-2xl font-semibold text-gray-800" > { format ( currentDate , "MMMM yyyy" ) } </ h2 >
23- < button
24- onClick = { handleNextMonth }
25- className = "px-4 py-2 text-white bg-blue-600 rounded-md shadow-md hover:bg-blue-700 transition-all duration-300"
26- >
20+ < button onClick = { handleNextMonth } className = "px-4 py-2 text-white bg-blue-600 rounded-md shadow-md hover:bg-blue-700 transition-all duration-300" >
2721 Next
2822 </ button >
2923 </ header >
@@ -32,30 +26,3 @@ export default function CalendarPage() {
3226 </ main >
3327 ) ;
3428}
35-
36- function CalendarGrid ( { currentDate } : { currentDate : Date } ) {
37- const start = startOfMonth ( currentDate ) ;
38- const end = endOfMonth ( currentDate ) ;
39-
40- const days = [ ] ;
41- for ( let day = start ; day <= end ; day = addDays ( day , 1 ) ) {
42- days . push (
43- < div
44- key = { day . toString ( ) }
45- className = "flex flex-col items-center justify-center p-4 border border-gray-300 rounded-lg bg-white shadow-sm hover:shadow-lg transition-all duration-200"
46- >
47- < div className = "text-lg font-medium text-gray-800" > { format ( day , "d" ) } </ div >
48- { /* Placeholder for events */ }
49- < div className = "mt-2 text-sm text-gray-600" >
50- < p > Sample Event</ p >
51- </ div >
52- </ div >
53- ) ;
54- }
55-
56- return (
57- < div className = "grid grid-cols-7 gap-4 w-full max-w-2xl mt-6" >
58- { days }
59- </ div >
60- ) ;
61- }
0 commit comments