Przeglądaj źródła

fix: phone hero fits its content; even spacing everywhere else

The hero spanned three square rows on phones (449-614px tall) while its
content needs about 400px, so the leftover showed as a band of empty
space under the byline.

- Phones: the hero is a full-width header row as tall as its content,
  with the cards packed below it. It isn't draggable there, drags below
  it snap correctly, and filters that leave it out hide it so their
  matches lead.
- Phones use the one-line headline, so the hero and the next card's
  title share the first screen, closer to the old card's density.
- On square cards, byline, statement, and links share spare height
  evenly instead of piling it above the headline.
- Desktop bio is 19px with slightly roomier spacing, which fills the
  square without crowding.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QEPoSHwHCYMNpm2iKxY9hL
Claude 1 miesiąc temu
rodzic
commit
4ac7ba43ac
4 zmienionych plików z 135 dodań i 65 usunięć
  1. 5 3
      app/page.tsx
  2. 74 8
      components/bento/bento-grid.tsx
  3. 38 38
      components/cards/hero.tsx
  4. 18 16
      styles/globals.css

+ 5 - 3
app/page.tsx

@@ -22,8 +22,8 @@ export default async function Page() {
   const [home, posts] = await Promise.all([getHomeData(), getLatestPosts()]);
   const [home, posts] = await Promise.all([getHomeData(), getLatestPosts()]);
 
 
   // Order matters: cards pack first-fit in this order. Sizes are columns × rows
   // Order matters: cards pack first-fit in this order. Sizes are columns × rows
-  // on phones (2 columns), wide phones (2), small tablets (2), tablets (3), and
-  // desktops (4).
+  // on phones (2 columns, below the hero's header row), wide phones (2), small
+  // tablets (2), tablets (3), and desktops (4).
   // On tablets:
   // On tablets:
   //   [hero      ][sky  ]
   //   [hero      ][sky  ]
   //   [hero      ][globe]
   //   [hero      ][globe]
@@ -49,13 +49,15 @@ export default async function Page() {
       tags: ["about"],
       tags: ["about"],
       label: "About Eric",
       label: "About Eric",
       size: [
       size: [
-        [2, 3],
+        [2, 1],
         [2, 2],
         [2, 2],
         [2, 2],
         [2, 2],
         [2, 2],
         [2, 2],
         [2, 2],
         [2, 2],
       ],
       ],
       still: true,
       still: true,
+      // On phones a header row as tall as its content (its phone size is unused).
+      header: true,
       content: <HeroCard avatarUrl={home.avatarUrl} dogUrl={home.dogUrl} />,
       content: <HeroCard avatarUrl={home.avatarUrl} dogUrl={home.dogUrl} />,
     },
     },
     {
     {

+ 74 - 8
components/bento/bento-grid.tsx

@@ -41,6 +41,11 @@ export type BentoItem = {
   content: ReactNode;
   content: ReactNode;
   /** Skip the entrance animation (keep it off the LCP card). */
   /** Skip the entrance animation (keep it off the LCP card). */
   still?: boolean;
   still?: boolean;
+  /**
+   * On phones, a full-width row above the cards, as tall as its content, and
+   * not draggable there. A regular card from wide phones up.
+   */
+  header?: boolean;
 };
 };
 
 
 type Drag = {
 type Drag = {
@@ -65,11 +70,16 @@ type Drag = {
   cell: { x: number; y: number } | null;
   cell: { x: number; y: number } | null;
   /** Reading order when the drag began: the others always re-pack in this order. */
   /** Reading order when the drag began: the others always re-pack in this order. */
   base: string[];
   base: string[];
+  /** Rows above the packed cards (a phone header row), and where those cards start. */
+  shift: number;
+  top: number;
 };
 };
 
 
 // Pointer-downs on these never start a card drag.
 // Pointer-downs on these never start a card drag.
 const INTERACTIVE =
 const INTERACTIVE =
   "a,button,input,textarea,select,label,canvas,[data-nodrag],[contenteditable=true]";
   "a,button,input,textarea,select,label,canvas,[data-nodrag],[contenteditable=true]";
+/** The tier whose header cards become a content-height row above the grid. */
+const HEADER_TIER = 0;
 /** Press and hold this long before a touch drag starts (quicker moves scroll). */
 /** Press and hold this long before a touch drag starts (quicker moves scroll). */
 const HOLD_MS = 380;
 const HOLD_MS = 380;
 /** Holding a card this close to the top or bottom of the viewport scrolls. */
 /** Holding a card this close to the top or bottom of the viewport scrolls. */
@@ -85,6 +95,13 @@ const slotOf = (el: HTMLElement) => ({
   height: el.offsetHeight,
   height: el.offsetHeight,
 });
 });
 
 
+/** Where the held card will land, in grid rows (below any header row). */
+const ghostOf = (d: Drag, layout: Cell[]) => {
+  const c = layout.find((cell) => cell.id === d.id);
+
+  return c ? { ...c, y: c.y + d.shift } : null;
+};
+
 /** Keep the dragged card under the pointer, wherever its slot is now. */
 /** Keep the dragged card under the pointer, wherever its slot is now. */
 function glue(grid: HTMLElement, d: Drag) {
 function glue(grid: HTMLElement, d: Drag) {
   const g = grid.getBoundingClientRect();
   const g = grid.getBoundingClientRect();
@@ -109,12 +126,19 @@ export function BentoGrid({ items }: { items: BentoItem[] }) {
   // Layouts the visitor arranged by dragging, per view and tier.
   // Layouts the visitor arranged by dragging, per view and tier.
   const [custom, setCustom] = useState<Record<string, Cell[]>>({});
   const [custom, setCustom] = useState<Record<string, Cell[]>>({});
   const [ghost, setGhost] = useState<Cell | null>(null);
   const [ghost, setGhost] = useState<Cell | null>(null);
+  const hasHeader = items.some((i) => i.header);
   const layouts = useMemo(
   const layouts = useMemo(
     () =>
     () =>
       TIERS.map(
       TIERS.map(
         (t, i) =>
         (t, i) =>
           custom[`${view}:${i}`] ??
           custom[`${view}:${i}`] ??
-          pack(display, (id) => byId.get(id)?.size[i] ?? [1, 1], t.cols),
+          pack(
+            i === HEADER_TIER
+              ? display.filter((id) => !byId.get(id)?.header)
+              : display,
+            (id) => byId.get(id)?.size[i] ?? [1, 1],
+            t.cols,
+          ),
       ),
       ),
     [custom, display, view, byId],
     [custom, display, view, byId],
   );
   );
@@ -242,7 +266,10 @@ export function BentoGrid({ items }: { items: BentoItem[] }) {
           Math.max(Math.round((d.x - g.left - d.grabX) / pitch), 0),
           Math.max(Math.round((d.x - g.left - d.grabX) / pitch), 0),
           d.cols - held.w,
           d.cols - held.w,
         );
         );
-        const y = Math.max(Math.round((d.y - g.top - d.grabY) / pitch), 0);
+        const y = Math.max(
+          Math.round((d.y - g.top - d.top - d.grabY) / pitch),
+          0,
+        );
 
 
         if (!d.cell || d.cell.x !== x || d.cell.y !== y) {
         if (!d.cell || d.cell.x !== x || d.cell.y !== y) {
           d.cell = { x, y };
           d.cell = { x, y };
@@ -260,9 +287,17 @@ export function BentoGrid({ items }: { items: BentoItem[] }) {
 
 
             before.current = snapshot();
             before.current = snapshot();
             setCustom((c) => ({ ...c, [key]: next }));
             setCustom((c) => ({ ...c, [key]: next }));
-            if (viewRef.current === "all") setOrder(readingOrder(next));
+            if (viewRef.current === "all") {
+              // The new reading order, with any header card kept in its place.
+              const packed = new Set(next.map((c) => c.id));
+              const rest = readingOrder(next);
+
+              setOrder((o) =>
+                o.map((id) => (packed.has(id) ? rest.shift()! : id)),
+              );
+            }
           }
           }
-          setGhost(next.find((c) => c.id === d.id) ?? null);
+          setGhost(ghostOf(d, next));
         }
         }
       }
       }
       if (near) d.frame = requestAnimationFrame(frame);
       if (near) d.frame = requestAnimationFrame(frame);
@@ -278,9 +313,19 @@ export function BentoGrid({ items }: { items: BentoItem[] }) {
       d.grabX = Math.min(Math.max(d.startX - r.left, 0), r.width);
       d.grabX = Math.min(Math.max(d.startX - r.left, 0), r.width);
       d.grabY = Math.min(Math.max(d.startY - r.top, 0), r.height);
       d.grabY = Math.min(Math.max(d.startY - r.top, 0), r.height);
       d.base = readingOrder(layoutsRef.current[d.tier]);
       d.base = readingOrder(layoutsRef.current[d.tier]);
+      // On phones the packed cards start below the header row (or its gap, when hidden).
+      if (d.shift) {
+        const header = grid.querySelector<HTMLElement>(
+          ":scope > [data-header]",
+        );
+
+        d.top =
+          (header?.offsetHeight ?? 0) +
+          (parseFloat(getComputedStyle(grid).rowGap) || 0);
+      }
       d.el.setAttribute("data-dragging", "true");
       d.el.setAttribute("data-dragging", "true");
       wrapRef.current?.setAttribute("data-dragging", "true");
       wrapRef.current?.setAttribute("data-dragging", "true");
-      setGhost(layoutsRef.current[d.tier].find((c) => c.id === d.id) ?? null);
+      setGhost(ghostOf(d, layoutsRef.current[d.tier]));
       document.documentElement.style.userSelect = "none";
       document.documentElement.style.userSelect = "none";
       window.getSelection()?.removeAllRanges();
       window.getSelection()?.removeAllRanges();
       if (d.touch) navigator.vibrate?.(8);
       if (d.touch) navigator.vibrate?.(8);
@@ -367,6 +412,10 @@ export function BentoGrid({ items }: { items: BentoItem[] }) {
       const el = target.closest<HTMLElement>("[data-card]");
       const el = target.closest<HTMLElement>("[data-card]");
 
 
       if (!el || !grid.contains(el)) return;
       if (!el || !grid.contains(el)) return;
+      const tier = tierFor(window.innerWidth);
+
+      // A phone header is a fixed row, not a card to move.
+      if (tier === HEADER_TIER && el.hasAttribute("data-header")) return;
       const r = el.getBoundingClientRect();
       const r = el.getBoundingClientRect();
       const d: Drag = {
       const d: Drag = {
         id: el.dataset.card!,
         id: el.dataset.card!,
@@ -381,10 +430,13 @@ export function BentoGrid({ items }: { items: BentoItem[] }) {
         active: false,
         active: false,
         frame: 0,
         frame: 0,
         hold: 0,
         hold: 0,
-        tier: tierFor(window.innerWidth),
+        tier,
         cols: 0,
         cols: 0,
         cell: null,
         cell: null,
         base: [],
         base: [],
+        shift:
+          tier === HEADER_TIER && grid.hasAttribute("data-has-header") ? 1 : 0,
+        top: 0,
       };
       };
 
 
       d.cols = TIERS[d.tier].cols;
       d.cols = TIERS[d.tier].cols;
@@ -480,7 +532,11 @@ export function BentoGrid({ items }: { items: BentoItem[] }) {
       onPointerLeave={onGridLeave}
       onPointerLeave={onGridLeave}
       onPointerMove={onGridMove}
       onPointerMove={onGridMove}
     >
     >
-      <ul ref={gridRef} className="bento">
+      <ul
+        ref={gridRef}
+        className="bento"
+        data-has-header={hasHeader ? "" : undefined}
+      >
         {/* DOM order never changes (moving nodes would restart their animations
         {/* DOM order never changes (moving nodes would restart their animations
             and reload iframes); each card's cell comes from the layout. */}
             and reload iframes); each card's cell comes from the layout. */}
         {items.map(({ id }) => {
         {items.map(({ id }) => {
@@ -494,11 +550,20 @@ export function BentoGrid({ items }: { items: BentoItem[] }) {
             const c = layout.find((cell) => cell.id === id);
             const c = layout.find((cell) => cell.id === id);
 
 
             if (!c) return;
             if (!c) return;
+            // Under a phone header row the cards start one row down.
+            const shift = t === HEADER_TIER && hasHeader ? 1 : 0;
+
             place[`--c${t}`] = c.x + 1;
             place[`--c${t}`] = c.x + 1;
-            place[`--r${t}`] = c.y + 1;
+            place[`--r${t}`] = c.y + 1 + shift;
             place[`--w${t}`] = c.w;
             place[`--w${t}`] = c.w;
             place[`--h${t}`] = c.h;
             place[`--h${t}`] = c.h;
           });
           });
+          if (item.header) {
+            place[`--c${HEADER_TIER}`] = 1;
+            place[`--r${HEADER_TIER}`] = 1;
+            place[`--w${HEADER_TIER}`] = TIERS[HEADER_TIER].cols;
+            place[`--h${HEADER_TIER}`] = 1;
+          }
 
 
           return (
           return (
             <li
             <li
@@ -515,6 +580,7 @@ export function BentoGrid({ items }: { items: BentoItem[] }) {
               className="card"
               className="card"
               data-card={id}
               data-card={id}
               data-dim={dim ? "true" : undefined}
               data-dim={dim ? "true" : undefined}
+              data-header={item.header ? "" : undefined}
               data-enter={item.still ? undefined : ""}
               data-enter={item.still ? undefined : ""}
               id={`card-${id}`}
               id={`card-${id}`}
               style={place as CSSProperties}
               style={place as CSSProperties}

+ 38 - 38
components/cards/hero.tsx

@@ -31,7 +31,7 @@ export function HeroCard({
   dogUrl: string;
   dogUrl: string;
 }) {
 }) {
   return (
   return (
-    <div className="relative flex h-full flex-col p-5 [container:hero/size] sm:p-6">
+    <div className="relative flex h-full flex-col justify-between p-5 [container:hero/inline-size] min-[480px]:[container:hero/size] sm:p-6">
       <div className="flex items-center gap-3.5">
       <div className="flex items-center gap-3.5">
         <AvatarFlip avatarUrl={avatarUrl} dogUrl={dogUrl} />
         <AvatarFlip avatarUrl={avatarUrl} dogUrl={dogUrl} />
         <div className="leading-tight">
         <div className="leading-tight">
@@ -51,51 +51,51 @@ export function HeroCard({
           </p>
           </p>
         </div>
         </div>
       </div>
       </div>
-      {/* Headline, bio, and links rest together at the foot of the card, so the
-          space above them is the only gap, whatever the card's height. */}
-      <div className="mt-auto pt-6">
+      {/* Byline, statement, and links share any spare height evenly. On phones
+          the card is as tall as its content, so they sit at these minimum gaps. */}
+      <div className="pt-5 min-[480px]:pt-6">
         <HeroTitle />
         <HeroTitle />
-        <p className="mt-4 max-w-[32em] text-[16px] leading-[1.5] text-pretty text-muted @max-[270px]/hero:text-[15px] min-[480px]:text-[17px] lg:text-[18px]">
+        <p className="mt-4 max-w-[32em] text-[16px] leading-[1.5] text-pretty text-muted @max-[270px]/hero:text-[15px] min-[480px]:text-[17px] lg:mt-5 lg:text-[19px]">
           An SDE II at AWS building agentic systems and generative UI. UCLA
           An SDE II at AWS building agentic systems and generative UI. UCLA
           &amp; Purdue alum. Passionate about crafting AI experiences that make
           &amp; Purdue alum. Passionate about crafting AI experiences that make
           life easier. Outside work, I&apos;m hiking with my dog Bert and
           life easier. Outside work, I&apos;m hiking with my dog Bert and
           planning to summit Mount Rainier in 2027!
           planning to summit Mount Rainier in 2027!
         </p>
         </p>
-        <nav
-          aria-label="Social links"
-          className="dock mt-6 flex items-center gap-2"
-        >
-          {socials.map((s) => (
-            <a
-              key={s.label}
-              aria-label={s.label}
-              className="lg grid size-10 place-items-center rounded-full transition-[scale,translate] duration-300 ease-out @max-[270px]/hero:size-9"
-              data-cursor={s.label}
-              href={s.href}
-              rel="noopener noreferrer"
-              target={s.href.startsWith("http") ? "_blank" : undefined}
-            >
-              <span aria-hidden className="lg-caustic" />
-              <svg
-                aria-hidden
-                className="size-4"
-                fill="currentColor"
-                viewBox="0 0 16 16"
-              >
-                <path d={s.path} />
-              </svg>
-            </a>
-          ))}
-          <Link
-            className="lg ml-1 inline-flex h-10 items-center gap-2 rounded-full px-4 text-[13px] font-medium transition-[scale] duration-300 hover:scale-[1.04] @max-[270px]/hero:h-9 @max-[270px]/hero:px-3.5"
-            data-cursor="Writing"
-            href="/blog"
+      </div>
+      <nav
+        aria-label="Social links"
+        className="dock mt-6 flex items-center gap-2 lg:mt-7"
+      >
+        {socials.map((s) => (
+          <a
+            key={s.label}
+            aria-label={s.label}
+            className="lg grid size-10 place-items-center rounded-full transition-[scale,translate] duration-300 ease-out @max-[270px]/hero:size-9"
+            data-cursor={s.label}
+            href={s.href}
+            rel="noopener noreferrer"
+            target={s.href.startsWith("http") ? "_blank" : undefined}
           >
           >
             <span aria-hidden className="lg-caustic" />
             <span aria-hidden className="lg-caustic" />
-            Read my blog
-          </Link>
-        </nav>
-      </div>
+            <svg
+              aria-hidden
+              className="size-4"
+              fill="currentColor"
+              viewBox="0 0 16 16"
+            >
+              <path d={s.path} />
+            </svg>
+          </a>
+        ))}
+        <Link
+          className="lg ml-1 inline-flex h-10 items-center gap-2 rounded-full px-4 text-[13px] font-medium transition-[scale] duration-300 hover:scale-[1.04] @max-[270px]/hero:h-9 @max-[270px]/hero:px-3.5"
+          data-cursor="Writing"
+          href="/blog"
+        >
+          <span aria-hidden className="lg-caustic" />
+          Read my blog
+        </Link>
+      </nav>
     </div>
     </div>
   );
   );
 }
 }

+ 18 - 16
styles/globals.css

@@ -426,6 +426,19 @@ html.ff {
     }
     }
   }
   }
 
 
+  /* Phones: a header card (the hero) is a full-width row of its own, as tall
+     as its content, so it never carries empty space. */
+  @media (max-width: 479px) {
+    .bento[data-has-header] {
+      grid-template-rows: auto;
+    }
+
+    /* When a filter doesn't include it, it steps aside so the matches lead. */
+    .bento > .card[data-header][data-dim] {
+      display: none;
+    }
+  }
+
   /* Where the held card will land: a soft, empty well of glass. */
   /* Where the held card will land: a soft, empty well of glass. */
   .bento-ghost {
   .bento-ghost {
     border-radius: 28px;
     border-radius: 28px;
@@ -949,28 +962,17 @@ html .notion-yt-lite {
 }
 }
 
 
 /*
 /*
- * The hero headline: one line that grows with its card (it runs ~6.4em wide),
- * or "Hey, I'm / Eric." on two lines when the card has the height for it.
- * How much height that takes depends on how the bio wraps, so each type size
- * (phones 16px, tablets 17px, desktops 18px) gets its own threshold.
+ * The hero headline: one line that grows with its card (it runs ~6.2em wide),
+ * or "Hey, I'm / Eric." on two lines when a square card has the height for
+ * it. How much height that takes depends on how the bio wraps, so each type
+ * size gets its own threshold. (On phones the card fits its content, so the
+ * line stays single.)
  */
  */
 .hero-title {
 .hero-title {
   font-size: clamp(2rem, 15.5cqi, 5.2rem);
   font-size: clamp(2rem, 15.5cqi, 5.2rem);
   line-height: 1.02;
   line-height: 1.02;
 }
 }
 
 
-/* Tall phone cards. */
-@container hero (min-height: 470px) and (max-aspect-ratio: 9 / 10) {
-  .hero-title {
-    font-size: 23cqi;
-    line-height: 0.98;
-  }
-
-  .hero-tail {
-    display: block;
-  }
-}
-
 /* Square cards, from wide phones up. */
 /* Square cards, from wide phones up. */
 @media (max-width: 639px) {
 @media (max-width: 639px) {
   @container hero (min-height: 480px) and (min-aspect-ratio: 9 / 10) {
   @container hero (min-height: 480px) and (min-aspect-ratio: 9 / 10) {