2.0.0 • Published 7 months ago

parley.js v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

Parley.js

An oversimplified library for HTML5 dialogs

Parley.js is a small utility replacing window.prompt and window.confirm.

Minimum requirements

NeedsVersionMDN
ECMAScriptPromiseES2015see
HTML<dialog>HTML5see

Without Babel, code also needs async and await keywords (ES2017).

Usage

import * as Parley from "parley.js";
import "parley.js/dist/default.css";
// ...

If you have a bundler that supports SCSS and TypeScript, you can import the source files directly:

import * as Parley from "parley.js/src";
// ...

Also, you can use UNPKG:

<link rel="stylesheet" href="https://unpkg.com/parley.js/dist/default.css" />
<script type="module">
    import * as Parley from "https://unpkg.com/parley.js";
    // ...
</script>

Parley.fire

It takes configuration and responds with a Promise. Depending on the input type, configuration and output vary. But if the parley was cancelled (by the cancel button or the escape key) the output is always false.

Base configuration

NameDescriptionDefault
titleThe title displayed in parley. Supports HTML""
messageThe HTML message of the parley.""
cancelButtonHTMLThe HTML content of the cancel button.Cancel"
confirmButtonHTMLThe HTML content of the confirm button."OK"
valueThe default value.undefined
inputOptionsThe input-type-specific; see bellow{}

Input options

Input typesConfiguration typeOutput / Defaut value type
"number" "range"NumberOptionsnumber
"textarea"TextareaOptionsstring
"tel" "text" "email" "search" "password"TextOptionsstring
"checkbox" "select" "radio"SelectOptionsstring, string[] for checkbox
"noneneverboolean
interface NumberOptions {
    min?: number;
    max?: number;
    step?: number;
    placeholder?: string;
}

interface TextareaOptions {
    rows?: number;
    cols?: number;
    placeholder?: string;
}

interface TextOptions {
    /**
     * Regular expression used to validate the input
     */
    pattern?: RegExp;
    placeholder?: string;
}

interface SelectionOptions {
    /**
     * The key is the value of the input.
     * The value is the label html of the input.
     */
    [value: string]: string;
}

Parley.close and Parley.cancel

Both functions close the parley immediately. While Parley.cancel() causes to return false, Parley.close() returns the user value.

1.1.1

7 months ago

1.1.0

7 months ago

2.0.0

7 months ago

1.0.14

8 months ago

1.0.13

9 months ago

1.0.11

1 year ago

1.0.9

1 year ago

1.0.8

1 year ago

1.0.7

1 year ago

1.0.5

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago