Skip to content

Commit 9e7aff3

Browse files
authored
refactor: simplify props, contexts (#2211)
1 parent 8d281da commit 9e7aff3

102 files changed

Lines changed: 2187 additions & 2343 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/CustomCaption.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import React from "react";
22

33
import { format } from "date-fns";
4-
import { MonthCaptionProps, DayPicker, useCalendar } from "react-day-picker";
4+
import {
5+
MonthCaptionProps,
6+
DayPicker,
7+
useCalendarContext
8+
} from "react-day-picker";
59

610
function CustomMonthCaption(props: MonthCaptionProps) {
7-
const { goToMonth, nextMonth, previousMonth } = useCalendar();
11+
const { goToMonth, nextMonth, previousMonth } = useCalendarContext();
812
return (
913
<h2>
1014
{format(props.month.date, "MMM yyy")}

examples/CustomMultiple.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React, { useState } from "react";
22

33
import { isSameDay } from "date-fns";
4-
import { DayMouseEventHandler, DayPicker } from "react-day-picker";
4+
import { DayEventHandler, DayPicker } from "react-day-picker";
55

66
export function CustomMultiple() {
77
const [value, setValue] = useState<Date[]>([]);
88

9-
const handleDayClick: DayMouseEventHandler = (day, modifiers) => {
9+
const handleDayClick: DayEventHandler<React.MouseEvent> = (
10+
day,
11+
modifiers
12+
) => {
1013
const newValue = [...value];
1114
if (modifiers.selected) {
1215
const index = value.findIndex((d) => isSameDay(day, d));

examples/CustomSingle.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { DayPicker, DayPickerProps, type Mode } from "react-day-picker";
44

55
export function CustomSingle() {
66
const [selectedDate, setSelectedDate] = useState<Date | undefined>();
7-
const modifiers: DayPickerProps<Mode>["modifiers"] = {};
7+
const modifiers: DayPickerProps["modifiers"] = {};
88
if (selectedDate) {
99
modifiers.selected = selectedDate;
1010
}

examples/CustomWeek.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ beforeEach(() => {
1515

1616
describe("when a day is clicked", () => {
1717
beforeEach(async () => {
18-
await act(() => user.click(gridcell(today)));
18+
await user.click(gridcell(today));
1919
});
2020
test("the whole week should appear selected", () => {
2121
const week = [
@@ -33,7 +33,7 @@ describe("when a day is clicked", () => {
3333
});
3434
describe("when clicking the day again", () => {
3535
beforeEach(async () => {
36-
await act(() => user.click(gridcell(today)));
36+
await user.click(gridcell(today));
3737
});
3838
test("the whole week should not be selected", () => {
3939
const week = [

examples/Dialog.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React, { useEffect, useId, useRef, useState } from "react";
22

33
import { format, isValid, parse } from "date-fns";
4-
import { DayPicker, type SelectHandler } from "react-day-picker";
4+
import { DayPicker } from "react-day-picker";
55

66
export function Dialog() {
77
const dialogRef = useRef<HTMLDialogElement>(null);
@@ -45,7 +45,7 @@ export function Dialog() {
4545
* Function to handle the DayPicker select event: update the input value and
4646
* the selected date, and set the month.
4747
*/
48-
const handleDayPickerSelect: SelectHandler<"single"> = (date) => {
48+
const handleDayPickerSelect = (date: Date | undefined) => {
4949
if (!date) {
5050
setInputValue("");
5151
setSelectedDate(undefined);

examples/Input.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from "react";
33

44
import { format } from "date-fns";
55

6-
import { act, render, screen } from "@/test/render";
6+
import { render, screen } from "@/test/render";
77
import { user } from "@/test/user";
88

99
import { Input } from "./Input";

examples/Keyboard.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import React, { useState } from "react";
22

3-
import { DayPicker, type DayPickerProps } from "react-day-picker";
3+
import {
4+
DayPicker,
5+
type DayPickerProps,
6+
type PropsSingle
7+
} from "react-day-picker";
48

5-
export function Keyboard(props: DayPickerProps<"single">) {
9+
export function Keyboard(props: DayPickerProps & PropsSingle) {
610
const [selected, setSelected] = useState<Date | undefined>(undefined);
711
return (
812
<DayPicker

examples/MultipleMinMax.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@ import { addDays } from "date-fns";
44
import { DayPicker } from "react-day-picker";
55

66
export function MultipleMinMax() {
7-
const defaultSelected = [new Date(), addDays(new Date(), 1)];
8-
return (
9-
<DayPicker
10-
defaultSelected={defaultSelected}
11-
mode="multiple"
12-
min={2}
13-
max={5}
14-
/>
15-
);
7+
const selected = [new Date(), addDays(new Date(), 1)];
8+
return <DayPicker selected={selected} mode="multiple" min={2} max={5} />;
169
}

examples/None.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import React from "react";
33
import { DayPicker } from "react-day-picker";
44

55
export function None() {
6-
return <DayPicker mode="default" />;
6+
return <DayPicker />;
77
}

examples/Range.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe("when a day in the range is clicked", () => {
4949
describe("when a day in the range is clicked again", () => {
5050
const day = days[2];
5151
beforeEach(async () => act(() => user.click(gridcell(day))));
52-
test("no day should be selected (??)", () => {
52+
test("no day should be selected", () => {
5353
expect(getAllSelectedDays()).toHaveLength(0);
5454
});
5555
test("should match the snapshot", () => {

0 commit comments

Comments
 (0)