Image Hotspot | Numbered Pins on a Photo to Guide a Shop or Product
An image hotspot block: numbered pins on a single photo of a shop, showroom or product, each opening a note about that spot. Swap the image URL, the original image size, each pin's fractional coordinates and the note text, and it works as a store guide, a product feature tour, highlights of a property or guest room, or an exhibit explainer. It loads with one note already open, and the open pin and the note's number share the same amber square so the link between them is obvious. Opening and closing take 180 ms; with reduced motion they switch instantly. React + Tailwind CSS with no dependencies — edit the usage example at the top of the code panel, or pull it in with the npx shadcn command below. Under the hood, pin positions are stored as fractions of the original image and the frame uses container-type: size so CSS calc with cqw/cqh reproduces the object-fit: cover math; change the crop (2:1, 3:2, 4:3) and every pin stays on the same object. Pins are buttons with aria-expanded and aria-controls; arrow keys and Home/End move between them, and Escape or the close button returns focus to the pin. When the frame is narrow or pins sit close together, pins become 24×24 px number tags and the note moves below the photo instead of covering it. The same notes are listed under the photo as a numbered list for screen readers and print.
Preview
店内の6か所を写真でご案内
番号を押すと、その場所の説明が開きます
06 か所

02焙煎機
毎週火曜と金曜の朝に、その週に出す豆を店内で焼いています。焼いている間は香りが店の外まで届きます。
02 / 06
1. 窓際の2人席
朝は窓から光が入る、向かい合わせの2人席です。足元にコンセントが1口あります。
2. 焙煎機
毎週火曜と金曜の朝に、その週に出す豆を店内で焼いています。焼いている間は香りが店の外まで届きます。
3. グラインダー
注文を受けてから1杯分だけ挽きます。挽き目は豆の種類と淹れ方に合わせて変えています。
4. エスプレッソマシン
2杯を同時に抽出できます。ラテなどミルクを使う飲み物も、ここで泡立てて仕上げます。
5. 豆の棚
常に7種類の豆を置いています。瓶の中の豆の色で焙煎の深さを見比べられ、100gから量り売りします。
6. 焼き菓子のケース
クロワッサンとマフィンは近くのパン屋から毎朝届きます。売り切れた時点で終わりです。
狭い画面で小さくした番号も 24×24px 以上にしています(出典: W3C「WCAG 2.2」達成基準 2.5.8 ターゲットのサイズ(最低限)、2026年11月4日確認)。写真と説明は表示サンプルです。
Read the full description
An image hotspot block: numbered pins on a single photo of a shop, showroom or product, each opening a note about that spot. Swap the image URL, the original image size, each pin's fractional coordinates and the note text, and it works as a store guide, a product feature tour, highlights of a property or guest room, or an exhibit explainer. It loads with one note already open, and the open pin and the note's number share the same amber square so the link between them is obvious. Opening and closing take 180 ms; with reduced motion they switch instantly. React + Tailwind CSS with no dependencies — edit the usage example at the top of the code panel, or pull it in with the npx shadcn command below. Under the hood, pin positions are stored as fractions of the original image and the frame uses container-type: size so CSS calc with cqw/cqh reproduces the object-fit: cover math; change the crop (2:1, 3:2, 4:3) and every pin stays on the same object. Pins are buttons with aria-expanded and aria-controls; arrow keys and Home/End move between them, and Escape or the close button returns focus to the pin. When the frame is narrow or pins sit close together, pins become 24×24 px number tags and the note moves below the photo instead of covering it. The same notes are listed under the photo as a numbered list for screen readers and print.
- Added:
- 2026-10-18
- Updated:
- 2026-11-04
- Dependencies:
- None
- tags
- #image-hotspot #hotspot #annotation #photo #store-guide #product-tour #disclosure #container-query #object-fit #keyboard #a11y #print #react #tailwind #no-dependency
/**
* 使い方(自分の写真に差し替えるときは、ここに並べた値だけを書き換える)
*
* import ImageHotspotTour from "@/components/first-ch/image-hotspot-tour";
*
* <ImageHotspotTour
* heading="ショールームの見どころ"
* guide="番号を押すと、その場所の説明が開きます"
* photo={{
* src: "/images/showroom.webp", // 画像のURL
* w: 1600, // 元画像の幅(px)
* h: 1067, // 元画像の高さ(px)
* alt: "ショールームの全景。左に受付、中央に展示棚、右奥に試着室がある",
* }}
* spots={[
* // 番号は配列の順(01, 02, …)。x・y は元画像の幅・高さに対する割合(0〜1)
* { x: 0.22, y: 0.48, title: "受付", body: "ご予約のお名前をお伝えください。" },
* { x: 0.55, y: 0.36, title: "展示棚", body: "新作は毎月1日に入れ替えます。" },
* { x: 0.83, y: 0.6, title: "試着室", body: "2室あり、鏡は全身が映ります。" },
* ]}
* initialOpen={0} // 最初に開いておく番号(0始まり)。何も開かないなら null
* />
*
* 割合の求め方: 画像編集ソフトで物の中心の座標(px)を読み、x = 横の座標 ÷ 元画像の幅、y = 縦の座標 ÷ 元画像の高さ。
* 以下が完全な実装です(このファイルをそのまま置けば動きます。依存ライブラリなし)。
*/
"use client";
import {
useEffect,
useId,
useLayoutEffect,
useRef,
useState,
useSyncExternalStore,
type CSSProperties,
type KeyboardEvent,
} from "react";
/**
* 画像ホットスポット(Image Hotspot)(BLK-101)
*
* 差別化: isometric-floor-map は自作の立体模型を自由に見て回る型、coachmark-product-tour は画面の部品を決まった順に
* 照らす操作案内で、実写1枚に注釈を重ねる型は無かった。本ブロックは写真に対する割合で持った点を、切り抜き方を
* 変えても同じ物の上に置き続け、同じ説明を写真の下の番号付きリストにも出す。英字キッカー・末尾の矢印リンク・角丸は外した。
*
* 汎用技法メモ:
* 1) 切り抜いても点がずれない座標: 点は元写真に対する割合 (x, y) で持つ。写真の枠を container-type: size にし、
* object-fit: cover で描かれる写真の大きさを CSS だけで再現する。
* --dw: max(100cqw, 100cqh * 縦横比) --dh: max(100cqh, 100cqw / 縦横比)
* left: calc((100cqw - var(--dw)) * 焦点x + var(--dw) * x) top も同様
* 焦点は object-position と同じ値にする。JS で測らないので、サーバー描画の時点から位置が合っている。
* 2) 狭いときの切り替え: ResizeObserver で枠の大きさを受け、同じ式で点どうしの最短距離を出す。
* 枠が狭い・点が近すぎる・点が枠の外に出たときは、点を小さな番号だけにして説明を写真の下に出す(吹き出しで写真を隠さない)。
* 小さくした点も 24×24px を下回らない(WCAG 2.2 達成基準 2.5.8 の下限)。
* 3) 選択の対応: 開いている点と、説明の見出しの番号を同じアンバーの四角にし、一覧の該当項目もアンバーにする。
* 最初から1件を開いておき(initialOpen)、押すと説明が出る仕組みを静止画の時点で見せる。
* 4) 開閉の作法: 点は名前つきの button で aria-expanded と aria-controls を持つ開閉ボタン。開いてもフォーカスは点に残し、
* Tab で次に説明の中のボタンへ進めるよう、吹き出しは点の直後に置く。前へ・次へは押したボタンへフォーカスを戻し、
* 閉じるボタンと Esc は点へフォーカスを返す。点の上の左右キーで前後の点へ移る。
* 出るときは @starting-style(Tailwind の starting:)、消えるときは 180ms だけ残してから外し、どちらも opacity と
* transform だけを動かす。prefers-reduced-motion: reduce では残さずにすぐ消し、出るときも動かさない。
*/
export type Spot = { x: number; y: number; title: string; body: string };
export type Photo = { src: string; w: number; h: number; alt: string };
export const DEFAULT_PHOTO: Photo = {
src: "/designs/image-hotspot-tour.webp",
w: 1536,
h: 1024,
alt: "自家焙煎のコーヒースタンドの店内。左の大きな窓際に木の2人席、奥の壁際に黒い焙煎機、中央の木のカウンターにグラインダーとエスプレッソマシン、右の壁の棚に豆の入ったガラス瓶、カウンターの右端に焼き菓子のケースがある",
};
export const DEFAULT_SPOTS: Spot[] = [
{
x: 0.15,
y: 0.56,
title: "窓際の2人席",
body: "朝は窓から光が入る、向かい合わせの2人席です。足元にコンセントが1口あります。",
},
{
x: 0.31,
y: 0.39,
title: "焙煎機",
body: "毎週火曜と金曜の朝に、その週に出す豆を店内で焼いています。焼いている間は香りが店の外まで届きます。",
},
{
x: 0.485,
y: 0.4,
title: "グラインダー",
body: "注文を受けてから1杯分だけ挽きます。挽き目は豆の種類と淹れ方に合わせて変えています。",
},
{
x: 0.62,
y: 0.46,
title: "エスプレッソマシン",
body: "2杯を同時に抽出できます。ラテなどミルクを使う飲み物も、ここで泡立てて仕上げます。",
},
{
x: 0.83,
y: 0.25,
title: "豆の棚",
body: "常に7種類の豆を置いています。瓶の中の豆の色で焙煎の深さを見比べられ、100gから量り売りします。",
},
{
x: 0.88,
y: 0.55,
title: "焼き菓子のケース",
body: "クロワッサンとマフィンは近くのパン屋から毎朝届きます。売り切れた時点で終わりです。",
},
];
const pad = (n: number) => String(n).padStart(2, "0");
const gcd = (a: number, b: number): number => (b ? gcd(b, a % b) : a);
type Frame = { id: string; label: string; ratio: string; ar: number };
function framesFor(photo: Photo): Frame[] {
const g = gcd(photo.w, photo.h) || 1;
return [
{ id: "wide", label: "横長", ratio: "2:1", ar: 2 },
{ id: "photo", label: "元の比率", ratio: `${photo.w / g}:${photo.h / g}`, ar: photo.w / photo.h },
{ id: "std", label: "標準", ratio: "4:3", ar: 4 / 3 },
];
}
/** 枠より狭い・点がこれより近いときは番号だけの点にして、説明を写真の下に出す */
const COMPACT_WIDTH = 600;
const MIN_GAP = 44;
/** 説明を閉じるときに残す時間(ms)。transition の duration と同じ値 */
const LEAVE_MS = 180;
const NARROW_QUERY = "(max-width: 639px)";
const isNarrow = () => window.matchMedia(NARROW_QUERY).matches;
function subscribeNarrow(cb: () => void) {
const mq = window.matchMedia(NARROW_QUERY);
mq.addEventListener("change", cb);
return () => mq.removeEventListener("change", cb);
}
const reducedMotion = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches;
type Layout = { w: number; h: number; pts: { x: number; y: number; inside: boolean }[] };
/** object-fit: cover と同じ計算で、枠の中での点の位置を出す(CSS の calc と同じ式) */
export function layoutFor(w: number, h: number, photo: Photo, spots: Spot[], focus: { x: number; y: number }): Layout {
const ar = photo.w / photo.h;
const dw = Math.max(w, h * ar);
const dh = Math.max(h, w / ar);
const pts = spots.map((s) => {
const x = (w - dw) * focus.x + dw * s.x;
const y = (h - dh) * focus.y + dh * s.y;
return { x, y, inside: x >= 12 && x <= w - 12 && y >= 12 && y <= h - 12 };
});
return { w, h, pts };
}
/** 吹き出しの幅(px)。w-[17rem] と同じ値 */
const BUBBLE_W = 272;
/**
* 吹き出しの置き場所を選ぶ。点の右・左(上下2通り)と、真下・真上(点の上に掛かる範囲で横へずらしながら)を試し、
* 枠に収まり、ほかの点を隠さない置き方のうち、点にいちばん近い所に置く。
* 返す x・y は点を原点にした吹き出しの左上。そういう置き方が無ければ fits: false(説明を写真の下に出す)。
*/
export function placeBubble(l: Layout, i: number, bw: number, bh: number) {
const p = l.pts[i];
const GAP = 24;
const M = 8;
const cands = [
{ x: p.x + GAP, y: p.y - 12 },
{ x: p.x + GAP, y: p.y + 12 - bh },
{ x: p.x - GAP - bw, y: p.y - 12 },
{ x: p.x - GAP - bw, y: p.y + 12 - bh },
];
for (let x = p.x - bw + 16; x <= p.x - 16; x += 8) cands.push({ x, y: p.y + GAP }, { x, y: p.y - GAP - bh });
let best = { x: 0, y: 0, fits: false, score: Infinity };
for (const c of cands) {
if (c.x < M || c.y < M || c.x + bw > l.w - M || c.y + bh > l.h - M) continue;
// 点の四角(32px)が少しでも重なれば「隠す」とみなす
const covered = l.pts.filter(
(q, j) => j !== i && q.inside && q.x > c.x - 16 && q.x < c.x + bw + 16 && q.y > c.y - 16 && q.y < c.y + bh + 16,
).length;
const dist = Math.hypot(c.x + bw / 2 - p.x, c.y + bh / 2 - p.y);
if (covered > 0) continue;
const score = dist;
if (score < best.score) best = { x: c.x - p.x, y: c.y - p.y, fits: true, score };
}
return best;
}
const FOCUS_RING = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-600";
const NAV_BTN = `inline-flex h-9 items-center gap-1.5 border border-stone-300 bg-white px-3 text-[12px] font-bold text-stone-800 transition-colors hover:border-stone-900 disabled:cursor-not-allowed disabled:border-stone-200 disabled:text-stone-300 motion-reduce:transition-none ${FOCUS_RING}`;
/** 開いている点と、説明の見出しの番号に共通の色(同じ四角で対応を示す) */
const ACTIVE_CHIP = "border-amber-600 bg-amber-600 text-white";
export type ImageHotspotTourProps = {
/** 写真の上に出す短い見出し */
heading?: string;
/** 見出しの下の1行ガイド */
guide?: string;
photo?: Photo;
spots?: Spot[];
/** object-position と同じ焦点(0〜1) */
focus?: { x: number; y: number };
/** 最初に開いておく点(0始まり)。null なら何も開かない */
initialOpen?: number | null;
/** 切り抜きの切り替え(見本用)を出すか */
showCropSwitch?: boolean;
/** 見出しの要素。ページの見出し階層に合わせて変える(既定 h2) */
headingTag?: "h1" | "h2" | "p";
};
export default function ImageHotspotTour({
heading = "店内の6か所を写真でご案内",
guide = "番号を押すと、その場所の説明が開きます",
photo = DEFAULT_PHOTO,
spots = DEFAULT_SPOTS,
focus = { x: 0.5, y: 0.5 },
initialOpen = 1,
showCropSwitch = true,
headingTag,
}: ImageHotspotTourProps) {
const Heading = headingTag ?? "h2";
const uid = useId();
const headingId = `${uid}-heading`;
const panelId = `${uid}-note`;
const noteTitleId = `${uid}-note-title`;
const N = spots.length;
const frames = framesFor(photo);
const [active, setActive] = useState<number | null>(
initialOpen !== null && initialOpen >= 0 && initialOpen < N ? initialOpen : null,
);
// 閉じた直後の 180ms だけ、消えていく説明を残す
const [leaving, setLeaving] = useState<number | null>(null);
// 未選択の間は画面幅で決める(狭い画面は元の比率。2:1 では写真が低くなりすぎる)
const [picked, setPicked] = useState<string | null>(null);
const narrow = useSyncExternalStore(subscribeNarrow, isNarrow, () => false);
const frameId = picked ?? (narrow ? "photo" : "wide");
const [size, setSize] = useState<{ w: number; h: number } | null>(null);
const [announce, setAnnounce] = useState("");
const frameRef = useRef<HTMLDivElement>(null);
const pinRefs = useRef<(HTMLButtonElement | null)[]>([]);
const prevRef = useRef<HTMLButtonElement>(null);
const nextRef = useRef<HTMLButtonElement>(null);
const pendingFocus = useRef<"prev" | "next" | null>(null);
const leaveTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
const bubbleRef = useRef<HTMLDivElement>(null);
const belowRef = useRef<HTMLDivElement>(null);
// 利用者が開いたとき(最初から開いている見本ではなく)だけ、写真の下の説明を画面に入れる
const userOpened = useRef(false);
// 吹き出しの高さ(置き場所の計算に使う)。出したあとに実測して合わせる
const [bubbleH, setBubbleH] = useState(200);
useEffect(() => {
const el = frameRef.current;
if (!el) return;
const ro = new ResizeObserver(([entry]) => {
const { width, height } = entry.contentRect;
setSize({ w: width, h: height });
});
ro.observe(el);
return () => ro.disconnect();
}, []);
useEffect(
() => () => {
if (leaveTimer.current) clearTimeout(leaveTimer.current);
},
[],
);
const layout = size ? layoutFor(size.w, size.h, photo, spots, focus) : null;
let minGap = Infinity;
if (layout) {
const pts = layout.pts.filter((p) => p.inside);
for (let i = 0; i < pts.length; i++)
for (let j = i + 1; j < pts.length; j++)
minGap = Math.min(minGap, Math.hypot(pts[i].x - pts[j].x, pts[i].y - pts[j].y));
}
const compact = layout !== null && (layout.w < COMPACT_WIDTH || minGap < MIN_GAP);
const isInside = (i: number) => !layout || layout.pts[i].inside;
// 画面に出している説明(閉じている途中なら、その点)
const shown = active ?? leaving;
const place = layout && shown !== null ? placeBubble(layout, shown, BUBBLE_W, bubbleH) : null;
// 吹き出しを写真の上に出せないとき(狭い・近い・点が枠の外・枠に収まらない)は、説明を写真の下に出す
const noteBelow = compact || (shown !== null && !isInside(shown)) || (place !== null && !place.fits);
useEffect(() => {
if (!userOpened.current || active === null || !noteBelow) return;
belowRef.current?.scrollIntoView({ block: "nearest", behavior: reducedMotion() ? "auto" : "smooth" });
}, [active, noteBelow]);
useLayoutEffect(() => {
const h = bubbleRef.current?.offsetHeight;
if (h && Math.abs(h - bubbleH) > 4) setBubbleH(h);
});
// 前へ・次へで説明が別の点の下へ移っても、押したボタンにフォーカスを戻す
useLayoutEffect(() => {
const target = pendingFocus.current;
if (!target) return;
pendingFocus.current = null;
(target === "prev" ? prevRef : nextRef).current?.focus();
}, [active]);
const stopLeaving = () => {
if (leaveTimer.current) clearTimeout(leaveTimer.current);
leaveTimer.current = null;
setLeaving(null);
};
const open = (i: number) => {
userOpened.current = true;
stopLeaving();
setActive(i);
setAnnounce(`${i + 1} / ${N}、${spots[i].title}`);
};
const close = (returnFocus: boolean) => {
const i = active;
if (i === null) return;
setActive(null);
setAnnounce("");
if (returnFocus) pinRefs.current[i]?.focus();
if (reducedMotion()) return;
if (leaveTimer.current) clearTimeout(leaveTimer.current);
setLeaving(i);
leaveTimer.current = setTimeout(() => {
leaveTimer.current = null;
setLeaving(null);
}, LEAVE_MS);
};
const step = (dir: -1 | 1) => {
if (active === null) return;
const n = active + dir;
if (n < 0 || n >= N) return;
pendingFocus.current = dir < 0 ? "prev" : "next";
open(n);
};
const onRootKeyDown = (e: KeyboardEvent<HTMLElement>) => {
if (e.key === "Escape" && active !== null) {
e.preventDefault();
close(true);
}
};
const onPinKeyDown = (e: KeyboardEvent<HTMLButtonElement>, i: number) => {
let n: number | null = null;
if (e.key === "ArrowRight" || e.key === "ArrowDown") n = Math.min(N - 1, i + 1);
else if (e.key === "ArrowLeft" || e.key === "ArrowUp") n = Math.max(0, i - 1);
else if (e.key === "Home") n = 0;
else if (e.key === "End") n = N - 1;
if (n === null) return;
e.preventDefault();
pinRefs.current[n]?.focus();
if (active !== null) open(n);
};
const showFromList = (i: number) => {
open(i);
const pin = pinRefs.current[i];
if (!pin) return;
frameRef.current?.scrollIntoView({ block: "nearest", behavior: reducedMotion() ? "auto" : "smooth" });
pin.focus({ preventScroll: true });
};
const frameDef = frames.find((f) => f.id === frameId) ?? frames[0];
const note = (placement: "bubble" | "below") => {
if (shown === null) return null;
const isLeaving = active === null;
const s = spots[shown];
// 枠を測るまで(サーバー描画の時点)は、点が右寄りなら左へ、下寄りなら上へ出す
let side = "";
if (placement === "bubble" && !place) {
side = `${s.x > 0.55 ? "right-6" : "left-6"} ${s.y > 0.5 ? "bottom-[-0.75rem]" : "top-[-0.75rem]"}`;
}
const motion = `transition-[opacity,transform] duration-[180ms] ease-out starting:translate-y-1 starting:opacity-0 motion-reduce:transition-none ${
isLeaving ? "pointer-events-none translate-y-1 opacity-0" : ""
}`;
const counter = (
<p className={`font-display text-[11px] font-semibold tabular-nums text-stone-400 ${placement === "below" ? "ml-2" : ""}`}>
{pad(shown + 1)} / {pad(N)}
</p>
);
return (
<div
ref={placement === "bubble" ? bubbleRef : belowRef}
style={placement === "bubble" && place ? { left: place.x, top: place.y } : undefined}
id={isLeaving ? undefined : panelId}
role="group"
aria-labelledby={isLeaving ? undefined : noteTitleId}
aria-hidden={isLeaving || undefined}
inert={isLeaving}
className={
placement === "bubble"
? `absolute z-20 w-[17rem] border border-t-2 border-stone-300 border-t-amber-600 bg-white p-4 text-left shadow-[0_18px_40px_-22px_rgba(28,25,23,0.5)] print:hidden ${motion} ${side}`
: `border-b border-l-2 border-stone-200 border-l-amber-600 py-3.5 pr-1 pl-3.5 print:hidden ${motion}`
}
>
<div className="flex items-start justify-between gap-3">
<h3
id={isLeaving ? undefined : noteTitleId}
className="flex items-center gap-2 text-[15px] leading-[1.5] font-bold text-stone-900"
>
<span
className={`font-display inline-flex h-6 min-w-6 shrink-0 items-center justify-center border px-1 text-[11px] font-bold tabular-nums ${ACTIVE_CHIP}`}
>
{pad(shown + 1)}
</span>
{s.title}
</h3>
<button
type="button"
onClick={() => close(true)}
className={`-mt-1 -mr-1 inline-flex h-8 w-8 shrink-0 items-center justify-center text-stone-500 transition-colors hover:text-stone-900 motion-reduce:transition-none ${FOCUS_RING}`}
>
<svg aria-hidden="true" viewBox="0 0 16 16" className="h-3.5 w-3.5" fill="none">
<path d="M3 3l10 10M13 3L3 13" stroke="currentColor" strokeWidth="1.6" />
</svg>
<span className="sr-only">説明を閉じる</span>
</button>
</div>
<p className="mt-2 text-[13px] leading-[1.85] text-stone-600">{s.body}</p>
{/* 写真の下に出すときは、画面右下に固定のボタンを置くサイトでも隠れないよう、前へ・次へを左にまとめる */}
<div
className={`mt-3 flex items-center gap-2 border-t border-stone-200 pt-3 ${
placement === "bubble" ? "justify-between" : "justify-start"
}`}
>
<button ref={prevRef} type="button" onClick={() => step(-1)} disabled={shown === 0} className={NAV_BTN}>
<svg aria-hidden="true" viewBox="0 0 16 16" className="h-3 w-3" fill="none">
<path d="M10 3L5 8l5 5" stroke="currentColor" strokeWidth="1.6" />
</svg>
前へ
</button>
{placement === "bubble" && counter}
<button ref={nextRef} type="button" onClick={() => step(1)} disabled={shown === N - 1} className={NAV_BTN}>
次へ
<svg aria-hidden="true" viewBox="0 0 16 16" className="h-3 w-3" fill="none">
<path d="M6 3l5 5-5 5" stroke="currentColor" strokeWidth="1.6" />
</svg>
</button>
{placement === "below" && counter}
</div>
</div>
);
};
return (
<section
aria-labelledby={headingId}
onKeyDown={onRootKeyDown}
className="w-full max-w-6xl bg-white px-1 text-stone-900"
>
<div className="flex items-end justify-between gap-4">
<div className="min-w-0">
<Heading id={headingId} className="text-[18px] leading-[1.45] font-bold tracking-tight text-stone-900 sm:text-[22px]">
{heading}
</Heading>
<p className="mt-0.5 text-[12px] leading-[1.6] text-stone-500 sm:text-[13px]">{guide}</p>
</div>
<p className="hidden shrink-0 pb-0.5 text-[11px] font-medium text-stone-400 sm:block">
<span className="font-display tabular-nums">{pad(N)}</span> か所
</p>
</div>
<figure className="mt-3">
<div
ref={frameRef}
onClick={(e) => {
if (e.target === e.currentTarget || (e.target as HTMLElement).tagName === "IMG") close(false);
}}
style={
{
aspectRatio: frameDef.ar,
containerType: "size",
"--dw": `max(100cqw, 100cqh * ${photo.w / photo.h})`,
"--dh": `max(100cqh, 100cqw / ${photo.w / photo.h})`,
} as CSSProperties
}
className="relative w-full bg-stone-100"
>
{/* eslint-disable-next-line @next/next/no-img-element -- 静的書き出しのため最適化なしの img を使う */}
<img
src={photo.src}
alt={photo.alt}
width={photo.w}
height={photo.h}
decoding="async"
draggable={false}
style={{ objectPosition: `${focus.x * 100}% ${focus.y * 100}%` }}
className="absolute inset-0 block h-full w-full object-cover select-none"
/>
{spots.map((s, i) => {
const isActive = active === i;
const hidden = !isInside(i);
return (
<div
key={i}
style={{
left: `calc((100cqw - var(--dw)) * ${focus.x} + var(--dw) * ${s.x})`,
top: `calc((100cqh - var(--dh)) * ${focus.y} + var(--dh) * ${s.y})`,
}}
className={`absolute h-0 w-0 ${shown === i ? "z-20" : "z-10"} ${hidden ? "hidden" : ""}`}
>
<button
ref={(el) => {
pinRefs.current[i] = el;
}}
type="button"
aria-expanded={isActive}
aria-controls={panelId}
aria-label={`${i + 1}. ${s.title}`}
onClick={() => (isActive ? close(false) : open(i))}
onKeyDown={(e) => onPinKeyDown(e, i)}
className={`font-display absolute top-0 left-0 inline-flex -translate-x-1/2 -translate-y-1/2 items-center justify-center border font-bold tabular-nums shadow-[0_4px_14px_-6px_rgba(28,25,23,0.6)] transition-[transform,background-color,border-color,color] duration-[180ms] motion-reduce:transition-none ${FOCUS_RING} ${
compact ? "h-6 w-6 text-[10px]" : "h-8 w-8 text-[11px] hover:scale-110 motion-reduce:hover:scale-100"
} ${isActive ? `${ACTIVE_CHIP} scale-110 motion-reduce:scale-100` : "border-white bg-white/95 text-stone-900"}`}
>
{pad(i + 1)}
</button>
{shown === i && !noteBelow && note("bubble")}
</div>
);
})}
</div>
{noteBelow && note("below")}
<div className="mt-3 flex flex-wrap items-center justify-between gap-x-4 gap-y-2 print:hidden">
{showCropSwitch && (
<div role="group" aria-label="写真の切り抜き方" className="flex items-center gap-1">
<span className="mr-1.5 text-[11px] font-medium text-stone-500">切り抜き</span>
{frames.map((f) => (
<button
key={f.id}
type="button"
aria-pressed={frameId === f.id}
onClick={() => setPicked(f.id)}
className={`inline-flex h-8 items-center gap-1.5 border px-2.5 text-[12px] font-bold transition-colors motion-reduce:transition-none ${FOCUS_RING} ${
frameId === f.id
? "border-stone-900 bg-stone-900 text-white"
: "border-stone-200 bg-white text-stone-600 hover:border-stone-400"
}`}
>
{f.label}
<span className={`font-display text-[10px] tabular-nums ${frameId === f.id ? "text-amber-300" : "text-stone-400"}`}>
{f.ratio}
</span>
</button>
))}
</div>
)}
<figcaption className="text-[11px] leading-[1.7] text-stone-500">
{showCropSwitch && "切り抜きを変えても、点は同じ物の上に残ります。"}番号の上の左右キーで前後へ、Esc で閉じます。
</figcaption>
</div>
</figure>
<ol className="mt-8 grid list-none gap-x-10 p-0 sm:grid-cols-2 lg:grid-cols-3" aria-label="写真の注釈の一覧">
{spots.map((s, i) => (
<li
key={i}
className={`grid grid-cols-[2.25rem_minmax(0,1fr)] gap-x-2 border-t py-4 transition-colors duration-[180ms] motion-reduce:transition-none ${
active === i ? "border-amber-600" : "border-stone-200"
}`}
>
<span
aria-hidden="true"
className={`font-display pt-0.5 text-[13px] font-bold tabular-nums ${active === i ? "text-amber-700" : "text-stone-400"}`}
>
{pad(i + 1)}
</span>
<div>
<h3 className="text-[14px] leading-[1.6] font-bold text-stone-900">
<span className="sr-only">{i + 1}. </span>
{s.title}
</h3>
<p className="mt-1 text-[13px] leading-[1.85] text-stone-600">{s.body}</p>
<button
type="button"
onClick={() => showFromList(i)}
className={`mt-2 text-[12px] font-bold text-stone-700 underline decoration-stone-300 underline-offset-4 transition-colors hover:decoration-amber-600 motion-reduce:transition-none print:hidden ${FOCUS_RING}`}
>
写真の上で見る
<span className="sr-only">({s.title})</span>
</button>
</div>
</li>
))}
</ol>
<p className="mt-2 border-t border-stone-200 pt-3 text-[11px] leading-[1.7] text-stone-400">
狭い画面で小さくした番号も 24×24px 以上にしています(出典:{" "}
<a
href="https://www.w3.org/TR/WCAG22/#target-size-minimum"
className={`underline decoration-stone-300 underline-offset-2 hover:text-stone-600 ${FOCUS_RING}`}
>
W3C「WCAG 2.2」達成基準 2.5.8 ターゲットのサイズ(最低限)
</a>
、2026年11月4日確認)。写真と説明は表示サンプルです。
</p>
<p aria-live="polite" className="sr-only">
{announce}
</p>
</section>
);
}
Add to your project via shadcn CLI
npx shadcn@latest add https://designs.first-ch.com/r/image-hotspot-tour.json