Skip to content

Commit

Permalink
chore: update name of files
Browse files Browse the repository at this point in the history
  • Loading branch information
gpbl committed Jun 21, 2024
1 parent 74ca3d4 commit 57c2daa
Show file tree
Hide file tree
Showing 36 changed files with 73 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/components/Chevron.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { ChevronFlag, UI } from "../UI";
import { useProps } from "../contexts/props";
import { useProps } from "../contexts";

/**
* Render the chevron icon used in the navigation buttons and dropdowns.
Expand Down
2 changes: 1 addition & 1 deletion src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { type SelectHTMLAttributes } from "react";

import { UI } from "../UI";
import { useProps } from "../contexts/props";
import { useProps } from "../contexts";

import { Chevron as DefaultChevron } from "./Chevron";
import { Option as DefaultOption } from "./Option";
Expand Down
2 changes: 1 addition & 1 deletion src/components/DropdownNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";

import { UI } from "../UI";
import type { CalendarMonth } from "../classes";
import { useProps } from "../contexts/props";
import { useProps } from "../contexts";

import { MonthsDropdown } from "./MonthsDropdown";
import { YearsDropdown } from "./YearsDropdown";
Expand Down
2 changes: 1 addition & 1 deletion src/components/Month.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";

import { UI } from "../UI";
import type { CalendarMonth } from "../classes/CalendarMonth";
import { useProps } from "../contexts/props";
import { useProps } from "../contexts";

import { MonthCaption as DefaultMonthCaption } from "./MonthCaption";
import { Week as DefaultWeek } from "./Week";
Expand Down
2 changes: 1 addition & 1 deletion src/components/MonthCaption.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";

import { UI } from "../UI";
import type { CalendarMonth } from "../classes";
import { useProps } from "../contexts/props";
import { useProps } from "../contexts";

import { DropdownNav } from "./DropdownNav";

Expand Down
2 changes: 1 addition & 1 deletion src/components/Week.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getUnixTime } from "date-fns/getUnixTime";

import { UI } from "../UI";
import type { CalendarDay, CalendarWeek } from "../classes";
import { useProps } from "../contexts/props";
import { useProps } from "../contexts";

import { DayWrapper } from "./DayWrapper";
import { WeekNumber as DefaultWeekNumber } from "./WeekNumber";
Expand Down
2 changes: 1 addition & 1 deletion src/components/WeekNumber.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from "react";

import { UI, WeekNumberFlag } from "../UI";
import type { CalendarWeek } from "../classes";
import { useProps } from "../contexts/props";
import { useProps } from "../contexts";

/**
* Render the cell with the number of the week.
Expand Down
2 changes: 1 addition & 1 deletion src/components/Weekday.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { UI } from "../UI";
import { useProps } from "../contexts/props";
import { useProps } from "../contexts";

/**
* Render the column header with the weekday name (e.g. "Mo", "Tu", etc.).
Expand Down
2 changes: 1 addition & 1 deletion src/components/Weekdays.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { UI } from "../UI";
import { useProps } from "../contexts/props";
import { useProps } from "../contexts";
import { getWeekdays } from "../helpers/getWeekdays";

import { Weekday as DefaultWeekday } from "./Weekday";
Expand Down
3 changes: 1 addition & 2 deletions src/components/YearsDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { startOfMonth } from "date-fns/startOfMonth";

import { UI } from "../UI";
import type { CalendarMonth } from "../classes/CalendarMonth";
import { useCalendar } from "../contexts/calendar";
import { useProps } from "../contexts/props";
import { useCalendar, useProps } from "../contexts";

import { Dropdown as DefaultDropdown } from "./Dropdown";

Expand Down
8 changes: 4 additions & 4 deletions src/contexts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from "./calendar";
export * from "./focus";
export * from "./modifiers";
export * from "./props";
export * from "./useCalendar";
export * from "./useFocus";
export * from "./useModifiers";
export * from "./useProps";
8 changes: 4 additions & 4 deletions src/contexts/providers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import type {
PropsSingle
} from "../types";

import { CalendarContextProvider } from "./calendar";
import { FocusContextProvider } from "./focus";
import { ModifiersContextProvider } from "./modifiers";
import { PropsContextProvider, useProps } from "./props";
import { CalendarContextProvider } from "./useCalendar";
import { FocusContextProvider } from "./useFocus";
import { ModifiersContextProvider } from "./useModifiers";
import { PropsContextProvider, useProps } from "./useProps";

function SelectionProviders({ children }: PropsWithChildren) {
const props = useProps();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderHook } from "@/test/renderHook";

import { useCalendar } from "./calendar";
import { useCalendar } from "./useCalendar";

it("should return the next month", () => {
const { result } = renderHook(useCalendar, {
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/calendar.tsx → src/contexts/useCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getPreviousMonth } from "../helpers/getPreviousMonth";
import { getWeeks } from "../helpers/getWeeks";
import { useControlledValue } from "../helpers/useControlledValue";

import { useProps } from "./props";
import { useProps } from "./useProps";

/** @private */
const CalendarContext = createContext<CalendarContextValue | undefined>(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { renderHook } from "@/test/renderHook";

import { useFocus } from "./focus";
import { useFocus } from "./useFocus";

const month = new Date(2020, 0, 1);
const today = new Date(2020, 0, 14);
Expand Down
6 changes: 3 additions & 3 deletions src/contexts/focus.tsx → src/contexts/useFocus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import type { CalendarDay } from "../classes";
import { getNextFocus } from "../helpers/getNextFocus";
import type { MoveFocusBy, MoveFocusDir, Mode } from "../types";

import { useCalendar } from "./calendar";
import { useModifiers } from "./modifiers";
import { useProps } from "./props";
import { useCalendar } from "./useCalendar";
import { useModifiers } from "./useModifiers";
import { useProps } from "./useProps";

const FocusContext = createContext<FocusContextValue | undefined>(undefined);

Expand Down
4 changes: 2 additions & 2 deletions src/contexts/modifiers.tsx → src/contexts/useModifiers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import type {
import { isDateInRange } from "../utils";
import { dateMatchModifiers } from "../utils/dateMatchModifiers";

import { useCalendar } from "./calendar";
import { useProps } from "./props";
import { useCalendar } from "./useCalendar";
import { useProps } from "./useProps";

/** @private */
const ModifiersContext = createContext<ModifiersContextValue | undefined>(
Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions src/dateUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export { addDays } from "date-fns/addDays";
export { addMonths } from "date-fns/addMonths";
export { addYears } from "date-fns/addYears";
export { differenceInCalendarDays } from "date-fns/differenceInCalendarDays";
export { differenceInCalendarMonths } from "date-fns/differenceInCalendarMonths";
export { endOfISOWeek } from "date-fns/endOfISOWeek";
export { endOfMonth } from "date-fns/endOfMonth";
export { endOfWeek } from "date-fns/endOfWeek";
export { endOfYear } from "date-fns/endOfYear";
export { format } from "date-fns/format";
export { getISOWeek } from "date-fns/getISOWeek";
export { getUnixTime } from "date-fns/getUnixTime";
export { getWeek } from "date-fns/getWeek";
export { isAfter } from "date-fns/isAfter";
export { isBefore } from "date-fns/isBefore";
export { isDate } from "date-fns/isDate";
export { isSameDay } from "date-fns/isSameDay";
export { isSameMonth } from "date-fns/isSameMonth";
export { isSameYear } from "date-fns/isSameYear";
export { setMonth } from "date-fns/setMonth";
export { setYear } from "date-fns/setYear";
export { startOfISOWeek } from "date-fns/startOfISOWeek";
export { startOfMonth } from "date-fns/startOfMonth";
export { startOfWeek } from "date-fns/startOfWeek";
export { startOfYear } from "date-fns/startOfYear";
2 changes: 1 addition & 1 deletion src/helpers/getDates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { isAfter } from "date-fns/isAfter";
import { startOfISOWeek } from "date-fns/startOfISOWeek";
import { startOfWeek } from "date-fns/startOfWeek";

import { PropsContextValue } from "../contexts/props";
import { PropsContextValue } from "../contexts";
import type { Mode, DayPickerProps } from "../types";

/** The number of days in a month when having 6 weeks. */
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getDisplayMonths.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { addMonths } from "date-fns/addMonths";

import type { PropsContextValue } from "../contexts/props";
import type { PropsContextValue } from "../contexts";

export function getDisplayMonths(
firstDisplayedMonth: Date,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getDropdownMonths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { isBefore } from "date-fns/isBefore";
import { startOfMonth } from "date-fns/startOfMonth";

import { DropdownOption } from "../components/Dropdown";
import { PropsContextValue } from "../contexts/props";
import { PropsContextValue } from "../contexts";

/** Return the months to show in the dropdown. */
export function getDropdownMonths(
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getDropdownYears.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { startOfMonth } from "date-fns/startOfMonth";
import { startOfYear } from "date-fns/startOfYear";

import { DropdownOption } from "../components/Dropdown";
import { PropsContextValue } from "../contexts/props";
import { PropsContextValue } from "../contexts";

/** Return the years to show in the dropdown. */
export function getDropdownYears(
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getInitialMonth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addMonths } from "date-fns/addMonths";
import { differenceInCalendarMonths } from "date-fns/differenceInCalendarMonths";
import { startOfMonth } from "date-fns/startOfMonth";

import type { PropsContextValue } from "../contexts/props";
import type { PropsContextValue } from "../contexts";

/** Return the start month based on the props passed to DayPicker. */
export function getInitialMonth(
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getMonths.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CalendarMonth } from "../classes";
import type { PropsContextValue } from "../contexts/props";
import type { PropsContextValue } from "../contexts/useProps";

import { getMonths } from "./getMonths";

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getMonths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { startOfISOWeek } from "date-fns/startOfISOWeek";
import { startOfWeek } from "date-fns/startOfWeek";

import { CalendarWeek, CalendarDay, CalendarMonth } from "../classes";
import type { PropsContextValue } from "../contexts/props";
import type { PropsContextValue } from "../contexts";

/** Return the months to display in the calendar. */
export function getMonths(
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getNextFocus.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { CalendarDay } from "../classes";
import type { PropsContextValue } from "../contexts/props";
import type { PropsContextValue } from "../contexts/useProps";
import type { MoveFocusBy, MoveFocusDir } from "../types";

import { getNextFocus } from "./getNextFocus";
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getNextFocus.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";

import { CalendarDay } from "../classes";
import type { PropsContextValue } from "../contexts/props";
import type { PropsContextValue } from "../contexts";
import type { MoveFocusBy, MoveFocusDir, Mode } from "../types";
import { dateMatchModifiers } from "../utils/dateMatchModifiers";

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getNextMonth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addMonths } from "date-fns/addMonths";
import { differenceInCalendarMonths } from "date-fns/differenceInCalendarMonths";
import { startOfMonth } from "date-fns/startOfMonth";

import { PropsContextValue } from "../contexts/props";
import { PropsContextValue } from "../contexts";

/**
* Return the next month the user can navigate to according to the given
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getPossibleFocusDate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
endOfWeek
} from "date-fns";

import type { PropsContextValue } from "../contexts/props";
import type { PropsContextValue } from "../contexts/useProps";
import type { MoveFocusBy, MoveFocusDir, Mode } from "../types";

import { getPossibleFocusDate } from "./getPossibleFocusDate";
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getPossibleFocusDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { min } from "date-fns/min";
import { startOfISOWeek } from "date-fns/startOfISOWeek";
import { startOfWeek } from "date-fns/startOfWeek";

import type { PropsContextValue } from "../contexts/props";
import type { PropsContextValue } from "../contexts";
import type { MoveFocusBy, MoveFocusDir } from "../types";
import { Mode } from "../types";

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/getPreviousMonth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { addMonths } from "date-fns/addMonths";
import { differenceInCalendarMonths } from "date-fns/differenceInCalendarMonths";
import { startOfMonth } from "date-fns/startOfMonth";

import type { PropsContextValue } from "../contexts/props";
import type { PropsContextValue } from "../contexts";

/**
* Return the next previous the user can navigate to, according to the given
Expand Down
4 changes: 2 additions & 2 deletions src/types/deprecated.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
type MonthCaptionProps
} from "../components/MonthCaption";
import { Week, type WeekProps } from "../components/Week";
import { useCalendar } from "../contexts/calendar";
import { useProps, type PropsContextValue } from "../contexts/props";
import { useCalendar } from "../contexts";
import { useProps, type PropsContextValue } from "../contexts";
import { labelDay, labelNext, labelWeekday, labelWeekNumber } from "../labels";

import type { PropsMulti, PropsRange, PropsSingle } from "./props";
Expand Down
5 changes: 4 additions & 1 deletion src/types/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import type {
WeekNumberMouseEventHandler,
Modifiers,
DateRange,
Mode
Mode,
DateUtils
} from "./shared";

/**
Expand Down Expand Up @@ -324,6 +325,8 @@ export interface PropsBase {
onPrevClick?: MonthChangeEventHandler;
/** Event handler when a week number is clicked */
onWeekNumberClick?: WeekNumberMouseEventHandler;

dateUtils?: Partial<DateUtils> | undefined;
}
/**
* The props when the single selection is required.
Expand Down
3 changes: 3 additions & 0 deletions src/types/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
SelectionState
} from "../UI";
import * as components from "../components/custom-components";
import * as dateUtils from "../dateUtils";
import {
formatCaption,
formatDay,
Expand Down Expand Up @@ -52,6 +53,8 @@ export type CustomComponents = {
[key in keyof typeof components]?: (typeof components)[key];
};

export type DateUtils = typeof dateUtils;

/** Represent a map of formatters used to render localized content. */
export type Formatters = {
/** Format the caption of a month grid. */
Expand Down
1 change: 0 additions & 1 deletion test/renderHook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { renderHook as testingLibraryRenderHook } from "@testing-library/react";
import { DayPickerProps } from "react-day-picker";

import { ContextProviders } from "../src/contexts/providers";
import { Mode } from "../src/types";

/** Render a hook wrapped with the {@link ContextProviders} Provider. */
export function renderHook<TResult>(
Expand Down

0 comments on commit 57c2daa

Please sign in to comment.