Skip to content

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
p-sam committed Jan 14, 2020
2 parents a7921f7 + efb3cba commit f93b02d
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ prompt([options, parentBrowserWindow]).then(...).catch(...)
| ------------- | ------------- |
| title | (optional, string) The title of the prompt window. Defaults to 'Prompt'. |
| label | (optional, string) The label which appears on the prompt for the input field. Defaults to 'Please input a value:'. |
| buttonLabels | (optional, object) The text for the OK/cancel buttons. Properties are 'ok' and 'cancel'. Defaults to null. |
| value | (optional, string) The default value for the input field. Defaults to null.|
| 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. |
| selectOptions | (optional, object) The items for the select dropdown if using the '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. |
| width | (optional, integer) The width of the prompt window. Defaults to 370. |
| minWidth | (optional, integer) The minimum allowed width for the prompt window. Same default value as width. |
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function electronPrompt(options, parentWindow) {
resizable: false,
title: 'Prompt',
label: 'Please input a value:',
buttonLabels: null,
alwaysOnTop: false,
value: null,
type: 'input',
Expand Down
3 changes: 2 additions & 1 deletion lib/page/prompt.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ select#data {
padding: 0 .5em 0 0;
}

#buttons > button {
#buttons > button,
#buttons > input[type=submit] {
border-radius: 2px;
border: 0;
margin: 0 0 0 .5em;
Expand Down
6 changes: 3 additions & 3 deletions lib/page/prompt.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
</head>
<body>
<div id="container">
<div id="form">
<form id="form">
<div id="label">...</div>
<div id="data-container"></div>
<div id="buttons">
<button id="cancel">Cancel</button>
<button id="ok">OK</button>
<button type="submit" id="ok">OK</button>
</div>
</div>
</form>
</div>
<script src="prompt.js"></script>
</body>
Expand Down
12 changes: 10 additions & 2 deletions lib/page/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ docReady(() => {
document.querySelector('#label').textContent = promptOptions.label;
}

if (promptOptions.buttonLabels && promptOptions.buttonLabels.ok) {
document.querySelector('#ok').textContent = promptOptions.buttonLabels.ok;
}

if (promptOptions.buttonLabels && promptOptions.buttonLabels.cancel) {
document.querySelector('#cancel').textContent = promptOptions.buttonLabels.cancel;
}

try {
if (promptOptions.customStylesheet) {
const customStyleContent = fs.readFileSync(promptOptions.customStylesheet);
Expand All @@ -69,8 +77,8 @@ docReady(() => {
return promptError(error);
}

document.querySelector('#ok').addEventListener('click', () => promptSubmit());
document.querySelector('#cancel').addEventListener('click', () => promptCancel());
document.querySelector('#form').addEventListener('submit', promptSubmit);
document.querySelector('#cancel').addEventListener('click', promptCancel);

const dataContainerEl = document.querySelector('#data-container');

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "electron-prompt",
"version": "1.4.0",
"version": "1.5.0",
"description": "Electron helper to prompt for a value via input or select",
"keywords": [
"electron",
Expand Down

0 comments on commit f93b02d

Please sign in to comment.