packbook.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. "use client";
  2. import Image from "next/image";
  3. import { useEffect, useRef, useState } from "react";
  4. import { Eyebrow, TextLink } from "./ui";
  5. import buy from "@/assets/packbook/buy.webp";
  6. import identify from "@/assets/packbook/identify.webp";
  7. import pack from "@/assets/packbook/pack.webp";
  8. import share from "@/assets/packbook/share.webp";
  9. import wall from "@/assets/packbook/wall.webp";
  10. import { useT } from "@/components/locale-provider";
  11. import { projects } from "@/config/site";
  12. import { cn } from "@/lib/utils";
  13. // In order; each screen's label and alt text live in messages/ (packbook.screens).
  14. const SCREENS = [wall, identify, pack, share, buy];
  15. export function PackBookCard() {
  16. const {
  17. packbook: t,
  18. common: { open },
  19. } = useT();
  20. const screens = SCREENS.map((src, i) => ({ src, ...t.screens[i] }));
  21. const [index, setIndex] = useState(0);
  22. const [hovering, setHovering] = useState(false);
  23. const [loaded, setLoaded] = useState(1);
  24. const rootRef = useRef<HTMLDivElement>(null);
  25. const go = (i: number) => {
  26. setLoaded((n) => Math.max(n, i + 2));
  27. setIndex(i);
  28. };
  29. // Flip through the app while the card is hovered.
  30. useEffect(() => {
  31. if (!hovering) return;
  32. const id = window.setInterval(
  33. () =>
  34. setIndex((i) => {
  35. const next = (i + 1) % SCREENS.length;
  36. setLoaded((n) => Math.max(n, next + 2));
  37. return next;
  38. }),
  39. 1800,
  40. );
  41. return () => window.clearInterval(id);
  42. }, [hovering]);
  43. return (
  44. <div
  45. ref={rootRef}
  46. className="@container flex h-full gap-4 p-5 max-sm:flex-row sm:flex-col sm:p-6"
  47. onPointerEnter={(e) => {
  48. if (e.pointerType !== "touch") {
  49. setLoaded((n) => Math.max(n, 3));
  50. setHovering(true);
  51. }
  52. }}
  53. onPointerLeave={() => setHovering(false)}
  54. >
  55. <div className="flex min-w-0 flex-col max-sm:flex-1 max-sm:justify-between">
  56. <div>
  57. <Eyebrow>{t.eyebrow}</Eyebrow>
  58. <h2 className="title mt-1 text-[24px]">PackBook</h2>
  59. <p className="mt-1.5 text-[15px] leading-snug text-muted">
  60. {t.pitch}
  61. </p>
  62. </div>
  63. <div className="mt-3 flex flex-wrap gap-1 sm:hidden">
  64. {screens.map((s, i) => (
  65. <button
  66. key={s.label}
  67. className={cn(
  68. "rounded-full border px-2 py-0.5 text-[11px] font-medium",
  69. i === index
  70. ? "border-glacier text-ink"
  71. : "border-line text-muted",
  72. )}
  73. type="button"
  74. onClick={() => go(i)}
  75. >
  76. {s.label}
  77. </button>
  78. ))}
  79. </div>
  80. <TextLink
  81. className="mt-3 sm:hidden"
  82. cursor={open}
  83. href={projects.packbook.href}
  84. >
  85. {projects.packbook.linkLabel}
  86. </TextLink>
  87. </div>
  88. <button
  89. aria-label={t.next}
  90. className="relative mx-auto aspect-[720/1564] h-full max-h-full min-h-0 shrink-0 rounded-[1.6rem] bg-[#0b0b0c] p-[5px] shadow-[0_24px_48px_-24px_rgb(0_0_0/0.6)] transition-transform duration-500 ease-out [transform:perspective(900px)_rotateY(calc(var(--tx,0)*-12deg))_rotateX(calc(var(--ty,0)*8deg))] sm:min-h-0 sm:flex-1"
  91. data-cursor={t.nextCursor}
  92. type="button"
  93. onClick={() => go((index + 1) % SCREENS.length)}
  94. >
  95. <span className="relative block size-full overflow-hidden rounded-[1.25rem] bg-[#f4f0e8]">
  96. {screens.slice(0, loaded).map((s, i) => (
  97. <Image
  98. key={s.label}
  99. fill
  100. alt={s.alt}
  101. className={cn(
  102. "object-cover object-top transition-[opacity,scale] duration-500",
  103. i === index
  104. ? "scale-100 opacity-100"
  105. : "scale-[1.04] opacity-0",
  106. )}
  107. sizes="(max-width: 640px) 160px, 220px"
  108. src={s.src}
  109. />
  110. ))}
  111. </span>
  112. </button>
  113. <div className="hidden items-center justify-between sm:flex">
  114. {/* On a narrow card the dots tighten up to leave room for the link. */}
  115. <div className="-ml-[9px] flex @max-[215px]:-ml-[5px]">
  116. {screens.map((s, i) => (
  117. <button
  118. key={s.label}
  119. aria-label={t.show(s.label)}
  120. className="group/dot grid size-6 place-items-center @max-[215px]:w-4"
  121. type="button"
  122. onClick={() => go(i)}
  123. >
  124. <span
  125. className={cn(
  126. "h-1.5 rounded-full transition-all duration-500",
  127. i === index
  128. ? "w-4 bg-glacier"
  129. : "w-1.5 bg-line-strong group-hover/dot:bg-muted",
  130. )}
  131. />
  132. </button>
  133. ))}
  134. </div>
  135. <TextLink href={projects.packbook.href}>
  136. {projects.packbook.linkLabel}
  137. </TextLink>
  138. </div>
  139. </div>
  140. );
  141. }