Components Buttons

Button

Give one action a clear label and a native keyboard target.

Live previewGo + JavaScript
mono-studio-042

Usage

Set Label and Type to use the button inside a form. Set CopyText for the optional copy action shown here. Space and Enter activate the focused button.

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

Go usage
Go usage
err := mono.UI.Render(w, "button", mono.Props{
	"CopyText": "mono-studio-042",
	"Label":    "Copy project ID",
	"Type":     "button",
})
Rendered HTML
Rendered HTML
<div id="demo-button" data-mono="button" class="mu-stack">
  <code class="mu-small" data-copy-value>mono-studio-042</code>
  <button class="mu-btn mu-primary" type="button" >Copy project ID</button>
  <output class="mu-small" role="status"></output>
</div>
Go template
Go template
<div id="{{.ID}}" data-mono="button" class="mu-stack">
  {{if .CopyText}}<code class="mu-small" data-copy-value>{{.CopyText}}</code>{{end}}
  <button class="mu-btn mu-primary" type="{{or .Type "button"}}" {{if .Disabled}}disabled{{end}}>{{.Label}}</button>
  {{if .CopyText}}<output class="mu-small" role="status"></output>{{end}}
</div>
Component CSS
Component CSS
[data-mono="button"] { justify-items: start; }
JavaScript module
JavaScript module
export function mount(root) {
  const value = root.querySelector('[data-copy-value]');
  if (!value) return;
  root.querySelector('button').addEventListener('click', async () => {
    const status = root.querySelector('output');
    try {
      await navigator.clipboard.writeText(value.textContent);
      status.textContent = 'Copied.';
    } catch {
      const selection = window.getSelection();
      const range = document.createRange();
      range.selectNodeContents(value);
      selection?.removeAllRanges();
      selection?.addRange(range);
      status.textContent = 'Text selected. Use your device’s copy command.';
    }
  });
}
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.css">
<script type="module" src="./button.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
Example properties (JSON)
example.json
{
  "CopyText": "mono-studio-042",
  "Label": "Copy project ID",
  "Type": "button"
}