Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update date-fns imports #1436

Merged
merged 4 commits into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/react-day-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
},
"main": "dist/index.js",
"module": "dist/index.esm.js",
"browser": "dist/react-day-picker.min.js",
"unpkg": "dist/react-day-picker.min.js",
"types": "dist/index.d.ts",
"style": "dist/style.css",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { addDays, Locale, startOfWeek } from 'date-fns';
import addDays from 'date-fns/addDays';
import startOfWeek from 'date-fns/startOfWeek';

import type { Locale } from 'date-fns';

/**
* Generate a series of 7 days, starting from the week, to use for formatting
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';

import { isSameYear, setMonth as setDateMonth, startOfMonth } from 'date-fns';
import isSameYear from 'date-fns/isSameYear';
import setMonth from 'date-fns/setMonth';
import startOfMonth from 'date-fns/startOfMonth';

import { Dropdown } from 'components/Dropdown';
import { useDayPicker } from 'contexts/DayPicker';
Expand Down Expand Up @@ -36,22 +38,19 @@ export function MonthsDropdown(props: MonthsDropdownProps): JSX.Element {
// only display the months included in the range
const date = startOfMonth(fromDate);
for (let month = fromDate.getMonth(); month <= toDate.getMonth(); month++) {
dropdownMonths.push(setDateMonth(date, month));
dropdownMonths.push(setMonth(date, month));
}
} else {
// display all the 12 months
const date = startOfMonth(new Date()); // Any date should be OK, as we just need the year
for (let month = 0; month <= 11; month++) {
dropdownMonths.push(setDateMonth(date, month));
dropdownMonths.push(setMonth(date, month));
}
}

const handleChange: React.ChangeEventHandler<HTMLSelectElement> = (e) => {
const selectedMonth = Number(e.target.value);
const newMonth = setDateMonth(
startOfMonth(props.displayMonth),
selectedMonth
);
const newMonth = setMonth(startOfMonth(props.displayMonth), selectedMonth);
props.onChange(newMonth);
};

Expand Down
2 changes: 1 addition & 1 deletion packages/react-day-picker/src/components/Row/Row.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';

import { getUnixTime } from 'date-fns';
import getUnixTime from 'date-fns/getUnixTime';

import { Day } from 'components/Day';
import { WeekNumber } from 'components/WeekNumber';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {
addDays,
differenceInCalendarDays,
endOfWeek,
getWeek,
Locale,
startOfWeek
} from 'date-fns';
import type { Locale } from 'date-fns';

import addDays from 'date-fns/addDays';
import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
import endOfWeek from 'date-fns/endOfWeek';
import getWeek from 'date-fns/getWeek';
import startOfWeek from 'date-fns/startOfWeek';

import { MonthWeek } from './getMonthWeeks';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import {
addWeeks,
endOfMonth,
getWeeksInMonth,
Locale,
startOfMonth
} from 'date-fns';
import type { Locale } from 'date-fns';

import addWeeks from 'date-fns/addWeeks';
import endOfMonth from 'date-fns/endOfMonth';
import getWeeksInMonth from 'date-fns/getWeeksInMonth';
import startOfMonth from 'date-fns/startOfMonth';

import { daysToMonthWeeks } from './daysToMonthWeeks';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';

import { setYear, startOfMonth, startOfYear } from 'date-fns';
import setYear from 'date-fns/setYear';
import startOfMonth from 'date-fns/startOfMonth';
import startOfYear from 'date-fns/startOfYear';

import { Dropdown } from 'components/Dropdown';
import { useDayPicker } from 'contexts/DayPicker';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { format, Locale } from 'date-fns';
import type { Locale } from 'date-fns';
import format from 'date-fns/format';

/**
* The default formatter for the caption.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { format, Locale } from 'date-fns';
import type { Locale } from 'date-fns';
import format from 'date-fns/format';

/**
* The default formatter for the Day button.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { format, Locale } from 'date-fns';
import type { Locale } from 'date-fns';
import format from 'date-fns/format';

/**
* The default formatter for the Month caption.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { format, Locale } from 'date-fns';
import type { Locale } from 'date-fns';
import format from 'date-fns/format';

/**
* The default formatter for the name of the weekday.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from 'date-fns';
import format from 'date-fns/format';

/**
* The default formatter for the Year caption.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from 'date-fns';
import format from 'date-fns/format';

import { DayLabel } from 'types/Labels';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { format } from 'date-fns';
import format from 'date-fns/format';

import { WeekdayLabel } from 'types/Labels';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { startOfDay, startOfMonth, endOfMonth } from 'date-fns';
import endOfMonth from 'date-fns/endOfMonth';
import startOfDay from 'date-fns/startOfDay';
import startOfMonth from 'date-fns/startOfMonth';

import { DayPickerBase } from 'types/DayPickerBase';

Expand Down
14 changes: 6 additions & 8 deletions packages/react-day-picker/src/contexts/Focus/FocusContext.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { createContext, ReactNode, useState } from 'react';

import {
addDays,
addMonths,
addWeeks,
addYears,
endOfWeek,
startOfWeek
} from 'date-fns';
import addDays from 'date-fns/addDays';
import addMonths from 'date-fns/addMonths';
import addWeeks from 'date-fns/addWeeks';
import addYears from 'date-fns/addYears';
import endOfWeek from 'date-fns/endOfWeek';
import startOfWeek from 'date-fns/startOfWeek';

import { useModifiers } from '../Modifiers';
import { useNavigation } from '../Navigation';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { addDays, endOfMonth, startOfMonth } from 'date-fns';
import addDays from 'date-fns/addDays';
import endOfMonth from 'date-fns/endOfMonth';
import startOfMonth from 'date-fns/startOfMonth';

import { getActiveModifiers } from 'contexts/Modifiers';
import { Modifiers } from 'types/Modifiers';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isSameMonth } from 'date-fns';
import isSameMonth from 'date-fns/isSameMonth';

import { ActiveModifiers, Modifiers } from 'types/Modifiers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { differenceInCalendarDays, isSameDay } from 'date-fns';
import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
import isSameDay from 'date-fns/isSameDay';

import { DateRange } from 'types/Matchers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { differenceInCalendarDays, isDate, isSameDay } from 'date-fns';
import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
import isDate from 'date-fns/isDate';
import isSameDay from 'date-fns/isSameDay';

import {
isDateAfterType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { createContext, ReactNode } from 'react';

import { addMonths, isBefore, isSameMonth } from 'date-fns';
import addMonths from 'date-fns/addMonths';
import isBefore from 'date-fns/isBefore';
import isSameMonth from 'date-fns/isSameMonth';

import { useDayPicker } from '../DayPicker';
import { useNavigationState } from './useNavigationState';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { startOfMonth } from 'date-fns';
import startOfMonth from 'date-fns/startOfMonth';

import { useDayPicker } from 'contexts/DayPicker';
import { useControlledValue } from 'hooks/useControlledValue';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { addMonths, differenceInCalendarMonths, startOfMonth } from 'date-fns';
import addMonths from 'date-fns/addMonths';
import differenceInCalendarMonths from 'date-fns/differenceInCalendarMonths';
import startOfMonth from 'date-fns/startOfMonth';

/**
* Return the months to display in the component according to the number of
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { addMonths, differenceInCalendarMonths, startOfMonth } from 'date-fns';
import addMonths from 'date-fns/addMonths';
import differenceInCalendarMonths from 'date-fns/differenceInCalendarMonths';
import startOfMonth from 'date-fns/startOfMonth';

import { DayPickerContextValue } from 'contexts/DayPicker';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { addMonths, differenceInCalendarMonths, startOfMonth } from 'date-fns';
import addMonths from 'date-fns/addMonths';
import differenceInCalendarMonths from 'date-fns/differenceInCalendarMonths';
import startOfMonth from 'date-fns/startOfMonth';

/**
* Returns the next month the user can navigate to according to the given
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { addMonths, differenceInCalendarMonths, startOfMonth } from 'date-fns';
import addMonths from 'date-fns/addMonths';
import differenceInCalendarMonths from 'date-fns/differenceInCalendarMonths';
import startOfMonth from 'date-fns/startOfMonth';

/**
* Returns the next previous the user can navigate to, according to the given
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { createContext, ReactNode } from 'react';

import { isSameDay } from 'date-fns';
import isSameDay from 'date-fns/isSameDay';

import { DayPickerBase } from 'types/DayPickerBase';
import {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, { createContext, ReactNode } from 'react';

import { differenceInCalendarDays, isAfter, isBefore } from 'date-fns';
import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
import isAfter from 'date-fns/isAfter';
import isBefore from 'date-fns/isBefore';

import { DayPickerBase } from 'types/DayPickerBase';
import { DayPickerRangeProps, isDayPickerRange } from 'types/DayPickerRange';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { isAfter, isBefore, isSameDay } from 'date-fns';
import isAfter from 'date-fns/isAfter';
import isBefore from 'date-fns/isBefore';
import isSameDay from 'date-fns/isSameDay';

import { DateRange } from 'types/Matchers';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from 'react';

import { isSameDay } from 'date-fns';
import isSameDay from 'date-fns/isSameDay';

import { ButtonProps } from 'components/Button';
import { DayContent } from 'components/DayContent';
Expand Down
4 changes: 3 additions & 1 deletion packages/react-day-picker/src/hooks/useInput/useInput.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import React, { useState } from 'react';

import { differenceInCalendarDays, format as _format, parse } from 'date-fns';
import differenceInCalendarDays from 'date-fns/differenceInCalendarDays';
import _format from 'date-fns/format';
import enUS from 'date-fns/locale/en-US';
import parse from 'date-fns/parse';

import { parseFromToProps } from 'contexts/DayPicker/utils';
import { DayPickerBase } from 'types/DayPickerBase';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-day-picker/src/types/DayPickerBase.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Locale } from 'date-fns';
import type { Locale } from 'date-fns';

import { CaptionLayout, CaptionProps } from 'components/Caption';
import { CaptionLabelProps } from 'components/CaptionLabel';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-day-picker/src/types/Labels.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Locale } from 'date-fns';
import type { Locale } from 'date-fns';

import { ActiveModifiers } from 'types/Modifiers';

Expand Down
2 changes: 1 addition & 1 deletion website/examples/custom-single.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function App() {
const handleDayClick = (day: Date) => setSelectedDay(day);

const footer = selectedDay ? (
<p>You selected ${selectedDay.toDateString()}</p>
<p>You selected {selectedDay.toDateString()}.</p>
) : (
<p>Please pick a day.</p>
);
Expand Down
8 changes: 5 additions & 3 deletions website/examples/multiple-min-max.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ export default function App() {
const [days, setDays] = React.useState<Date[]>();

const footer =
days && days.length > 0
? `You selected ${days.length} day(s).`
: `Please pick one or more days.`;
days && days.length > 0 ? (
<p>You selected {days.length} day(s).</p>
) : (
<p>Please pick one or more days.</p>
);

return (
<DayPicker
Expand Down
8 changes: 5 additions & 3 deletions website/examples/multiple.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ export default function App() {
const [days, setDays] = React.useState<Date[] | undefined>(initialDays);

const footer =
days && days.length > 0
? `You selected ${days.length} day(s).`
: `Please pick one or more days.`;
days && days.length > 0 ? (
<p>You selected {days.length} day(s).</p>
) : (
<p>Please pick one or more days.</p>
);

return (
<DayPicker
Expand Down