Skip to content

ssight/native-prompt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

native-prompt

Create native prompts with Node.js and Electron

What is this?

While alert and confirm are both supported in Electron, prompt isn't (see this issue). native-prompt aims to fix this by allowing you to create prompt boxes that are native to the user's OS. As an added bonus, it also works in Node.js.

Screenshots

Windows

A prompt showing on Windows

Linux

A prompt showing on Linux

MacOS

A prompt showing on MacOS

Installation

Through NPM:

npm i native-prompt

...or the long way:

npm install native-prompt@latest --save

Usage

Synopsis

prompt (title, body, options)

title:string

The title you want to display at the top of the window

body:string

Any helpful text to go inside the message box

options: { defaultText?: string; mask?: boolean }

Any (optional) extra options (see below)

Options

defaultText?: string

The text you want to already be in the input box beforehand

mask?: boolean

Whether you want the box to have a hidden input

Examples

Importing

Javascript

const prompt = require('native-prompt')

Typescript

import prompt from 'native-prompt'

Async function usage

(async () => {
    const text = await prompt("This is a title.", "What would you really like to see next?", { defaultText: "Nothing" });
    if (text) {
        // Do something with the input
    } else {
        // The user either clicked cancel or left the space blank
    }
})()

Regular promise usage

prompt("This is a title.", "What would you really like to see next?", { defaultText: "Nothing" }).then(text => {
    if (text) {
        // Do something with the input
    } else {
        // The user either clicked cancel or left the space blank
    }
})

Masked textbox example

(async () => {
    const password = await prompt("Login", "Enter your password to log back in.", { mask: true });
    if (isCorrectPassword(password)) {
        // Log the user in
    } else {
        // The user's entered their username or password incorrect
    }
})()

Notes

  • If you plan on using asar to package your electron app, make sure to read this
  • For differences between 1.x and 2.x, see this wiki page.

About

Create native prompts with Node.js and Electron

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published