Skip to main content

Installation and usage

Installation

npm install electron-prompts

Usage

Import and instantiate a PromptManager for your project:

import PromptManager from "electron-prompts"

const prompts = new PromptManager({
devMode: true,
})

Create and spawn a prompt using Prompt Templates:

const pTemplate = {
windowTitle: "electron-prompts",
cancelButton: {
classes: ["btn", "btn-secondary"],
// value: "Lets slow'r down there partner..."
},
elements: [
{
type: "header",
value: "The easiest prompts ever!",
},
{
type: "paragraph",
value: "An easy tool to enable spawning prompts from the Electron main process",
},
{
name: "testValue",
type: "input",
placeholder: "Test input",
classes: ["form-control"],
value: "With inputs!",
},
{
type: "paragraph",
value: "Also paragraphs",
},
{
name: "testValue",
type: "input",
placeholder: "Or even another input!",
classes: ["form-control"],
value: "",
},
],
buttons: [
{
name: "submit",
classes: ["btn", "btn-primary"],
value: "Save Changes",
},
],
}

Calling the async spawn() method on the PromptManager instance, passing a Prompt Template, will create a window and wait until the user input is captured to resolve:

const result = await prompts.spawn(pTemplate)

Logo

Once the prompt has been completed, the method returns a Prompt Result object, or null if prompt was closed or cancelled