2017-03-20 16:38:14 -04:00
import { Injectable } from '@angular/core' ;
2018-03-16 14:56:22 +01:00
import { Cordova , IonicNativePlugin , Plugin } from '@ionic-native/core' ;
2016-02-15 17:22:50 -05:00
2016-04-29 23:56:49 -04:00
export interface DatePickerOptions {
2016-03-06 13:51:12 -05:00
/**
* The mode of the date picker
* Values: date | time | datetime
*/
2016-04-29 23:56:49 -04:00
mode : string ;
2016-03-06 13:51:12 -05:00
/**
* Selected date
*/
2016-08-15 03:58:06 -04:00
date : Date | string | number ;
2016-03-06 13:51:12 -05:00
/**
* Minimum date
* Default: empty String
*/
2016-08-15 03:58:06 -04:00
minDate? : Date | string | number ;
2016-03-06 13:51:12 -05:00
/**
* Maximum date
2018-03-16 14:56:22 +01:00
* Default: empty String
2016-03-06 13:51:12 -05:00
*/
2016-08-15 03:58:06 -04:00
maxDate? : Date | string | number ;
2016-03-06 13:51:12 -05:00
/**
* Label for the dialog title. If empty, uses android default (Set date/Set time).
2018-03-16 14:56:22 +01:00
* Default: empty String
2016-03-06 13:51:12 -05:00
*/
2016-04-29 23:56:49 -04:00
titleText? : string ;
2016-03-06 13:51:12 -05:00
/**
* Label of BUTTON_POSITIVE (done button) on Android
*/
2016-04-29 23:56:49 -04:00
okText? : string ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Label of BUTTON_NEGATIVE (cancel button). If empty, uses android.R.string.cancel.
*/
2016-04-29 23:56:49 -04:00
cancelText? : string ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Label of today button. If empty, doesn't show the option to select current date.
*/
2016-04-29 23:56:49 -04:00
todayText? : string ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Label of now button. If empty, doesn't show the option to select current time.
*/
2016-04-29 23:56:49 -04:00
nowText? : string ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Shows time dialog in 24 hours format.
*/
2016-04-29 23:56:49 -04:00
is24Hour? : boolean ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Choose the Android theme for the picker. You can use the DatePicker.ANDROID_THEMES property.
* Values: 1: THEME_TRADITIONAL | 2: THEME_HOLO_DARK | 3: THEME_HOLO_LIGHT | 4: THEME_DEVICE_DEFAULT_DARK | 5: THEME_DEVICE_DEFAULT_LIGHT
*/
2016-04-29 23:56:49 -04:00
androidTheme? : number ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Shows or hide dates earlier then selected date.
*/
2016-11-01 23:13:43 -05:00
allowOldDates? : boolean ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Shows or hide dates after selected date.
*/
2016-04-29 23:56:49 -04:00
allowFutureDates? : boolean ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Label of done button.
*/
2016-04-29 23:56:49 -04:00
doneButtonLabel? : string ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Hex color of done button.
*/
2016-04-29 23:56:49 -04:00
doneButtonColor? : string ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Label of cancel button.
*/
2016-04-29 23:56:49 -04:00
cancelButtonLabel? : string ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Hex color of cancel button.
*/
2016-04-29 23:56:49 -04:00
cancelButtonColor? : string ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* X position of date picker. The position is absolute to the root view of the application.
*/
2016-04-29 23:56:49 -04:00
x? : number ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Y position of date picker. The position is absolute to the root view of the application.
*/
2016-04-29 23:56:49 -04:00
y? : number ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Interval between options in the minute section of the date picker.
*/
2016-04-29 23:56:49 -04:00
minuteInterval? : number ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Force the UIPopoverArrowDirection enum. The value any will revert to default UIPopoverArrowDirectionAny and let the app choose the proper direction itself.
*/
2016-04-29 23:56:49 -04:00
popoverArrowDirection? : string ;
2016-12-06 08:02:00 -05:00
2016-10-11 09:13:56 -04:00
/**
* Force locale for datePicker.
*/
2016-04-29 23:56:49 -04:00
locale? : string ;
2016-03-06 13:51:12 -05:00
}
2016-02-15 17:22:50 -05:00
/**
2016-03-13 15:45:07 -04:00
* @name Date Picker
2016-03-12 18:30:16 -05:00
* @description
2016-02-15 17:22:50 -05:00
* The DatePicker plugin allows the user to fetch date or time using native dialogs.
*
* @usage
2016-07-20 17:17:09 +02:00
* ```typescript
2018-10-10 16:13:45 -05:00
* import { DatePicker } from '@ionic-native/date-picker/ngx';
2016-03-24 13:00:18 -04:00
*
2017-03-20 16:38:14 -04:00
* constructor(private datePicker: DatePicker) { }
2016-03-24 13:00:18 -04:00
*
2017-03-20 16:38:14 -04:00
*
* ...
*
*
* this.datePicker.show({
2016-03-06 14:31:00 -05:00
* date: new Date(),
2017-03-20 16:38:14 -04:00
* mode: 'date',
* androidTheme: this.datePicker.ANDROID_THEMES.THEME_HOLO_DARK
2016-03-06 14:31:00 -05:00
* }).then(
2016-07-20 17:17:09 +02:00
* date => console.log('Got date: ', date),
* err => console.log('Error occurred while getting date: ', err)
2016-03-06 14:31:00 -05:00
* );
2016-02-15 17:22:50 -05:00
* ```
2016-10-11 09:13:56 -04:00
* @interfaces
* DatePickerOptions
2016-02-15 17:22:50 -05:00
*/
@Plugin ( {
2016-10-27 12:48:50 -05:00
pluginName : 'DatePicker' ,
2016-03-12 18:30:16 -05:00
plugin : 'cordova-plugin-datepicker' ,
2016-03-12 19:08:47 -05:00
pluginRef : 'datePicker' ,
2016-11-29 13:11:15 -05:00
repo : 'https://github.com/VitaliiBlagodir/cordova-plugin-datepicker' ,
platforms : [ 'Android' , 'iOS' , 'Windows' ]
2016-02-15 17:22:50 -05:00
} )
2017-03-20 16:38:14 -04:00
@Injectable ( )
2017-04-27 00:36:12 -04:00
export class DatePicker extends IonicNativePlugin {
2016-10-11 09:14:17 -04:00
/**
2017-03-20 16:38:14 -04:00
* @hidden
2016-10-11 09:14:17 -04:00
*/
2017-03-20 16:38:14 -04:00
ANDROID_THEMES = {
2016-10-11 09:13:56 -04:00
THEME_TRADITIONAL : 1 ,
THEME_HOLO_DARK : 2 ,
THEME_HOLO_LIGHT : 3 ,
THEME_DEVICE_DEFAULT_DARK : 4 ,
THEME_DEVICE_DEFAULT_LIGHT : 5
} ;
2016-02-15 17:22:50 -05:00
/**
* Shows the date and/or time picker dialog(s)
2016-07-08 15:19:13 -04:00
* @param {DatePickerOptions} options Options for the date picker.
2016-02-15 17:22:50 -05:00
* @returns {Promise<Date>} Returns a promise that resolves with the picked date and/or time, or rejects with an error.
*/
2016-03-04 15:42:21 -06:00
@Cordova ( )
2017-03-20 16:38:14 -04:00
show ( options : DatePickerOptions ) : Promise < Date > {
2016-10-11 09:13:56 -04:00
return ;
}
2016-07-08 00:50:03 +02:00
}