Try 'magnetic button'
View code

Number 97: Light that rides the border

Specification

Catalogue
No. 97 of 110
Interaction
Loading, Feedback
Element
Card, Form
Preview
Live component
Imports
react 19.3.1
Added

Notes

A band of coloured light travels round the edge of a box while something works inside it, then fades where it stands.

The box itself says it is busy, so the visitor keeps their eyes on the thing they asked for instead of hunting for a spinner.

One registered angle turns a conic gradient once every 1.96s, linear. A crisp copy is masked to a 1.5px ring on the edge; a soft copy is masked to a 10px ring and blurred 10px, so light spills a little way into the surface. The hues are the site's category colours, two lobes on opposite sides. On a card the beam turns while hovered and holds still otherwise; on the entry page it runs while the prompt works (3.6s) and fades out over 0.6s when the work is done. Under reduced motion the beam stands still.

Changed from the library: one family (rotate) and one look (glow), colours from the site's palette.

Code

React and plain CSS
"use client";

import { useEffect, useId, useState, type FormEvent } from "react";
import type { LivePreviewProps } from "@/components/live/types";
import styles from "./border-beam.module.css";

/** How long the entry page's prompt "works" before the beam fades away. */
const WORK_MS = 3600;

function Beam() {
  return (
    <>
      <span className={styles.glow} aria-hidden="true">
        <span className={styles.glowRing} />
      </span>
      <span className={styles.edge} aria-hidden="true" />
    </>
  );
}

/** The entry page: a prompt box that carries the beam while it works, then lets it go. */
function PromptBox() {
  const [working, setWorking] = useState(false);
  const [prompt, setPrompt] = useState("");
  const [done, setDone] = useState<string | null>(null);
  const inputId = useId();

  useEffect(() => {
    if (!working) return;
    const id = window.setTimeout(() => {
      setWorking(false);
      setDone(prompt.trim() || "A draft");
    }, WORK_MS);
    return () => window.clearTimeout(id);
  }, [working, prompt]);

  function submit(event: FormEvent<HTMLFormElement>) {
    event.preventDefault();
    if (working) return;
    setDone(null);
    setWorking(true);
  }

  return (
    <form className={styles.prompt} data-beam={working ? "on" : "off"} data-running={working || undefined} onSubmit={submit}>
      <Beam />
      <label className={styles.label} htmlFor={inputId}>
        Prompt
      </label>
      <input
        id={inputId}
        className={styles.input}
        value={prompt}
        onChange={(e) => setPrompt(e.target.value)}
        placeholder="A poster for the spring open day"
        autoComplete="off"
        readOnly={working}
      />
      <div className={styles.foot}>
        <p className={styles.note} aria-live="polite">
          {working ? "Working on it" : done ? `Ready: ${done}` : "The beam runs while it works"}
        </p>
        <button type="submit" className={styles.button} aria-disabled={working || undefined}>
          {working ? "Working" : "Generate"}
        </button>
      </div>
    </form>
  );
}

export default function BorderBeam({ active, context }: LivePreviewProps) {
  if (context === "detail") return <PromptBox />;
  return (
    <div className={styles.tile} data-beam="on" data-running={active || undefined}>
      <Beam />
    </div>
  );
}

More like this

Sign-up that hands over the next issue

Type, FeedbackForms and inputs

Huddle you can join

Press, FeedbackCards and accordions

Cookie choice that folds away

FeedbackOverlays and toasts

Was this helpful

FeedbackForms and inputs

Sign-up form that waits before it complains

Type, FeedbackForms and inputs

Code field that behaves as one input

Type, FeedbackForms and inputs