From c9ccffb301e2980a7da2e8369624997f23310611 Mon Sep 17 00:00:00 2001 From: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com> Date: Thu, 1 Aug 2024 23:59:42 +1200 Subject: [PATCH 1/3] feat: upgrade react-day-picker to v9 --- package.json | 2 +- pnpm-lock.yaml | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index c516bd9c..2e885de9 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "oidc-client-ts": "^3.0.1", "react": "^18.3.1", "react-compiler-runtime": "file:./libs/react-compiler-runtime", - "react-day-picker": "^8.10.1", + "react-day-picker": "^9.0.6", "react-dom": "^18.3.1", "react-hook-form": "^7.52.1", "react-i18next": "^15.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1f49d1d7..276a617a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -144,8 +144,8 @@ importers: specifier: file:./libs/react-compiler-runtime version: file:libs/react-compiler-runtime react-day-picker: - specifier: ^8.10.1 - version: 8.10.1(date-fns@3.6.0)(react@18.3.1) + specifier: ^9.0.6 + version: 9.0.6(react@18.3.1) react-dom: specifier: ^18.3.1 version: 18.3.1(react@18.3.1) @@ -2950,11 +2950,10 @@ packages: react-compiler-runtime@file:libs/react-compiler-runtime: resolution: {directory: libs/react-compiler-runtime, type: directory} - react-day-picker@8.10.1: - resolution: {integrity: sha512-TMx7fNbhLk15eqcMt+7Z7S2KF7mfTId/XJDjKE8f+IUcFn0l08/kI4FiYTL/0yuOLmEcbR4Fwe3GJf/NiiMnPA==} + react-day-picker@9.0.6: + resolution: {integrity: sha512-q4TUrUgA/TZbtrnoXYZrcQRky+HUHqnRmsldDG/jjsYQQehmQPRv4gWihEMrmcfI3sVWQlhUXx3bbnCYhfVMiA==} peerDependencies: - date-fns: ^2.28.0 || ^3.0.0 - react: ^16.8.0 || ^17.0.0 || ^18.0.0 + react: '>=16.8.0' react-dom@18.3.1: resolution: {integrity: sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==} @@ -6321,7 +6320,7 @@ snapshots: dependencies: react: 18.3.1 - react-day-picker@8.10.1(date-fns@3.6.0)(react@18.3.1): + react-day-picker@9.0.6(react@18.3.1): dependencies: date-fns: 3.6.0 react: 18.3.1 From ef090ec497d6c84c2b5a784c169cc7569a88b2e8 Mon Sep 17 00:00:00 2001 From: SeanCassiere <33615041+SeanCassiere@users.noreply.github.com> Date: Fri, 2 Aug 2024 02:47:41 +1200 Subject: [PATCH 2/3] refactor: make the changes v9 migration changes --- src/components/ui/calendar.tsx | 234 +++++++++++++++++---------------- 1 file changed, 122 insertions(+), 112 deletions(-) diff --git a/src/components/ui/calendar.tsx b/src/components/ui/calendar.tsx index c8fb0fae..ed77b90c 100644 --- a/src/components/ui/calendar.tsx +++ b/src/components/ui/calendar.tsx @@ -2,9 +2,8 @@ import * as React from "react"; import { DayPicker, useDayPicker, - useNavigation, - type CaptionLayout, type DropdownProps, + type Matcher, } from "react-day-picker"; import { buttonVariants } from "@/components/ui/button"; @@ -17,111 +16,118 @@ import { SelectTrigger, } from "@/components/ui/select"; -import { setMonth } from "@/lib/config/date-fns"; +import { addMonths } from "@/lib/config/date-fns"; import { cn } from "@/lib/utils"; export type CalendarProps = React.ComponentProps; -const DEFAULT_FROM_YEAR = 1900; - function Calendar({ className, classNames, showOutsideDays = true, - fromYear, - toYear, + startMonth, + endMonth, + hidden, captionLayout, ...props }: CalendarProps) { - const layout: CaptionLayout = captionLayout || "dropdown-buttons"; + const layout: CalendarProps["captionLayout"] = captionLayout || "dropdown"; + + const calendarStartMonth = startMonth ?? new Date(1900, 0, 0); + const calendarEndMonth = + endMonth ?? new Date(new Date().getFullYear() + 15, 11); - const currentYear = new Date().getFullYear(); + const hiddenIsArray = Array.isArray(hidden); - const oldestYear = fromYear ?? DEFAULT_FROM_YEAR; - const newestYear = toYear ?? currentYear + 15; + const calendarHiddenOptions: Matcher[] = [ + ...(startMonth ? [{ before: startMonth }] : []), + ...(endMonth ? [{ after: endMonth }] : []), + ...(hiddenIsArray ? hidden : []), + hidden && !hiddenIsArray ? hidden : [], + ]; return (