Components Buttons

Eye Follow Button

Give a call to action a pair of eyes that follow the pointer and occasionally blink.

Live previewGo + JavaScript

Move your pointer to guide the eyes.

Eyes

Usage

Set Label to the action the reader can take. Supply Href to create a link, or omit it for a native button. Inside a form, set Type to submit or reset. Disabled turns off the action. Set EyeCount to 1 or 2, adjust pupil travel with Range from 0 to 1, and set Speed in milliseconds for a faster or slower response. Set Blink to false to keep the eyes open, or use BlinkIntensity from 0 to 1 to control how far they close. Links and form buttons work with the keyboard, on touchscreens, and with JavaScript disabled. Readers who prefer reduced motion see still eyes.

Register eye-follow-button with Head and pass its properties to Render. Go setup guide

Style the pill with --eye-button-bg, --eye-button-ink, --eye-button-padding, and --eye-button-radius. Use --eye-size, --eye-pupil-size, and --eye-gap for its proportions, or --eye-white and --eye-pupil-color for the eye and pupil colors.

Go usage
Go usage
err := mono.UI.Render(w, "eye-follow-button", mono.Props{
	"EyeCount": 2,
	"Href":     "../components/exhibit-gallery.html",
	"Label":    "View the gallery",
})
Rendered HTML
Rendered HTML
<a id="demo-eye-follow-button" data-mono="eye-follow-button" class="mu-eye-follow"
  
  
   href="../components/exhibit-gallery.html">
  <span class="mu-eye-label">View the gallery</span>
  <span class="mu-eye-pair" aria-hidden="true">
    <span class="mu-eye-socket" data-eye><span class="mu-eye-lid"><span class="mu-eye-pupil" data-pupil></span></span></span><span class="mu-eye-socket" data-eye><span class="mu-eye-lid"><span class="mu-eye-pupil" data-pupil></span></span></span>
  </span>
</a>
A single-eye submit button
A single-eye submit button
// Render inside a form. Enter and Space activate the native submit button.
err := mono.UI.Render(w, "eye-follow-button", mono.Props{
	"Label":    "Save changes",
	"Type":     "submit",
	"EyeCount": 1,
	"Range":    0.65,
	"Speed":    120,
	"Blink":    false,
})
Go template
Go template
{{define "eye-follow-attrs"}}id="{{.ID}}" data-mono="eye-follow-button" class="mu-eye-follow"
  {{if ne .Range nil}}data-range="{{.Range}}"{{end}}
  {{if eq (print .Blink) "false"}}data-blink="off"{{end}}
  {{if or (ne .Speed nil) (ne .BlinkIntensity nil)}}style="{{if ne .Speed nil}}--eye-speed:{{.Speed}}ms;{{end}}{{if ne .BlinkIntensity nil}}--eye-blink-intensity:{{.BlinkIntensity}};{{end}}"{{end}}{{end}}
{{define "eye-follow-socket"}}<span class="mu-eye-socket" data-eye><span class="mu-eye-lid"><span class="mu-eye-pupil" data-pupil></span></span></span>{{end}}
{{define "eye-follow-content"}}
  <span class="mu-eye-label">{{or .Label "Take a look"}}</span>
  <span class="mu-eye-pair" aria-hidden="true">
    {{template "eye-follow-socket"}}{{if ne (print .EyeCount) "1"}}{{template "eye-follow-socket"}}{{end}}
  </span>
{{end}}
{{if and .Href (not .Disabled)}}<a {{template "eye-follow-attrs" .}} href="{{.Href}}">{{template "eye-follow-content" .}}</a>
{{else}}<button {{template "eye-follow-attrs" .}} type="{{if eq .Type "submit" "reset"}}{{.Type}}{{else}}button{{end}}" {{if .Disabled}}disabled{{end}}>{{template "eye-follow-content" .}}</button>{{end}}
Component CSS
Component CSS
.mu-eye-follow[data-mono] {
  display: inline-flex;
  width: fit-content;
  max-width: 100%;
  min-height: 2.875em;
  align-items: center;
  justify-content: space-between;
  gap: .75em;
  padding: var(--eye-button-padding, .3125em .3125em .3125em 1.25em);
  border: 0;
  border-radius: var(--eye-button-radius, 999px);
  appearance: none;
  background: var(--eye-button-bg, #101010);
  color: var(--eye-button-ink, #fff);
  box-shadow: 0 .14em .22em #0002, 0 .03em .08em #0002;
  font: 600 1rem/1.2 Inter, "Helvetica Neue", Arial, sans-serif;
  letter-spacing: -.025em;
  text-align: start;
  text-decoration: none;
  vertical-align: middle;
  cursor: pointer;
}
.mu-eye-follow:focus-visible {
  outline: 2px solid #141414;
  outline-offset: 3px;
  box-shadow: 0 0 0 3px #fff;
}
.mu-eye-follow:active:not(:disabled) { box-shadow: none; }
.mu-eye-follow:disabled { cursor: not-allowed; opacity: .55; }
.mu-eye-label { min-width: 0; overflow-wrap: anywhere; }
.mu-eye-pair { display: inline-flex; flex: none; align-items: center; gap: var(--eye-gap, .25em); }
.mu-eye-socket {
  display: grid;
  width: var(--eye-size, 2.1875em);
  aspect-ratio: 1;
}
.mu-eye-lid {
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 50%;
  background: var(--eye-white, #fff);
}
.mu-eye-pupil {
  width: min(100%, var(--eye-pupil-size, .68em));
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--eye-pupil-color, #111);
  transform: translate(var(--eye-x, 0px), var(--eye-y, 0px));
  transition: transform max(0ms, var(--eye-speed, 90ms)) ease-out;
}
@media (prefers-reduced-motion: no-preference) {
  .mu-eye-follow:not(:disabled, [data-blink="off"]) .mu-eye-lid {
    animation: mu-eye-blink 5.4s ease-in-out infinite;
  }
  @keyframes mu-eye-blink {
    0%, 92%, 96%, 100% { transform: scaleY(1); }
    94% { transform: scaleY(calc(1 - clamp(0, var(--eye-blink-intensity, .96), 1))); }
  }
}
@media (prefers-reduced-motion: reduce) {
  .mu-eye-pupil { transition: none; transform: none; }
}
@media (forced-colors: active) {
  .mu-eye-follow[data-mono] { border: 1px solid ButtonText; box-shadow: none; }
  .mu-eye-follow:focus-visible { outline-color: Highlight; }
  .mu-eye-lid { forced-color-adjust: none; background: ButtonText; }
  .mu-eye-pupil { background: ButtonFace; }
}
JavaScript module
JavaScript module
const active = new Set();
const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
let listeners;
let pointer;
let frame;

function center(eyes) {
  for (const { pupil } of eyes) {
    pupil.style.removeProperty('--eye-x');
    pupil.style.removeProperty('--eye-y');
  }
}

function resetPointer() {
  if (!pointer && !frame) return;
  pointer = null;
  cancelAnimationFrame(frame);
  frame = 0;
  for (const button of active) center(button.eyes);
}

function draw() {
  frame = 0;
  if (!pointer) return;
  const positions = [];
  // Measure all visible eyes before writing any transforms.
  for (const { eyes, range } of active) {
    for (const { socket, pupil } of eyes) {
      const rect = socket.getBoundingClientRect();
      const dx = pointer.x - (rect.left + rect.width / 2);
      const dy = pointer.y - (rect.top + rect.height / 2);
      const distance = Math.max(Math.hypot(dx, dy), rect.width * 1.5, 1);
      const radiusX = Math.max(0, (socket.clientWidth - pupil.offsetWidth) / 2);
      const radiusY = Math.max(0, (socket.clientHeight - pupil.offsetHeight) / 2);
      positions.push({ pupil, x: dx / distance * radiusX * range, y: dy / distance * radiusY * range });
    }
  }
  for (const { pupil, x, y } of positions) {
    pupil.style.setProperty('--eye-x', x.toFixed(2) + 'px');
    pupil.style.setProperty('--eye-y', y.toFixed(2) + 'px');
  }
}

function schedule() {
  if (pointer && !frame) frame = requestAnimationFrame(draw);
}

function syncListeners() {
  if (!active.size) {
    listeners?.abort();
    listeners = null;
    resetPointer();
    return;
  }
  if (listeners) return;
  listeners = new AbortController();
  const options = { passive: true, signal: listeners.signal };
  window.addEventListener('pointermove', event => {
    if (event.pointerType === 'touch') { resetPointer(); return; }
    pointer = { x: event.clientX, y: event.clientY };
    schedule();
  }, options);
  window.addEventListener('pointerdown', event => {
    if (event.pointerType === 'touch') resetPointer();
  }, options);
  window.addEventListener('pointerout', event => {
    if (!event.relatedTarget) resetPointer();
  }, options);
  window.addEventListener('blur', resetPointer, options);
  window.addEventListener('resize', schedule, options);
  window.addEventListener('scroll', schedule, { ...options, capture: true });
  document.addEventListener('visibilitychange', () => {
    if (document.hidden) resetPointer();
  }, options);
}

export function mount(root) {
  if (!('IntersectionObserver' in window)) return;
  const eyes = Array.from(root.querySelectorAll('[data-eye]'), socket => ({
    socket, pupil: socket.querySelector('[data-pupil]'),
  })).filter(eye => eye.pupil);
  const value = root.getAttribute('data-range')?.trim();
  const range = value && Number.isFinite(Number(value)) ? Math.min(1, Math.max(0, Number(value))) : .9;
  if (!eyes.length || !range) return;
  const button = { eyes, range };
  let visible = false;

  function syncButton() {
    const enabled = visible && root.isConnected && !reducedMotion.matches
      && !root.matches(':disabled, [aria-disabled="true"]');
    if (enabled === active.has(button)) return;
    if (enabled) {
      active.add(button);
      schedule();
    } else {
      active.delete(button);
      center(eyes);
    }
    syncListeners();
  }

  const attributes = new MutationObserver(syncButton);
  const viewport = new IntersectionObserver(entries => {
    visible = entries[entries.length - 1].isIntersecting;
    if (visible) {
      reducedMotion.addEventListener('change', syncButton);
      attributes.observe(root, { attributes: true, attributeFilter: ['disabled', 'aria-disabled'] });
    } else {
      reducedMotion.removeEventListener('change', syncButton);
      attributes.disconnect();
    }
    syncButton();
  });
  viewport.observe(root);
}
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="./eye-follow-button.css">
<script type="module" src="./eye-follow-button.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 eye-follow-button
Example properties (JSON)
example.json
{
  "EyeCount": 2,
  "Href": "../components/exhibit-gallery.html",
  "Label": "View the gallery"
}