Components Overlays

Sheet

Open a side panel to edit a set of related preferences.

Live previewGo + JavaScript

Display settings

Choose the overlays that appear on your proof.

Visible layers

Usage

Provide Items with Label, Value, and optional Checked. Apply emits mono:apply with detail.values. Changes made before cancelling are discarded on the next open.

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

Go usage
Go usage
err := mono.UI.Render(w, "sheet", mono.Props{
	"Cancel":      "Cancel",
	"Confirm":     "Apply",
	"Description": "Choose the overlays that appear on your proof.",
	"Items": []any{
		map[string]any{
			"Checked": true,
			"Label":   "Column guides",
			"Value":   "columns",
		},
		map[string]any{
			"Label": "Trim marks",
			"Value": "trim",
		},
		map[string]any{
			"Label": "Baseline grid",
			"Value": "baseline",
		},
	},
	"Legend":  "Visible layers",
	"Result":  "Display settings applied.",
	"Title":   "Display settings",
	"Trigger": "Display settings",
})
Rendered HTML
Rendered HTML
<div id="demo-sheet" data-mono="sheet" data-message="Display settings applied." class="mu-stack">
  <button type="button" class="mu-btn mu-primary" data-open commandfor="demo-sheet-dialog" command="show-modal">Display settings</button>
  <dialog id="demo-sheet-dialog" class="mu-panel" aria-labelledby="demo-sheet-title" aria-describedby="demo-sheet-description">
    <form method="dialog" class="mu-stack">
      <header class="mu-stack">
        <h3 id="demo-sheet-title" class="mu-title">Display settings</h3>
        <p id="demo-sheet-description" class="mu-muted">Choose the overlays that appear on your proof.</p>
      </header>
      <fieldset class="mu-stack"><legend class="mu-label">Visible layers</legend>
        <label class="mu-row"><input type="checkbox" name="layers" value="columns" checked> Column guides</label><label class="mu-row"><input type="checkbox" name="layers" value="trim"> Trim marks</label><label class="mu-row"><input type="checkbox" name="layers" value="baseline"> Baseline grid</label>
      </fieldset>
      <div class="mu-row">
        <button class="mu-btn" type="button" data-cancel commandfor="demo-sheet-dialog" command="close">Cancel</button>
        <button class="mu-btn mu-primary" type="submit" value="confirm">Apply</button>
      </div>
    </form>
  </dialog>
  <p class="mu-small" data-result role="status"></p>
</div>
Go template
Go template
<div id="{{.ID}}" data-mono="sheet" 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="checkbox" name="layers" value="{{.Value}}"{{if .Checked}} checked{{end}}> {{.Label}}</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="sheet"] > button { justify-self: start; align-self: flex-start; }
[data-mono="sheet"] > [data-result]:empty { display: none; }
[data-mono="sheet"] 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="sheet"] dialog::backdrop { background: #1118; }
[data-mono="sheet"] form > .mu-row:last-child { justify-content: flex-end; }
[data-mono="sheet"] dialog { margin: 0 0 0 auto; inset: 0; height: 100dvh; max-height: 100dvh; border-radius: .75rem 0 0 .75rem; }
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 values = new FormData(form).getAll('layers');
    for (const field of form.querySelectorAll('[name="layers"]')) field.defaultChecked = field.checked;
    result.textContent = root.dataset.message;
    root.dispatchEvent(new CustomEvent('mono:apply', { bubbles: true, detail: { values } }));
  });
}
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="./sheet.css">
<script type="module" src="./sheet.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 sheet
Example properties (JSON)
example.json
{
  "Cancel": "Cancel",
  "Confirm": "Apply",
  "Description": "Choose the overlays that appear on your proof.",
  "Items": [
    {
      "Checked": true,
      "Label": "Column guides",
      "Value": "columns"
    },
    {
      "Label": "Trim marks",
      "Value": "trim"
    },
    {
      "Label": "Baseline grid",
      "Value": "baseline"
    }
  ],
  "Legend": "Visible layers",
  "Result": "Display settings applied.",
  "Title": "Display settings",
  "Trigger": "Display settings"
}