Skip to content

Commit 960a3fd

Browse files
committed
Updated react-day-picker dependency and ran upgrade guide
1 parent 7613bff commit 960a3fd

File tree

2 files changed

+38
-28
lines changed

2 files changed

+38
-28
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"@floating-ui/react": "^0.19.2",
2828
"@headlessui/react": "2.2.0",
2929
"date-fns": "^3.6.0",
30-
"react-day-picker": "^8.10.1",
30+
"react-day-picker": "^9.5.1",
3131
"react-transition-state": "^2.1.2",
3232
"recharts": "^2.13.3",
3333
"tailwind-merge": "^2.5.2"

src/components/input-elements/Calendar/Calendar.tsx

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
import React from "react";
33
import {
44
DayPicker,
5-
DayPickerRangeProps,
6-
DayPickerSingleProps,
7-
useNavigation,
5+
useDayPicker,
6+
type PropsSingle,
7+
type PropsRange,
8+
type PropsBase,
89
} from "react-day-picker";
910

1011
import {
@@ -17,7 +18,7 @@ import { addYears, format } from "date-fns";
1718
import { Text } from "../../text-elements/Text";
1819
import { NavButton } from "./NavButton";
1920

20-
function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
21+
function Calendar<T extends (PropsSingle | PropsRange) & PropsBase>({
2122
mode,
2223
defaultMonth,
2324
selected,
@@ -34,49 +35,57 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
3435
showOutsideDays={true}
3536
mode={mode as any}
3637
defaultMonth={defaultMonth}
37-
selected={selected}
38+
selected={selected as any}
3839
onSelect={onSelect as any}
3940
locale={locale}
4041
disabled={disabled}
4142
weekStartsOn={weekStartsOn}
4243
classNames={{
4344
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
4445
month: "space-y-4",
45-
caption: "flex justify-center pt-2 relative items-center",
46+
month_caption: "flex justify-center pt-2 relative items-center",
4647
caption_label:
4748
"text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis font-medium",
4849
nav: "space-x-1 flex items-center",
49-
nav_button:
50-
"flex items-center justify-center p-1 h-7 w-7 outline-none focus:ring-2 transition duration-100 border border-tremor-border dark:border-dark-tremor-border hover:bg-tremor-background-muted dark:hover:bg-dark-tremor-background-muted rounded-tremor-small focus:border-tremor-brand-subtle dark:focus:border-dark-tremor-brand-subtle focus:ring-tremor-brand-muted dark:focus:ring-dark-tremor-brand-muted text-tremor-content-subtle dark:text-dark-tremor-content-subtle hover:text-tremor-content dark:hover:text-dark-tremor-content",
51-
nav_button_previous: "absolute left-1",
52-
nav_button_next: "absolute right-1",
53-
table: "w-full border-collapse space-y-1",
54-
head_row: "flex",
55-
head_cell:
50+
button_previous:
51+
"flex items-center justify-center p-1 h-7 w-7 outline-none focus:ring-2 transition duration-100 border border-tremor-border dark:border-dark-tremor-border hover:bg-tremor-background-muted dark:hover:bg-dark-tremor-background-muted rounded-tremor-small focus:border-tremor-brand-subtle dark:focus:border-dark-tremor-brand-subtle focus:ring-tremor-brand-muted dark:focus:ring-dark-tremor-brand-muted text-tremor-content-subtle dark:text-dark-tremor-content-subtle hover:text-tremor-content dark:hover:text-dark-tremor-content absolute left-1",
52+
button_next:
53+
"flex items-center justify-center p-1 h-7 w-7 outline-none focus:ring-2 transition duration-100 border border-tremor-border dark:border-dark-tremor-border hover:bg-tremor-background-muted dark:hover:bg-dark-tremor-background-muted rounded-tremor-small focus:border-tremor-brand-subtle dark:focus:border-dark-tremor-brand-subtle focus:ring-tremor-brand-muted dark:focus:ring-dark-tremor-brand-muted text-tremor-content-subtle dark:text-dark-tremor-content-subtle hover:text-tremor-content dark:hover:text-dark-tremor-content absolute right-1",
54+
month_grid: "w-full border-collapse space-y-1",
55+
weekdays: "flex",
56+
weekday:
5657
"w-9 font-normal text-center text-tremor-content-subtle dark:text-dark-tremor-content-subtle",
57-
row: "flex w-full mt-0.5",
58-
cell: "text-center p-0 relative focus-within:relative text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis",
59-
day: "h-9 w-9 p-0 hover:bg-tremor-background-subtle dark:hover:bg-dark-tremor-background-subtle outline-tremor-brand dark:outline-dark-tremor-brand rounded-tremor-default",
60-
day_today: "font-bold",
61-
day_selected:
58+
week: "flex w-full mt-0.5",
59+
day: "text-center p-0 relative focus-within:relative text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis",
60+
day_button:
61+
"h-9 w-9 p-0 hover:bg-tremor-background-subtle dark:hover:bg-dark-tremor-background-subtle outline-tremor-brand dark:outline-dark-tremor-brand rounded-tremor-default",
62+
today: "font-bold",
63+
selected:
6264
"aria-selected:bg-tremor-background-emphasis aria-selected:text-tremor-content-inverted dark:aria-selected:bg-dark-tremor-background-emphasis dark:aria-selected:text-dark-tremor-content-inverted ",
63-
day_disabled:
65+
disabled:
6466
"text-tremor-content-subtle dark:text-dark-tremor-content-subtle disabled:hover:bg-transparent",
65-
day_outside: "text-tremor-content-subtle dark:text-dark-tremor-content-subtle",
67+
outside: "text-tremor-content-subtle dark:text-dark-tremor-content-subtle",
6668
...classNames,
6769
}}
6870
components={{
69-
IconLeft: ({ ...props }) => <ArrowLeftHeadIcon className="h-4 w-4" {...props} />,
70-
IconRight: ({ ...props }) => <ArrowRightHeadIcon className="h-4 w-4" {...props} />,
71-
Caption: ({ ...props }) => {
72-
const { goToMonth, nextMonth, previousMonth, currentMonth } = useNavigation();
71+
Chevron: (props) => {
72+
if (props.orientation === "left") {
73+
return <ArrowLeftHeadIcon className="h-4 w-4" {...props} />;
74+
}
75+
76+
return <ArrowRightHeadIcon className="h-4 w-4" {...props} />;
77+
},
78+
MonthCaption: ({ calendarMonth }) => {
79+
const { goToMonth, nextMonth, previousMonth } = useDayPicker();
7380

7481
return (
7582
<div className="flex justify-between items-center">
7683
<div className="flex items-center space-x-1">
7784
{enableYearNavigation && (
7885
<NavButton
79-
onClick={() => currentMonth && goToMonth(addYears(currentMonth, -1))}
86+
onClick={() =>
87+
calendarMonth.date && goToMonth(addYears(calendarMonth.date, -1))
88+
}
8089
icon={DoubleArrowLeftHeadIcon}
8190
/>
8291
)}
@@ -87,7 +96,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
8796
</div>
8897

8998
<Text className="text-tremor-default tabular-nums capitalize text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis font-medium">
90-
{format(props.displayMonth, "LLLL yyy", { locale })}
99+
{format(calendarMonth.date, "LLLL yyy", { locale })}
91100
</Text>
92101

93102
<div className="flex items-center space-x-1">
@@ -97,7 +106,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
97106
/>
98107
{enableYearNavigation && (
99108
<NavButton
100-
onClick={() => currentMonth && goToMonth(addYears(currentMonth, 1))}
109+
onClick={() => calendarMonth.date && goToMonth(addYears(calendarMonth.date, 1))}
101110
icon={DoubleArrowRightHeadIcon}
102111
/>
103112
)}
@@ -107,6 +116,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
107116
},
108117
}}
109118
{...other}
119+
hideNavigation
110120
/>
111121
);
112122
}

0 commit comments

Comments
 (0)