Skip to content

Commit

Permalink
v1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
p-sam committed Dec 20, 2018
2 parents 272e998 + f14c81c commit 4840e60
Show file tree
Hide file tree
Showing 5 changed files with 1,106 additions and 1,139 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ prompt([options, parentBrowserWindow]).then(...).catch(...)

### Options object (optional)

| Key | Explaination |
| Key | Explanation |
| ------------- | ------------- |
| width | (optional, integer) The width of the prompt window. Defaults to 370. |
| height | (optional, integer) The height of the prompt window. Defaults to 130. |
Expand All @@ -58,9 +58,12 @@ prompt([options, parentBrowserWindow]).then(...).catch(...)
| type | (optional, string) The type of input field, either 'input' for a standard text input field or 'select' for a dropdown type input. Defaults to 'input'.|
| inputAttrs | (optional, object) The attributes of the input field, analagous to the HTML attributes: `{type: 'text', required: true}` -> `<input type="text" required>`. Used if the type is 'input' |
| selectOptions | (optional, object) The items for the select dropdown if using te 'select' type in the format 'value': 'display text', where the value is what will be given to the then block and the display text is what the user will see. |
| useHtmlLabel | (optional, boolean) Whether the label should be interpreted as HTML or not. Defaults to false. |
| icon | (optional, string) The path to an icon image to use in the title bar. Defaults to null and uses electron's icon. |
| customStylesheet | (optional, string) The local path of a CSS file to stylize the prompt window. Defaults to null. |

If not supplied, it uses the defaults listed in the table above.

### parentBrowserWindow
### parentBrowserWindow (optional)

(optional) The window in which to display the prompt on. If not supplied, the parent window of the prompt will be null.
The window in which to display the prompt on. If not supplied, the parent window of the prompt will be null.
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ function electronPrompt(options, parentWindow) {
value: null,
type: 'input',
selectOptions: null,
icon: null
icon: null,
useHtmlLabel: false,
customStylesheet: null
},
options || {}
);
Expand Down
26 changes: 23 additions & 3 deletions lib/page/prompt.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const fs = require('fs');
const {ipcRenderer} = require('electron');
const docReady = require('doc-ready');

Expand Down Expand Up @@ -42,11 +43,30 @@ docReady(() => {

try {
promptOptions = JSON.parse(ipcRenderer.sendSync('prompt-get-options:' + promptId));
} catch (e) {
return promptError(e);
} catch (error) {
return promptError(error);
}

if (promptOptions.useHtmlLabel) {
document.getElementById('label').innerHTML = promptOptions.label;
} else {
document.getElementById('label').textContent = promptOptions.label;
}

try {
if (promptOptions.customStylesheet) {
const customStyleContent = fs.readFileSync(promptOptions.customStylesheet);
if (customStyleContent) {
const customStyle = document.createElement('style');
customStyle.setAttribute('rel', 'stylesheet');
customStyle.appendChild(document.createTextNode(customStyleContent));
document.head.appendChild(customStyle);
}
}
} catch (error) {
return promptError(error);
}

document.getElementById('label').textContent = promptOptions.label;
document.getElementById('ok').addEventListener('click', () => promptSubmit());
document.getElementById('cancel').addEventListener('click', () => promptCancel());

Expand Down
Loading

0 comments on commit 4840e60

Please sign in to comment.