Components Navigation

Sidebar

Place section destinations in a compact sidebar with collapsible link groups.

Live previewGo + HTML

Usage

Choose a Title for the landmark and supply Groups with Label, Open, and Links. Mark the active link with Current. Native details handles keyboard toggling.

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

Go usage
Go usage
err := mono.UI.Render(w, "sidebar", mono.Props{
	"Groups": []any{
		map[string]any{
			"Label": "Resources",
			"Links": []any{
				map[string]any{
					"Current": true,
					"Href":    "/docs.html",
					"Label":   "Documentation",
				},
				map[string]any{
					"Href":  "/icons.html",
					"Label": "Icon library",
				},
			},
			"Open": true,
		},
		map[string]any{
			"Label": "Playgrounds",
			"Links": []any{
				map[string]any{
					"Href":  "/index.html#motion",
					"Label": "Motion",
				},
				map[string]any{
					"Href":  "/index.html#responsive",
					"Label": "Responsive layouts",
				},
			},
			"Open": false,
		},
	},
	"Title": "Studio workspace",
})
Rendered HTML
Rendered HTML
<nav data-mono="sidebar" id="demo-sidebar" class="mu-card mu-stack" aria-labelledby="demo-sidebar-heading">
  <h3 class="mu-label" id="demo-sidebar-heading">Studio workspace</h3>
  <details open><summary class="mu-small mu-disclosure">Resources</summary>
    <ul class="mu-list"><li><a href="/docs.html" aria-current="page">Documentation</a></li><li><a href="/icons.html" >Icon library</a></li></ul>
  </details><details ><summary class="mu-small mu-disclosure">Playgrounds</summary>
    <ul class="mu-list"><li><a href="/index.html#motion" >Motion</a></li><li><a href="/index.html#responsive" >Responsive layouts</a></li></ul>
  </details>
</nav>
Go template
Go template
<nav data-mono="sidebar" id="{{.ID}}" class="mu-card mu-stack" aria-labelledby="{{.ID}}-heading">
  <h3 class="mu-label" id="{{.ID}}-heading">{{.Title}}</h3>
  {{range .Groups}}<details {{if .Open}}open{{end}}><summary class="mu-small mu-disclosure">{{.Label}}</summary>
    <ul class="mu-list">{{range .Links}}<li><a href="{{.Href}}" {{if .Current}}aria-current="page"{{end}}>{{.Label}}</a></li>{{end}}</ul>
  </details>{{end}}
</nav>
Component CSS
Component CSS
[data-mono="sidebar"] { width:100%; max-width:16rem; }
[data-mono="sidebar"] details { border-top:1px solid #d7d7d7; padding-top:.55rem; }
[data-mono="sidebar"] ul { margin:.4rem 0 0; padding:0; }
[data-mono="sidebar"] a { display:block; padding:.35rem .55rem; color:inherit; border-radius:.22rem; text-decoration:none; font-size:.9rem; }
[data-mono="sidebar"] a:is(:hover,[aria-current]) { background:#eee; }
[data-mono="sidebar"] a[aria-current] { font-weight:650; }
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="./sidebar.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 sidebar
Example properties (JSON)
example.json
{
  "Groups": [
    {
      "Label": "Resources",
      "Links": [
        {
          "Current": true,
          "Href": "/docs.html",
          "Label": "Documentation"
        },
        {
          "Href": "/icons.html",
          "Label": "Icon library"
        }
      ],
      "Open": true
    },
    {
      "Label": "Playgrounds",
      "Links": [
        {
          "Href": "/index.html#motion",
          "Label": "Motion"
        },
        {
          "Href": "/index.html#responsive",
          "Label": "Responsive layouts"
        }
      ],
      "Open": false
    }
  ],
  "Title": "Studio workspace"
}