Skip to content

Commit

Permalink
feat: implement date panels
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Feb 9, 2025
1 parent 45909fb commit 642b10b
Show file tree
Hide file tree
Showing 9 changed files with 460 additions and 184 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/useCalendar/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { InjectionKey } from 'vue';
import { CalendarContext } from './types';

export const CalendarContextKey: InjectionKey<CalendarContext> = Symbol('CalendarContext');
46 changes: 41 additions & 5 deletions packages/core/src/useCalendar/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Temporal } from '@js-temporal/polyfill';
import { MaybeRefOrGetter } from 'vue';
import { WeekInfo } from '../i18n/getWeekInfo';
import { Ref } from 'vue';
import { Maybe } from '../types';

export type CalendarIdentifier =
| 'buddhist'
Expand All @@ -20,18 +24,50 @@ export type CalendarIdentifier =
| 'persian'
| 'roc';

export interface CalendarDay {
export interface CalendarDayCell {
type: 'day';
value: Temporal.ZonedDateTime;

dayOfMonth: number;

label: string;
isToday: boolean;

isOutsideMonth: boolean;

selected: boolean;
disabled: boolean;
focused: boolean;
}

export interface CalendarMonthCell {
type: 'month';
label: string;
value: Temporal.ZonedDateTime;
monthOfYear: number;
selected: boolean;
disabled: boolean;
focused: boolean;
}

export interface CalendarYearCell {
type: 'year';
label: string;
value: Temporal.ZonedDateTime;
year: number;
selected: boolean;
disabled: boolean;
focused: boolean;
}

export type CalendarCellProps = CalendarDayCell | CalendarMonthCell | CalendarYearCell;

export type CalendarPanelType = 'day' | 'month' | 'year';

export interface CalendarContext {
locale: Ref<string>;
weekInfo: Ref<WeekInfo>;
calendar: Ref<CalendarIdentifier>;
selectedDate: MaybeRefOrGetter<Temporal.ZonedDateTime>;
getMinDate: () => Maybe<Temporal.ZonedDateTime>;
getMaxDate: () => Maybe<Temporal.ZonedDateTime>;
getFocusedDate: () => Temporal.ZonedDateTime;
setFocusedDate: (date: Temporal.ZonedDateTime) => void;
setDate: (date: Temporal.ZonedDateTime, panel?: CalendarPanelType) => void;
}
Loading

0 comments on commit 642b10b

Please sign in to comment.