Components Buttons

Button group

Group related actions in a compact, connected control.

Live previewGo + JavaScript
Cover

Front cover on uncoated stock.

Contents

The publication index and credits.

Colophon

Type and production notes.

Usage

Supply Label and a list of Items with Label and Description. The two buttons move through that list. Buttons at the sequence boundaries are disabled.

Register button-group with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "button-group", mono.Props{
	"Items": []any{
		map[string]any{
			"Description": "Front cover on uncoated stock.",
			"Label":       "Cover",
		},
		map[string]any{
			"Description": "The publication index and credits.",
			"Label":       "Contents",
		},
		map[string]any{
			"Description": "Type and production notes.",
			"Label":       "Colophon",
		},
	},
	"Label": "Proof sheet",
})
Rendered HTML
Rendered HTML
<section id="demo-button-group" data-mono="button-group" class="mu-stack" aria-label="Proof sheet">
  <div class="mu-stack" data-pages>
    <div><strong>Cover</strong><p class="mu-muted">Front cover on uncoated stock.</p></div><div><strong>Contents</strong><p class="mu-muted">The publication index and credits.</p></div><div><strong>Colophon</strong><p class="mu-muted">Type and production notes.</p></div>
  </div>
  <div role="group" aria-label="Proof sheet controls" hidden>
    <button type="button" class="mu-btn" data-previous>Previous</button><button type="button" class="mu-btn" data-next>Next</button>
  </div>
  <output class="mu-small mu-muted" role="status"></output>
</section>
Go template
Go template
<section id="{{.ID}}" data-mono="button-group" class="mu-stack" aria-label="{{.Label}}">
  <div class="mu-stack" data-pages>
    {{range .Items}}<div><strong>{{.Label}}</strong><p class="mu-muted">{{.Description}}</p></div>{{end}}
  </div>
  <div role="group" aria-label="{{.Label}} controls" hidden>
    <button type="button" class="mu-btn" data-previous>Previous</button><button type="button" class="mu-btn" data-next>Next</button>
  </div>
  <output class="mu-small mu-muted" role="status"></output>
</section>
Component CSS
Component CSS
[data-mono="button-group"] [role="group"]:not([hidden]) { display: inline-flex; justify-self: start; }
[data-mono="button-group"] [role="group"] button:first-child { border-radius: .4rem 0 0 .4rem; }
[data-mono="button-group"] [role="group"] button:last-child { border-radius: 0 .4rem .4rem 0; margin-left: -1px; }
JavaScript module
JavaScript module
export function mount(root) {
  const pages = [...root.querySelector('[data-pages]').children];
  if (!pages.length) return;
  const controls = root.querySelector('[role="group"]');
  const previous = controls.querySelector('[data-previous]');
  const next = controls.querySelector('[data-next]');
  let index = 0;
  function show() {
    pages.forEach((page, i) => { page.hidden = i !== index; });
    previous.disabled = index === 0;
    next.disabled = index === pages.length - 1;
    root.querySelector('output').textContent = (index + 1) + ' of ' + pages.length + ' · ' + pages[index].querySelector('strong').textContent;
  }
  previous.addEventListener('click', () => { index--; show(); if (previous.disabled && !next.disabled) next.focus(); });
  next.addEventListener('click', () => { index++; show(); if (next.disabled && !previous.disabled) previous.focus(); });
  controls.hidden = false;
  show();
}
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="./button-group.css">
<script type="module" src="./button-group.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 button-group
Example properties (JSON)
example.json
{
  "Items": [
    {
      "Description": "Front cover on uncoated stock.",
      "Label": "Cover"
    },
    {
      "Description": "The publication index and credits.",
      "Label": "Contents"
    },
    {
      "Description": "Type and production notes.",
      "Label": "Colophon"
    }
  ],
  "Label": "Proof sheet"
}