import { forwardRef } from 'react'; import { range } from 'lodash-es'; import { AnimatePresence, motion } from 'motion/react'; import { useTranslation } from '#hooks'; export const CALENDAR_ANIMATION_DURATION = 0.2; // seconds export type CalendarProps = { month: number; onSelection: (date: Date) => void; year: number; }; export const Calendar = forwardRef(function Calendar(props, ref) { const { t } = useTranslation('libui'); const firstDay = new Date(props.year, props.month).getDay(); const lastDay = new Date(props.year, props.month + 1, 0).getDate(); const days = range(1, lastDay + 1); const daysOfWeek = [ t('days.sunday'), t('days.monday'), t('days.tuesday'), t('days.wednesday'), t('days.thursday'), t('days.friday'), t('days.saturday') ]; return (
{daysOfWeek.map((label) => (
{label.charAt(0).toUpperCase()}
))} {firstDay > 0 &&
} {days.map((day) => ( ))}
); });