Components Overlays

Hover card

Show a small profile on pointer hover or by activating its disclosure.

Live previewGo + JavaScript
Field Studio

Field Studio

An independent publishing studio working in print and digital editions.

Usage

Use Label for the trigger and Initials, Title, and Description for the profile. Activate the summary to pin the profile open. Escape dismisses the card. Native disclosure remains available without the module.

Register hover-card with Head and pass its properties to Render. Go setup guide

Go usage
Go usage
err := mono.UI.Render(w, "hover-card", mono.Props{
	"Description": "An independent publishing studio working in print and digital editions.",
	"Initials":    "FS",
	"Label":       "Field Studio",
	"Title":       "Field Studio",
})
Rendered HTML
Rendered HTML
<details id="demo-hover-card" data-mono="hover-card">
  <summary class="mu-btn">Field Studio</summary>
  <article class="mu-card mu-stack">
    <span class="mu-badge" aria-hidden="true">FS</span>
    <h3 class="mu-title">Field Studio</h3><p class="mu-muted">An independent publishing studio working in print and digital editions.</p>
  </article>
</details>
Go template
Go template
<details id="{{.ID}}" data-mono="hover-card">
  <summary class="mu-btn">{{.Label}}</summary>
  <article class="mu-card mu-stack">
    <span class="mu-badge" aria-hidden="true">{{.Initials}}</span>
    <h3 class="mu-title">{{.Title}}</h3><p class="mu-muted">{{.Description}}</p>
  </article>
</details>
Component CSS
Component CSS
[data-mono="hover-card"] { position: relative; width: fit-content; }
[data-mono="hover-card"] summary { list-style: none; }
[data-mono="hover-card"] summary::-webkit-details-marker { display: none; }
[data-mono="hover-card"] article { width: min(18rem, 72vw); max-width: 100%; margin-top: .45rem; }
[data-mono="hover-card"][open] { width: min(18rem, 100%); }
[data-mono="hover-card"] .mu-badge { align-self: flex-start; justify-self: start; }
JavaScript module
JavaScript module
export function mount(root) {
  const trigger = root.querySelector('summary');
  let pinned = root.open;
  let inside = false;

  function dismiss(event) {
    if (event.key === 'Escape' && root.open) {
      pinned = false;
      root.open = false;
      document.removeEventListener('keydown', dismiss);
    }
  }
  root.addEventListener('toggle', () => {
    if (root.open) document.addEventListener('keydown', dismiss);
    else document.removeEventListener('keydown', dismiss);
  });
  root.addEventListener('pointerenter', event => {
    if (event.pointerType === 'touch') return;
    inside = true;
    root.open = true;
  });
  root.addEventListener('pointerleave', () => {
    inside = false;
    if (!pinned && !root.contains(document.activeElement)) root.open = false;
  });
  trigger.addEventListener('click', event => {
    event.preventDefault();
    pinned = !pinned;
    root.open = pinned;
  });
  root.addEventListener('focusout', event => {
    if (!inside && !root.contains(event.relatedTarget)) {
      pinned = false;
      root.open = 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

HTML head
<link rel="stylesheet" href="./base.css">
<link rel="stylesheet" href="./hover-card.css">
<script type="module" src="./hover-card.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 hover-card
Example properties (JSON)
example.json
{
  "Description": "An independent publishing studio working in print and digital editions.",
  "Initials": "FS",
  "Label": "Field Studio",
  "Title": "Field Studio"
}