Skip to content
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

chore: typescript support #60

Merged
merged 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,196 @@
// Type definitions for TOAST UI DatePicker v4.0.3
// TypeScript Version: 3.8.3

export type CalendarType = 'date' | 'month' | 'year';
export type DatePickerEventType = 'change' | 'close' | 'draw' | 'open';
export type DateRangePickerEventType = 'change:start' | 'change:end';

export interface CalendarOptions {
language?: string;
showToday?: boolean;
showJumpButtons?: boolean;
date?: Date;
type?: CalendarType;
usageStatistics?: boolean;
}

export interface DefaultPickerOptions {
type?: CalendarType;
selectableRanges?: Array<[Date | number, Date | number]>;
calendar?: CalendarOptions;
showAlways?: boolean;
autoClose?: boolean;
language?: string;
usageStatistics?: boolean;
}

export interface DatePickerOptions extends DefaultPickerOptions {
input?: {
element?: HTMLElement | string;
format?: string;
};
openers?: Array<string | HTMLElement>;
date?: Date;
timePicker?: object | boolean;
}

export interface DateRangePickerOptions extends DefaultPickerOptions {
startpicker: {
input: HTMLInputElement;
container: HTMLElement;
date?: Date;
};
endpicker: {
input: HTMLInputElement;
container: HTMLElement;
date?: Date;
};
format?: string;
}

export class Calendar {
public addCssClass(className: string): void;

public changeLanguage(language: string): void;

public destroy(): void;

public draw(options: object): void;

public drawNext(): void;

public drawPrev(): void;

public getDate(): Date;

public getDateElements(): [HTMLElement];

public getNextDate(): Date;

public getNextYearDate(): Date;

public getPrevDate(): Date;

public getPrevYearDate(): Date;

public getType(): CalendarType;

public hide(): void;

public moveCssClass(className: string): void;

public show(): void;

public on(
type: 'draw',
handler: (evt: { date: Date; type: string; dateElements: HTMLElement }) => void
): void;

static localeTexts: Record<string, object>;
}

export class DateRangePicker {
public addRange(start: Date | number, end: Date | number): void;

public changeLanguage(language: string): void;

public destroy(): void;

public setStartDate: (newDate: Date) => void;

public getStartDate: () => Date;

public setEndDate: (newDate: Date) => void;

public getEndDate: () => Date;

public getStartPicker: () => any;

public getEndPicker: () => any;

public setRange(ranges: Array<[Date | number, Date | number]>): void;

public removeRange(start: Date | number, end: Date | number, type?: CalendarType): void;

public on(type: DateRangePickerEventType, handler: Function): void;
}

export default class DatePicker {
constructor(container: string | HTMLElement, options?: DatePickerOptions);

public addCssClass(className: string): void;

public addOpener(opener: HTMLElement | string): void;

public addRange(start: Date | number, end: Date | number): void;

public changeLanguage(language: string): void;

public disable(): void;

public enable(): void;

public drawLowerCalendar(date: Date): void;

public drawUpperCalendar(date: Date): void;

public findOverlappedRange(startDate: Date | number, endDate: Date | number): void;

public getCalendar(): Calendar;

public getCalendarType(): CalendarType;

public getDateElements(): [HTMLElement];

public getLocaleText(): Record<string, object>;

public getTimePicker(): unknown;

public getType(): CalendarType;

public isDisabled(): boolean;

public isOpened(): boolean;

public isSelectable(date: Date): boolean;

public isSelected(date: Date): boolean;

public open(): void;

public close(): void;

public removeAllOpeners(): void;

public removeCssClass(className: string): void;

public removeOpener(opener: HTMLElement | string): void;

public removeRange(start: Date | number, end: Date | number, type: CalendarType | null): void;

public setDateFormat(format: string): void;

public setInput(element: HTMLElement, options: { format: string; syncFromInput: boolean }): void;

public setNull(): void;

public setType(type: string): void;

public toggle(): void;

public destroy(): void;

public on(type: DatePickerEventType, handler: Function): void;

public setStartDate: (newDate: Date) => void;

public getDate: () => Date;

public setDate: (newDate: Date) => void;

static localeTexts: Record<string, object>;

static createRangePicker(props: DateRangePickerOptions): DateRangePicker;

static createCalendar(wrapperElement: string | HTMLElement, options: CalendarOptions): Calendar;
}
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"version": "4.0.3",
"description": "TOAST UI Components: DatePicker",
"main": "dist/tui-date-picker",
"types": "index.d.ts",
"files": [
"dist"
"dist",
"index.d.ts"
],
"scripts": {
"test": "karma start --no-single-run",
Expand Down