Skip to content

Commit 7b75c12

Browse files
committed
Updated react-day-picker dependency and ran upgrade guide
Updated functionality on DatePicker and DateRangePicker components Fixed issue with tests failing to run correctly Fixed a few styling issues
1 parent 7613bff commit 7b75c12

File tree

8 files changed

+75
-50
lines changed

8 files changed

+75
-50
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ dist
44
storybook-static
55
package-lock.json
66
.vscode
7-
yarn.lock
7+
yarn.lock
8+
.idea

jest.config.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module.exports = {
33
testEnvironment: "jsdom",
44
moduleDirectories: ["node_modules", "src"],
55
moduleNameMapper: {
6-
".(css|less|scss)$": "identity-obj-proxy",
7-
"components/(.*)": "<rootDir>/src/components/$1",
8-
"assets/(.*)": "<rootDir>/src/assets/$1",
6+
"\\.(css|less|scss)$": "identity-obj-proxy",
7+
"^components/(.*)$": "<rootDir>/src/components/$1",
8+
"^assets/(.*)$": "<rootDir>/src/assets/$1",
99
},
1010
transformIgnorePatterns: ["<rootDir>/node_modules/(?!react-dnd|dnd-core|@react-dnd)"],
1111
};

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"

pnpm-lock.yaml

Lines changed: 25 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
"use client";
22
import React from "react";
3-
import {
4-
DayPicker,
5-
DayPickerRangeProps,
6-
DayPickerSingleProps,
7-
useNavigation,
8-
} from "react-day-picker";
3+
import { DayPicker, useDayPicker, PropsSingle, PropsRange, PropsBase } from "react-day-picker";
94

105
import {
116
ArrowLeftHeadIcon,
@@ -17,6 +12,9 @@ import { addYears, format } from "date-fns";
1712
import { Text } from "../../text-elements/Text";
1813
import { NavButton } from "./NavButton";
1914

15+
export type DayPickerSingleProps = PropsBase & PropsSingle;
16+
export type DayPickerRangeProps = PropsBase & PropsRange;
17+
2018
function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
2119
mode,
2220
defaultMonth,
@@ -34,49 +32,57 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
3432
showOutsideDays={true}
3533
mode={mode as any}
3634
defaultMonth={defaultMonth}
37-
selected={selected}
35+
selected={selected as any}
3836
onSelect={onSelect as any}
3937
locale={locale}
4038
disabled={disabled}
4139
weekStartsOn={weekStartsOn}
4240
classNames={{
4341
months: "flex flex-col sm:flex-row space-y-4 sm:space-x-4 sm:space-y-0",
4442
month: "space-y-4",
45-
caption: "flex justify-center pt-2 relative items-center",
43+
month_caption: "flex justify-center pt-2 relative items-center",
4644
caption_label:
4745
"text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis font-medium",
4846
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:
47+
button_previous:
48+
"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",
49+
button_next:
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 absolute right-1",
51+
month_grid: "w-full border-collapse space-y-1",
52+
weekdays: "flex",
53+
weekday:
5654
"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:
55+
week: "flex w-full mt-0.5",
56+
day: "text-center p-0 relative focus-within:relative text-tremor-default text-tremor-content-emphasis dark:text-dark-tremor-content-emphasis hover:bg-tremor-background-subtle dark:hover:bg-dark-tremor-background-subtle rounded-tremor-default",
57+
day_button:
58+
"h-9 w-9 p-0 outline-tremor-brand dark:outline-dark-tremor-brand rounded-tremor-default",
59+
today: "font-bold",
60+
selected:
6261
"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:
62+
disabled:
6463
"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",
64+
outside: "text-tremor-content-subtle dark:text-dark-tremor-content-subtle",
6665
...classNames,
6766
}}
6867
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();
68+
Chevron: (props) => {
69+
if (props.orientation === "left") {
70+
return <ArrowLeftHeadIcon className="h-4 w-4" {...props} />;
71+
}
72+
73+
return <ArrowRightHeadIcon className="h-4 w-4" {...props} />;
74+
},
75+
MonthCaption: ({ calendarMonth }) => {
76+
const { goToMonth, nextMonth, previousMonth } = useDayPicker();
7377

7478
return (
7579
<div className="flex justify-between items-center">
7680
<div className="flex items-center space-x-1">
7781
{enableYearNavigation && (
7882
<NavButton
79-
onClick={() => currentMonth && goToMonth(addYears(currentMonth, -1))}
83+
onClick={() =>
84+
calendarMonth.date && goToMonth(addYears(calendarMonth.date, -1))
85+
}
8086
icon={DoubleArrowLeftHeadIcon}
8187
/>
8288
)}
@@ -87,7 +93,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
8793
</div>
8894

8995
<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 })}
96+
{format(calendarMonth.date, "LLLL yyy", { locale: locale as any })}
9197
</Text>
9298

9399
<div className="flex items-center space-x-1">
@@ -97,7 +103,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
97103
/>
98104
{enableYearNavigation && (
99105
<NavButton
100-
onClick={() => currentMonth && goToMonth(addYears(currentMonth, 1))}
106+
onClick={() => calendarMonth.date && goToMonth(addYears(calendarMonth.date, 1))}
101107
icon={DoubleArrowRightHeadIcon}
102108
/>
103109
)}
@@ -107,6 +113,7 @@ function Calendar<T extends DayPickerSingleProps | DayPickerRangeProps>({
107113
},
108114
}}
109115
{...other}
116+
hideNavigation
110117
/>
111118
);
112119
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export { default as Calendar } from "./Calendar";
1+
export { default as Calendar, DayPickerSingleProps, DayPickerRangeProps } from "./Calendar";

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
"use client";
22
import { tremorTwMerge } from "lib";
33
import React, { useMemo } from "react";
4-
import { DayPickerSingleProps } from "react-day-picker";
54

65
import { startOfMonth, startOfToday } from "date-fns";
76
import { enUS } from "date-fns/locale";
87

98
import { Popover, PopoverButton, PopoverPanel, Transition } from "@headlessui/react";
109
import { CalendarIcon, XCircleIcon } from "assets";
11-
import { Calendar } from "components/input-elements/Calendar";
10+
import { Calendar, DayPickerSingleProps } from "components/input-elements/Calendar";
1211
import { makeDatePickerClassName } from "components/input-elements/DatePicker/datePickerUtils";
1312
import { useInternalState } from "hooks";
1413
import { Color } from "../../../lib/inputTypes";

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { CalendarIcon, XCircleIcon } from "assets";
44
import { startOfMonth, startOfToday } from "date-fns";
55
import { tremorTwMerge } from "lib";
66
import React, { ReactElement, useMemo, useState } from "react";
7-
import { DateRange, DayPickerRangeProps } from "react-day-picker";
7+
import { DateRange } from "react-day-picker";
88
import {
99
constructValueToNameMapping,
1010
getNodeText,
@@ -19,7 +19,7 @@ import {
1919
parseStartDate,
2020
} from "./dateRangePickerUtils";
2121

22-
import { Calendar } from "components/input-elements/Calendar";
22+
import { Calendar, DayPickerRangeProps } from "components/input-elements/Calendar";
2323
import { DateRangePickerItemProps } from "components/input-elements/DateRangePicker/DateRangePickerItem";
2424
import { SelectItem } from "components/input-elements/Select";
2525
import { enUS } from "date-fns/locale";
@@ -277,16 +277,17 @@ const DateRangePicker = React.forwardRef<HTMLDivElement, DateRangePickerProps>((
277277
disabled={disabledDays}
278278
enableYearNavigation={enableYearNavigation}
279279
classNames={{
280-
day_range_middle: tremorTwMerge(
280+
range_middle: tremorTwMerge(
281281
"!rounded-none aria-selected:!bg-tremor-background-subtle aria-selected:dark:!bg-dark-tremor-background-subtle aria-selected:!text-tremor-content aria-selected:dark:!bg-dark-tremor-background-subtle",
282282
),
283-
day_range_start:
283+
range_start:
284284
"rounded-r-none rounded-l-tremor-small aria-selected:text-tremor-brand-inverted dark:aria-selected:text-dark-tremor-brand-inverted",
285-
day_range_end:
285+
range_end:
286286
"rounded-l-none rounded-r-tremor-small aria-selected:text-tremor-brand-inverted dark:aria-selected:text-dark-tremor-brand-inverted",
287287
}}
288288
weekStartsOn={weekStartsOn}
289289
{...props}
290+
role={"dialog"}
290291
/>
291292
</PopoverPanel>
292293
</Transition>

0 commit comments

Comments
 (0)