Skip to content

chore: rename useGetModifiers to createGetModifiers #2751

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/DayPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TZDate } from "@date-fns/tz";
import { UI, DayFlag, SelectionState } from "./UI.js";
import type { CalendarDay } from "./classes/CalendarDay.js";
import { DateLib, defaultLocale } from "./classes/DateLib.js";
import { createGetModifiers } from "./helpers/createGetModifiers.js";
import { getClassNamesForModifiers } from "./helpers/getClassNamesForModifiers.js";
import { getComponents } from "./helpers/getComponents.js";
import { getDataAttributes } from "./helpers/getDataAttributes.js";
Expand All @@ -28,7 +29,6 @@ import { useAnimation } from "./useAnimation.js";
import { useCalendar } from "./useCalendar.js";
import { type DayPickerContext, dayPickerContext } from "./useDayPicker.js";
import { useFocus } from "./useFocus.js";
import { useGetModifiers } from "./useGetModifiers.js";
import { useSelection } from "./useSelection.js";
import { rangeIncludesDate } from "./utils/rangeIncludesDate.js";
import { isDateRange } from "./utils/typeguards.js";
Expand Down Expand Up @@ -156,7 +156,7 @@ export function DayPicker(initialProps: DayPickerProps) {
goToMonth
} = calendar;

const getModifiers = useGetModifiers(days, props, dateLib);
const getModifiers = createGetModifiers(days, props, dateLib);

const {
isSelected,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { DayFlag } from "./UI";
import { CalendarDay, defaultDateLib } from "./classes/index";
import { useGetModifiers } from "./useGetModifiers";
import { DayFlag } from "../UI";
import { CalendarDay, defaultDateLib } from "../classes/index";

import { createGetModifiers } from "./createGetModifiers";

const dateLib = defaultDateLib;

Expand Down Expand Up @@ -37,10 +38,9 @@ const props = {
timeZone: "UTC"
};

describe("useGetModifiers", () => {
describe("createGetModifiers", () => {
describe("default props", () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const getModifiers = useGetModifiers(days, props, dateLib);
const getModifiers = createGetModifiers(days, props, dateLib);

test("return the modifiers for a given day", () => {
const modifiers = getModifiers(day2);
Expand Down Expand Up @@ -112,8 +112,7 @@ describe("useGetModifiers", () => {
const endMonth = new Date(displayedMonth);
endMonth.setDate(1);

// eslint-disable-next-line react-hooks/rules-of-hooks
const getModifiers = useGetModifiers(
const getModifiers = createGetModifiers(
days,
{ ...props, startMonth, endMonth },
dateLib
Expand Down
12 changes: 5 additions & 7 deletions src/useGetModifiers.tsx → src/helpers/createGetModifiers.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { DayFlag } from "./UI.js";
import type { CalendarDay, DateLib } from "./classes/index.js";
import type { DayPickerProps, Modifiers } from "./types/index.js";
import { dateMatchModifiers } from "./utils/dateMatchModifiers.js";
import { DayFlag } from "../UI.js";
import type { CalendarDay, DateLib } from "../classes/index.js";
import type { DayPickerProps, Modifiers } from "../types/index.js";
import { dateMatchModifiers } from "../utils/dateMatchModifiers.js";

/**
* Return a function to get the modifiers for a given day.
*
* NOTE: this is not an hook, but a factory for `getModifiers`.
*
* @private
*/
export function useGetModifiers(
export function createGetModifiers(
days: CalendarDay[],
props: DayPickerProps,
dateLib: DateLib
Expand Down