Annotated product screenshots: notes that point at the real screen

Build a feature section where notes sit around one product screen and pointing at a note draws a leader line to the exact part it describes, which lifts, in React.

6 min read

The real component. Click the picture to open it live and try it before you read how it was built.

Feature grids list what a product does. An annotated screen shows where it lives. Point at a note and a thin line draws from it to the part of the screen it describes, and that part lifts.

The screen marks its own parts

The example screen is drawn in code, and the parts a note can point at carry a data-note attribute. Replace it with your own product's screen and keep the attributes.

Measuring the line

When the active note changes, a small hook measures the note's anchor dot and the near edge of the target part in the frame's own coordinates and returns an SVG path. It also marks the part as active so it can lift. Because it measures on change, the frame can scale freely.

src/registry/features/annotated-screen/use-leader-line.ts

"use client";

import { useLayoutEffect, useState, type RefObject } from "react";

export interface LeaderLine {
  path: string;
  // Where the line ends, for the small dot on the screen.
  end: { x: number; y: number };
}

// The path from the pointed-at note's anchor to the near edge of the screen part it describes, in the frame's own
// coordinates. It also marks that part with data-active, so the screen can lift it; the mark is removed when the
// note is let go. Measured when the note changes, so the frame may scale freely.
export function useLeaderLine(frameRef: RefObject<HTMLElement | null>, activeId: string | null): LeaderLine | null {
  const [line, setLine] = useState<LeaderLine | null>(null);

  useLayoutEffect(() => {
    const frame = frameRef.current;
    if (!frame || !activeId) return setLine(null);
    const anchor = frame.querySelector<HTMLElement>(`[data-anchor="${activeId}"]`);
    const target = frame.querySelector<HTMLElement>(`[data-note="${activeId}"]`);
    if (!anchor || !target) return setLine(null);
    target.setAttribute("data-active", "");
    const box = frame.getBoundingClientRect();
    const from = anchor.getBoundingClientRect();
    const to = target.getBoundingClientRect();
    const start = { x: from.left + from.width / 2 - box.left, y: from.top + from.height / 2 - box.top };
    const isLeft = start.x < to.left - box.left;
    const end = { x: (isLeft ? to.left : to.right) - box.left, y: to.top + to.height / 2 - box.top };
    const bend = (end.x - start.x) / 2;
    setLine({
      path: `M ${start.x} ${start.y} C ${start.x + bend} ${start.y}, ${end.x - bend} ${end.y}, ${end.x} ${end.y}`,
      end,
    });
    return () => target.removeAttribute("data-active");
  }, [frameRef, activeId]);

  return line;
}
The leader line hook

src/registry/features/annotated-screen/features-annotated-screen.tsx

"use client";

import { useRef, useState, type ReactNode } from "react";
import { AnimatePresence, MotionConfig, motion } from "motion/react";
import { ScaleToFit } from "@/components/ui/scale-to-fit";
import { EASE_OUT } from "@/lib/motion";
import { SectionHeading } from "@/components/ui/section-heading";
import { SectionColumn } from "@/components/ui/section-column";
import { NoteButton } from "./note-button";
import type { ScreenNote } from "./types";
import { useLeaderLine } from "./use-leader-line";

export interface FeaturesAnnotatedScreenProps {
  title: ReactNode;
  subtitle?: ReactNode;
  // Your product's screen. Mark each part a note talks about with data-note="<the note's id>", and give those parts
  // data-active: styles (they get the attribute while their note is pointed at).
  screen: ReactNode;
  // The width the screen is laid out at before it is scaled to fit, in px.
  screenWidth?: number;
  notes: ScreenNote[];
  className?: string;
}

// One real screen in the middle with short notes around it. Pointing at a note draws a thin line from it to the
// part of the screen it describes, and that part lifts, so the visitor sees exactly where each feature lives.
export function FeaturesAnnotatedScreen(props: FeaturesAnnotatedScreenProps) {
  const { title, subtitle, screen, screenWidth = 720, notes, className } = props;
  const [activeId, setActiveId] = useState<string | null>(null);
  const frameRef = useRef<HTMLDivElement>(null);
  const line = useLeaderLine(frameRef, activeId);
  const column = (side: ScreenNote["side"]) =>
    notes
      .filter((note) => note.side === side)
      .map((note) => <NoteButton key={note.id} note={note} isActive={note.id === activeId} onActivate={setActiveId} />);

  return (
    <MotionConfig reducedMotion="user">
      <SectionColumn isWide className={className}>
        <SectionHeading title={title} subtitle={subtitle} align="center" />
        <div
          ref={frameRef}
          onMouseLeave={() => setActiveId(null)}
          className="relative grid gap-6 lg:flex lg:items-center lg:gap-10"
        >
          <div className="order-2 grid gap-2 sm:grid-cols-2 lg:order-1 lg:w-56 lg:shrink-0 lg:grid-cols-1 lg:gap-16">
            {column("left")}
          </div>
          <ScaleToFit width={screenWidth} className="order-1 lg:order-2 lg:min-w-0 lg:flex-1">
            {screen}
          </ScaleToFit>
          <div className="order-3 grid gap-2 sm:grid-cols-2 lg:w-56 lg:shrink-0 lg:grid-cols-1 lg:gap-16">
            {column("right")}
          </div>
          <svg aria-hidden className="pointer-events-none absolute inset-0 hidden size-full overflow-visible lg:block">
            <AnimatePresence>
              {line && (
                <motion.g key={activeId} initial={{ opacity: 1 }} exit={{ opacity: 0, transition: { duration: 0.12 } }}>
                  <motion.path
                    d={line.path}
                    fill="none"
                    className="stroke-sky-600"
                    strokeWidth={1.5}
                    initial={{ pathLength: 0 }}
                    animate={{ pathLength: 1 }}
                    transition={{ duration: 0.45, ease: EASE_OUT }}
                  />
                  <circle cx={line.end.x} cy={line.end.y} r={3.5} className="fill-sky-600" />
                </motion.g>
              )}
            </AnimatePresence>
          </svg>
        </div>
      </SectionColumn>
    </MotionConfig>
  );
}
The section

More articles