-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: calendar core #10
base: v0
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the discussion in the time-maintainers Discord channel
* @returns {Temporal.ZonedDateTime} The end of the given unit. | ||
*/ | ||
export const endOf = (date: Temporal.ZonedDateTime, unit: 'day' | 'week' | 'month' | 'year' | 'workWeek' | 'decade'): Temporal.ZonedDateTime => { | ||
export function endOf({ | ||
date, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the direction here. I started a discussion in the time-maintainers discord around these types of methods...
Calendar Core
Summary
The CalendarCore class provides a set of functionalities for managing calendar events, view modes, and period navigation. This class is designed to be used in various calendar applications where precise date management and event handling are required.
Motivation
The motivation behind this class is to provide a reusable and efficient core for calendar functionalities that can be integrated into different applications, ensuring consistent and simplified management of calendar events, view modes, and period navigation.
Parameters
weekStartsOn?: number
events?: TEvent[]
viewMode: ViewMode
locale?: Parameters<Temporal.PlainDate['toLocaleString']>['0']
Returns
getDaysWithEvents(): Array<Day<TEvent>>
getDaysNames(): string[]
changeViewMode(newViewMode: ViewMode): void
goToPreviousPeriod(): void
goToNextPeriod(): void
goToCurrentPeriod(): void
goToSpecificPeriod(date: Temporal.PlainDate): void
updateCurrentTime(): void
getEventProps(id: Event['id']): { style: CSSProperties } | null
getCurrentTimeMarkerProps(): { style: CSSProperties; currentTime: string | undefined }
groupDaysBy(props: Omit<GroupDaysByProps<TEvent>, 'weekStartsOn'>): (Day<TEvent> | null)[][]
Example Usage
useCalendar hook
Summary
The useCalendar hook provides a comprehensive set of functionalities for managing calendar events, view modes, and period navigation.
Motivation
The motivation behind this hook is to provide a reusable and efficient way to integrate calendar functionalities into React components, ensuring consistent and simplified management of calendar events, view modes, and period navigation.
Parameters
weekStartsOn?: number
events: Event[]
viewMode: 'month' | 'week' | number
locale?: string
onChangeViewMode?: ({ value: number; unit: "month" | "week" | "day"; }) => void
onChangeViewMode?: (viewMode: value: number; unit: "month" | "week" | "day";) => void
reducer?: (state: CalendarState, action: CalendarAction) => CalendarState
Returns
firstDayOfPeriod: Temporal.PlainDate
currentPeriod: string
goToPreviousPeriod: MouseEventHandler<HTMLButtonElement>
goToNextPeriod: MouseEventHandler<HTMLButtonElement>
goToCurrentPeriod: MouseEventHandler<HTMLButtonElement>
goToSpecificPeriod: (date: Temporal.PlainDate) => void
days: Day[]
daysNames: string[]
viewMode: 'month' | 'week' | number
changeViewMode: (newViewMode: 'month' | 'week' | number) => void
getEventProps: (id: string) => { style: CSSProperties } | null
getEventProps: (id: string) => { style: CSSProperties } | null
getEventProps: (id: string) => { style: CSSProperties } | null
getCurrentTimeMarkerProps: () => { style: CSSProperties, currentTime: Temporal.PlainTime }
isPending: boolean
groupDaysBy: ({ days: Day[], unit: 'week' | 'month', fillMissingDays?: boolean }) => Day[][]
fillMissingDays
parameter can be used to fill in missing days with previous or next month's days.Example Usage