1.0.0 • Published 6 years ago

prompt-view v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

PromptView

Lightweight dialogue component for prompting user input.

This probably isn't on your playlist

Usage

The component was designed to match the look-and-feel of Atom's usual modal dialogues (such as those used by its go-to-line and fuzzy-finder packages).

const PromptView = require("prompt-view");

let view = new PromptView();
let answer = await view.promptUser({
	headerText: "What's your favourite movie?",
	footerText: "Enter a name or YouTube URL",
});

The same PromptView can be used multiple times, even if messages differ. Package authors need not create more than one PromptView throughout their package's lifecycle:

answer = await view.promptUser({
	headerText: "What's your second favourite movie?",
	footerText: `You answered "${answer}" last time.`,
});

Properties may be set during construction, or set at the time the user is prompted for input:

view = new PromptView({headerHTML: "<b>Enter something:</b>"});
view.promptView().then(reply => …);

// Same as:
view = new PromptView();
view.promptView({headerHTML: "<b>Enter something:</b>"});

Browsers

Although this component was written with Atom projects in mind, it works in ordinary browser environments too, with the following caveats:

  1. No styling is applied; authors must provide this in their own stylesheets.

  2. The hidden attribute is used to control visibility, unless the container element is a <dialog> element.

  3. Newly-created PromptView objects are appended to the page's <body> node. Authors should move this somewhere more suitable if a different location in the DOM is required.

Instance properties

The full list of supported properties are:

NameTypeDefaultDescription
autoFocusBooleantrueSet and restore focus when toggling prompt.
autoHideBooleantrueHide the prompt upon losing focus.
elementHTMLElementTop-level wrapper representing the PromptView in Atom's workspace.
elementClassString"prompt"Space-separated list of CSS classes assigned to the instance's element.
elementTagNameString"div"Name of the HTML tag used to create element. This property can only be set during construction, using the original option-hash passed to the constructor function.
footerClassString"prompt-footer"Space-separated list of CSS classes assigned to instance's footer.
footerElementHTMLElementContent block displayed below inputField, empty unless headerText or headerHTML have been set.
footerHTMLString""HTML representation of the footerElement's contents.
footerTagNameString"footer"Name of the HTML tag used to create footerElement. This property can only be set during construction using the original option-hash passed to the constructor function.
footerTextString""A plain-text representation of the footerElement's content.
headerClassString"prompt-header"Space-separated list of CSS classes assigned to instance's headerElement.
headerElementHTMLElementContent block displayed above inputField, empty unless headerText or headerHTML have been set.
headerHTMLString""HTML representation of the headerElement's content.
headerTagNameString"header"Name of the HTML tag used to create headerElement. This property can only be set during construction, using the original option-hash passed to the constructor function.
headerTextString""A plain-text representation of the headerElement's content.
inputString""Text currently entered into the instance's inputField. Writing to this property will replace whatever text has been entered in the field.
inputFieldTextEditor, HTMLFormElementMiniature editing bar where user types their input.
isPendingBooleanfalseWhether the view is waiting for user to confirm their input.
placeholderString""Placeholder text displayed by inputField when empty.