mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 22:37:03 +00:00
daterangepicker: typings for v3.0.1 (#25476)
* daterangepicker: typings for v3.0.1 See release notes for v3.0.0: https://github.com/dangrossman/daterangepicker/releases/tag/v3.0.0 * fix react-bootstrap-daterangepicker * fix linting errors * support for .data('daterangepicker')
This commit is contained in:
committed by
Sheetal Nandi
parent
c5907ddf17
commit
2c008db385
@@ -1,80 +1,116 @@
|
||||
import moment = require("moment")
|
||||
import daterangepicker = require("daterangepicker");
|
||||
import moment = require('moment');
|
||||
import daterangepicker = require('daterangepicker');
|
||||
|
||||
function tests_simple() {
|
||||
$('#daterange').daterangepicker();
|
||||
$('input[name="daterange"]').daterangepicker({
|
||||
timePicker: true,
|
||||
timePickerIncrement: 30,
|
||||
locale: {
|
||||
format: 'MM/DD/YYYY h:mm A'
|
||||
}
|
||||
});
|
||||
$('input[name="daterange"]')
|
||||
.daterangepicker({
|
||||
timePicker: true,
|
||||
timePickerIncrement: 30,
|
||||
locale: {
|
||||
format: 'MM/DD/YYYY h:mm A'
|
||||
},
|
||||
maxSpan: { days: 10 },
|
||||
applyButtonClasses: 'my-apply-class',
|
||||
cancelButtonClasses: 'my-cancel-class',
|
||||
showDropdowns: true,
|
||||
maxYear: 3000,
|
||||
minYear: 2000
|
||||
})
|
||||
.data('daterangepicker')
|
||||
.remove();
|
||||
|
||||
$('#reportrange').daterangepicker({
|
||||
ranges: {
|
||||
'Today': [moment(), moment()],
|
||||
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
||||
Today: [moment(), moment()],
|
||||
Yesterday: [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
||||
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
|
||||
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
|
||||
'This Month': [moment().startOf('month'), moment().endOf('month')],
|
||||
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
|
||||
'Last Month': [
|
||||
moment()
|
||||
.subtract(1, 'month')
|
||||
.startOf('month'),
|
||||
moment()
|
||||
.subtract(1, 'month')
|
||||
.endOf('month')
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
$('input[name="datefilter"]').on('apply.daterangepicker', function (ev, picker) {
|
||||
$(this).val(picker.startDate.format('MM/DD/YYYY') + ' - ' + picker.endDate.format('MM/DD/YYYY'));
|
||||
$('input[name="datefilter"]').on('apply.daterangepicker', function(ev, picker) {
|
||||
$(this).val(
|
||||
`${picker.startDate.format('MM/DD/YYYY')} - ${picker.endDate.format('MM/DD/YYYY')}`
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
$('input[name="datefilter"]').on('cancel.daterangepicker', function (ev, picker) {
|
||||
$('input[name="datefilter"]').on('cancel.daterangepicker', function(ev, picker) {
|
||||
$(this).val('');
|
||||
});
|
||||
|
||||
$('#demo').daterangepicker({
|
||||
"startDate": "05/06/2016",
|
||||
"endDate": "05/12/2016"
|
||||
}, function (start: moment.Moment, end: moment.Moment, label: string) {
|
||||
console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
|
||||
});
|
||||
|
||||
$(function() {
|
||||
|
||||
function cb(start: moment.Moment, end: moment.Moment) {
|
||||
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
|
||||
}
|
||||
cb(moment().subtract(29, 'days'), moment());
|
||||
|
||||
$('#reportrange').daterangepicker({
|
||||
ranges: {
|
||||
'Today': [moment(), moment()],
|
||||
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
||||
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
|
||||
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
|
||||
'This Month': [moment().startOf('month'), moment().endOf('month')],
|
||||
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
|
||||
}
|
||||
}, cb);
|
||||
|
||||
$('#reportrange').daterangepicker({
|
||||
ranges: {
|
||||
'Today': [moment(), moment()],
|
||||
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
||||
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
|
||||
'Last 30 Days': [moment().subtract(29, 'days'), moment()]
|
||||
$('#demo').daterangepicker(
|
||||
{
|
||||
startDate: '05/06/2016',
|
||||
endDate: '05/12/2016'
|
||||
},
|
||||
showCustomRangeLabel: false
|
||||
}, cb);
|
||||
(start: moment.Moment, end: moment.Moment, label: string) => {
|
||||
console.log(
|
||||
"New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
$('#endDate').daterangepicker({
|
||||
singleDatePicker: true,
|
||||
startDate: moment()
|
||||
$(() => {
|
||||
function cb(start: moment.Moment, end: moment.Moment) {
|
||||
$('#reportrange span').html(
|
||||
`${start.format('MMMM D, YYYY')} - ${end.format('MMMM D, YYYY')}`
|
||||
);
|
||||
}
|
||||
cb(moment().subtract(29, 'days'), moment());
|
||||
|
||||
$('#reportrange').daterangepicker(
|
||||
{
|
||||
ranges: {
|
||||
Today: [moment(), moment()],
|
||||
Yesterday: [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
||||
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
|
||||
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
|
||||
'This Month': [moment().startOf('month'), moment().endOf('month')],
|
||||
'Last Month': [
|
||||
moment()
|
||||
.subtract(1, 'month')
|
||||
.startOf('month'),
|
||||
moment()
|
||||
.subtract(1, 'month')
|
||||
.endOf('month')
|
||||
]
|
||||
}
|
||||
},
|
||||
cb
|
||||
);
|
||||
|
||||
$('#reportrange').daterangepicker(
|
||||
{
|
||||
ranges: {
|
||||
Today: [moment(), moment()],
|
||||
Yesterday: [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
|
||||
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
|
||||
'Last 30 Days': [moment().subtract(29, 'days'), moment()]
|
||||
},
|
||||
showCustomRangeLabel: false
|
||||
},
|
||||
cb
|
||||
);
|
||||
|
||||
$('#endDate').daterangepicker({
|
||||
singleDatePicker: true,
|
||||
startDate: moment()
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
declare const host: HTMLElement;
|
||||
function test_from_amd() {
|
||||
var picker = new daterangepicker(host);
|
||||
console.log(picker.startDate.format("YYYY-MM-DD"));
|
||||
const picker = new daterangepicker(host);
|
||||
console.log(picker.startDate.format('YYYY-MM-DD'));
|
||||
}
|
||||
|
||||
Vendored
+71
-47
@@ -1,4 +1,4 @@
|
||||
// Type definitions for Date Range Picker v2.1.30
|
||||
// Type definitions for Date Range Picker 3.0
|
||||
// Project: http://www.daterangepicker.com/
|
||||
// Definitions by: SirMartin <https://github.com/SirMartin>
|
||||
// Steven Masala <https://github.com/smasala>
|
||||
@@ -7,62 +7,81 @@
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
/// <reference types="jquery"/>
|
||||
import moment = require("moment");
|
||||
import moment = require('moment');
|
||||
|
||||
declare global {
|
||||
interface JQuery {
|
||||
daterangepicker(settings?: daterangepicker.Settings): JQuery;
|
||||
daterangepicker(settings?: daterangepicker.Settings, callback?: daterangepicker.DataRangePickerCallback): JQuery;
|
||||
daterangepicker: ((
|
||||
options?: daterangepicker.Options,
|
||||
callback?: daterangepicker.DataRangePickerCallback
|
||||
) => JQuery) & { defaultOptions?: daterangepicker.Options };
|
||||
data(key: 'daterangepicker'): daterangepicker | undefined;
|
||||
}
|
||||
}
|
||||
|
||||
declare const daterangepicker: daterangepicker.DateRangePicker;
|
||||
declare class daterangepicker {
|
||||
constructor(
|
||||
element: HTMLElement,
|
||||
options?: daterangepicker.Options,
|
||||
callback?: daterangepicker.DataRangePickerCallback
|
||||
);
|
||||
|
||||
startDate: moment.Moment;
|
||||
endDate: moment.Moment;
|
||||
container: JQuery;
|
||||
|
||||
setStartDate(date: daterangepicker.DateOrString): void;
|
||||
setEndDate(date: daterangepicker.DateOrString): void;
|
||||
remove(): void;
|
||||
}
|
||||
|
||||
declare namespace daterangepicker {
|
||||
type DataRangePickerCallback = (start: moment.Moment, end: moment.Moment, label: string | null) => any;
|
||||
type DataRangePickerCallback = (
|
||||
start: moment.Moment,
|
||||
end: moment.Moment,
|
||||
label: string | null
|
||||
) => void;
|
||||
|
||||
interface DateRangePicker {
|
||||
new (element: HTMLElement, settings?: daterangepicker.Settings, callback?: DataRangePickerCallback): DateRangePicker;
|
||||
|
||||
startDate: moment.Moment;
|
||||
endDate: moment.Moment;
|
||||
container: JQuery;
|
||||
|
||||
setStartDate(date: Date | moment.Moment | string): void;
|
||||
setEndDate(date: Date | moment.Moment | string): void;
|
||||
remove(): void;
|
||||
}
|
||||
type DateOrString = string | moment.Moment | Date;
|
||||
|
||||
interface DatepickerEventObject extends JQueryEventObject {
|
||||
date: Date;
|
||||
format(format?: string): string;
|
||||
}
|
||||
|
||||
interface Settings {
|
||||
interface Options {
|
||||
/**
|
||||
* The start of the initially selected date range
|
||||
*/
|
||||
startDate?: string | moment.Moment | Date;
|
||||
startDate?: DateOrString;
|
||||
/**
|
||||
* The end of the initially selected date range
|
||||
*/
|
||||
endDate?: string | moment.Moment | Date;
|
||||
endDate?: DateOrString;
|
||||
/**
|
||||
* The earliest date a user may select
|
||||
* The earliest date a user may select
|
||||
*/
|
||||
minDate?: string | moment.Moment | Date;
|
||||
minDate?: DateOrString;
|
||||
/**
|
||||
* The latest date a user may select
|
||||
*/
|
||||
maxDate?: string | moment.Moment | Date;
|
||||
maxDate?: DateOrString;
|
||||
/**
|
||||
* The maximum span between the selected start and end dates. Can have any property you can add to a moment object (i.e. days, months)
|
||||
*/
|
||||
dateLimit?: any;
|
||||
maxSpan?: moment.MomentInput | moment.Duration;
|
||||
/**
|
||||
* Show year and month select boxes above calendars to jump to a specific month and year
|
||||
*/
|
||||
showDropdowns?: boolean;
|
||||
/**
|
||||
* The minimum year shown in the dropdowns when `showDropdowns` is set to true.
|
||||
*/
|
||||
minYear?: number;
|
||||
/**
|
||||
* The maximum year shown in the dropdowns when `showDropdowns` is set to true.
|
||||
*/
|
||||
maxYear?: number;
|
||||
/**
|
||||
* Show localized week numbers at the start of each week on the calendars
|
||||
*/
|
||||
@@ -90,15 +109,25 @@ declare namespace daterangepicker {
|
||||
/**
|
||||
* Set predefined date ranges the user can select from.Each key is the label for the range, and its value an array with two dates representing the bounds of the range.
|
||||
*/
|
||||
ranges?: any;
|
||||
ranges?: { [name: string]: [DateOrString, DateOrString] };
|
||||
/**
|
||||
* (string: 'left'/'right'/'center') Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to
|
||||
* Whether to show the 'Custom Range' label or just pre-defined ranges
|
||||
*/
|
||||
opens?: string;
|
||||
showCustomRangeLabel?: boolean;
|
||||
/**
|
||||
* (string: 'down' or 'up') Whether the picker appears below (default) or above the HTML element it's attached to
|
||||
* Normally, if you use the `ranges` option to specify pre-defined date ranges, calendars
|
||||
* for choosing a custom date range are not shown until the user clicks "Custom Range".
|
||||
* When this option is set to true, the calendars for choosing a custom date range are always shown instead.
|
||||
*/
|
||||
drops?: string;
|
||||
alwaysShowCalendars?: boolean;
|
||||
/**
|
||||
* Whether the picker appears aligned to the left, to the right, or centered under the HTML element it's attached to
|
||||
*/
|
||||
opens?: 'left' | 'right' | 'center';
|
||||
/**
|
||||
* Whether the picker appears below (default) or above the HTML element it's attached to
|
||||
*/
|
||||
drops?: 'down' | 'up';
|
||||
/**
|
||||
* CSS class names that will be added to all buttons in the picker
|
||||
*/
|
||||
@@ -106,11 +135,11 @@ declare namespace daterangepicker {
|
||||
/**
|
||||
* CSS class string that will be added to the apply button
|
||||
*/
|
||||
applyClass?: string;
|
||||
applyButtonClasses?: string;
|
||||
/**
|
||||
* CSS class string that will be added to the cancel button
|
||||
*/
|
||||
cancelClass?: string;
|
||||
* CSS class string that will be added to the cancel button
|
||||
*/
|
||||
cancelButtonClasses?: string;
|
||||
/**
|
||||
* Allows you to provide localized strings for buttons and labels, customize the date display format, and change the first day of week for the calendars.
|
||||
*/
|
||||
@@ -124,33 +153,28 @@ declare namespace daterangepicker {
|
||||
*/
|
||||
autoApply?: boolean;
|
||||
/**
|
||||
* When enabled, the two calendars displayed will always be for two sequential months (i.e.January and February), and both will be advanced when clicking the left or right arrows above the calendars.When disabled, the two calendars can be individually advanced and display any month/ year.
|
||||
* When enabled, the two calendars displayed will always be for two sequential months (i.e.
|
||||
* January and February), and both will be advanced when clicking the left or right arrows
|
||||
* above the calendars.When disabled, the two calendars can be individually advanced and
|
||||
* display any month/ year.
|
||||
*/
|
||||
linkedCalendars?: boolean;
|
||||
/**
|
||||
* jQuery selector of the parent element that the date range picker will be added to, if not provided this will be 'body'
|
||||
*/
|
||||
parentEl?: string;
|
||||
/**
|
||||
* A function that is passed each date in the two calendars before they are displayed, and may return true or false to indicate whether that date should be available for selection or not.
|
||||
*/
|
||||
isInvalidDate?(startDate: string | moment.Moment | Date, endDate?: string | moment.Moment | Date): boolean;
|
||||
isInvalidDate?(startDate: DateOrString, endDate?: DateOrString): boolean;
|
||||
/**
|
||||
* A function that is passed each date in the two calendars before they are displayed, and may return a string or array of CSS class names to apply to that date's calendar cell.
|
||||
*/
|
||||
isCustomDate?(date: string | moment.Moment | Date): string | string[] | undefined;
|
||||
isCustomDate?(date: DateOrString): string | string[] | undefined;
|
||||
/**
|
||||
* Indicates whether the date range picker should automatically update the value of an < input > element it's attached to at initialization and when the selected dates change.
|
||||
*/
|
||||
autoUpdateInput?: boolean;
|
||||
/**
|
||||
* Normally, if you use the ranges option to specify pre- defined date ranges, calendars for choosing a custom date range are not shown until the user clicks "Custom Range".When this option is set to true, the calendars for choosing a custom date range are always shown instead.
|
||||
*/
|
||||
alwaysShowCalendars?: boolean;
|
||||
/**
|
||||
* Whether to show the 'Custom Range' label or just pre-defined ranges
|
||||
*/
|
||||
showCustomRangeLabel?: boolean;
|
||||
* jQuery selector of the parent element that the date range picker will be added to, if not provided this will be 'body'
|
||||
*/
|
||||
parentEl?: string;
|
||||
}
|
||||
|
||||
interface Locale {
|
||||
|
||||
@@ -1,79 +1 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json",
|
||||
"rules": {
|
||||
"adjacent-overload-signatures": false,
|
||||
"array-type": false,
|
||||
"arrow-return-shorthand": false,
|
||||
"ban-types": false,
|
||||
"callable-types": false,
|
||||
"comment-format": false,
|
||||
"dt-header": false,
|
||||
"eofline": false,
|
||||
"export-just-namespace": false,
|
||||
"import-spacing": false,
|
||||
"interface-name": false,
|
||||
"interface-over-type-literal": false,
|
||||
"jsdoc-format": false,
|
||||
"max-line-length": false,
|
||||
"member-access": false,
|
||||
"new-parens": false,
|
||||
"no-any-union": false,
|
||||
"no-boolean-literal-compare": false,
|
||||
"no-conditional-assignment": false,
|
||||
"no-consecutive-blank-lines": false,
|
||||
"no-construct": false,
|
||||
"no-declare-current-package": false,
|
||||
"no-duplicate-imports": false,
|
||||
"no-duplicate-variable": false,
|
||||
"no-empty-interface": false,
|
||||
"no-for-in-array": false,
|
||||
"no-inferrable-types": false,
|
||||
"no-internal-module": false,
|
||||
"no-irregular-whitespace": false,
|
||||
"no-mergeable-namespace": false,
|
||||
"no-misused-new": false,
|
||||
"no-namespace": false,
|
||||
"no-object-literal-type-assertion": false,
|
||||
"no-padding": false,
|
||||
"no-redundant-jsdoc": false,
|
||||
"no-redundant-jsdoc-2": false,
|
||||
"no-redundant-undefined": false,
|
||||
"no-reference-import": false,
|
||||
"no-relative-import-in-test": false,
|
||||
"no-self-import": false,
|
||||
"no-single-declare-module": false,
|
||||
"no-string-throw": false,
|
||||
"no-unnecessary-callback-wrapper": false,
|
||||
"no-unnecessary-class": false,
|
||||
"no-unnecessary-generics": false,
|
||||
"no-unnecessary-qualifier": false,
|
||||
"no-unnecessary-type-assertion": false,
|
||||
"no-useless-files": false,
|
||||
"no-var-keyword": false,
|
||||
"no-var-requires": false,
|
||||
"no-void-expression": false,
|
||||
"no-trailing-whitespace": false,
|
||||
"object-literal-key-quotes": false,
|
||||
"object-literal-shorthand": false,
|
||||
"one-line": false,
|
||||
"one-variable-per-declaration": false,
|
||||
"only-arrow-functions": false,
|
||||
"prefer-conditional-expression": false,
|
||||
"prefer-const": false,
|
||||
"prefer-declare-function": false,
|
||||
"prefer-for-of": false,
|
||||
"prefer-method-signature": false,
|
||||
"prefer-template": false,
|
||||
"radix": false,
|
||||
"semicolon": false,
|
||||
"space-before-function-paren": false,
|
||||
"space-within-parens": false,
|
||||
"strict-export-declare-modifiers": false,
|
||||
"trim-file": false,
|
||||
"triple-equals": false,
|
||||
"typedef-whitespace": false,
|
||||
"unified-signatures": false,
|
||||
"void-return": false,
|
||||
"whitespace": false
|
||||
}
|
||||
}
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ declare namespace ReactBootstrapDaterangepicker {
|
||||
|
||||
export interface EventHandler { (event?: any, picker?: any): any; }
|
||||
|
||||
export interface Props extends daterangepicker.Settings{
|
||||
export interface Props extends daterangepicker.Options{
|
||||
onShow?: EventHandler;
|
||||
onHide?: EventHandler;
|
||||
onShowCalendar?: EventHandler;
|
||||
|
||||
Reference in New Issue
Block a user