Try 'magnetic button'
View code

Number 40: Contact sheet for picking photos

Specification

Catalogue
No. 40 of 110
Interaction
Press
Element
Media, Picker
Preview
Live component
Imports
react 19.3.1
Added

Notes

A photographer's client circles the frames they want and strikes out the rest, with a larger view of each.

Proofing done on the site instead of by email: every frame keeps its ID, a choice is marked with a shape as well as colour, and the counts are always in view.

Selected: a ring in the brand colour; rejected: struck through and faded; both also said in words. Arrow keys move through the grid, S selects, X rejects. Under 480px wide the larger view is dropped and the grid fills the width. Changed from the library: no film-strip decoration.

The names, figures and pictures in the demo are sample content; a real build uses the client's own.

Code

React and plain CSS
"use client";

import { useRef, useState, type CSSProperties, type KeyboardEvent } from "react";
import type { LivePreviewProps } from "@/components/live/types";
import { PieceStage } from "@/components/pieces/stage/PieceStage";
import type { Tour } from "@/components/pieces/stage/tour";
import "./contact-sheet.css";

const S = "/samples";

type Mark = "select" | "reject" | undefined;

const FRAMES = Array.from({ length: 12 }, (_, i) => ({
  id: `R2-${String(14 + i).padStart(3, "0")}`,
  // Each frame a slightly different crop and exposure of the same set-up.
  style: {
    transform: `scale(${1.15 + (i % 4) * 0.12}) translate(${((i * 7) % 11) - 5}%, ${((i * 5) % 9) - 3}%)`,
    filter: `brightness(${0.9 + ((i * 3) % 5) * 0.05})`,
  } as CSSProperties,
}));

const COLS = 4;

function ContactSheetDemo() {
  const [cur, setCur] = useState(0);
  const [marks, setMarks] = useState<Record<string, Mark>>({ "R2-016": "select", "R2-019": "reject" });
  const btns = useRef<(HTMLButtonElement | null)[]>([]);
  const mark = (m: Mark) => {
    const id = FRAMES[cur]!.id;
    setMarks((x) => ({ ...x, [id]: x[id] === m ? undefined : m }));
  };
  const move = (i: number) => {
    setCur(i);
    btns.current[i]?.focus();
  };
  const onKey = (e: KeyboardEvent, i: number) => {
    const map: Record<string, number> = { ArrowRight: i + 1, ArrowLeft: i - 1, ArrowDown: i + COLS, ArrowUp: i - COLS };
    if (e.key in map) {
      e.preventDefault();
      const n = map[e.key];
      if (n !== undefined && n >= 0 && n < FRAMES.length) move(n);
    } else if (e.key.toLowerCase() === "s") mark("select");
    else if (e.key.toLowerCase() === "x") mark("reject");
  };
  const counts = Object.values(marks).reduce((c, m) => (m ? { ...c, [m]: c[m] + 1 } : c), { select: 0, reject: 0 });
  const f = FRAMES[cur]!;
  const m = marks[f.id];

  return (
    <div className="dm">
      <div className="cs">
        <div className="cs-loupe" aria-hidden="true">
          <div className="cs-shot" data-mark={m}>
            <img src={`${S}/studio-flowers.svg`} alt="" style={f.style} />
          </div>
          <span>{f.id}</span>
        </div>
        <div className="cs-side">
          <div className="cs-grid" role="grid" aria-label="Frames from the shoot. Arrow keys move, S selects, X rejects">
            {[0, 1, 2].map((r) => (
              <div key={r} role="row" className="cs-row">
                {FRAMES.slice(r * COLS, r * COLS + COLS).map((fr, k) => {
                  const i = r * COLS + k;
                  const mk = marks[fr.id];
                  return (
                    <div key={fr.id} role="gridcell">
                      <button
                        ref={(el) => {
                          btns.current[i] = el;
                        }}
                        type="button"
                        className="cs-frame"
                        tabIndex={i === cur ? 0 : -1}
                        aria-current={i === cur || undefined}
                        data-mark={mk}
                        aria-label={`Frame ${fr.id}${mk === "select" ? ", selected" : mk === "reject" ? ", rejected" : ""}`}
                        onClick={() => setCur(i)}
                        onKeyDown={(e) => onKey(e, i)}
                      >
                        <img src={`${S}/studio-flowers.svg`} alt="" style={fr.style} />
                      </button>
                    </div>
                  );
                })}
              </div>
            ))}
          </div>
          <div className="cs-actions">
            <button type="button" className="dm-btn" aria-pressed={m === "select"} onClick={() => mark("select")}>
              Select
            </button>
            <button type="button" className="dm-btn" aria-pressed={m === "reject"} onClick={() => mark("reject")}>
              Reject
            </button>
            <p className="dm-small" aria-live="polite">
              {f.id}: {m === "select" ? "Selected" : m === "reject" ? "Rejected" : "Not marked"} · {counts.select} selected, {counts.reject} rejected
            </p>
          </div>
        </div>
      </div>
    </div>
  );
}

// What a hovered card shows: the piece used the way a visitor would.
const TOUR: Tour = [
  { click: ".cs-frame", nth: 5, wait: 700 },
  { click: ".dm-btn", text: "Select" },
  { click: ".cs-frame", nth: 9, wait: 700 },
  { click: ".dm-btn", text: "Reject" },
];

export default function ContactSheetEntry(props: LivePreviewProps) {
  return (
    <PieceStage {...props} label="Contact sheet for picking photos" sample tour={TOUR}>
      <ContactSheetDemo />
    </PieceStage>
  );
}

More like this

Card stack that deals the next picture

Press, Layout AnimationMedia and galleries

Bookshelf

Press, Layout AnimationMedia and galleries

Image panels that widen

Hover, Layout AnimationMedia and galleries

Photo grid that opens into the photo

Layout AnimationMedia and galleries

A photo for each option

PressTabs

Before and after slider

DragMedia and galleries