Components Data display

Message scroller

Read a chronological transcript and jump directly to the latest message.

Live previewGo + JavaScript

Proof discussion

  1. Ada

    The first spread is ready for review.

  2. Morgan

    Checking the margin and title size now.

  3. Ada

    I have a second cover sample as well.

  4. Morgan

    Please send the version on uncoated stock.

  5. Ada

    It is in the studio folder.

Usage

Keep Messages in chronological order. The enhanced view opens at the latest entry and follows new additions while the reader is near the bottom. Scrolling back preserves their position. Add new list items to the log to announce incoming messages.

Register message-scroller with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "message-scroller", mono.Props{
	"Messages": []any{
		map[string]any{
			"Author": "Ada",
			"Text":   "The first spread is ready for review.",
		},
		map[string]any{
			"Author": "Morgan",
			"Text":   "Checking the margin and title size now.",
		},
		map[string]any{
			"Author": "Ada",
			"Text":   "I have a second cover sample as well.",
		},
		map[string]any{
			"Author": "Morgan",
			"Text":   "Please send the version on uncoated stock.",
		},
		map[string]any{
			"Author": "Ada",
			"Text":   "It is in the studio folder.",
		},
	},
	"Title": "Proof discussion",
})
Rendered HTML
Rendered HTML
<section data-mono="message-scroller" id="demo-message-scroller" class="mu-card mu-stack" aria-labelledby="demo-message-scroller-heading">
  <h3 class="mu-label" id="demo-message-scroller-heading">Proof discussion</h3>
  <div class="mu-transcript" data-log role="log" aria-labelledby="demo-message-scroller-heading" aria-live="polite" aria-relevant="additions" tabindex="0">
    <ol class="mu-list"><li><strong class="mu-small">Ada</strong><p>The first spread is ready for review.</p></li><li><strong class="mu-small">Morgan</strong><p>Checking the margin and title size now.</p></li><li><strong class="mu-small">Ada</strong><p>I have a second cover sample as well.</p></li><li><strong class="mu-small">Morgan</strong><p>Please send the version on uncoated stock.</p></li><li><strong class="mu-small">Ada</strong><p>It is in the studio folder.</p></li></ol>
  </div>
  <div><button data-latest type="button" class="mu-btn" hidden>Jump to latest</button></div>
</section>
Go template
Go template
<section data-mono="message-scroller" id="{{.ID}}" class="mu-card mu-stack" aria-labelledby="{{.ID}}-heading">
  <h3 class="mu-label" id="{{.ID}}-heading">{{.Title}}</h3>
  <div class="mu-transcript" data-log role="log" aria-labelledby="{{.ID}}-heading" aria-live="polite" aria-relevant="additions" tabindex="0">
    <ol class="mu-list">{{range .Messages}}<li><strong class="mu-small">{{.Author}}</strong><p>{{.Text}}</p></li>{{end}}</ol>
  </div>
  <div><button data-latest type="button" class="mu-btn" hidden>Jump to latest</button></div>
</section>
Component CSS
Component CSS
[data-mono="message-scroller"] .mu-transcript { max-height:10rem; overflow:auto; overscroll-behavior:contain; scrollbar-width:thin; }
[data-mono="message-scroller"] ol { margin:0; padding:0; list-style:none; }
[data-mono="message-scroller"] li { padding:.45rem .6rem; border-top:1px solid #ddd; overflow-wrap:anywhere; }
[data-mono="message-scroller"] .mu-transcript:focus-visible { outline:2px solid currentColor; outline-offset:2px; }
JavaScript module
JavaScript module
export function mount(root) {
  const log = root.querySelector('[data-log]');
  const latest = root.querySelector('[data-latest]');
  const list = log.querySelector('ol');
  let follow = true;
  const update = () => {
    follow = log.scrollHeight - log.scrollTop - log.clientHeight <= 3;
    latest.disabled = follow;
  };
  function bottom() {
    log.scrollTop = log.scrollHeight;
    update();
  }
  latest.hidden = false;
  latest.addEventListener('click', () => { bottom(); log.focus({ preventScroll: true }); });
  log.addEventListener('scroll', update, { passive: true });
  const observer = new MutationObserver(() => {
    if (follow) bottom();
    else update();
  });
  observer.observe(list, { childList: true });
  bottom();
}
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="./message-scroller.css">
<script type="module" src="./message-scroller.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 message-scroller
Example properties (JSON)
example.json
{
  "Messages": [
    {
      "Author": "Ada",
      "Text": "The first spread is ready for review."
    },
    {
      "Author": "Morgan",
      "Text": "Checking the margin and title size now."
    },
    {
      "Author": "Ada",
      "Text": "I have a second cover sample as well."
    },
    {
      "Author": "Morgan",
      "Text": "Please send the version on uncoated stock."
    },
    {
      "Author": "Ada",
      "Text": "It is in the studio folder."
    }
  ],
  "Title": "Proof discussion"
}