hover-ui

Frame

Viewfinder corners around the pointer that snap to frame whatever clickable thing you hover.

npx shadcn@latest add https://hoverui.fun/r/frame.json

Adds components/cursors/frame.tsx. The CLI also installs the useCursor hook it runs on, once, into your hooks folder. The files are yours from there.

Move through the preview, then hover the controls and press.

Kind
Marks
Dependencies
None
License
MIT

Usage

Any element
import { FrameCursor } from "@/components/cursors/frame";

export function Section() {
  return (
    <section>
      <FrameCursor />
      {/* this section now wears Frame */}
    </section>
  );
}

Put it inside <body> in your root layout to wear it on every page. Nested cursors take over inside their own element.

Props

className
Colors the cursor through currentColor, e.g. text-pink-500. To read on any background, pass text-white mix-blend-difference, as this site does.
Hover targets
a, button, input, select, textarea, label, [role=button], [data-cursor-label]

Source

frame.tsx
"use client";

import { useRef } from "react";
import { cursorRoot, useCursor } from "@/hooks/use-cursor";

/** Viewfinder corners around the pointer that snap to frame whatever clickable thing you hover. */
export function FrameCursor({ className = "" }: { className?: string }) {
  const s = useRef({ l: 0, t: 0, r: 0, b: 0 });
  const ref = useCursor((p, el) => {
    const st = s.current;
    const box = p.hover?.getBoundingClientRect();
    const [l, t, r, b] = box ? [box.left - 6, box.top - 6, box.right + 6, box.bottom + 6] : [p.x - 12, p.y - 12, p.x + 12, p.y + 12];
    const k = p.ease(18);
    st.l += (l - st.l) * k;
    st.t += (t - st.t) * k;
    st.r += (r - st.r) * k;
    st.b += (b - st.b) * k;
    const [tl, tr, bl, br, dot] = el.children as HTMLCollectionOf<HTMLElement>;
    tl.style.transform = `translate(${st.l}px, ${st.t}px)`;
    tr.style.transform = `translate(${st.r}px, ${st.t}px)`;
    bl.style.transform = `translate(${st.l}px, ${st.b}px)`;
    br.style.transform = `translate(${st.r}px, ${st.b}px)`;
    dot.style.transform = `translate(${p.x}px, ${p.y}px)`;
  });

  return (
    <div ref={ref} aria-hidden className={`${cursorRoot} ${className}`}>
      <div className="absolute size-2 border-t border-l border-current" />
      <div className="absolute size-2 -translate-x-full border-t border-r border-current" />
      <div className="absolute size-2 -translate-y-full border-b border-l border-current" />
      <div className="absolute size-2 -translate-full border-r border-b border-current" />
      <div className="absolute size-1 -translate-1/2 rounded-full bg-current" />
    </div>
  );
}

It runs on the useCursor hook, which has its own source and API.

More marks cursors

Made a cursor of your own? Contributed cursors carry their maker's name on their page.

Contribute a cursor