vUX / Prompt / v4.1.0

Ask first.
Then act on the answer.

Styled alert, confirm and input dialogs that hand the answer back as a Promise, sit above every modal on the page and never freeze your scripts.

resolved with nothing yet
if (await ask.confirm("Delete these cards?", { danger: true })) remove()

01Playground

The controls on the left set config on one live instance; the ones on the right are per-call options for the next dialog. Every answer lands in the log, so you can see what Cancel, Escape and a backdrop click each resolve with.

config
next dialog
Equivalent code

                

02Real flows

The three jobs a prompt usually does in an app: guard a destructive action, collect one value with a check that may go to the server, and cope when two parts of the page ask at the same moment.

danger: true

Delete with a guard

Focus starts on Cancel and OK turns red, so a stray Enter cannot delete anything.

  • invite-front.png
  • invite-back.png
  • guests.txt
validate()

Rename with an async check

The name is checked against a fake server (600ms). "taken" is refused; OK waits while it checks.

Wedding cards

queue

Two questions at once

Two instances ask together. The second waits its turn instead of landing on top of the first.

03Bad input fails immediately

Every config property and every per-call option is checked when it is set, so a typo throws to your code instead of opening a dialog that silently ignores it.

No error yet. Press one of the buttons above.