Components Forms

Slider

Choose a numeric value along a bounded scale.

Live previewGo + JavaScript

Usage

Pass Min, Max, Step, and Value as numbers. Arrow keys adjust the native range input. The optional module updates its visible output while dragging.

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

Go usage
Go usage
err := mono.UI.Render(w, "slider", mono.Props{
	"Label": "Preview opacity",
	"Max":   100,
	"Min":   0,
	"Name":  "opacity",
	"Step":  5,
	"Unit":  "%",
	"Value": 75,
})
Rendered HTML
Rendered HTML
<div id="demo-slider" data-mono="slider" class="mu-stack">
  <div class="mu-row">
    <label for="demo-slider-value" class="mu-label">Preview opacity</label>
    <span aria-hidden="true" class="mu-small mu-badge" data-readout hidden><span>75</span>%</span>
  </div>
  <input type="range" id="demo-slider-value" name="opacity" min="0" max="100" step="5" value="75" >
  <div class="mu-range-limits mu-small mu-muted" aria-hidden="true"><span>0%</span><span>100%</span></div>
</div>
Go template
Go template
<div id="{{.ID}}" data-mono="slider" class="mu-stack">
  <div class="mu-row">
    <label for="{{.ID}}-value" class="mu-label">{{.Label}}</label>
    <span aria-hidden="true" class="mu-small mu-badge" data-readout hidden><span>{{.Value}}</span>{{.Unit}}</span>
  </div>
  <input type="range" id="{{.ID}}-value" name="{{or .Name .ID}}" min="{{.Min}}" max="{{.Max}}" step="{{or .Step 1}}" value="{{.Value}}" {{if .Disabled}}disabled{{end}}>
  <div class="mu-range-limits mu-small mu-muted" aria-hidden="true"><span>{{.Min}}{{.Unit}}</span><span>{{.Max}}{{.Unit}}</span></div>
</div>
Component CSS
Component CSS
[data-mono="slider"] .mu-row, [data-mono="slider"] .mu-range-limits { display: flex; justify-content: space-between; }
[data-mono="slider"] input { width: 100%; margin: .35rem 0; accent-color: #161616; }
JavaScript module
JavaScript module
export function mount(root) {
  const input = root.querySelector('input');
  const output = root.querySelector('[data-readout]');
  const number = output.querySelector('span');
  const update = () => { number.textContent = input.value; };
  update();
  output.hidden = false;
  input.addEventListener('input', update);
  input.form?.addEventListener('reset', () => setTimeout(update, 0));
}
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="./slider.css">
<script type="module" src="./slider.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 slider
Example properties (JSON)
example.json
{
  "Label": "Preview opacity",
  "Max": 100,
  "Min": 0,
  "Name": "opacity",
  "Step": 5,
  "Unit": "%",
  "Value": 75
}