22
33import * as React from "react" ;
44
5- import { ChevronLeftIcon , ChevronRightIcon } from "lucide-react" ;
5+ import { CaptionProps , DayPicker , useNavigation } from "react-day-picker" ;
6+ import {
7+ ChevronLeft ,
8+ ChevronLeftIcon ,
9+ ChevronRight ,
10+ ChevronRightIcon ,
11+ } from "lucide-react" ;
612import {
713 Select ,
814 SelectContent ,
@@ -11,16 +17,34 @@ import {
1117 SelectValue ,
1218} from "./select" ;
1319import { enUS , es } from "date-fns/locale" ;
20+ import { format , formatDate } from "date-fns" ;
1421
15- import { DayPicker } from "react-day-picker" ;
1622import { buttonVariants } from "./button" ;
1723import { capitalizeFirstDateLetter } from "@/utils/date" ;
1824import { cn } from "@/lib/utils" ;
19- import { format } from "date-fns" ;
2025import { useLocale } from "next-intl" ;
2126
2227export type CalendarProps = React . ComponentProps < typeof DayPicker > ;
23-
28+ function CustomCaptionComponent ( props : CaptionProps ) {
29+ const { goToMonth, nextMonth, previousMonth } = useNavigation ( ) ;
30+ return (
31+ < div className = 'flex items-center justify-between ' >
32+ < button
33+ disabled = { ! previousMonth }
34+ onClick = { ( ) => previousMonth && goToMonth ( previousMonth ) }
35+ >
36+ < ChevronLeft />
37+ </ button >
38+ < h2 className = 'text-lg' > { formatDate ( props . displayMonth , "MMM yyy" ) } </ h2 >
39+ < button
40+ disabled = { ! nextMonth }
41+ onClick = { ( ) => nextMonth && goToMonth ( nextMonth ) }
42+ >
43+ < ChevronRight />
44+ </ button >
45+ </ div >
46+ ) ;
47+ }
2448function Calendar ( {
2549 className,
2650 classNames,
@@ -101,6 +125,7 @@ function Calendar({
101125 ...classNames ,
102126 } }
103127 components = { {
128+ Caption : CustomCaptionComponent ,
104129 IconLeft : ( { ...props } ) => < ChevronLeftIcon className = 'h-4 w-4' /> ,
105130 IconRight : ( { ...props } ) => < ChevronRightIcon className = 'h-4 w-4' /> ,
106131 Dropdown : ( { ...props } ) => (
0 commit comments