From d4183853313482fea63ce3e2ef8c3157509d81a9 Mon Sep 17 00:00:00 2001 From: Christian Chown Date: Sat, 24 Nov 2018 18:02:24 +0000 Subject: [PATCH 1/4] Extend typings to include the Enhanced Default Functionality --- types/react-infinite-calendar/index.d.ts | 34 ++++++++++++++----- .../react-infinite-calendar-tests.tsx | 13 ++++++- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/types/react-infinite-calendar/index.d.ts b/types/react-infinite-calendar/index.d.ts index 2110d4dbd0..3f0c827ed9 100644 --- a/types/react-infinite-calendar/index.d.ts +++ b/types/react-infinite-calendar/index.d.ts @@ -6,16 +6,18 @@ import * as React from 'react'; +export type DateType = Date | string | number; + export interface ReactInfiniteCalendarProps { - selected?: Date | boolean; - width?: number | 'auto'; + selected?: DateType | false | { start: DateType; end: DateType }; + width?: number | 'auto' | '100%'; height?: number | 'auto'; - min?: Date; - max?: Date; - minDate?: Date; - maxDate?: Date; + min?: DateType; + max?: DateType; + minDate?: DateType; + maxDate?: DateType; disabledDays?: Array<0 | 1 | 2 | 3 | 4 | 5 | 6>; - disabledDates?: Date[]; + disabledDates?: DateType[]; display?: 'days' | 'years'; displayOptions?: { hideYearsOnSelect?: boolean; @@ -55,12 +57,28 @@ export interface ReactInfiniteCalendarProps { weekdayColor?: string; }; className?: string; - onSelect?: (date: string) => void; + onSelect?: (date: string | { eventType: EVENT_TYPE; start: Date; end: Date }) => void; onScroll?: (scrollTop: number) => void; onScrollEnd?: (scrollTop: number) => void; rowHeight?: number; autoFocus?: boolean; tabIndex?: number; + Component?: CalendarClass; +} + +export class Calendar extends React.Component {} +export type CalendarClass = React.ComponentClass; + +export function withRange(component: CalendarClass): CalendarClass; +export function withDateSelection(component: CalendarClass): CalendarClass; +export function withMultipleDates(component: CalendarClass): CalendarClass; +export function withKeyboardSupport(component: CalendarClass): CalendarClass; +export function defaultMultipleDateInterpolation(component: CalendarClass): CalendarClass; + +export enum EVENT_TYPE { + START = 1, + HOVER, + END } export default class ReactInfiniteCalendar extends React.Component {} diff --git a/types/react-infinite-calendar/react-infinite-calendar-tests.tsx b/types/react-infinite-calendar/react-infinite-calendar-tests.tsx index ff1918d539..ba4b6a0ec7 100644 --- a/types/react-infinite-calendar/react-infinite-calendar-tests.tsx +++ b/types/react-infinite-calendar/react-infinite-calendar-tests.tsx @@ -1,5 +1,11 @@ import * as React from 'react'; -import ReactInfiniteCalendar from 'react-infinite-calendar'; +import ReactInfiniteCalendar, { + Calendar, + withRange, + withKeyboardSupport, + withMultipleDates, + withDateSelection +} from 'react-infinite-calendar'; const test: React.SFC = () => ( ( tabIndex={1} /> ); + +const testWithRange = withRange(Calendar); +const testWithDateSelection = withDateSelection(Calendar); +const testWithKeyboardSupport = withKeyboardSupport(Calendar); +const testWithMultipleDate = withMultipleDates(Calendar); From 97c9978a5636017e3df50a6dba07d6184d2eae63 Mon Sep 17 00:00:00 2001 From: Christian Chown Date: Tue, 27 Nov 2018 12:05:37 +0000 Subject: [PATCH 2/4] Correct onSelect signature for unenhanced calendars --- types/react-infinite-calendar/index.d.ts | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/types/react-infinite-calendar/index.d.ts b/types/react-infinite-calendar/index.d.ts index 3f0c827ed9..8d17e6dd4e 100644 --- a/types/react-infinite-calendar/index.d.ts +++ b/types/react-infinite-calendar/index.d.ts @@ -8,6 +8,21 @@ import * as React from 'react'; export type DateType = Date | string | number; +export enum EVENT_TYPE { + START = 1, + HOVER, + END +} + +export interface RangedSelection { + eventType: EVENT_TYPE; + start: Date; + end: Date; +} + +type RangedSelectFunction = (rangedDate: RangedSelection) => void; +type DateSelectFunction = (date: string) => void; + export interface ReactInfiniteCalendarProps { selected?: DateType | false | { start: DateType; end: DateType }; width?: number | 'auto' | '100%'; @@ -57,7 +72,7 @@ export interface ReactInfiniteCalendarProps { weekdayColor?: string; }; className?: string; - onSelect?: (date: string | { eventType: EVENT_TYPE; start: Date; end: Date }) => void; + onSelect?: DateSelectFunction | RangedSelectFunction; onScroll?: (scrollTop: number) => void; onScrollEnd?: (scrollTop: number) => void; rowHeight?: number; @@ -75,10 +90,4 @@ export function withMultipleDates(component: CalendarClass): CalendarClass; export function withKeyboardSupport(component: CalendarClass): CalendarClass; export function defaultMultipleDateInterpolation(component: CalendarClass): CalendarClass; -export enum EVENT_TYPE { - START = 1, - HOVER, - END -} - export default class ReactInfiniteCalendar extends React.Component {} From aa7352876a9c634bcae92726746bd92ea0c02005 Mon Sep 17 00:00:00 2001 From: Christian Chown Date: Tue, 27 Nov 2018 12:13:54 +0000 Subject: [PATCH 3/4] Export onSelect function types --- types/react-infinite-calendar/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/react-infinite-calendar/index.d.ts b/types/react-infinite-calendar/index.d.ts index 8d17e6dd4e..10a246c5ae 100644 --- a/types/react-infinite-calendar/index.d.ts +++ b/types/react-infinite-calendar/index.d.ts @@ -20,8 +20,8 @@ export interface RangedSelection { end: Date; } -type RangedSelectFunction = (rangedDate: RangedSelection) => void; -type DateSelectFunction = (date: string) => void; +export type RangedSelectFunction = (rangedDate: RangedSelection) => void; +export type DateSelectFunction = (date: string) => void; export interface ReactInfiniteCalendarProps { selected?: DateType | false | { start: DateType; end: DateType }; From e6924a21bba6f7f30810c69d3796bce5ce6a9129 Mon Sep 17 00:00:00 2001 From: Christian Chown Date: Tue, 27 Nov 2018 17:29:18 +0000 Subject: [PATCH 4/4] DateSelectFunction takes a Date, not a string --- types/react-infinite-calendar/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/react-infinite-calendar/index.d.ts b/types/react-infinite-calendar/index.d.ts index 10a246c5ae..ac09df7bf4 100644 --- a/types/react-infinite-calendar/index.d.ts +++ b/types/react-infinite-calendar/index.d.ts @@ -21,7 +21,7 @@ export interface RangedSelection { } export type RangedSelectFunction = (rangedDate: RangedSelection) => void; -export type DateSelectFunction = (date: string) => void; +export type DateSelectFunction = (date: Date) => void; export interface ReactInfiniteCalendarProps { selected?: DateType | false | { start: DateType; end: DateType };