Components Overlays

Drawer

Choose an option in a bottom-anchored modal panel.

Live previewGo + JavaScript

Paper stock

Select a stock for the next proof.

Available stock

Usage

Use Items with Label, Value, and optional Checked for the initial choice. Apply commits the selected value and emits mono:choose. The native dialog supports Escape and keeps keyboard focus inside while open.

Register drawer with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "drawer", mono.Props{
	"Cancel":      "Cancel",
	"Confirm":     "Use stock",
	"Description": "Select a stock for the next proof.",
	"Items": []any{
		map[string]any{
			"Checked": true,
			"Label":   "Natural white",
			"Value":   "natural",
		},
		map[string]any{
			"Label": "Warm ivory",
			"Value": "ivory",
		},
		map[string]any{
			"Label": "Bright white",
			"Value": "bright",
		},
	},
	"Legend":  "Available stock",
	"Result":  "Selected",
	"Title":   "Paper stock",
	"Trigger": "Choose paper",
})
Rendered HTML
Rendered HTML
<div id="demo-drawer" data-mono="drawer" data-message="Selected" class="mu-stack">
  <button type="button" class="mu-btn mu-primary" data-open commandfor="demo-drawer-dialog" command="show-modal">Choose paper</button>
  <dialog id="demo-drawer-dialog" class="mu-panel" aria-labelledby="demo-drawer-title" aria-describedby="demo-drawer-description">
    <form method="dialog" class="mu-stack">
      <header class="mu-stack">
        <h3 id="demo-drawer-title" class="mu-title">Paper stock</h3>
        <p id="demo-drawer-description" class="mu-muted">Select a stock for the next proof.</p>
      </header>
      <fieldset class="mu-stack"><legend class="mu-label">Available stock</legend>
        <label class="mu-row"><input type="radio" name="stock" value="natural" required checked> <span>Natural white</span></label><label class="mu-row"><input type="radio" name="stock" value="ivory" required> <span>Warm ivory</span></label><label class="mu-row"><input type="radio" name="stock" value="bright" required> <span>Bright white</span></label>
      </fieldset>
      <div class="mu-row">
        <button class="mu-btn" type="button" data-cancel commandfor="demo-drawer-dialog" command="close">Cancel</button>
        <button class="mu-btn mu-primary" type="submit" value="confirm">Use stock</button>
      </div>
    </form>
  </dialog>
  <p class="mu-small" data-result role="status"></p>
</div>
Go template
Go template
<div id="{{.ID}}" data-mono="drawer" 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" 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>
      <fieldset class="mu-stack"><legend class="mu-label">{{.Legend}}</legend>
        {{range .Items}}<label class="mu-row"><input type="radio" name="stock" value="{{.Value}}" required{{if .Checked}} checked{{end}}> <span>{{.Label}}</span></label>{{end}}
      </fieldset>
      <div class="mu-row">
        <button class="mu-btn" type="button" data-cancel commandfor="{{.ID}}-dialog" command="close">{{.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="drawer"] > button { justify-self: start; align-self: flex-start; }
[data-mono="drawer"] > [data-result]:empty { display: none; }
[data-mono="drawer"] 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="drawer"] dialog::backdrop { background: #1118; }
[data-mono="drawer"] form > .mu-row:last-child { justify-content: flex-end; }
[data-mono="drawer"] dialog { margin: auto auto 0; inset: auto 0 0; width: min(100%, 32rem); border-radius: 1rem 1rem 0 0; padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); }
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();
    form.reset();
    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', () => {
    const field = form.querySelector('input:checked');
    if (!field) return;
    for (const option of form.querySelectorAll('[name="stock"]')) option.defaultChecked = option.checked;
    result.textContent = root.dataset.message + ': ' + field.parentElement.textContent.trim();
    root.dispatchEvent(new CustomEvent('mono:choose', { bubbles: true, detail: { value: field.value } }));
  });
}
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="./drawer.css">
<script type="module" src="./drawer.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 drawer
Example properties (JSON)
example.json
{
  "Cancel": "Cancel",
  "Confirm": "Use stock",
  "Description": "Select a stock for the next proof.",
  "Items": [
    {
      "Checked": true,
      "Label": "Natural white",
      "Value": "natural"
    },
    {
      "Label": "Warm ivory",
      "Value": "ivory"
    },
    {
      "Label": "Bright white",
      "Value": "bright"
    }
  ],
  "Legend": "Available stock",
  "Result": "Selected",
  "Title": "Paper stock",
  "Trigger": "Choose paper"
}