BLK-118Blocks

Tap-to-Open New Year Greeting Envelope — Washi Envelope with Business Start Date

A company New Year notice: tap the washi envelope and the flap turns up, the greeting card slides out, and a final line announces the first business day of the year. Entering one date updates the year on the card and the date and weekday in the notice. The envelope folds and flap are clip-path polygons; the washi paper, mizuhiki cord and pine are text-free generated sample photos that can be swapped through props. The card text is real vertical Japanese text. The envelope is a button, so click, tap, Enter and Space all open it. The opening uses only transform and opacity and takes about 1.2 seconds; under prefers-reduced-motion it starts open. No dependencies.

Preview

新年のご挨拶

本年も変わらぬご愛顧のほど、よろしくお願い申し上げます。

新年は1月5日(火)より営業いたします

ひのき工務店

Share on X

Read the full description

A company New Year notice: tap the washi envelope and the flap turns up, the greeting card slides out, and a final line announces the first business day of the year. Entering one date updates the year on the card and the date and weekday in the notice. The envelope folds and flap are clip-path polygons; the washi paper, mizuhiki cord and pine are text-free generated sample photos that can be swapped through props. The card text is real vertical Japanese text. The envelope is a button, so click, tap, Enter and Space all open it. The opening uses only transform and opacity and takes about 1.2 seconds; under prefers-reduced-motion it starts open. No dependencies.

Added:
2026-11-13
Dependencies:
None
tags
#block #motion #nenga #new-year #envelope #seasonal #notice #vertical-writing #writing-mode #clip-path #3d-transform #date-input #keyboard #reduced-motion #generated-image #no-dependency
"use client";

import { useEffect, useId, useState, type CSSProperties } from "react";

/**
 * 押すと封が開く、会社の新年のご挨拶
 *
 * 和紙の封筒を押すと、ふたが上へ返り、挨拶状が上へ抜け出して、最後に営業開始日の1行が出る。
 * 営業開始日を1つ入れると、挨拶状の年と下の1行の日付・曜日が変わる。
 *
 * 汎用技法メモ:
 * 1. **形はコード、質感は画像**。封筒の左右・下の折り返しとふたは clip-path の多角形で切り、
 *    中に和紙の写真を敷く。折り返しごとに背景の位置と明るさの重ねを変えると、同じ1枚の写真でも別の紙に見える。
 *    clip-path で切った要素には影が付かないので、影は親の filter: drop-shadow() で付ける。
 * 2. **ふたは rotateX で返し、途中で重なり順を入れ替える**。閉じているあいだは挨拶状より手前、
 *    返り切る前の半分の時刻で z-index を後ろへ回す(transition の delay を半分にする)。
 * 3. **開く動きは transform と opacity だけ**。ふた 0〜0.5秒、挨拶状 0.4〜1.2秒、最後の1行 1.2秒から。
 *    prefers-reduced-motion: reduce では最初から開いた状態で出し、動きを付けない。
 * 4. **文字は画像にしない**。挨拶状は writing-mode: vertical-rl の本物の文字なので、検索・読み上げ・翻訳に載る。
 *    写真3枚(封筒の和紙・挨拶状の和紙・水引と松)は props で差し替えられる見本。
 */

const PAGE = "#fbf8f2";
const INK = "#2b2118";
const MUTED = "#6f6253";
const SHU = "#c8442f";
const GOLD = "#c9a35a";
const MINCHO = '"Hiragino Mincho ProN", "Yu Mincho", YuMincho, "Noto Serif JP", serif';

const WEEK = ["日", "月", "火", "水", "木", "金", "土"];
const KANJI_DIGIT = ["〇", "一", "二", "三", "四", "五", "六", "七", "八", "九"];

export type NengaEnvelopeGreetingProps = {
  /** 挨拶状と下の1行に入れる会社名 */
  companyName?: string;
  /** 営業開始日の初期値(YYYY-MM-DD) */
  startDate?: string;
  /** 挨拶状の本文(縦書きの2列) */
  greetingLines?: [string, string];
  /** 封筒の和紙の写真 */
  envelopeImage?: string;
  /** 挨拶状の和紙の写真 */
  letterImage?: string;
  /** 水引と松の写真(背景を抜いた webp) */
  decorationImage?: string;
  /** 見出しの要素。ページの主見出しにするときだけ "h1" */
  headingTag?: "h1" | "h2" | "p";
};

function parseDate(value: string) {
  const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
  if (!m) return null;
  const y = Number(m[1]);
  const mo = Number(m[2]);
  const d = Number(m[3]);
  const date = new Date(y, mo - 1, d);
  if (date.getMonth() !== mo - 1) return null;
  return { y, mo, d, w: WEEK[date.getDay()] };
}

function kanjiYear(y: number) {
  return String(y)
    .split("")
    .map((c) => KANJI_DIGIT[Number(c)])
    .join("");
}

/** 1月の営業開始ならその年、12月なら翌年を挨拶の年にする */
function greetingYear(p: { y: number; mo: number }) {
  return p.mo >= 7 ? p.y + 1 : p.y;
}

export default function NengaEnvelopeGreeting({
  companyName = "ひのき工務店",
  startDate = "2027-01-05",
  greetingLines = ["旧年中は格別のお引き立てを賜り", "厚く御礼申し上げます"],
  envelopeImage = "/designs/nenga-envelope-greeting-washi.webp",
  letterImage = "/designs/nenga-envelope-greeting-letter.webp",
  decorationImage = "/designs/nenga-envelope-greeting-mizuhiki.webp",
  headingTag,
}: NengaEnvelopeGreetingProps) {
  const uid = useId();
  const Heading = headingTag ?? "h2";
  const [open, setOpen] = useState(false);
  const [still, setStill] = useState(false);
  const [date, setDate] = useState(startDate);

  useEffect(() => {
    const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
    const apply = () => {
      setStill(mq.matches);
      if (mq.matches) setOpen(true);
    };
    apply();
    mq.addEventListener("change", apply);
    return () => mq.removeEventListener("change", apply);
  }, []);

  const parsed = parseDate(date) ?? parseDate(startDate)!;
  const year = greetingYear(parsed);
  const notice = `新年は${parsed.mo}月${parsed.d}日(${parsed.w})より営業いたします`;

  const t = (ms: number) => (still ? "0ms" : `${ms}ms`);
  const vars = {
    "--washi": `linear-gradient(rgba(255,251,242,.3),rgba(255,251,242,.3)), url(${envelopeImage})`,
    "--letter": `url(${letterImage})`,
  } as CSSProperties;

  const flapStyle: CSSProperties = {
    transformOrigin: "50% 0%",
    transform: open ? "rotateX(180deg)" : "rotateX(0deg)",
    transition: `transform ${t(520)} cubic-bezier(.45,.05,.3,1), z-index 0s linear ${open ? t(260) : t(260)}`,
    zIndex: open ? 1 : 5,
    transformStyle: "preserve-3d",
  };

  const letterStyle: CSSProperties = {
    transform: open ? "translate3d(0,-58%,0) rotate(-1.6deg)" : "translate3d(0,0,0) rotate(0deg)",
    transition: `transform ${t(780)} cubic-bezier(.2,.75,.25,1) ${open ? t(420) : "0ms"}`,
  };

  const fade = (delay: number): CSSProperties => ({
    opacity: open ? 1 : 0,
    transform: open ? "translateY(0)" : "translateY(6px)",
    transition: `opacity ${t(420)} ease ${open ? t(delay) : "0ms"}, transform ${t(420)} ease ${open ? t(delay) : "0ms"}`,
  });

  return (
    <section
      className="relative mx-auto w-full max-w-6xl border border-stone-200 bg-white text-stone-900"
      aria-labelledby={`${uid}-title`}
    >
      <div className="flex items-baseline gap-4 px-5 py-4 sm:px-8 sm:py-5">
        <span className="hidden font-display text-xs font-semibold tracking-[0.18em] text-stone-500 sm:inline">BLK-116</span>
        <Heading id={`${uid}-title`} className="text-[clamp(1.15rem,3.2vw,2rem)] font-bold leading-[1.4]">
          新年のご挨拶
        </Heading>
      </div>

      <div className="grid border-t border-stone-200 lg:grid-cols-[minmax(0,1fr)_18rem]">
        <div className="relative overflow-hidden px-4 pb-10 pt-[clamp(11rem,50vw,17rem)] sm:px-8 lg:pb-8 lg:pt-[12.5rem]" style={{ background: PAGE, ...vars }}>
          <div className="relative mx-auto w-[min(88%,30rem)] lg:w-[22.5rem]" style={{ perspective: "1400px" }}>
            <button
              type="button"
              onClick={() => setOpen((v) => !v)}
              aria-expanded={open}
              aria-controls={`${uid}-letter`}
              aria-label={open ? "封筒を閉じる" : "封筒を開いて新年のご挨拶を読む"}
              className="group relative block aspect-[3/2] w-full cursor-pointer focus-visible:outline-2 focus-visible:outline-offset-[10px] focus-visible:outline-[#b45309]"
              style={{ transformStyle: "preserve-3d" }}
            >
              <span
                aria-hidden="true"
                className="absolute inset-0"
                style={{
                  backgroundImage: "linear-gradient(rgba(70,45,15,.22),rgba(70,45,15,.12)), var(--washi)",
                  backgroundSize: "cover",
                  backgroundPosition: "30% 70%",
                  boxShadow: "0 18px 28px -18px rgba(60,40,20,.45)",
                }}
              />

              <span aria-hidden="true" className="absolute inset-x-0 top-0 h-full" style={flapStyle}>
                <span
                  className="absolute inset-x-0 top-0 h-[78%]"
                  style={{
                    clipPath: "polygon(0 0, 100% 0, 54% 96%, 50% 100%, 46% 96%)",
                    backgroundImage:
                      "linear-gradient(180deg, rgba(255,255,255,.08), rgba(90,60,20,.10)), var(--washi)",
                    backgroundSize: "cover",
                    backgroundPosition: "60% 20%",
                    backfaceVisibility: "hidden",
                  }}
                />
                <span
                  className="absolute inset-x-0 top-0 h-[78%]"
                  style={{
                    clipPath: "polygon(46% 4%, 50% 0, 54% 4%, 100% 100%, 0 100%)",
                    backgroundImage: "linear-gradient(0deg, rgba(70,45,15,.04), rgba(70,45,15,.16)), var(--washi)",
                    backgroundSize: "cover",
                    backgroundPosition: "10% 40%",
                    transform: "rotateX(180deg)",
                    backfaceVisibility: "hidden",
                  }}
                />
              </span>

              <span
                id={`${uid}-letter`}
                className="absolute left-[6%] top-[5%] z-[2] block aspect-[7/5] w-[88%]"
                style={letterStyle}
              >
                <span
                  className="absolute inset-0 overflow-hidden"
                  style={{
                    backgroundImage: "linear-gradient(rgba(255,255,255,.55),rgba(255,255,255,.55)), var(--letter)",
                    backgroundSize: "cover",
                    boxShadow: "0 1px 2px rgba(60,40,20,.18), 0 10px 22px -12px rgba(60,40,20,.35)",
                    containerType: "inline-size",
                  }}
                >
                  <span
                    className="absolute right-[5.5%] top-[7%] block aspect-square w-[10%] rounded-full"
                    style={{ background: SHU }}
                  />
                  <span
                    lang="ja"
                    className="absolute right-[18%] top-[7%] block whitespace-nowrap"
                    style={{ writingMode: "vertical-rl", fontFamily: MINCHO, color: INK }}
                  >
                    <span className="block text-[7.4cqw] font-semibold leading-none tracking-[0.16em]">謹賀新年</span>
                    <span className="block pt-[2cqw] text-[2.6cqw] leading-[1.9] tracking-[0.08em]" style={{ marginLeft: "0", marginRight: "3cqw" }}>
                      {greetingLines[0]}
                      <br />
                      {greetingLines[1]}
                    </span>
                    <span className="block pt-[14cqw] text-[2.3cqw] leading-none tracking-[0.12em]" style={{ marginRight: "2.6cqw", color: MUTED }}>
                      {kanjiYear(year)}年 元旦
                    </span>
                    <span className="block pt-[10cqw] text-[2.9cqw] font-semibold leading-none tracking-[0.14em]" style={{ marginRight: "2.4cqw" }}>
                      {companyName}
                    </span>
                  </span>
                </span>
              </span>

              <span
                aria-hidden="true"
                className="absolute inset-0 z-[3]"
                style={{ filter: "drop-shadow(0 -1px 1.5px rgba(70,45,15,.28))" }}
              >
                <span
                  className="absolute inset-0"
                  style={{
                    clipPath: "polygon(0 0, 50% 52%, 0 100%)",
                    backgroundImage: "linear-gradient(90deg, rgba(255,255,255,.10), rgba(0,0,0,0)), var(--washi)",
                    backgroundSize: "cover",
                    backgroundPosition: "0% 50%",
                  }}
                />
                <span
                  className="absolute inset-0"
                  style={{
                    clipPath: "polygon(100% 0, 50% 52%, 100% 100%)",
                    backgroundImage: "linear-gradient(270deg, rgba(90,60,20,.06), rgba(0,0,0,0)), var(--washi)",
                    backgroundSize: "cover",
                    backgroundPosition: "100% 30%",
                  }}
                />
              </span>
              <span
                aria-hidden="true"
                className="absolute inset-0 z-[4]"
                style={{ filter: "drop-shadow(0 -1.5px 2px rgba(70,45,15,.30))" }}
              >
                <span
                  className="absolute inset-0"
                  style={{
                    clipPath: "polygon(0 100%, 41% 47%, 59% 47%, 100% 100%)",
                    backgroundImage: "linear-gradient(180deg, rgba(255,255,255,.12), rgba(90,60,20,.04)), var(--washi)",
                    backgroundSize: "cover",
                    backgroundPosition: "50% 100%",
                  }}
                />
              </span>

              {/* eslint-disable-next-line @next/next/no-img-element -- 静的書き出しのため next/image の最適化を使わない */}
              <img
                src={decorationImage}
                alt=""
                width={480}
                height={416}
                decoding="async"
                className="pointer-events-none absolute -right-[13%] bottom-[-21%] z-[6] w-[52%] max-w-none"
                style={{ filter: "drop-shadow(0 6px 6px rgba(60,40,20,.25))" }}
              />
            </button>
          </div>

          <div className="mx-auto mt-[clamp(3.5rem,11vw,5rem)] lg:mt-12 w-[min(94%,34rem)] border-t pt-6 text-center" style={{ borderColor: GOLD }}>
            <div aria-live="polite" className={open ? "" : "sr-only"}>
              <p className="text-[15px] leading-[2] sm:text-base" style={{ fontFamily: MINCHO, color: INK, ...fade(1100) }}>
                本年も変わらぬご愛顧のほど、よろしくお願い申し上げます。
              </p>
              <p
                className="mt-3 text-[17px] font-semibold leading-[1.8] tracking-[0.04em] sm:text-lg"
                style={{ fontFamily: MINCHO, color: INK, ...fade(1250) }}
              >
                {notice}
              </p>
              <p className="mt-1 text-[13px]" style={{ color: MUTED, ...fade(1350) }}>
                {companyName}
              </p>
            </div>
          </div>
        </div>

        <div className="flex flex-col gap-5 border-t border-stone-200 px-5 py-6 sm:px-8 lg:border-l lg:border-t-0 lg:px-6">
          <label className="flex flex-col gap-2 text-sm font-semibold" htmlFor={`${uid}-date`}>
            営業開始日
            <input
              id={`${uid}-date`}
              type="date"
              value={date}
              onChange={(e) => setDate(e.target.value)}
              className="min-h-11 border border-stone-300 bg-white px-3 text-base font-normal focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#b45309]"
            />
          </label>
          <button
            type="button"
            onClick={() => setOpen((v) => !v)}
            className="min-h-11 border border-[#b45309] bg-[#b45309] px-4 text-sm font-semibold text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#b45309]"
          >
            {open ? "封を閉じる" : "封を開く"}
          </button>
        </div>
      </div>
    </section>
  );
}

Add to your project via shadcn CLI

npx shadcn@latest add https://designs.first-ch.com/r/nenga-envelope-greeting.json