import { formatDate } from '@transferwise/formatting'; import { useIntl } from 'react-intl'; import { getFocusableTime } from '../../GetFocusableTime/GetFocusableTime'; import TableLink from '../../TableLink'; interface MonthCalendarTableProps { selectedDate: Date | null; focusedDate?: Date | null; min: Date | null; max: Date | null; viewYear: number; placeholder?: string; onSelect: (date: number) => void; } const ROWS = 3; const COLS = 4; const MONTH_ONLY_FORMAT: Intl.DateTimeFormatOptions = { month: 'short' }; const MonthCalendarTable = ({ selectedDate, focusedDate, min, max, viewYear, placeholder, onSelect, }: MonthCalendarTableProps) => { const { locale } = useIntl(); const getLink = (month: number) => { return ( ); }; const isActive = (month: number) => { return !!(month === selectedDate?.getMonth() && viewYear === selectedDate?.getFullYear()); }; const isFocused = (month: number) => { return !!(month === focusedDate?.getMonth() && viewYear === focusedDate?.getFullYear()); }; const isThisMonth = (month: number) => { return viewYear === new Date().getFullYear() && month === new Date().getMonth(); }; const isDisabled = (month: number) => { const date = new Date(viewYear, month); return !!( (min && date < new Date(min.getFullYear(), min.getMonth())) || (max && date > new Date(max.getFullYear(), max.getMonth())) ); }; const autofocusMonth = (() => { const months = Array.from({ length: ROWS * COLS }, (_, index) => index); return getFocusableTime({ isActive: isFocused, isNow: isThisMonth, isDisabled, timeSpan: months, }); })(); return ( {Array.from({ length: ROWS }, (_, rowIndex) => ( {Array.from({ length: COLS }, (_, colIndex) => ( ))} ))}
{placeholder}
{getLink(rowIndex * COLS + colIndex)}
); }; export default MonthCalendarTable;