Components Buttons

Toggle

Represent an independent on/off choice as a compact labeled control.

Live previewGo + HTML

Usage

Checked sets the initial value. The underlying checkbox supports focus, Space, form submission, and the change event. The indicator also communicates selection without color.

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

Go usage
Go usage
err := mono.UI.Render(w, "toggle", mono.Props{
	"Checked": true,
	"Label":   "Bookmarked",
	"Name":    "bookmarked",
})
Rendered HTML
Rendered HTML
<label id="demo-toggle" data-mono="toggle">
  <input class="mu-sr-only" type="checkbox" name="bookmarked" value="on" checked >
  <span class="mu-btn"><span class="mu-toggle-indicator" aria-hidden="true"></span>Bookmarked</span>
</label>
Go template
Go template
<label id="{{.ID}}" data-mono="toggle">
  <input class="mu-sr-only" type="checkbox" name="{{or .Name .ID}}" value="{{or .Value "on"}}" {{if .Checked}}checked{{end}} {{if .Disabled}}disabled{{end}}>
  <span class="mu-btn"><span class="mu-toggle-indicator" aria-hidden="true"></span>{{.Label}}</span>
</label>
Component CSS
Component CSS
[data-mono="toggle"] { display: inline-flex; position: relative; cursor: pointer; }
[data-mono="toggle"] .mu-toggle-indicator { width: .8em; height: .8em; border: 1px solid currentColor; border-radius: 2px; }
[data-mono="toggle"] input:checked + .mu-btn { background: #171717; color: white; }
[data-mono="toggle"] input:checked + .mu-btn .mu-toggle-indicator { height: .4em; border-width: 0 0 2px 2px; border-radius: 0; transform: rotate(-45deg); }
[data-mono="toggle"] input:focus-visible + .mu-btn { outline: 2px solid #222; outline-offset: 3px; }
[data-mono="toggle"] input:disabled + .mu-btn { opacity: .5; }
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

HTML head
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./toggle.css">

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 toggle
Example properties (JSON)
example.json
{
  "Checked": true,
  "Label": "Bookmarked",
  "Name": "bookmarked"
}