Skip to content

Commit

Permalink
Create d.ts file (#28)
Browse files Browse the repository at this point in the history
* dts-gen -m calendarx

* finish d.ts

* add Weekday type

* tweak types

* type tweaks

* formatting

* improve types

* use latest types
  • Loading branch information
mfix22 authored Nov 18, 2020
1 parent ca5f087 commit 1e5c471
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
100 changes: 100 additions & 0 deletions calendarx.d.ts
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';
};
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"unpkg": "dist/calendarx.umd.js",
"module": "dist/calendarx.module.js",
"esmodule": "dist/calendarx.modern.js",
"types": "calendarx.d.ts",
"files": [
"dist"
],
Expand Down

0 comments on commit 1e5c471

Please sign in to comment.