mirror of
https://github.com/danielsogl/awesome-cordova-plugins.git
synced 2025-04-15 20:57:07 +08:00

BREAKING CHANGE: You can remove the plugin import from the app.module.ts because of the changed Inject decorator
180 lines
3.9 KiB
TypeScript
180 lines
3.9 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core';
|
|
|
|
export interface DatePickerOptions {
|
|
/**
|
|
* The mode of the date picker
|
|
* Values: date | time | datetime
|
|
*/
|
|
mode: string;
|
|
|
|
/**
|
|
* Selected date
|
|
*/
|
|
date: Date | string | number;
|
|
|
|
/**
|
|
* Minimum date
|
|
* Default: empty String
|
|
*/
|
|
minDate?: Date | string | number;
|
|
|
|
/**
|
|
* Maximum date
|
|
* Default: empty String
|
|
*/
|
|
maxDate?: Date | string | number;
|
|
|
|
/**
|
|
* Label for the dialog title. If empty, uses android default (Set date/Set time).
|
|
* Default: empty String
|
|
*/
|
|
titleText?: string;
|
|
|
|
/**
|
|
* Label of BUTTON_POSITIVE (done button) on Android
|
|
*/
|
|
okText?: string;
|
|
|
|
/**
|
|
* Label of BUTTON_NEGATIVE (cancel button). If empty, uses android.R.string.cancel.
|
|
*/
|
|
cancelText?: string;
|
|
|
|
/**
|
|
* Label of today button. If empty, doesn't show the option to select current date.
|
|
*/
|
|
todayText?: string;
|
|
|
|
/**
|
|
* Label of now button. If empty, doesn't show the option to select current time.
|
|
*/
|
|
nowText?: string;
|
|
|
|
/**
|
|
* Shows time dialog in 24 hours format.
|
|
*/
|
|
is24Hour?: boolean;
|
|
|
|
/**
|
|
* 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
|
|
*/
|
|
androidTheme?: number;
|
|
|
|
/**
|
|
* Shows or hide dates earlier then selected date.
|
|
*/
|
|
allowOldDates?: boolean;
|
|
|
|
/**
|
|
* Shows or hide dates after selected date.
|
|
*/
|
|
allowFutureDates?: boolean;
|
|
|
|
/**
|
|
* Label of done button.
|
|
*/
|
|
doneButtonLabel?: string;
|
|
|
|
/**
|
|
* Hex color of done button.
|
|
*/
|
|
doneButtonColor?: string;
|
|
|
|
/**
|
|
* Label of cancel button.
|
|
*/
|
|
cancelButtonLabel?: string;
|
|
|
|
/**
|
|
* Hex color of cancel button.
|
|
*/
|
|
cancelButtonColor?: string;
|
|
|
|
/**
|
|
* X position of date picker. The position is absolute to the root view of the application.
|
|
*/
|
|
x?: number;
|
|
|
|
/**
|
|
* Y position of date picker. The position is absolute to the root view of the application.
|
|
*/
|
|
y?: number;
|
|
|
|
/**
|
|
* Interval between options in the minute section of the date picker.
|
|
*/
|
|
minuteInterval?: number;
|
|
|
|
/**
|
|
* Force the UIPopoverArrowDirection enum. The value any will revert to default UIPopoverArrowDirectionAny and let the app choose the proper direction itself.
|
|
*/
|
|
popoverArrowDirection?: string;
|
|
|
|
/**
|
|
* Force locale for datePicker.
|
|
*/
|
|
locale?: string;
|
|
}
|
|
|
|
/**
|
|
* @name Date Picker
|
|
* @description
|
|
* The DatePicker plugin allows the user to fetch date or time using native dialogs.
|
|
*
|
|
* @usage
|
|
* ```typescript
|
|
* import { DatePicker } from '@ionic-native/date-picker/ngx';
|
|
*
|
|
* constructor(private datePicker: DatePicker) { }
|
|
*
|
|
*
|
|
* ...
|
|
*
|
|
*
|
|
* this.datePicker.show({
|
|
* date: new Date(),
|
|
* mode: 'date',
|
|
* androidTheme: this.datePicker.ANDROID_THEMES.THEME_HOLO_DARK
|
|
* }).then(
|
|
* date => console.log('Got date: ', date),
|
|
* err => console.log('Error occurred while getting date: ', err)
|
|
* );
|
|
* ```
|
|
* @interfaces
|
|
* DatePickerOptions
|
|
*/
|
|
@Plugin({
|
|
pluginName: 'DatePicker',
|
|
plugin: 'cordova-plugin-datepicker',
|
|
pluginRef: 'datePicker',
|
|
repo: 'https://github.com/VitaliiBlagodir/cordova-plugin-datepicker',
|
|
platforms: ['Android', 'iOS', 'Windows']
|
|
})
|
|
@Injectable({
|
|
providedIn: 'root'
|
|
})
|
|
export class DatePicker extends IonicNativePlugin {
|
|
/**
|
|
* @hidden
|
|
*/
|
|
ANDROID_THEMES = {
|
|
THEME_TRADITIONAL: 1,
|
|
THEME_HOLO_DARK: 2,
|
|
THEME_HOLO_LIGHT: 3,
|
|
THEME_DEVICE_DEFAULT_DARK: 4,
|
|
THEME_DEVICE_DEFAULT_LIGHT: 5
|
|
};
|
|
|
|
/**
|
|
* Shows the date and/or time picker dialog(s)
|
|
* @param {DatePickerOptions} options Options for the date picker.
|
|
* @returns {Promise<Date>} Returns a promise that resolves with the picked date and/or time, or rejects with an error.
|
|
*/
|
|
@Cordova()
|
|
show(options: DatePickerOptions): Promise<Date> {
|
|
return;
|
|
}
|
|
}
|