From 6f26fa57404f2473bca30749e889b4c92b1fe102 Mon Sep 17 00:00:00 2001 From: ToastHawaii Date: Sun, 28 Feb 2016 15:43:57 +0100 Subject: [PATCH] Update to TypeScript 1.8 Use String Literal Types Differ between alert and promt settings Update metadata --- sweetalert/sweetalert.d.ts | 67 +++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 26 deletions(-) diff --git a/sweetalert/sweetalert.d.ts b/sweetalert/sweetalert.d.ts index ca48097f4..2ce1a0ee8 100644 --- a/sweetalert/sweetalert.d.ts +++ b/sweetalert/sweetalert.d.ts @@ -1,4 +1,4 @@ -// Type definitions for SweetAlert 1.1.0 +// Type definitions for SweetAlert 1.1.3 // Project: https://github.com/t4t5/sweetalert/ // Definitions by: Markus Peloso // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -11,6 +11,10 @@ declare module "sweetalert" { } declare module SweetAlert { + type AlertType = "warning" | "error" | "success" | "info"; + + type PromtType = "input" | "prompt"; + interface SettingsBase { /** * A description for the modal. @@ -18,12 +22,6 @@ declare module SweetAlert { */ text?: string; - /** - * The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". You can also set it as "input" to get a prompt modal. - * Default: null - */ - type?: string; - /** * If set to true, the user can dismiss the modal by pressing the Escape key. * Default: true @@ -112,7 +110,29 @@ declare module SweetAlert { * If set to false, the modal's animation will be disabled. Possible animations: "slide-from-top", "slide-from-bottom", "pop" (use true instead) and "none" (use false instead). * Default: true */ - animation?: boolean | string; + animation?: boolean | "slide-from-top" | "slide-from-bottom" | "pop" | "none" | string; + + /** + * Set to true to disable the buttons and show that something is loading. + * Default: false + */ + showLoaderOnConfirm?: boolean; + } + + interface AlertModalSettings extends SettingsBase { + /** + * The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". You can also set it as "input" to get a prompt modal. + * Default: null + */ + type?: AlertType; + } + + interface PromtModalSettings extends SettingsBase { + /** + * The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". You can also set it as "input" to get a prompt modal. + * Default: null + */ + type?: PromtType; /** * Change the type of the input field when using type: "input" (this can be useful if you want users to type in their password for example). @@ -131,22 +151,16 @@ declare module SweetAlert { * Default: null */ inputValue?: string; - - /** - * Set to true to disable the buttons and show that something is loading. - * Default: false - */ - showLoaderOnConfirm?: boolean; } - interface Settings extends SettingsBase { + interface Settings { /** * The title of the modal. */ title: string; } - interface SetDefaultsSettings extends SettingsBase { + interface SetDefaultsSettings { /** * The title of the modal. * Default: null @@ -154,11 +168,6 @@ declare module SweetAlert { title?: string; } - /** - * Is true or false if the user confirms or cancels the alert. Except for the type "input", then when the user confirms the alert, this variable contains the value of the input element. - */ - type CallbackArgument = boolean | string; - interface SweetAlertStatic { /** * SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert. @@ -179,18 +188,24 @@ declare module SweetAlert { * @param text A description for the modal. * @param type The type of the modal. SweetAlert comes with 4 built-in types which will show a corresponding icon animation: "warning", "error", "success" and "info". You can also set it as "input" to get a prompt modal. */ - (title: string, text: string, type: string): void; + (title: string, text: string, type: AlertType | PromtType): void; /** * SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert. - * @param callback The callback from the users action. The value is true or false if the user confirms or cancels the alert. Except for the type "input", then when the user confirms the alert, the argument contains the value of the input element. + * @param callback The callback from the users action. The value is true or false if the user confirms or cancels the alert. */ - (settings: Settings, callback?: (isConfirmOrInputValue: CallbackArgument) => any): void; + (settings: Settings & AlertModalSettings, callback?: (isConfirm: boolean) => any): void; + + /** + * SweetAlert automatically centers itself on the page and looks great no matter if you're using a desktop computer, mobile or tablet. An awesome replacement for JavaScript's alert. + * @param callback The callback from the users action. When the user confirms the prompt, the argument contains the value of the input element. When the user cancels the prompt, the argument is false. + */ + (settings: Settings & PromtModalSettings, callback?: (isConfirmOrInputValue: boolean | string) => any): void; /** * If you end up using a lot of the same settings when calling SweetAlert, you can use setDefaults at the start of your program to set them once and for all! */ - setDefaults(settings: SetDefaultsSettings): void; + setDefaults(settings: SetDefaultsSettings & AlertModalSettings & PromtModalSettings): void; /** * Close the currently open SweetAlert programmatically. @@ -212,4 +227,4 @@ declare module SweetAlert { */ disableButtons(): void; } -} \ No newline at end of file +}