Simon Egersand
2017-08-13 b7c12fd6cdde561098ea3cfea6bd272c0a33e1ad
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     /*
90      Define the dates that can be selected. The function receives (currentDate, selectedDate)
91      and should return a true or false whether the currentDate is valid or not. See selectable dates.
92      */
fe4c5c 93     isValidDate?: (currentDate: any, selectedDate: any) => boolean;
92485e 94     /*
IV 95      Customize the way that the days are shown in the day picker. The accepted function has
96      the selectedDate, the current date and the default calculated props for the cell,
97      and must return a React component. See appearance customization
98      */
fe4c5c 99     renderDay?: (props: any, currentDate: any, selectedDate: any) => React.Component<any, any>;
92485e 100     /*
IV 101      Customize the way that the months are shown in the month picker.
102      The accepted function has the selectedDate, the current date and the default calculated
103      props for the cell, the month and the year to be shown, and must return a
104      React component. See appearance customization
105      */
fe4c5c 106     renderMonth?: (props: any, month: number, year: number, selectedDate: any) => React.Component<any, any>;
92485e 107     /*
IV 108      Customize the way that the years are shown in the year picker.
109      The accepted function has the selectedDate, the current date and the default calculated
110      props for the cell, the year to be shown, and must return a React component.
111      See appearance customization
112      */
fe4c5c 113     renderYear?: (props: any, year: number, selectedDate: any) => React.Component<any, any>;
92485e 114     /*
IV 115      Whether to use moment's strict parsing when parsing input.
116      */
117     strictParsing?: boolean;
118     /*
119      When true, once the day has been selected, the react-datetime will be automatically closed.
120      */
121     closeOnSelect?: boolean;
fe4c5c 122     /*
MV 123      Allow to add some constraints to the time selector. It accepts an object with the format
124      {hours:{ min: 9, max: 15, step:2}} so the hours can't be lower than 9 or higher than 15, and
125      it will change adding or subtracting 2 hours everytime the buttons are clicked. The constraints
126      can be added to the hours, minutes, seconds and milliseconds.
127     */
049c33 128     timeConstraints?: Object;
fe4c5c 129     /*
MV 130      When true, keep the picker open when click event is triggered outside of component. When false,
131      close it.
132     */
133     disableOnClickOutside?: boolean;
92485e 134   }
IV 135
136   interface DatetimeComponent extends React.ComponentClass<DatetimepickerProps> {
137   }
138 }
139
140 declare module "react-datetime" {
141   var ReactDatetime: ReactDatetime.DatetimeComponent;
142   export = ReactDatetime;
143 }