Components Layout
Resizable panels
Change the width of two neighboring panels with a pointer or the keyboard.
Outline
Draft · Revise · Publish
Page notes
Keep the outline nearby as you revise the introduction.
Usage
Set Initial to a percentage for the first panel, between 20 and 80. Drag the separator or focus it and press the arrow keys to move in five-percent steps. Home and End move it to either limit.
Register resizable with Head and pass its properties to Render. Go setup guide
Go usage
err := mono.UI.Render(w, "resizable", mono.Props{
"FirstBody": "Draft · Revise · Publish",
"FirstTitle": "Outline",
"Initial": 45,
"Label": "Workspace columns",
"SecondBody": "Keep the outline nearby as you revise the introduction.",
"SecondTitle": "Page notes",
})Rendered HTML
<section data-mono="resizable" id="demo-resizable" aria-label="Workspace columns" data-initial="45">
<section class="mu-pane" id="demo-resizable-first"><h3 class="mu-label">Outline</h3><p class="mu-muted mu-small">Draft · Revise · Publish</p></section>
<span role="separator" hidden tabindex="0" data-handle aria-controls="demo-resizable-first" aria-label="Outline width" aria-orientation="vertical" aria-valuemin="20" aria-valuemax="80"></span>
<section class="mu-pane"><h3 class="mu-label">Page notes</h3><p class="mu-muted mu-small">Keep the outline nearby as you revise the introduction.</p></section>
</section>Go template
<section data-mono="resizable" id="{{.ID}}" aria-label="{{.Label}}" data-initial="{{.Initial}}">
<section class="mu-pane" id="{{.ID}}-first"><h3 class="mu-label">{{.FirstTitle}}</h3><p class="mu-muted mu-small">{{.FirstBody}}</p></section>
<span role="separator" hidden tabindex="0" data-handle aria-controls="{{.ID}}-first" aria-label="{{.FirstTitle}} width" aria-orientation="vertical" aria-valuemin="20" aria-valuemax="80"></span>
<section class="mu-pane"><h3 class="mu-label">{{.SecondTitle}}</h3><p class="mu-muted mu-small">{{.SecondBody}}</p></section>
</section>Component CSS
[data-mono="resizable"] { display:grid; grid-template-columns:1fr 1fr; width:100%; min-height:7.5rem; border:1px solid #bbb; border-radius:.4rem; }
[data-mono="resizable"][data-mounted] { grid-template-columns:minmax(0,var(--mu-split,45%)) 1rem minmax(0,1fr); }
[data-mono="resizable"] .mu-pane { min-width:0; padding:.8rem; overflow-wrap:anywhere; }
[data-mono="resizable"] [data-handle] { position:relative; background:#eee; touch-action:none; cursor:col-resize; }
[data-mono="resizable"] [data-handle]::after { content:""; position:absolute; top:38%; bottom:38%; left:calc(50% - 1px); width:2px; border-radius:1rem; background:#888; }
[data-mono="resizable"] [data-handle]:focus-visible { z-index:1; outline:2px solid #171717; outline-offset:1px; }JavaScript module
export function mount(root) {
const handle = root.querySelector('[data-handle]');
let percent = 45;
let dragging = null;
function set(value) {
percent = Math.round(Math.max(20, Math.min(80, value)));
root.style.setProperty('--mu-split', percent + '%');
handle.setAttribute('aria-valuenow', String(percent));
handle.setAttribute('aria-valuetext', percent + ' percent');
}
handle.addEventListener('pointerdown', event => {
if (event.button !== 0 || dragging !== null) return;
dragging = event.pointerId;
handle.setPointerCapture(dragging);
handle.focus({ preventScroll: true });
});
handle.addEventListener('pointermove', event => {
if (event.pointerId !== dragging) return;
const rect = root.getBoundingClientRect();
if (!rect.width) return;
const rtl = getComputedStyle(root).direction === 'rtl';
const distance = rtl ? rect.right - event.clientX : event.clientX - rect.left;
set(100 * distance / rect.width);
});
handle.addEventListener('lostpointercapture', () => { dragging = null; });
handle.addEventListener('keydown', event => {
const step = getComputedStyle(root).direction === 'rtl' ? -5 : 5;
const targets = { ArrowLeft: percent - step, ArrowRight: percent + step, Home: 20, End: 80 };
if (!Object.hasOwn(targets, event.key)) return;
event.preventDefault();
set(targets[event.key]);
});
const initial = Number.parseFloat(root.dataset.initial);
set(Number.isFinite(initial) ? initial : 45);
root.dataset.mounted = '';
handle.hidden = false;
}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
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./resizable.css">
<script type="module" src="./resizable.js"></script>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 resizableExample properties (JSON)
{
"FirstBody": "Draft · Revise · Publish",
"FirstTitle": "Outline",
"Initial": 45,
"Label": "Workspace columns",
"SecondBody": "Keep the outline nearby as you revise the introduction.",
"SecondTitle": "Page notes"
}