Two-month range calendar composition
SuMoTuWeThFrSa
SuMoTuWeThFrSa
import { RangeCalendar } from '@/components/ui/range-calendar'
...import { RangeCalendar } from '@/components/ui/range-calendar'
export default function RangeCalendarDemoExample() {
return (
<RangeCalendar
startMonth={new Date(2026, 7, 1)}
endMonth={new Date(2026, 8, 1)}
/>
)
}
Installation
npx @fictjs/shadcn@latest add range-calendarCopy the Fict shadcn component into your project.
Source
components/ui/range-calendar.tsx
src/components/ui/range-calendar.tsx
import { cn } from '@/lib/cn'
import { Calendar } from '@/components/ui/calendar'
type RangeCalendarProps = {
class?: string
startMonth?: Date | string
endMonth?: Date | string
[key: string]: unknown
}
function normalizeMonth(value: Date | string | undefined, fallback: Date): Date {
if (!value) return fallback
const date = value instanceof Date ? value : new Date(value)
if (Number.isNaN(date.getTime())) return fallback
return new Date(date.getFullYear(), date.getMonth(), 1)
}
function addMonth(value: Date): Date {
return new Date(value.getFullYear(), value.getMonth() + 1, 1)
}
export function RangeCalendar(props: RangeCalendarProps) {
const baseMonth = normalizeMonth(props.startMonth, new Date())
const nextMonth = normalizeMonth(props.endMonth, addMonth(baseMonth))
const { class: className, startMonth, endMonth, ...rest } = props
return (
<div class={cn('grid gap-4 md:grid-cols-2', className)} {...rest}>
<Calendar month={baseMonth} />
<Calendar month={nextMonth} />
</div>
)
}
Usage