Frame
Viewfinder corners around the pointer that snap to frame whatever clickable thing you hover.
npx shadcn@latest add https://hoverui.fun/ r/ frame.jsonAdds 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.Open this on a computer to move it around: it follows a mouse, not a finger.
- Kind
- Marks
- Hook
- useCursor
- Dependencies
- None
- License
- MIT
Usage
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
"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
- RegisterA printer's registration mark. Exact crosshair; the ring opens and fills over anything clickable.
- StampA rubber stamp that lifts over controls and leaves a fading inked seal on every click.
- CaretA text caret sized to the line beneath it that blinks when you stop. A block caret over controls.
- HalftoneA halftone dot screen round the pointer. Over controls it turns to the next ink's angle; hold to spread the ink, click to pulse.
- PenA fountain pen that writes your path in ink, thick and thin as the nib turns, fading as it dries. It underlines controls with a flourish; a click leaves a blot.
Made a cursor of your own? Contributed cursors carry their maker's name on their page.
Contribute a cursor