Skip to content

Commit 83e5c8c

Browse files
ffflorianrbuckton
authored andcommitted
Add types for electron-prompt (DefinitelyTyped#38027)
1 parent 13d22ea commit 83e5c8c

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import prompt = require('electron-prompt');
2+
import { BrowserWindow } from 'electron';
3+
4+
prompt({
5+
inputAttrs: {
6+
type: 'url',
7+
},
8+
label: 'URL:',
9+
title: 'Prompt example',
10+
value: 'http://example.org',
11+
}).then(r => {
12+
r; // $ExpectType string | null
13+
});
14+
15+
prompt({}, new BrowserWindow());

types/electron-prompt/index.d.ts

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Type definitions for electron-prompt 1.3
2+
// Project: https://github.com/p-sam/electron-prompt#readme
3+
// Definitions by: Florian Keller <https://github.com/ffflorian>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
// TypeScript Version: 2.6
6+
7+
import { BrowserWindow } from 'electron';
8+
9+
declare namespace prompt {
10+
interface Options {
11+
/**
12+
* The local path of a CSS file to stylize the prompt window.
13+
* Defaults to `null`.
14+
*/
15+
customStylesheet?: string | null;
16+
/** The height of the prompt window. Defaults to `130`. */
17+
height?: number;
18+
/**
19+
* The path to an icon image to use in the title bar. Defaults to `null`
20+
* and uses electron's icon.
21+
*/
22+
icon?: string | null;
23+
/**
24+
* The attributes of the input field, analagous to the HTML attributes:
25+
* `{type: 'text', required: true}` -> `<input type="text" required>`.
26+
* Used if the type is `'input'`.
27+
*/
28+
inputAttrs?: Record<string, any>;
29+
/**
30+
* The label which appears on the prompt for the input field. Defaults
31+
* to `'Please input a value:'`.
32+
*/
33+
label?: string;
34+
/**
35+
* Whether the prompt window can be resized or not. Defaults to
36+
* `false`.
37+
*/
38+
resizable?: boolean;
39+
/**
40+
* The items for the select dropdown if using the `'select'` type in the
41+
* format `'value'`: `'display text'`, where the value is what will be
42+
* given to the then block and the display text is what the user will
43+
* see.
44+
*/
45+
selectOptions?: object;
46+
/** The title of the prompt window. Defaults to `'Prompt'`. */
47+
title?: string;
48+
/**
49+
* The type of input field, either `'input'` for a standard text input
50+
* field or 'select' for a dropdown type input. Defaults to `'input'`.
51+
*/
52+
type?: `'input'` | 'select';
53+
/**
54+
* Whether the label should be interpreted as HTML or not. Defaults to
55+
* `false`.
56+
*/
57+
useHtmlLabel?: boolean;
58+
/** The default value for the input field. Defaults to `null`. */
59+
value?: string | null;
60+
/** The width of the prompt window. Defaults to `370`. */
61+
width?: number;
62+
}
63+
}
64+
65+
declare function prompt(options?: prompt.Options, parentBrowserWindow?: BrowserWindow): Promise<string | null>;
66+
67+
export = prompt;

types/electron-prompt/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"dependencies": {
4+
"electron": "latest"
5+
}
6+
}

types/electron-prompt/tsconfig.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"dom",
6+
"es6"
7+
],
8+
"noImplicitAny": true,
9+
"noImplicitThis": true,
10+
"strictFunctionTypes": true,
11+
"strictNullChecks": true,
12+
"baseUrl": "../",
13+
"typeRoots": [
14+
"../"
15+
],
16+
"types": [],
17+
"noEmit": true,
18+
"forceConsistentCasingInFileNames": true
19+
},
20+
"files": [
21+
"index.d.ts",
22+
"electron-prompt-tests.ts"
23+
]
24+
}

types/electron-prompt/tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "dtslint/dt.json" }

0 commit comments

Comments
 (0)