From ac481c0360165cb40b4569f3e01f69aa499c92ab Mon Sep 17 00:00:00 2001 From: "e.timofeeva@elonsoft.ru" Date: Mon, 13 May 2024 09:30:17 +0300 Subject: [PATCH] feat(react,Calendar): fill all available space with next month dates --- packages/react/src/components/Calendar/Calendar.tsx | 2 +- packages/react/src/components/Calendar/useCalendar.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/react/src/components/Calendar/Calendar.tsx b/packages/react/src/components/Calendar/Calendar.tsx index b8819991b..799e17de2 100644 --- a/packages/react/src/components/Calendar/Calendar.tsx +++ b/packages/react/src/components/Calendar/Calendar.tsx @@ -37,7 +37,7 @@ export const Calendar = (inProps: CalendarProps) => { throw new Error('No provider for DateAdapterContext.'); } - const { dates, prevDates, nextDates } = useCalendar(year, month, weekStart); + const { dates, prevDates, nextDates } = useCalendar(year, month, weekStart, rows); const getButtonProps = (year: number, month: number, date: number) => { const current = new Date(year, month, date); diff --git a/packages/react/src/components/Calendar/useCalendar.ts b/packages/react/src/components/Calendar/useCalendar.ts index 995df1699..eb6310937 100644 --- a/packages/react/src/components/Calendar/useCalendar.ts +++ b/packages/react/src/components/Calendar/useCalendar.ts @@ -3,7 +3,8 @@ import { useMemo } from 'react'; export const useCalendar = ( year: number, month: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11, - weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6 + weekStart: 0 | 1 | 2 | 3 | 4 | 5 | 6, + rows: 'max' | 'auto' ) => { const result = useMemo(() => { const dates = []; @@ -29,13 +30,13 @@ export const useCalendar = ( i = 1; - while (date.getDay() !== weekStart) { + while (date.getDay() !== weekStart || (rows === 'max' && nextDates.length + prevDates.length + dates.length < 42)) { nextDates.push(i++); date.setDate(i); } return { dates, prevDates, nextDates }; - }, [year, month, weekStart]); + }, [year, month, weekStart, rows]); return result; };