-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #286 from diegosteiner/develop
Release 23.12.1
- Loading branch information
Showing
114 changed files
with
2,682 additions
and
1,993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
V23.11.2 | ||
V23.12.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { Dispatch, SetStateAction, createContext, useState } from "react"; | ||
import MonthsCalendar from "./MonthsCalendar"; | ||
import YearCalendar from "./YearCalendar"; | ||
import * as React from "react"; | ||
import { DateElementFactory } from "./CalendarDate"; | ||
import { CalendarNav } from "./CalendarNav"; | ||
import getYear from "date-fns/getYear"; | ||
import addMonths from "date-fns/addMonths"; | ||
import subMonths from "date-fns/subMonths"; | ||
import { parseDate } from "../../services/date"; | ||
|
||
type CalendarProps = { | ||
initialFirstDate?: string; | ||
dateElementFactory: DateElementFactory; | ||
defaultView?: ViewType; | ||
months?: number; | ||
}; | ||
|
||
export type ViewType = "months" | "year"; | ||
type CalendarViewContextType = { | ||
view: ViewType; | ||
setView?: Dispatch<SetStateAction<ViewType>>; | ||
}; | ||
export const CalendarViewContext = createContext<CalendarViewContextType>({ view: "months" }); | ||
|
||
function Calendar({ initialFirstDate, defaultView, months, dateElementFactory }: CalendarProps) { | ||
const [view, setView] = useState<ViewType>(defaultView || "months"); | ||
const [firstDate, setFirstDate] = useState<Date>(parseDate(initialFirstDate)); | ||
const gotoNextMonth = () => setFirstDate((prevFirstDate) => addMonths(prevFirstDate, 1)); | ||
const gotoPrevMonth = () => setFirstDate((prevFirstDate) => subMonths(prevFirstDate, 1)); | ||
const gotoToday = () => setFirstDate(new Date()); | ||
|
||
return ( | ||
<CalendarViewContext.Provider value={{ view, setView }}> | ||
<div className="calendar"> | ||
<CalendarNav onNext={gotoNextMonth} onPrev={gotoPrevMonth} onToday={gotoToday}> | ||
{getYear(firstDate)} | ||
</CalendarNav> | ||
{({ months: MonthsCalendar, year: YearCalendar }[view] || MonthsCalendar)({ | ||
firstDate, | ||
months, | ||
dateElementFactory, | ||
})} | ||
<CalendarNav onNext={gotoNextMonth} onPrev={gotoPrevMonth} onToday={gotoToday}> | ||
{getYear(firstDate)} | ||
</CalendarNav> | ||
</div> | ||
</CalendarViewContext.Provider> | ||
); | ||
} | ||
|
||
export default Calendar; |
Oops, something went wrong.