
A new addition to my Thin UI library, a much needed modal dialog, this script is tiny and it works with anything you can throw at it. It’s written in Vanilla JavaScript with no dependencies.
One of my ongoing project needed several confirmations on several different pages. As these actions might be delayed, I needed something to work asynchronously. This script adds a custom confirm dialog with Promise support to your website application.
The modal returns a Promise with the selected option: true
if the user accepted, false
if the user clicked cancel and null
if the user closed the modal window.
The modal constructor takes four parameters: the title, the content and the button labels (“Accept” or “Cancel”).
See the example on the Thin UI page or a live Codepen below:
See the Pen RJS (alpha) by Ciprian (@ciprian) on CodePen.

Technical SEO specialist, JavaScript developer and senior full-stack developer. Owner of getButterfly.com.
If you like this article, go ahead and follow me on Twitter or buy me a coffee to support my work!
great piece of work, I adapted the class to include alerts and prompt dialogs