Skip to content

Commit 413e55b

Browse files
committed
Merge pull request DefinitelyTyped#8599 from trodi/bootbox
improved typing for bootbox modal options
2 parents c75063a + e147c24 commit 413e55b

File tree

2 files changed

+53
-34
lines changed

2 files changed

+53
-34
lines changed

bootbox/bootbox-tests.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ bootbox.confirm("Click cancel to pass test", function (result) {
1717
console.log(!result);
1818
});
1919
bootbox.confirm({
20-
message: "Click confirm to pass test",
20+
title: "Click confirm to pass test",
21+
message: "Please confirm this.",
2122
callback: function (result) {
2223
console.log(result);
2324
}
@@ -27,13 +28,13 @@ bootbox.prompt("Enter 'ok' to pass test", function (result) {
2728
console.log(result);
2829
});
2930
bootbox.prompt({
30-
message: "Enter 'ok' to pass test", callback: function (result) {
31+
title: "Enter 'ok' to pass test", callback: function (result) {
3132
console.log(result);
3233
}
3334
});
3435
bootbox.prompt({
3536
size: "large",
36-
message: "Enter 'ok' to pass test", callback: function (result) {
37+
title: "Enter 'ok' to pass test", callback: function (result) {
3738
console.log(result);
3839
}
3940
});
@@ -42,7 +43,7 @@ bootbox.prompt({
4243
bootbox.dialog({
4344
title: "Wassup?",
4445
message: "Test Dialog",
45-
callback: function (result) { }
46+
callback: function () { }
4647
});
4748

4849
// Testing the return object of the call. Using the pointer to disable the animation on success callback.
@@ -103,4 +104,4 @@ var localeOptions: BootboxLocaleValues = {
103104

104105
bootbox.addLocale("Nepali", localeOptions);
105106
bootbox.setLocale("Nepali");
106-
bootbox.removeLocale("Nepali");
107+
bootbox.removeLocale("Nepali");

bootbox/bootbox.d.ts

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,56 @@
11
// Type definitions for Bootbox 4.4.0
22
// Project: https://github.com/makeusabrew/bootbox
3-
// Definitions by: Vincent Bortone <https://github.com/vbortone/>, Kon Pik <https://github.com/konpikwastaken/>, Anup Kattel <https://github.com/kanup/>, Dominik Schroeter <https://github.com/icereed/>
3+
// Definitions by: Vincent Bortone <https://github.com/vbortone/>, Kon Pik <https://github.com/konpikwastaken/>, Anup Kattel <https://github.com/kanup/>, Dominik Schroeter <https://github.com/icereed/>, Troy McKinnon <https://github.com/trodi/>
44
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
55

66
/// <reference path="../jquery/jquery.d.ts" />
7-
interface BootboxAlertOptions {
7+
8+
/** Bootbox options shared by all modal types */
9+
interface BootboxBaseOptions {
10+
title?: string | Element;
11+
callback?: (result: boolean | string) => any;
12+
onEscape?: () => any | boolean;
13+
show?: boolean;
14+
backdrop?: boolean;
15+
closeButton?: boolean;
16+
animate?: boolean;
17+
className?: string;
818
size?: string;
9-
message: string;
19+
buttons?: BootboxButtonMap; // complex object where each key is of type BootboxButton
20+
}
21+
22+
/** Bootbox options available for custom modals */
23+
interface BootboxDialogOptions extends BootboxBaseOptions {
24+
message: string | Element;
25+
}
26+
27+
/** Bootbox options available for alert modals */
28+
interface BootboxAlertOptions extends BootboxDialogOptions {
1029
callback?: () => any;
30+
buttons?: BootboxAlertButtonMap;
1131
}
1232

13-
interface BootboxConfirmOptions {
14-
size?: string;
15-
message: string;
33+
/** Bootbox options available for confirm modals */
34+
interface BootboxConfirmOptions extends BootboxDialogOptions {
1635
callback: (result: boolean) => any;
36+
buttons?: BootboxConfirmPromptButtonMap;
1737
}
1838

19-
interface BootboxPromptOptions {
20-
size?: string;
21-
message?: string;
39+
/** Bootbox options available for prompt modals */
40+
interface BootboxPromptOptions extends BootboxBaseOptions {
41+
title: string;
2242
callback: (result: string) => any;
43+
buttons?: BootboxConfirmPromptButtonMap;
44+
}
45+
46+
/** Bootbox options available when setting defaults for modals */
47+
interface BootboxDefaultOptions {
48+
locale?: string;
49+
show?: boolean;
50+
backdrop?: boolean;
51+
closeButton?: boolean;
52+
animate?: boolean;
53+
className?: string;
2354
}
2455

2556
interface BootboxButton {
@@ -32,28 +63,15 @@ interface BootboxButtonMap {
3263
[key: string]: BootboxButton | Function;
3364
}
3465

35-
interface BootboxDialogOptions {
36-
message: string | Element;
37-
title?: string | Element;
38-
locale?: string;
39-
callback?: (result: boolean) => any;
40-
onEscape?: () => any | boolean;
41-
show?: boolean;
42-
backdrop?: boolean;
43-
closeButton?: boolean;
44-
animate?: boolean;
45-
className?: string;
46-
size?: string;
47-
buttons?: BootboxButtonMap; // complex object where each key is of type BootboxButton
66+
/** ButtonMap options for alerts modals */
67+
interface BootboxAlertButtonMap extends BootboxButtonMap {
68+
ok: BootboxButton | Function;
4869
}
4970

50-
interface BootboxDefaultOptions {
51-
locale?: string;
52-
show?: boolean;
53-
backdrop?: boolean;
54-
closeButton?: boolean;
55-
animate?: boolean;
56-
className?: string;
71+
/** ButtonMap options for confirm and prompt modals */
72+
interface BootboxConfirmPromptButtonMap extends BootboxButtonMap {
73+
confirm: BootboxButton | Function;
74+
cancel: BootboxButton | Function;
5775
}
5876

5977
interface BootboxLocaleValues {

0 commit comments

Comments
 (0)