Anna Kurylo
2018-10-17 ccc40e94e2da9fe9aa1cb560b97e3e618cefb1da
commit | author | age
92485e 1 // Type definitions for react-datetime
IV 2 // Project: https://github.com/YouCanBookMe/react-datetime
3 // Definitions by: Ivan Verevkin <vereva@x-root.org>
4
a20f58 5 // These are the typings for Typescript 1.8
b46c6e 6 // for Typescript 2.0+ see DateTime.d.ts
a20f58 7
92485e 8 //// <reference path="../moment/moment-node.d.ts" />
IV 9
10 declare module ReactDatetime {
11   import React = __React;
12   // import * as moment from 'moment';
13
14   export interface DatetimepickerProps {
15     /*
16      Represents the selected date by the component, in order to use it as a controlled component.
17      This prop is parsed by moment.js, so it is possible to use a date string or a moment.js date.
18      */
fe4c5c 19     value?: Date;
92485e 20     /*
IV 21      Represents the selected date for the component to use it as a uncontrolled component.
22      This prop is parsed by moment.js, so it is possible to use a date string or a moment.js date.
23      */
fe4c5c 24     defaultValue?: Date;
92485e 25     /*
c276ec 26      Represents the month which is viewed on opening the calendar when there is no selected date.
SVT 27      This prop is parsed by Moment.js, so it is possible to use a date `string` or a `moment` object.
28      */
29     viewDate?: Date;
30     /*
92485e 31      Defines the format for the date. It accepts any moment.js date format.
IV 32      If true the date will be displayed using the defaults for the current locale.
33      If false the datepicker is disabled and the component can be used as timepicker.
34      */
35     dateFormat?: boolean|string;
36     /*
37      Defines the format for the time. It accepts any moment.js time format.
38      If true the time will be displayed using the defaults for the current locale.
39      If false the timepicker is disabled and the component can be used as datepicker.
40      */
41     timeFormat?: boolean|string;
42     /*
c5845c 43      Whether to show an input field to edit the date manually.
92485e 44      */
IV 45     input?: boolean;
46     /*
c5845c 47      Whether to open or close the picker. If not set react-datetime will open the
92485e 48      datepicker on input focus and close it on click outside.
IV 49      */
50     open?: boolean;
51     /*
52      Manually set the locale for the react-datetime instance.
53      Moment.js locale needs to be loaded to be used, see i18n docs.
54      */
55     locale?: string;
56     /*
049c33 57      Whether to interpret input times as UTC or the user's local timezone.
TS 58      */
59     utc?: boolean;
60     /*
fe4c5c 61      Callback trigger when the date changes. The callback receives the selected `moment` object as
MV 62      only parameter, if the date in the input is valid. If the date in the input is not valid, the
63      callback receives the value of the input (a string).
92485e 64      */
fe4c5c 65     onChange?: (momentOrInputString: string|any) => void;
92485e 66     /*
IV 67      Callback trigger for when the user opens the datepicker.
68      */
fe4c5c 69     onFocus?: () => void;
92485e 70     /*
IV 71      Callback trigger for when the user clicks outside of the input, simulating a regular onBlur.
fe4c5c 72      The callback receives the selected `moment` object as only parameter, if the date in the input
MV 73      is valid. If the date in the input is not valid, the callback receives the value of the
74      input (a string).
92485e 75      */
fe4c5c 76     onBlur?: (momentOrInputString : string|any) => void;
92485e 77     /*
b8d07e 78      Callback trigger when the view mode changes. The callback receives the selected view mode
SE 79      string ('years', 'months', 'days', 'time') as only parameter.
80     */
81     onViewModeChange?: (viewMode: string) => void;
82     /*
d40f6d 83       Callback trigger when the user navigates to the previous month, year or decade.
DDD 84       The callback receives the amount and type ('month', 'year') as parameters.
85      */
86     onNavigateBack?: (amount: number, type: string) => void;
87     /*
88       Callback trigger when the user navigates to the next month, year or decade.
89       The callback receives the amount and type ('month', 'year') as parameters.
90      */
91     onNavigateForward?: (amount: number, type: string) => void;
92     /*
92485e 93      The default view to display when the picker is shown. ('years', 'months', 'days', 'time')
IV 94      */
95     viewMode?: string|number;
96     /*
97      Extra class names for the component markup.
98      */
99     className?: string;
100     /*
101      Defines additional attributes for the input element of the component.
102      */
103     inputProps?: Object;
104     /*
d40f6d 105      Replace the rendering of the input element. The accepted function has openCalendar
DDD 106      (a function which opens the calendar) and the default calculated props for the input.
b6f2dd 107      Must return a React component or null.
DF 108      */
109     renderInput?: (props: Object, openCalendar: Function) => React.Component<any, any>;
110     /*
92485e 111      Define the dates that can be selected. The function receives (currentDate, selectedDate)
IV 112      and should return a true or false whether the currentDate is valid or not. See selectable dates.
113      */
fe4c5c 114     isValidDate?: (currentDate: any, selectedDate: any) => boolean;
92485e 115     /*
IV 116      Customize the way that the days are shown in the day picker. The accepted function has
117      the selectedDate, the current date and the default calculated props for the cell,
118      and must return a React component. See appearance customization
119      */
fe4c5c 120     renderDay?: (props: any, currentDate: any, selectedDate: any) => React.Component<any, any>;
92485e 121     /*
IV 122      Customize the way that the months are shown in the month picker.
123      The accepted function has the selectedDate, the current date and the default calculated
124      props for the cell, the month and the year to be shown, and must return a
125      React component. See appearance customization
126      */
fe4c5c 127     renderMonth?: (props: any, month: number, year: number, selectedDate: any) => React.Component<any, any>;
92485e 128     /*
IV 129      Customize the way that the years are shown in the year picker.
130      The accepted function has the selectedDate, the current date and the default calculated
131      props for the cell, the year to be shown, and must return a React component.
132      See appearance customization
133      */
fe4c5c 134     renderYear?: (props: any, year: number, selectedDate: any) => React.Component<any, any>;
92485e 135     /*
IV 136      Whether to use moment's strict parsing when parsing input.
137      */
138     strictParsing?: boolean;
139     /*
140      When true, once the day has been selected, the react-datetime will be automatically closed.
141      */
142     closeOnSelect?: boolean;
fe4c5c 143     /*
MV 144      Allow to add some constraints to the time selector. It accepts an object with the format
145      {hours:{ min: 9, max: 15, step:2}} so the hours can't be lower than 9 or higher than 15, and
146      it will change adding or subtracting 2 hours everytime the buttons are clicked. The constraints
147      can be added to the hours, minutes, seconds and milliseconds.
148     */
049c33 149     timeConstraints?: Object;
fe4c5c 150     /*
MV 151      When true, keep the picker open when click event is triggered outside of component. When false,
152      close it.
153     */
154     disableOnClickOutside?: boolean;
92485e 155   }
IV 156
157   interface DatetimeComponent extends React.ComponentClass<DatetimepickerProps> {
158   }
159 }
160
161 declare module "react-datetime" {
162   var ReactDatetime: ReactDatetime.DatetimeComponent;
163   export = ReactDatetime;
164 }