-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* dts-gen -m calendarx * finish d.ts * add Weekday type * tweak types * type tweaks * formatting * improve types * use latest types
- Loading branch information
Showing
2 changed files
with
101 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import * as React from 'react'; | ||
|
||
export type DateLike = Date | string | number; | ||
|
||
export type Event = | ||
| { date: DateLike } | ||
| { startDate: DateLike; endDate: DateLike }; | ||
|
||
export type View = 'year' | 'month' | 'week' | 'day'; | ||
|
||
export type ButtonPropsGetter = (props?: { | ||
onClick?: () => void; | ||
}) => { | ||
role: string; | ||
'aria-label': string; | ||
onClick: () => void; | ||
}; | ||
|
||
export type Day = { | ||
date: Date; | ||
events: Event[]; | ||
isToday: boolean; | ||
isSame: (view: View) => boolean; | ||
}; | ||
|
||
export type Weekday = 0 | 1 | 2 | 3 | 4 | 5 | 6; | ||
|
||
export type JumpUnit = | ||
| View | ||
| 'years' | ||
| 'y' | ||
| 'months' | ||
| 'M' | ||
| 'weeks' | ||
| 'w' | ||
| 'days' | ||
| 'd'; | ||
|
||
export type Properties = { | ||
date: Date; | ||
days: Day[][]; | ||
headers: string[]; | ||
view: View; | ||
numDays: number; | ||
jump: (n: number, v?: JumpUnit) => void; | ||
goToNext: (n?: number) => void; | ||
goToPrev: (n?: number) => void; | ||
goToToday: () => void; | ||
goToDate: (date: DateLike) => void; | ||
getPrevButtonProps: ButtonPropsGetter; | ||
getNextButtonProps: ButtonPropsGetter; | ||
getTodayButtonProps: ButtonPropsGetter; | ||
setNumDays: (numDays: number) => void; | ||
}; | ||
|
||
export interface Options { | ||
initialDate?: DateLike; | ||
initialNumDays?: number; | ||
date?: DateLike; | ||
numDays?: number; | ||
events?: Event[]; | ||
weekStartsOn?: Weekday; | ||
headers?: string[]; | ||
} | ||
|
||
export interface Props extends Options { | ||
children: (properties: Properties) => React.ReactNode; | ||
} | ||
|
||
export function Calendar(props: Props): React.ReactNode; | ||
|
||
export function useCalendar(options?: Options): Properties; | ||
|
||
export namespace Calendar { | ||
function useCalendar(options?: Options): Properties; | ||
|
||
const days: { | ||
SUNDAY: 0; | ||
MONDAY: 1; | ||
TUESDAY: 2; | ||
WEDNESDAY: 3; | ||
THURSDAY: 4; | ||
FRIDAY: 5; | ||
SATURDAY: 6; | ||
}; | ||
|
||
const defaultProps: { | ||
events: Event[]; | ||
headers: string[]; | ||
initialNumDays: number; | ||
weekStartsOn: Weekday; | ||
}; | ||
|
||
const views: { | ||
DAY: 'day'; | ||
WEEK: 'week'; | ||
MONTH: 'month'; | ||
YEAR: 'year'; | ||
}; | ||
} |
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