Simon Egersand
2018-02-07 63e0b0b2fc6f361b5ac4751eb05bc5983aea5873
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     /*
IV 26      Defines the format for the date. It accepts any moment.js date format.
27      If true the date will be displayed using the defaults for the current locale.
28      If false the datepicker is disabled and the component can be used as timepicker.
29      */
30     dateFormat?: boolean|string;
31     /*
32      Defines the format for the time. It accepts any moment.js time format.
33      If true the time will be displayed using the defaults for the current locale.
34      If false the timepicker is disabled and the component can be used as datepicker.
35      */
36     timeFormat?: boolean|string;
37     /*
c5845c 38      Whether to show an input field to edit the date manually.
92485e 39      */
IV 40     input?: boolean;
41     /*
c5845c 42      Whether to open or close the picker. If not set react-datetime will open the
92485e 43      datepicker on input focus and close it on click outside.
IV 44      */
45     open?: boolean;
46     /*
47      Manually set the locale for the react-datetime instance.
48      Moment.js locale needs to be loaded to be used, see i18n docs.
49      */
50     locale?: string;
51     /*
049c33 52      Whether to interpret input times as UTC or the user's local timezone.
TS 53      */
54     utc?: boolean;
55     /*
fe4c5c 56      Callback trigger when the date changes. The callback receives the selected `moment` object as
MV 57      only parameter, if the date in the input is valid. If the date in the input is not valid, the
58      callback receives the value of the input (a string).
92485e 59      */
fe4c5c 60     onChange?: (momentOrInputString: string|any) => void;
92485e 61     /*
IV 62      Callback trigger for when the user opens the datepicker.
63      */
fe4c5c 64     onFocus?: () => void;
92485e 65     /*
IV 66      Callback trigger for when the user clicks outside of the input, simulating a regular onBlur.
fe4c5c 67      The callback receives the selected `moment` object as only parameter, if the date in the input
MV 68      is valid. If the date in the input is not valid, the callback receives the value of the
69      input (a string).
92485e 70      */
fe4c5c 71     onBlur?: (momentOrInputString : string|any) => void;
92485e 72     /*
b8d07e 73      Callback trigger when the view mode changes. The callback receives the selected view mode
SE 74      string ('years', 'months', 'days', 'time') as only parameter.
75     */
76     onViewModeChange?: (viewMode: string) => void;
77     /*
92485e 78      The default view to display when the picker is shown. ('years', 'months', 'days', 'time')
IV 79      */
80     viewMode?: string|number;
81     /*
82      Extra class names for the component markup.
83      */
84     className?: string;
85     /*
86      Defines additional attributes for the input element of the component.
87      */
88     inputProps?: Object;
89     /*
b6f2dd 90      Replace the rendering of the input element. The accepted function has openCalendar 
DF 91      (a function which opens the calendar) and the default calculated props for the input. 
92      Must return a React component or null.
93      */
94     renderInput?: (props: Object, openCalendar: Function) => React.Component<any, any>;
95     /*
92485e 96      Define the dates that can be selected. The function receives (currentDate, selectedDate)
IV 97      and should return a true or false whether the currentDate is valid or not. See selectable dates.
98      */
fe4c5c 99     isValidDate?: (currentDate: any, selectedDate: any) => boolean;
92485e 100     /*
IV 101      Customize the way that the days are shown in the day picker. The accepted function has
102      the selectedDate, the current date and the default calculated props for the cell,
103      and must return a React component. See appearance customization
104      */
fe4c5c 105     renderDay?: (props: any, currentDate: any, selectedDate: any) => React.Component<any, any>;
92485e 106     /*
IV 107      Customize the way that the months are shown in the month picker.
108      The accepted function has the selectedDate, the current date and the default calculated
109      props for the cell, the month and the year to be shown, and must return a
110      React component. See appearance customization
111      */
fe4c5c 112     renderMonth?: (props: any, month: number, year: number, selectedDate: any) => React.Component<any, any>;
92485e 113     /*
IV 114      Customize the way that the years are shown in the year picker.
115      The accepted function has the selectedDate, the current date and the default calculated
116      props for the cell, the year to be shown, and must return a React component.
117      See appearance customization
118      */
fe4c5c 119     renderYear?: (props: any, year: number, selectedDate: any) => React.Component<any, any>;
92485e 120     /*
IV 121      Whether to use moment's strict parsing when parsing input.
122      */
123     strictParsing?: boolean;
124     /*
125      When true, once the day has been selected, the react-datetime will be automatically closed.
126      */
127     closeOnSelect?: boolean;
fe4c5c 128     /*
MV 129      Allow to add some constraints to the time selector. It accepts an object with the format
130      {hours:{ min: 9, max: 15, step:2}} so the hours can't be lower than 9 or higher than 15, and
131      it will change adding or subtracting 2 hours everytime the buttons are clicked. The constraints
132      can be added to the hours, minutes, seconds and milliseconds.
133     */
049c33 134     timeConstraints?: Object;
fe4c5c 135     /*
MV 136      When true, keep the picker open when click event is triggered outside of component. When false,
137      close it.
138     */
139     disableOnClickOutside?: boolean;
92485e 140   }
IV 141
142   interface DatetimeComponent extends React.ComponentClass<DatetimepickerProps> {
143   }
144 }
145
146 declare module "react-datetime" {
147   var ReactDatetime: ReactDatetime.DatetimeComponent;
148   export = ReactDatetime;
149 }