Components Forms
Checkbox
Capture an independent yes-or-no choice in a form.
Usage
Give the control a Name and Value; a checked input submits that value. The whole label toggles the checkbox and Space toggles it from the keyboard.
Register checkbox with Head and pass its properties to Render. Go setup guide
Go usage
err := mono.UI.Render(w, "checkbox", mono.Props{
"Checked": true,
"Description": "Attach a PDF proof to the print request.",
"Label": "Include a digital proof",
"Name": "digital_proof",
"Value": "yes",
})Rendered HTML
<label id="demo-checkbox" data-mono="checkbox" class="mu-row">
<input type="checkbox" name="digital_proof" value="yes" checked aria-describedby="demo-checkbox-hint" aria-labelledby="demo-checkbox-label">
<span><strong class="mu-label" id="demo-checkbox-label">Include a digital proof</strong><span class="mu-small mu-muted" id="demo-checkbox-hint">Attach a PDF proof to the print request.</span></span>
</label>Go template
<label id="{{.ID}}" data-mono="checkbox" class="mu-row">
<input type="checkbox" name="{{or .Name .ID}}" value="{{or .Value "on"}}" {{if .Checked}}checked{{end}} {{if .Required}}required{{end}} {{if .Disabled}}disabled{{end}} {{if .Description}}aria-describedby="{{.ID}}-hint"{{end}} aria-labelledby="{{.ID}}-label">
<span><strong class="mu-label" id="{{.ID}}-label">{{.Label}}</strong>{{if .Description}}<span class="mu-small mu-muted" id="{{.ID}}-hint">{{.Description}}</span>{{end}}</span>
</label>Component CSS
[data-mono="checkbox"] { cursor: pointer; } [data-mono="checkbox"] input { accent-color: #171717; width: 1.1rem; height: 1.1rem; } [data-mono="checkbox"] .mu-small { display: block; }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.
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./checkbox.css">Copy into your project
Run this command from the Mono checkout. Set -out to the component directory in your application.
go run ./cmd/mono-ui add -out ./components checkboxExample properties (JSON)
{
"Checked": true,
"Description": "Attach a PDF proof to the print request.",
"Label": "Include a digital proof",
"Name": "digital_proof",
"Value": "yes"
}