11"use client" ;
22
33import { cn } from "@/lib/utils.ts" ;
4+ import dayjs from "dayjs" ;
45import { ChevronLeftIcon , ChevronRightIcon } from "lucide-react" ;
56import * as CalendarPrimitive from "react-composable-calendar" ;
6- import {
7- selectStartDateStrategy ,
8- selectEndDateStrategy ,
9- } from "react-composable-calendar/select-day-strategy" ;
7+ import { changeAtIndexStrategy } from "react-composable-calendar/select-day-strategy" ;
108import { Button } from "./button.tsx" ;
119
12- import dayjs from "dayjs" ;
13- import "dayjs/locale/en-gb" ;
14-
15- dayjs . locale ( "en-gb" ) ;
16-
17- export type CalendarProps = CalendarPrimitive . RootProps ;
18-
1910export function range ( length : number ) {
2011 return [ ...new Array ( length ) ] . map ( ( _ , i ) => i ) ;
2112}
2213
23- export function CalendarStartEndSeparate ( props : CalendarProps ) {
14+ export function CalendarStartEndSeparate ( props : CalendarPrimitive . RootProps ) {
2415 const { className, ...rest } = props ;
2516
2617 return (
2718 < CalendarPrimitive . Root className = { cn ( "max-w-lg p-3" , className ) } { ...rest } >
2819 < div className = "mb-2 flex items-center justify-end gap-2" >
2920 < div className = "grow" />
30- < CalendarPrimitive . ValueLabel className = "text-muted-foreground text-sm " />
21+ < CalendarPrimitive . ValueLabel
22+ fallback = "No date selected"
23+ className = "text-muted-foreground text-sm "
24+ />
3125 </ div >
3226
3327 < div className = "grid grid-cols-2 gap-6" >
3428 { range ( 2 ) . map ( ( index ) => (
35- < CalendarPrimitive . View key = { index } >
29+ < CalendarPrimitive . View
30+ defaultValue = { dayjs ( ) . add ( index , "month" ) }
31+ key = { index }
32+ >
3633 < div className = "mb-4 flex items-center justify-between" >
3734 < CalendarPrimitive . OffsetViewButton asChild offset = { - 1 } >
3835 < Button size = "icon" variant = "outline" className = "size-8" >
@@ -52,9 +49,7 @@ export function CalendarStartEndSeparate(props: CalendarProps) {
5249
5350 < CalendarPrimitive . Days className = "mb-1 grid grid-cols-7 gap-y-1" >
5451 < CalendarPrimitive . Day
55- selectDayStrategy = {
56- index === 0 ? selectStartDateStrategy : selectEndDateStrategy
57- }
52+ selectDayStrategy = { changeAtIndexStrategy ( index ) }
5853 className = "group relative aspect-square w-full cursor-pointer data-[neighboring]:invisible"
5954 >
6055 < CalendarPrimitive . DayInRange className = "absolute top-0 right-0 bottom-0 left-0 bg-foreground/10 data-end:rounded-r-lg data-start:rounded-l-lg" />
0 commit comments