Add types for muibox (#36183)

* Added typings for muibox

* Removed patch version
This commit is contained in:
diegose 2019-06-27 18:58:14 -03:00 committed by Benjamin Lichtman
parent f11abd2433
commit ba5e0a2a2b
4 changed files with 93 additions and 0 deletions

29
types/muibox/index.d.ts vendored Normal file
View File

@ -0,0 +1,29 @@
// Type definitions for muibox 1.0
// Project: https://github.com/chunkai1312/muibox
// Definitions by: Diego Mijelshon <https://github.com/diegose>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export function DialogProvider(_: any): any;
export function useDialog(): Dialog;
export function withDialog(): (WrappedComponent: any) => (props: any) => any;
export interface Dialog {
alert(options: AlertOptions | string): Promise<void>;
confirm(options: ConfirmOptions | string): Promise<void>;
prompt(options: PromptOptions | string): Promise<string>;
}
export interface AlertOptions {
title?: string;
message?: string;
ok?: string;
}
export interface ConfirmOptions extends AlertOptions {
cancel?: string;
}
export interface PromptOptions extends ConfirmOptions {
required?: boolean;
defaultValue?: string | number;
}

View File

@ -0,0 +1,40 @@
import * as muibox from "muibox";
const dialog = muibox.useDialog();
dialog.alert("Hello world").then(() => "bye");
dialog
.alert({ message: "Hello world", ok: "Close", title: "Salutation" })
.then(() => "bye");
dialog
.confirm("Are you sure?")
.then(() => "do it")
.catch(() => "don't do it");
dialog
.confirm({
message: "Are you sure?",
title: "Confirmation",
ok: "Sure",
cancel: "No"
})
.then(() => "do it")
.catch(() => "don't do it");
dialog
.prompt("What is your name?")
.then(name => `Hello ${name}`)
.catch(() => "canceled");
dialog
.prompt({
message: "What is your name?",
title: "Salutation",
ok: "Proceed",
cancel: "Quit",
defaultValue: "Joe",
required: true
})
.then(name => `Hello ${name}`)
.catch(() => "canceled");

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"muibox-tests.ts"
]
}

1
types/muibox/tslint.json Normal file
View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }