BLK-122Blocks

「店内で食べる」を押すとレシートが8%→10%で刷り直る注文確認画面|感熱紙の印字アニメーション

持ち帰りと店内飲食がある惣菜店で、ネット注文の客に税率の差を見せたいときの注文確認画面です。「持ち帰る/店内で食べる」を切り替えると、レシートの紙が切り取られて1行ずつ刷り直され、合計の横に「店内 +¥80」(持ち帰りに戻すと「持ち帰り −¥80」)の印が押されます。スマホでは切り替えの下に「店内だと 唐揚げ ×2 +¥20」の1行、広い画面では横の表に、店内にすると値段が変わる品を「唐揚げ ×2 ¥1,080→¥1,100 +¥20」のように並べます。持ち帰りの食べ物は8%で※付き、店内と酒類・保冷バッグは10%。消費税は税率ごとに合計してから1回だけ切り捨てます。「注文を変える」で6品の数量を変えると、変わった行と合計が光り、欄のすぐ下に合計が出ます(品が多いと欄の中だけが送られます)。品の配列を差し替えれば自店の品で試せます。動きを減らす設定では一度に表示します。税率は国税庁「消費税の軽減税率制度」で確認(2026-11-23)。店名・登録番号は架空の見本です。

プレビュー

BLK-122

同じ唐揚げ、店内だといくら高い?

店内だと 唐揚げ ×2 +¥20・店内の合計 ¥5,060

見本・領収書ではありません

惣菜の店(見本)

登録番号 T0000000000000(見本)

お持ち帰りの注文明細
品名[お持ち帰り]数量金額
オードブル盛合せ※1¥3,240
唐揚げ※2¥1,080
缶ビール2¥660

10%対象¥660(内消費税 ¥60)

8%対象¥4,320(内消費税 ¥320)

合計¥4,980

※は軽減税率対象

見本・領収書ではありません

持ち帰る:合計 ¥4,980(持ち帰り −¥80)

店内にすると変わる品(8%→10%)
品名持ち帰り→店内差
オードブル盛合せ ×1¥3,240から¥3,300+¥60
唐揚げ ×2¥1,080から¥1,100+¥20
合計¥4,980から¥5,060差は印に表示

缶ビールはどちらも10%で同じ金額

内消費税
金額にふくまれている消費税
軽減税率
持ち帰りの食べ物を8%にするしくみ(※の品)
登録番号
税務署に届けた店の番号(ここは見本)

税率の決まり:国税庁「消費税の軽減税率制度」(2026-11-23 確認)

X でシェア

詳しい説明を見る
追加日:
2026-11-23
依存:
なし
tags
#order-confirmation #receipt #thermal-paper #reduced-tax-rate #consumption-tax #takeout #eat-in #toggle #print-animation #stamp #aria-live #table #reduced-motion #japanese #ui #no-dependency #no-image
"use client";

import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";

/**
 * 店内/持ち帰りの切り替えで刷り直るレシート型の注文確認
 *
 * 差別化: フォーム部品の棚は入力・送信と送信後の案内が中心で、注文の中身から払う額を出す確認画面が無い。
 * 本ブロックは2択1つで税率(8%・10%)の行と※が変わるレシートを刷り直し、差額を印1つで見せる。
 * 英字の小見出し・見出しの「。」止め・末尾の矢印リンク・角丸のカードは使わない。
 *
 * 汎用技法メモ:
 * 1. **紙は出口から送り出す**。overflow:hidden の外枠を「まだ刷っていない高さ」だけ translateY で上へ、中の紙を同じだけ下へずらすと、
 *    窓の下端が刷った行の下端に来る。1行刷るたびにずらす量を 45〜80ms で縮めると、紙が出口から伸びてくる(高さも clip-path も動かさない)。
 *    切り取って落とす紙には前の明細と合計を載せたままにし、刷り直しの間も前の額が見えるようにする。
 * 2. **金額はいつも今の状態から描く**。動きは「何行目まで見せるか」だけを持ち、途中で切り替えたら
 *    タイマーを捨てて最初から刷り直す(古い印字を残さない)。prefers-reduced-motion では一度に出す。
 *    比べる数字(狭い幅の答えの1行・横の表)は紙の外に置き、刷り直しの間も消さない。
 * 3. **消費税は税率ごとに1回だけ切り捨てる**。行の税込額を税率ごとに足してから 8/108・10/110 を掛ける。
 * 4. **数量の変更は変わった行を光らせる**。刷り直さずに即時反映し、レシートの行・合計・押した欄の行を一度だけ淡く光らせる。
 *    同じ品を続けて押したら動きの名前を交互に替えてやり直す(要素を作り直すと押したボタンの焦点が外れる)。
 *
 * 店名・品名・単価・登録番号はすべて架空の見本。
 */

export type Kind = "food" | "alcohol" | "goods";
export type Mode = "takeout" | "eatin";
export type Item = { id: string; name: string; price: number; kind: Kind; qty: number };

export const DEFAULT_ITEMS: Item[] = [
  { id: "platter", name: "オードブル盛合せ", price: 3000, kind: "food", qty: 1 },
  { id: "karaage", name: "唐揚げ", price: 500, kind: "food", qty: 2 },
  { id: "potato", name: "ポテトサラダ", price: 300, kind: "food", qty: 0 },
  { id: "onigiri", name: "おにぎり", price: 150, kind: "food", qty: 0 },
  { id: "beer", name: "缶ビール", price: 300, kind: "alcohol", qty: 2 },
  { id: "bag", name: "保冷バッグ", price: 200, kind: "goods", qty: 0 },
];

const MAX_QTY = 9;
const LINE_MS = 45;
const CUT_MS = 200;

const PAPER = "#F6F1E4";
const INK = "#2B2B2B";
const AMBER = "#B45309";
const SHU = "#C8442F";

/** 持ち帰りの食品だけ 8%。店内は全部 10%、酒類と保冷バッグは常に 10% */
export const rateOf = (kind: Kind, mode: Mode) => (kind === "food" && mode === "takeout" ? 8 : 10);

export function calc(items: Item[], mode: Mode) {
  const lines = items
    .filter((it) => it.qty > 0)
    .map((it) => {
      const rate = rateOf(it.kind, mode);
      return { ...it, rate, total: Math.floor((it.price * it.qty * (100 + rate)) / 100) };
    });
  const base10 = lines.filter((l) => l.rate === 10).reduce((s, l) => s + l.total, 0);
  const base8 = lines.filter((l) => l.rate === 8).reduce((s, l) => s + l.total, 0);
  return {
    lines,
    base10,
    base8,
    tax10: Math.floor((base10 * 10) / 110),
    tax8: Math.floor((base8 * 8) / 108),
    total: base10 + base8,
  };
}

const yen = (n: number) => `¥${n.toLocaleString("ja-JP")}`;

/** 印の文言。今の紙の側から見た差を符号つきで言う(店内 +¥80/持ち帰り −¥80) */
export function stampText(mode: Mode, diff: number) {
  if (diff === 0) return "差額なし";
  const sign = diff > 0 ? "+" : "−";
  return `${mode === "eatin" ? "店内" : "持ち帰り"} ${sign}${yen(Math.abs(diff))}`;
}

/** 数量の欄に出す税率。店内と持ち帰りで変わる品かどうかが分かる言い方にする */
const rateNote = (kind: Kind) =>
  kind === "food" ? "持ち帰り8%※・店内10%" : kind === "alcohol" ? "どちらも10%(酒類)" : "どちらも10%";

const reduced = () =>
  typeof window !== "undefined" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;

/** 下端のギザギザ(切り口) */
const TEETH = 26;
const ZIGZAG = `polygon(0 0, 100% 0, ${Array.from({ length: TEETH * 2 + 1 }, (_, i) => {
  const x = 100 - (i * 100) / (TEETH * 2);
  return `${x.toFixed(2)}% ${i % 2 === 0 ? "40%" : "100%"}`;
}).join(", ")})`;

const PAPER_BG = {
  backgroundColor: PAPER,
  backgroundImage:
    "repeating-linear-gradient(0deg, rgba(43,43,43,.018) 0 1px, transparent 1px 3px), repeating-linear-gradient(90deg, rgba(120,90,40,.02) 0 1px, transparent 1px 4px)",
} as const;

function Stamp({ text }: { text: string }) {
  const est = [...text].reduce((s, c) => s + (/[ -鿿]/.test(c) ? 15 : 8.5), 0);
  return (
    <svg viewBox="0 0 124 44" width="112" height="40" aria-hidden="true" className="block" style={{ opacity: 0.9 }}>
      <rect x="2" y="2" width="120" height="40" rx="7" fill="none" stroke={SHU} strokeWidth="2.6" />
      <text
        x="62"
        y="28"
        textAnchor="middle"
        fontSize="15"
        fontWeight="700"
        fill={SHU}
        {...(est > 108 ? { textLength: 108, lengthAdjust: "spacingAndGlyphs" } : {})}
      >
        {text}
      </text>
    </svg>
  );
}

function QtyButton({ dir, label, item, disabled, onClick }: {
  dir: "minus" | "plus";
  label: string;
  item: string;
  disabled: boolean;
  onClick: () => void;
}) {
  return (
    <button
      type="button"
      className={`qty-${dir} relative grid size-11 shrink-0 place-items-center border border-stone-300 bg-white text-stone-800 transition-colors hover:border-stone-500 active:bg-stone-100 disabled:cursor-not-allowed disabled:opacity-35 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#B45309]`}
      data-item={item}
      aria-label={label}
      disabled={disabled}
      onClick={onClick}
    >
      <span aria-hidden="true" className="absolute h-0.5 w-3.5 bg-current" />
      {dir === "plus" && <span aria-hidden="true" className="absolute h-3.5 w-0.5 bg-current" />}
    </button>
  );
}

export default function ReceiptPrintSummary({
  headingTag: Heading = "h2",
  items: initialItems = DEFAULT_ITEMS,
  focusId = "karaage",
}: {
  headingTag?: "h1" | "h2" | "p";
  items?: Item[];
  /** 狭い幅で切り替えの下に1行で答える品(見出しの品) */
  focusId?: string;
}) {
  const uid = useId();
  const [items, setItems] = useState<Item[]>(initialItems);
  const [mode, setMode] = useState<Mode>("takeout");
  /** 何行目まで刷ったか。null は刷り上がり */
  const [printed, setPrinted] = useState<number | null>(null);
  const [cutting, setCutting] = useState(false);
  const [fallKey, setFallKey] = useState(0);
  const [stampKey, setStampKey] = useState(0);
  const [editOpen, setEditOpen] = useState(false);
  const [hidden, setHidden] = useState(0);
  const [paperH, setPaperH] = useState(0);
  /** 切り取って落とす紙に残す、切り替える前の金額 */
  const [fallMode, setFallMode] = useState<Mode>("takeout");
  /** 数量を変えた品を光らせる(key で動きをやり直す) */
  const [bump, setBump] = useState<{ id: string; key: number } | null>(null);

  const timers = useRef<number[]>([]);
  const paperRef = useRef<HTMLDivElement>(null);
  const editRef = useRef<HTMLUListElement>(null);
  const editTotalRef = useRef<HTMLParagraphElement>(null);
  const rowCount = useRef(0);

  const r = useMemo(() => calc(items, mode), [items, mode]);
  const fallen = useMemo(() => calc(items, fallMode), [items, fallMode]);
  const other = useMemo(() => calc(items, mode === "eatin" ? "takeout" : "eatin"), [items, mode]);
  const diff = r.total - other.total;

  // 行の番号(上から順に刷る)
  let n = 0;
  const idx = () => n++;
  const rowTop = idx(); // 見本の断り
  const rowShop = idx();
  const rowReg = idx();
  const rowHead = idx();
  const rowItems = (r.lines.length ? r.lines : [null]).map(() => idx());
  const row10 = r.base10 > 0 || r.base8 === 0 ? idx() : -1;
  const row8 = r.base8 > 0 ? idx() : -1;
  const rowTotal = idx();
  const rowNote = r.base8 > 0 ? idx() : -1;
  const rowBottom = idx();
  const rows = n;
  useEffect(() => {
    rowCount.current = rows;
  }, [rows]);

  const clear = () => {
    timers.current.forEach((t) => window.clearTimeout(t));
    timers.current = [];
  };
  useEffect(() => clear, []);

  const choose = (next: Mode) => {
    if (next === mode && printed === null && !cutting) return;
    clear();
    setMode(next);
    if (reduced()) {
      setCutting(false);
      setPrinted(null);
      setStampKey((k) => k + 1);
      return;
    }
    setFallMode(mode);
    setCutting(true);
    setPrinted(0);
    setFallKey((k) => k + 1);
    timers.current.push(window.setTimeout(() => setCutting(false), CUT_MS));
    const step = (i: number) => {
      timers.current.push(
        window.setTimeout(() => {
          if (i >= rowCount.current) {
            setPrinted(null);
            setStampKey((k) => k + 1);
            return;
          }
          setPrinted(i + 1);
          step(i + 1);
        }, i === 0 ? CUT_MS : LINE_MS),
      );
    };
    step(0);
  };

  const changeQty = (id: string, delta: number) => {
    setItems((list) =>
      list.map((it) => (it.id === id ? { ...it, qty: Math.max(0, Math.min(MAX_QTY, it.qty + delta)) } : it)),
    );
    setBump((b) => ({ id, key: (b?.key ?? 0) + 1 }));
  };

  // 刷った行の下端より下を隠す(外枠を上へ・紙を同じだけ下へずらし、窓の下端を行の下端に合わせる)
  useLayoutEffect(() => {
    const paper = paperRef.current;
    if (!paper) return;
    const h = paper.offsetHeight;
    setPaperH(h);
    if (printed === null) {
      setHidden(0);
      return;
    }
    if (printed === 0) {
      setHidden(h);
      return;
    }
    const el = paper.querySelector<HTMLElement>(`[data-row="${printed - 1}"]`);
    if (!el) return;
    const pr = paper.getBoundingClientRect();
    const er = el.getBoundingClientRect();
    setHidden(Math.max(0, h - (er.bottom - pr.top + 6)));
  }, [printed, items, mode]);

  const feedAnim = cutting ? "" : "transition-transform duration-[80ms] ease-linear";
  const shown = (i: number) => (printed === null || i < printed ? "opacity-100" : "opacity-0");
  const rowCls = (i: number) => `transition-opacity duration-75 ${shown(i)}`;
  const stampVisible = printed === null;
  // 同じ品を続けて押しても光り直すよう、動きの名前を交互に替える(要素は作り直さず、押したボタンの焦点を保つ)
  const bumpCls = (on: boolean) => (on && bump ? (bump.key % 2 ? "rp-bump-a" : "rp-bump-b") : "");
  // 持ち帰り→店内で金額が変わる品(見出しの問いへの答え)
  const takeoutCalc = mode === "takeout" ? r : other;
  const eatinCalc = mode === "eatin" ? r : other;
  const changes = takeoutCalc.lines
    .map((l) => ({ ...l, eatin: eatinCalc.lines.find((e) => e.id === l.id)?.total ?? l.total }))
    .filter((l) => l.eatin !== l.total);
  const same = takeoutCalc.lines.filter((l) => !changes.some((c) => c.id === l.id));
  const focus = changes.find((c) => c.id === focusId) ?? changes[0];
  const totalUp = eatinCalc.total - takeoutCalc.total;

  // 開いた数量の欄が画面の外なら、欄の下の合計まで見える所へ送る(欄の高さは画面の6割まで)
  useEffect(() => {
    if (!editOpen) return;
    editTotalRef.current?.scrollIntoView({ block: "nearest", behavior: reduced() ? "auto" : "smooth" });
  }, [editOpen]);

  return (
    <section
      className="rp-root @container w-full max-w-5xl border border-stone-200 bg-white text-stone-900"
      aria-labelledby={`${uid}-h`}
    >
      <style>{`
        @keyframes rp-fall { from { transform: translateY(0) rotate(0); opacity: 1 } to { transform: translateY(70%) rotate(7deg); opacity: 0 } }
        @keyframes rp-stamp { from { transform: scale(1.35) rotate(-6deg); opacity: 0 } to { transform: scale(1) rotate(-6deg); opacity: 1 } }
        @keyframes rp-bump-a { from { background-color: rgba(180,83,9,.22) } to { background-color: rgba(180,83,9,0) } }
        @keyframes rp-bump-b { from { background-color: rgba(180,83,9,.22) } to { background-color: rgba(180,83,9,0) } }
        .rp-fall { animation: rp-fall 640ms cubic-bezier(.5,0,.9,.5) forwards }
        .rp-bump-a { animation: rp-bump-a 700ms ease-out }
        .rp-bump-b { animation: rp-bump-b 700ms ease-out }
        .rp-stamp { transform: rotate(-6deg); animation: rp-stamp 170ms ease-out both }
        @media (prefers-reduced-motion: reduce) {
          .rp-fall { display: none }
          .rp-stamp, .rp-bump-a, .rp-bump-b { animation: none }
          .rp-root .rp-feed, .rp-root [data-row] { transition: none !important }
        }
      `}</style>

      <div className="flex items-baseline gap-3 border-b border-stone-200 px-4 py-2 @min-[40rem]:px-6 @min-[40rem]:py-3">
        <span className="font-display text-[11px] tracking-[0.18em] text-stone-500">BLK-122</span>
        <Heading id={`${uid}-h`} className="text-[15px] font-bold sm:text-[1.15rem]">
          同じ唐揚げ、店内だといくら高い?
        </Heading>
      </div>

      <div className="grid gap-x-4 gap-y-3 px-4 py-3 @min-[40rem]:grid-cols-[minmax(0,1fr)_320px] @min-[40rem]:grid-rows-[auto_auto_auto_1fr] @min-[40rem]:gap-y-4 @min-[40rem]:px-6 @min-[40rem]:py-6 @min-[40rem]:[grid-template-areas:'tog_paper'_'diff_paper'_'edit_paper'_'notes_paper'] @min-[56rem]:grid-cols-[minmax(0,22rem)_minmax(0,1fr)] @min-[56rem]:gap-x-10">
        {/* 2択 */}
        <div className="@min-[40rem]:[grid-area:tog]">
          <div role="group" aria-label="食べる場所" className="grid grid-cols-2 border border-stone-400">
            {(
              [
                ["takeout", "持ち帰る"],
                ["eatin", "店内で食べる"],
              ] as const
            ).map(([m, label], i) => (
              <button
                key={m}
                type="button"
                data-mode={m}
                aria-pressed={mode === m}
                onClick={() => choose(m)}
                className={`mode-${m} min-h-12 px-2 text-[15px] font-bold transition-colors focus-visible:relative focus-visible:z-10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#B45309] ${
                  i === 1 ? "border-l border-stone-400" : ""
                } ${mode === m ? "text-white" : "bg-white text-stone-800 hover:bg-amber-50"}`}
                style={mode === m ? { backgroundColor: AMBER } : undefined}
              >
                {label}
              </button>
            ))}
          </div>
          {/* 1列のときは表がレシートの下になるので、見出しの問いへの答えを切り替えの下に1行で出す(刷り直し中も消えない) */}
          <p className="rp-answer mt-1.5 text-[13px] leading-snug text-stone-700 @min-[40rem]:hidden">
            {focus ? (
              <>
                店内だと {focus.name} ×{focus.qty}{" "}
                <b className="font-mono tabular-nums" style={{ color: SHU }}>
                  +{yen(focus.eatin - focus.total)}
                </b>
                ・店内の合計 <span className="font-mono tabular-nums">{yen(eatinCalc.total)}</span>
              </>
            ) : (
              <>店内でも金額は変わりません(合計 {yen(r.total)})</>
            )}
          </p>
        </div>

        {/* レシートの紙 */}
        <div className="relative mx-auto w-full max-w-[340px] @min-[40rem]:[grid-area:paper] @min-[40rem]:mx-0 @min-[40rem]:justify-self-center">
          <div aria-hidden="true" className="relative z-10 mx-auto h-1.5 w-full bg-stone-600" />
          <div className="relative mx-auto w-[320px] max-w-[calc(100%-16px)]">
            {fallKey > 0 && cutting && (
              <div
                key={fallKey}
                aria-hidden="true"
                className="rp-fall pointer-events-none absolute inset-x-0 top-0 z-0"
                style={{ height: paperH || 360 }}
              >
                {/* 切り替える前の明細と合計を載せたまま落とし、刷り直しの間も前の額が見えるようにする */}
                <div className="h-[calc(100%-10px)] px-5 pt-[4.6rem] text-[12.5px] leading-[1.45]" style={{ ...PAPER_BG, color: INK }}>
                  {fallen.lines.map((l) => (
                    <div key={l.id} className="flex justify-between gap-2 opacity-70">
                      <span>
                        {l.name}
                        {l.rate === 8 && "※"}
                      </span>
                      <span className="font-mono tabular-nums">{yen(l.total)}</span>
                    </div>
                  ))}
                  <div className="mt-2 flex justify-between border-t border-stone-700 pt-1.5 text-[14px] font-bold">
                    <span>合計</span>
                    <span className="font-mono text-[17px] tabular-nums">{yen(fallen.total)}</span>
                  </div>
                </div>
                <div className="h-2.5" style={{ ...PAPER_BG, clipPath: ZIGZAG }} />
              </div>
            )}
            <div
              className={`rp-feed relative overflow-hidden ${feedAnim}`}
              style={{ transform: `translateY(${-hidden}px)` }}
            >
              <div
                ref={paperRef}
                className={`rp-feed relative drop-shadow-[0_1px_1px_rgba(0,0,0,0.12)] ${feedAnim}`}
                style={{ transform: `translateY(${hidden}px)`, color: INK }}
              >
                <div className="px-5 pb-2 pt-2 text-[12.5px] leading-[1.45] @min-[40rem]:pb-3 @min-[40rem]:pt-3 @min-[40rem]:leading-[1.55]" style={PAPER_BG}>
                  <p data-row={rowTop} className={`${rowCls(rowTop)} text-center text-[11px] tracking-wider`}>
                    見本・領収書ではありません
                  </p>
                  <p data-row={rowShop} className={`${rowCls(rowShop)} mt-1 text-center text-[14px] font-bold`}>
                    惣菜の店(見本)
                  </p>
                  <p data-row={rowReg} className={`${rowCls(rowReg)} text-center text-[11px]`}>
                    登録番号 <span className="font-mono">T0000000000000</span>(見本)
                  </p>

                  <table className="mt-2 w-full border-collapse">
                    <caption className="sr-only">
                      {mode === "eatin" ? "店内飲食" : "お持ち帰り"}の注文明細
                    </caption>
                    <thead>
                      <tr data-row={rowHead} className={`${rowCls(rowHead)} border-b border-dashed border-stone-500/60 text-[11px]`}>
                        <th scope="col" className="py-0.5 text-left font-normal">
                          品名<span className="ml-2">{mode === "eatin" ? "[店内飲食]" : "[お持ち帰り]"}</span>
                        </th>
                        <th scope="col" className="w-9 py-0.5 text-right font-normal">数量</th>
                        <th scope="col" className="w-[4.6rem] py-0.5 text-right font-normal">金額</th>
                      </tr>
                    </thead>
                    <tbody>
                      {r.lines.length === 0 ? (
                        <tr data-row={rowItems[0]} className={rowCls(rowItems[0])}>
                          <td colSpan={3} className="py-1 text-center">注文がありません</td>
                        </tr>
                      ) : (
                        r.lines.map((l, i) => (
                          <tr key={l.id} data-row={rowItems[i]} className={`${rowCls(rowItems[i])} ${bumpCls(bump?.id === l.id)}`}>
                            <td className="py-px pr-1">
                              {l.name}
                              {l.rate === 8 && <span className="ml-0.5">※</span>}
                            </td>
                            <td className="py-px text-right font-mono tabular-nums">{l.qty}</td>
                            <td className="py-px text-right font-mono tabular-nums">{yen(l.total)}</td>
                          </tr>
                        ))
                      )}
                    </tbody>
                  </table>

                  <div className="mt-1.5 border-t border-dashed border-stone-500/60 pt-1.5 text-[11.5px]">
                    {row10 >= 0 && (
                      <p data-row={row10} className={`${rowCls(row10)} flex justify-between gap-2`}>
                        <span>10%対象</span>
                        <span className="font-mono tabular-nums">
                          {yen(r.base10)}(内消費税 {yen(r.tax10)})
                        </span>
                      </p>
                    )}
                    {row8 >= 0 && (
                      <p data-row={row8} className={`${rowCls(row8)} flex justify-between gap-2`}>
                        <span>8%対象</span>
                        <span className="font-mono tabular-nums">
                          {yen(r.base8)}(内消費税 {yen(r.tax8)})
                        </span>
                      </p>
                    )}
                  </div>

                  <div
                    data-row={rowTotal}
                    className={`${rowCls(rowTotal)} mt-1.5 flex min-h-11 items-center justify-between gap-1 border-t border-stone-700 pt-1.5`}
                  >
                    <span className="text-[14px] font-bold">合計</span>
                    <span className="flex w-[112px] justify-center">
                      {stampVisible && (
                        <span key={stampKey} className="rp-stamp inline-block">
                          <Stamp text={stampText(mode, diff)} />
                        </span>
                      )}
                    </span>
                    <span className={`font-mono text-[17px] font-bold tabular-nums ${bumpCls(true)}`}>
                      {yen(r.total)}
                    </span>
                  </div>
                  {rowNote >= 0 && (
                    <p data-row={rowNote} className={`${rowCls(rowNote)} text-[11px]`}>
                      ※は軽減税率対象
                    </p>
                  )}
                  <p data-row={rowBottom} className={`${rowCls(rowBottom)} mt-2 text-center text-[11px] tracking-wider`}>
                    見本・領収書ではありません
                  </p>
                </div>
                <div aria-hidden="true" className="h-2.5" style={{ ...PAPER_BG, clipPath: ZIGZAG }} />
              </div>
            </div>
          </div>
          {/* 刷り上がってから1回だけ読み上げる(刷っている間は空)。目では印と表で見えるので、同じ差を画面に重ねない */}
          <p aria-live="polite" className="rp-live sr-only">
            {printed === null && (
              <>
                {mode === "eatin" ? "店内で食べる" : "持ち帰る"}:合計 {yen(r.total)}({stampText(mode, diff)})
              </>
            )}
          </p>
        </div>

        {/* 持ち帰り→店内で変わる品 */}
        <div className="@min-[40rem]:[grid-area:diff]">
          <table className="rp-diff w-full border-collapse text-[13px]">
            <caption className="pb-1.5 text-left text-[14px] font-bold">店内にすると変わる品(8%→10%)</caption>
            <thead className="sr-only">
              <tr>
                <th scope="col">品名</th>
                <th scope="col">持ち帰り→店内</th>
                <th scope="col">差</th>
              </tr>
            </thead>
            <tbody>
              {changes.length === 0 ? (
                <tr className="border-t border-stone-200">
                  <td colSpan={3} className="py-1.5">変わる品はありません</td>
                </tr>
              ) : (
                changes.map((c) => (
                  <tr key={c.id} className="border-t border-stone-200">
                    <th scope="row" className="py-1.5 pr-1.5 text-left font-medium">
                      {/* 品名の途中で折り返さない(折り返すなら数量の前で) */}
                      <span className="whitespace-nowrap">{c.name}</span>{" "}
                      <span className="whitespace-nowrap">×{c.qty}</span>
                    </th>
                    <td className="py-1.5 text-right font-mono tabular-nums whitespace-nowrap">
                      <span className={mode === "takeout" ? "font-bold" : "text-stone-500"}>{yen(c.total)}</span>
                      <span aria-hidden="true" className="px-0.5 text-stone-500">→</span>
                      <span className="sr-only">から</span>
                      <span className={mode === "eatin" ? "font-bold" : "text-stone-500"}>{yen(c.eatin)}</span>
                    </td>
                    <td className="py-1.5 pl-2 text-right font-mono font-bold tabular-nums whitespace-nowrap" style={{ color: SHU }}>
                      +{yen(c.eatin - c.total)}
                    </td>
                  </tr>
                ))
              )}
              <tr className="border-t-2 border-stone-700">
                <th scope="row" className="py-1.5 pr-1.5 text-left font-bold">合計</th>
                <td className="py-1.5 text-right font-mono tabular-nums whitespace-nowrap">
                  <span className={mode === "takeout" ? "font-bold" : "text-stone-500"}>{yen(takeoutCalc.total)}</span>
                  <span aria-hidden="true" className="px-0.5 text-stone-500">→</span>
                      <span className="sr-only">から</span>
                  <span className={mode === "eatin" ? "font-bold" : "text-stone-500"}>{yen(eatinCalc.total)}</span>
                </td>
                {/* 合計の差は紙の印だけで言う(同じ差を表でくり返さない。差が0のときに赤い「+¥0」も出さない) */}
                <td className="py-1.5 pl-2 text-right text-stone-500">
                  <span aria-hidden="true">—</span>
                  <span className="sr-only">{totalUp === 0 ? "差なし" : `差は印に表示`}</span>
                </td>
              </tr>
            </tbody>
          </table>
          {same.length > 0 && (
            <p className="mt-1 text-[12px] text-stone-600">
              {same.map((l) => l.name).join("・")}はどちらも10%で同じ金額
            </p>
          )}
        </div>

        {/* 注文を変える */}
        <div className="@min-[40rem]:self-start @min-[40rem]:[grid-area:edit]">
          <button
            type="button"
            className="edit-toggle flex min-h-12 w-full items-center justify-between border border-stone-300 bg-white px-4 text-[15px] font-bold text-stone-800 hover:border-stone-500 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#B45309]"
            aria-expanded={editOpen}
            aria-controls={`${uid}-edit`}
            onClick={() => setEditOpen((o) => !o)}
          >
            注文を変える
            <span
              aria-hidden="true"
              className={`size-2.5 border-b-2 border-r-2 border-stone-600 transition-transform ${
                editOpen ? "-rotate-[135deg] translate-y-0.5" : "rotate-45 -translate-y-0.5"
              }`}
            />
          </button>
          {/* 品が多いときは欄の中だけを送り、合計の行はそのすぐ下に置く(画面に貼りつけて品の行に重ねない) */}
          <ul
            ref={editRef}
            id={`${uid}-edit`}
            hidden={!editOpen}
            className="max-h-[min(28rem,60svh)] overflow-y-auto overscroll-contain border-x border-b border-stone-200"
          >
            {items.map((it) => (
                <li
                  key={it.id}
                  className={`flex items-center gap-2 border-t border-stone-200 px-3 py-2 first:border-t-0 ${bumpCls(bump?.id === it.id)}`}
                >
                  <span className="min-w-0 flex-1">
                    <span className="block text-[14px] font-medium">
                      {it.name}
                      {rateOf(it.kind, mode) === 8 && <span className="ml-0.5">※</span>}
                    </span>
                    <span className="block text-[12px] leading-snug text-stone-600">
                      <span className="font-mono tabular-nums">税抜{yen(it.price)}</span>・
                      <span className="inline-block whitespace-nowrap">{rateNote(it.kind)}</span>
                    </span>
                  </span>
                  <QtyButton
                    dir="minus"
                    item={it.id}
                    label={`${it.name}を1つ減らす`}
                    disabled={it.qty <= 0}
                    onClick={() => changeQty(it.id, -1)}
                  />
                  <output className="w-6 text-center font-mono text-[16px] font-bold tabular-nums" aria-label={`${it.name}の数量`}>
                    {it.qty}
                  </output>
                  <QtyButton
                    dir="plus"
                    item={it.id}
                    label={`${it.name}を1つ増やす`}
                    disabled={it.qty >= MAX_QTY}
                    onClick={() => changeQty(it.id, 1)}
                  />
                </li>
            ))}
          </ul>
          {/* 数量を変えている間も合計が見えるよう、欄のすぐ下に出す */}
          <p
            ref={editTotalRef}
            hidden={!editOpen}
            className="rp-edit-total flex items-baseline justify-between gap-2 border border-t-0 border-stone-300 bg-white px-3 py-2 text-[14px] shadow-[0_-1px_0_rgba(0,0,0,0.06)]"
          >
            <span className="font-bold">{mode === "eatin" ? "店内" : "持ち帰り"}の合計</span>
            {/* 差は紙の印に任せ、ここは合計だけ */}
            <b className={`font-mono text-[16px] tabular-nums ${bumpCls(true)}`}>{yen(r.total)}</b>
          </p>
        </div>

        {/* 言葉の注と出典 */}
        <div className="@min-[40rem]:[grid-area:notes]">
          <dl className="grid grid-cols-[auto_1fr] gap-x-2 gap-y-0.5 text-[12px] leading-relaxed text-stone-700">
            <dt className="font-bold">内消費税</dt>
            <dd>金額にふくまれている消費税</dd>
            <dt className="font-bold">軽減税率</dt>
            <dd>持ち帰りの食べ物を8%にするしくみ(※の品)</dd>
            <dt className="font-bold">登録番号</dt>
            <dd>税務署に届けた店の番号(ここは見本)</dd>
          </dl>
          <p className="mt-2 text-[12px] text-stone-600">
            税率の決まり:
            <a
              href="https://www.nta.go.jp/taxes/shiraberu/zeimokubetsu/shohi/keigenzeiritsu/index.htm"
              className="underline underline-offset-2 hover:text-stone-900 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#B45309]"
              target="_blank"
              rel="noopener noreferrer"
            >
              国税庁「消費税の軽減税率制度」
            </a>
            <span className="whitespace-nowrap">(2026-11-23 確認)</span>
          </p>
        </div>
      </div>
    </section>
  );
}

shadcn CLI でプロジェクトに追加

npx shadcn@latest add https://designs.first-ch.com/r/receipt-print-summary.json