Components Overlays

Alert dialog

Ask for explicit confirmation before performing an action.

Live previewGo + JavaScript

Archive this issue?

Move this issue out of the active list. You can restore it from the archive.

Usage

Set the prompt, button labels, and Result text. Focus starts on Cancel. Confirm emits mono:confirm for your application; Escape dismisses the prompt.

Register alert-dialog with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "alert-dialog", mono.Props{
	"Cancel":      "Keep issue",
	"Confirm":     "Archive issue",
	"Description": "Move this issue out of the active list. You can restore it from the archive.",
	"Result":      "The issue was marked for archive.",
	"Title":       "Archive this issue?",
	"Trigger":     "Review archive",
})
Rendered HTML
Rendered HTML
<div id="demo-alert-dialog" data-mono="alert-dialog" data-message="The issue was marked for archive." class="mu-stack">
  <button type="button" class="mu-btn mu-primary" data-open commandfor="demo-alert-dialog-dialog" command="show-modal">Review archive</button>
  <dialog id="demo-alert-dialog-dialog" class="mu-panel" role="alertdialog" aria-labelledby="demo-alert-dialog-title" aria-describedby="demo-alert-dialog-description">
    <form method="dialog" class="mu-stack">
      <header class="mu-stack">
        <h3 id="demo-alert-dialog-title" class="mu-title">Archive this issue?</h3>
        <p id="demo-alert-dialog-description" class="mu-muted">Move this issue out of the active list. You can restore it from the archive.</p>
      </header>
      
      <div class="mu-row">
        <button class="mu-btn" type="button" data-cancel commandfor="demo-alert-dialog-dialog" command="close" autofocus>Keep issue</button>
        <button class="mu-btn mu-primary" type="submit" value="confirm">Archive issue</button>
      </div>
    </form>
  </dialog>
  <p class="mu-small" data-result role="status"></p>
</div>
Go template
Go template
<div id="{{.ID}}" data-mono="alert-dialog" data-message="{{.Result}}" class="mu-stack">
  <button type="button" class="mu-btn mu-primary" data-open commandfor="{{.ID}}-dialog" command="show-modal">{{.Trigger}}</button>
  <dialog id="{{.ID}}-dialog" class="mu-panel" role="alertdialog" aria-labelledby="{{.ID}}-title" aria-describedby="{{.ID}}-description">
    <form method="dialog" class="mu-stack">
      <header class="mu-stack">
        <h3 id="{{.ID}}-title" class="mu-title">{{.Title}}</h3>
        <p id="{{.ID}}-description" class="mu-muted">{{.Description}}</p>
      </header>
      
      <div class="mu-row">
        <button class="mu-btn" type="button" data-cancel commandfor="{{.ID}}-dialog" command="close" autofocus>{{.Cancel}}</button>
        <button class="mu-btn mu-primary" type="submit" value="confirm">{{.Confirm}}</button>
      </div>
    </form>
  </dialog>
  <p class="mu-small" data-result role="status"></p>
</div>
Component CSS
Component CSS
[data-mono="alert-dialog"] > button { justify-self: start; align-self: flex-start; }
[data-mono="alert-dialog"] > [data-result]:empty { display: none; }
[data-mono="alert-dialog"] dialog { color: #171717; background: white; border: 1px solid #ccc; border-radius: .75rem; padding: 1.5rem; width: min(25rem, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); overflow: auto; margin: auto; box-shadow: 0 1.25rem 4rem #0003; }
[data-mono="alert-dialog"] dialog::backdrop { background: #1118; }
[data-mono="alert-dialog"] form > .mu-row:last-child { justify-content: flex-end; }
JavaScript module
JavaScript module
export function mount(root) {
  const dialog = root.querySelector('dialog');
  const form = dialog.querySelector('form');
  const trigger = root.querySelector('[data-open]');
  const result = root.querySelector('[data-result]');

  trigger.addEventListener('click', event => {
    event.preventDefault();
    if (!dialog.open) dialog.showModal();
  });
  dialog.querySelector('[data-cancel]').addEventListener('click', event => {
    event.preventDefault();
    dialog.close('cancel');
  });
  dialog.addEventListener('close', () => trigger.focus());
  form.addEventListener('submit', () => {
    result.textContent = root.dataset.message;
    root.dispatchEvent(new CustomEvent('mono:confirm', { bubbles: true }));
  });
}
Use the HTML in a static site

Copy the rendered HTML above. Download these assets into the same folder as your page, then add the tags below to its head.

Shared CSS Component CSS Ready-to-use module

HTML head
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./alert-dialog.css">
<script type="module" src="./alert-dialog.js"></script>

Copy into your project

Run this command from the Mono checkout. Set -out to the component directory in your application.

Terminal
go run ./cmd/mono-ui add -out ./components alert-dialog
Example properties (JSON)
example.json
{
  "Cancel": "Keep issue",
  "Confirm": "Archive issue",
  "Description": "Move this issue out of the active list. You can restore it from the archive.",
  "Result": "The issue was marked for archive.",
  "Title": "Archive this issue?",
  "Trigger": "Review archive"
}