Coastline
A pocket atlas of tidal pools.
Components Data display
Browse an ordered set of slides with explicit previous and next controls.
A pocket atlas of tidal pools.
A study of the city after closing time.
Tools and experiments from the print room.
Supply Label and Slides. Each slide accepts Title, Body, and optional Kicker. Use the buttons or focus the carousel and press Left, Right, Home or End. Before enhancement all slides appear in reading order.
Register carousel with Head and pass its properties to Render. Go setup guide
err := mono.UI.Render(w, "carousel", mono.Props{
"Label": "Featured editions",
"Slides": []any{
map[string]any{
"Body": "A pocket atlas of tidal pools.",
"Kicker": "Field edition",
"Title": "Coastline",
},
map[string]any{
"Body": "A study of the city after closing time.",
"Kicker": "Photo essay",
"Title": "Night shift",
},
map[string]any{
"Body": "Tools and experiments from the print room.",
"Kicker": "Workshop notes",
"Title": "Open studio",
},
},
})<section data-mono="carousel" id="demo-carousel" aria-label="Featured editions" class="mu-stack">
<div class="mu-stack"><article class="mu-card mu-stack" data-slide>
<span class="mu-muted mu-small">Field edition</span>
<h3 class="mu-title">Coastline</h3><p>A pocket atlas of tidal pools.</p>
</article><article class="mu-card mu-stack" data-slide>
<span class="mu-muted mu-small">Photo essay</span>
<h3 class="mu-title">Night shift</h3><p>A study of the city after closing time.</p>
</article><article class="mu-card mu-stack" data-slide>
<span class="mu-muted mu-small">Workshop notes</span>
<h3 class="mu-title">Open studio</h3><p>Tools and experiments from the print room.</p>
</article></div>
<div data-controls hidden><button type="button" class="mu-btn" data-prev>Previous</button><span class="mu-small" data-position aria-live="polite"></span><button type="button" class="mu-btn" data-next>Next</button></div>
</section><section data-mono="carousel" id="{{.ID}}" aria-label="{{.Label}}" class="mu-stack">
<div class="mu-stack">{{range .Slides}}<article class="mu-card mu-stack" data-slide>
{{with .Kicker}}<span class="mu-muted mu-small">{{.}}</span>{{end}}
<h3 class="mu-title">{{.Title}}</h3><p>{{.Body}}</p>
</article>{{end}}</div>
<div data-controls hidden><button type="button" class="mu-btn" data-prev>Previous</button><span class="mu-small" data-position aria-live="polite"></span><button type="button" class="mu-btn" data-next>Next</button></div>
</section>[data-mono="carousel"] [data-slide] { padding:1.35rem; border-left:4px solid #202020; }
[data-mono="carousel"] [data-controls]:not([hidden]) { display:flex; flex-wrap:wrap; align-items:center; justify-content:space-between; gap:.55rem; }
[data-mono="carousel"] [data-slide][hidden] { display:none; }export function mount(root) {
const slides = [...root.querySelectorAll('[data-slide]')];
if (slides.length < 2) return;
const position = root.querySelector('[data-position]');
let index = 0;
function show(next) {
index = (next + slides.length) % slides.length;
slides.forEach((slide, i) => { slide.hidden = i !== index; });
position.textContent = 'Slide ' + (index + 1) + ' of ' + slides.length;
}
root.setAttribute('aria-roledescription', 'carousel');
root.tabIndex = 0;
root.querySelector('[data-next]').addEventListener('click', () => show(index + 1));
root.querySelector('[data-prev]').addEventListener('click', () => show(index - 1));
root.addEventListener('keydown', event => {
const targets = { ArrowRight: index + 1, ArrowLeft: index - 1, Home: 0, End: slides.length - 1 };
if (!Object.hasOwn(targets, event.key)) return;
event.preventDefault();
show(targets[event.key]);
});
root.querySelector('[data-controls]').hidden = false;
show(0);
}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
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./carousel.css">
<script type="module" src="./carousel.js"></script>Run this command from the Mono checkout. Set -out to the component directory in your application.
go run ./cmd/mono-ui add -out ./components carousel{
"Label": "Featured editions",
"Slides": [
{
"Body": "A pocket atlas of tidal pools.",
"Kicker": "Field edition",
"Title": "Coastline"
},
{
"Body": "A study of the city after closing time.",
"Kicker": "Photo essay",
"Title": "Night shift"
},
{
"Body": "Tools and experiments from the print room.",
"Kicker": "Workshop notes",
"Title": "Open studio"
}
]
}