diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 25af6cb1a2..7751fce28f 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -30,6 +30,7 @@ const config = { "react/jsx-uses-react": "off", "react/react-in-jsx-scope": "off", "import/no-unresolved": "off", + "import/namespace": "off", "prettier/prettier": "warn", "no-console": "warn", "@typescript-eslint/no-unused-vars": "off", diff --git a/jest.config.ts b/jest.config.ts index 4110631f81..b9a1b22ce5 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -6,7 +6,8 @@ const config: Config.InitialOptions = { moduleNameMapper: { "@/test/(.*)": ["/test/$1"], "react-day-picker": ["/src/index.ts"], - "react-day-picker/(.*)": ["/src/$1"] + "react-day-picker/(.*)": ["/src/$1.js"], + "^(\\.\\.?\\/.+)\\.jsx?$": "$1" // see https://github.com/kulshekhar/ts-jest/issues/1057 }, testEnvironment: "jsdom", coverageReporters: ["lcov", "text", "clover"], diff --git a/package.json b/package.json index 0733c66808..d63b07428e 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "types": "./dist/cjs/index.d.ts", "module": "./dist/esm/index.js", "style": "./src/style.css", + "type": "module", "exports": { ".": { "require": { diff --git a/src/DayPicker.tsx b/src/DayPicker.tsx index a22c31013c..fd6ecc8d03 100644 --- a/src/DayPicker.tsx +++ b/src/DayPicker.tsx @@ -1,8 +1,8 @@ import React from "react"; -import { Calendar } from "./components/Calendar"; -import { ContextProviders } from "./contexts/providers"; -import type { DayPickerProps } from "./types"; +import { Calendar } from "./components/Calendar.js"; +import { ContextProviders } from "./contexts/providers.js"; +import type { DayPickerProps } from "./types/index.js"; /** * Render the date picker calendar. diff --git a/src/UI.ts b/src/UI.ts index f8705cf4c7..eabddd2dbe 100644 --- a/src/UI.ts +++ b/src/UI.ts @@ -1,4 +1,4 @@ -import type { CustomComponents, ClassNames, Styles } from "./types"; +import type { CustomComponents, ClassNames, Styles } from "./types/index.js"; /** * The UI elements composing DayPicker. These elements are mapped to diff --git a/src/classes/CalendarDay.ts b/src/classes/CalendarDay.ts index ed928ce090..7a4ba57910 100644 --- a/src/classes/CalendarDay.ts +++ b/src/classes/CalendarDay.ts @@ -1,5 +1,5 @@ -import { dateLib as defaultDateLib } from "../lib"; -import type { DateLib } from "../types"; +import { dateLib as defaultDateLib } from "../lib/index.js"; +import type { DateLib } from "../types/index.js"; /** * Represent the day displayed in the calendar. diff --git a/src/classes/CalendarMonth.ts b/src/classes/CalendarMonth.ts index 1693873f62..cd76ed82f3 100644 --- a/src/classes/CalendarMonth.ts +++ b/src/classes/CalendarMonth.ts @@ -1,4 +1,4 @@ -import { CalendarWeek } from "./CalendarWeek"; +import { CalendarWeek } from "./CalendarWeek.js"; /** Represent a month in a calendar year. Contains the weeks within the month. */ export class CalendarMonth { diff --git a/src/classes/CalendarWeek.ts b/src/classes/CalendarWeek.ts index b56fa5f0f3..09aec66848 100644 --- a/src/classes/CalendarWeek.ts +++ b/src/classes/CalendarWeek.ts @@ -1,4 +1,4 @@ -import { CalendarDay } from "./CalendarDay"; +import { CalendarDay } from "./CalendarDay.js"; /** Represent a week in a calendar month. */ export class CalendarWeek { diff --git a/src/classes/index.ts b/src/classes/index.ts index 998d86db68..a163cb8ca8 100644 --- a/src/classes/index.ts +++ b/src/classes/index.ts @@ -1,3 +1,3 @@ -export * from "./CalendarDay"; -export * from "./CalendarMonth"; -export * from "./CalendarWeek"; +export * from "./CalendarDay.js"; +export * from "./CalendarMonth.js"; +export * from "./CalendarWeek.js"; diff --git a/src/components/Calendar.tsx b/src/components/Calendar.tsx index 14767b924b..a408a93afb 100644 --- a/src/components/Calendar.tsx +++ b/src/components/Calendar.tsx @@ -1,12 +1,12 @@ import React from "react"; -import { UI, CalendarFlag } from "../UI"; -import { useCalendar, useProps } from "../contexts"; +import { UI, CalendarFlag } from "../UI.js"; +import { useCalendar, useProps } from "../contexts/index.js"; -import { Footer as DefaultFooter } from "./Footer"; -import { Month as DefaultMonth } from "./Month"; -import { Months as DefaultMonths } from "./Months"; -import { Nav as DefaultNav } from "./Nav"; +import { Footer as DefaultFooter } from "./Footer.js"; +import { Month as DefaultMonth } from "./Month.js"; +import { Months as DefaultMonths } from "./Months.js"; +import { Nav as DefaultNav } from "./Nav.js"; /** * Render the DayPicker Calendar with navigation and the month grids. diff --git a/src/components/Chevron.tsx b/src/components/Chevron.tsx index 984936ad3d..09f8b70e6a 100644 --- a/src/components/Chevron.tsx +++ b/src/components/Chevron.tsx @@ -1,7 +1,7 @@ import React from "react"; -import { ChevronFlag, UI } from "../UI"; -import { useProps } from "../contexts"; +import { ChevronFlag, UI } from "../UI.js"; +import { useProps } from "../contexts/index.js"; /** * Render the chevron icon used in the navigation buttons and dropdowns. diff --git a/src/components/Day.tsx b/src/components/Day.tsx index efc3589eae..91031b7bfa 100644 --- a/src/components/Day.tsx +++ b/src/components/Day.tsx @@ -1,8 +1,8 @@ import React from "react"; import type { ReactNode } from "react"; -import type { CalendarDay } from "../classes"; -import type { Modifiers } from "../types"; +import type { CalendarDay } from "../classes/index.js"; +import type { Modifiers } from "../types/index.js"; /** * Render the gridcell of a day in the calendar and handle the interaction and diff --git a/src/components/DayDate.tsx b/src/components/DayDate.tsx index b6c7abbb32..cbcf3e1414 100644 --- a/src/components/DayDate.tsx +++ b/src/components/DayDate.tsx @@ -1,7 +1,7 @@ import React from "react"; -import type { CalendarDay } from "../classes"; -import type { Modifiers } from "../types"; +import type { CalendarDay } from "../classes/index.js"; +import type { Modifiers } from "../types/index.js"; /** * Render the date as string inside the day grid cell. diff --git a/src/components/DayWrapper.tsx b/src/components/DayWrapper.tsx index 46136edd8d..a6eb336e49 100644 --- a/src/components/DayWrapper.tsx +++ b/src/components/DayWrapper.tsx @@ -1,15 +1,20 @@ import React from "react"; -import { UI, DayFlag } from "../UI"; -import { CalendarDay } from "../classes/CalendarDay"; -import { useCalendar, useFocus, useModifiers, useProps } from "../contexts"; -import { debounce } from "../helpers/debounce"; -import { getClassNamesForModifiers } from "../helpers/getClassNamesForModifiers"; -import { getStyleForModifiers } from "../helpers/getStyleForModifiers"; -import { useMulti, useRange, useSingle } from "../selection"; +import { UI, DayFlag } from "../UI.js"; +import { CalendarDay } from "../classes/CalendarDay.js"; +import { + useCalendar, + useFocus, + useModifiers, + useProps +} from "../contexts/index.js"; +import { debounce } from "../helpers/debounce.js"; +import { getClassNamesForModifiers } from "../helpers/getClassNamesForModifiers.js"; +import { getStyleForModifiers } from "../helpers/getStyleForModifiers.js"; +import { useMulti, useRange, useSingle } from "../selection/index.js"; -import { type DayProps, Day as DefaultDay } from "./Day"; -import { type DayDateProps, DayDate as DefaultDayDate } from "./DayDate"; +import { type DayProps, Day as DefaultDay } from "./Day.js"; +import { type DayDateProps, DayDate as DefaultDayDate } from "./DayDate.js"; /** * Provides a `Day` the day state and the html attributes. Developers may use a diff --git a/src/components/Dropdown.tsx b/src/components/Dropdown.tsx index fb395cbebc..0a12873902 100644 --- a/src/components/Dropdown.tsx +++ b/src/components/Dropdown.tsx @@ -1,11 +1,11 @@ import React, { type SelectHTMLAttributes } from "react"; -import { UI } from "../UI"; -import { useProps } from "../contexts"; +import { UI } from "../UI.js"; +import { useProps } from "../contexts/index.js"; -import { Chevron as DefaultChevron } from "./Chevron"; -import { Option as DefaultOption } from "./Option"; -import { Select as DefaultSelect } from "./Select"; +import { Chevron as DefaultChevron } from "./Chevron.js"; +import { Option as DefaultOption } from "./Option.js"; +import { Select as DefaultSelect } from "./Select.js"; /** An option to use in the dropdown. Maps to the `