import { Image } from '@components/common/Image.js'; import { Editable, EditableImageOverlay } from '@components/common/page-builder/index.js'; import React from 'react'; /** * Bento grid — an asymmetric mosaic of CTA tiles. One large hero tile * plus 1–4 supporting tiles in a 3-column responsive grid. Tile count * adapts the layout (2/3/4/5 total). * * - 2 tiles: hero spans column 1; small fills column 2 across both rows * - 3 tiles: hero col-1, two smalls stacked in col-2 * - 4 tiles: hero col-1 (rows 1-2), three smalls in 2x2 right area * (the 3rd small spans the full bottom width of the right area) * - 5 tiles: hero col-1 (rows 1-2), four smalls in 2x2 right area * * Tile images render through the core `` component (absolute- * positioned to fill the tile under the content scrim) so they get * responsive srcSet behaviour. `aria-label` on each tile link carries * the semantics; the image is decorative. */ export type BentoGap = 'sm' | 'md' | 'lg'; export type BentoTextColor = 'light' | 'dark'; export interface BentoLink { label: string; url: string; newTab: boolean; } export interface BentoTile { id: string; size: 'lg' | 'sm'; image: string | null; imageAlt: string; /** Natural intrinsic dimensions of `image`, captured at pick time. */ imageWidth?: number | null; imageHeight?: number | null; backgroundColor: string; eyebrow: string | null; heading: string; body: string | null; link: BentoLink; textColor: BentoTextColor; } export interface BentoGridProps { bentoGridWidget: { tiles: BentoTile[]; gap: BentoGap; minHeight: number; }; } const GAP_CLASS: Record = { sm: 'gap-2', md: 'gap-4', lg: 'gap-6' }; function smallTileSpan(totalSmall: number, index: number): string { // 0-indexed `index` is within the small-tiles list. These spans only apply on // the desktop 4-column layout (`lg:`), where the hero occupies the left 2×2 // block and the small tiles fill the right two columns across two rows. On // mobile/tablet the grid is 2-up and small tiles are always a single column. // Desktop fills of the right 2×2 area, by small-tile count: // 1 → fills the whole right half (mirrors the hero) // 2 → two full-height columns beside the hero // 3 → 2-up on top, the third spans the bottom row // 4 → clean 2×2 if (totalSmall === 1) return 'lg:col-span-2 lg:row-span-2'; if (totalSmall === 2) return 'lg:row-span-2'; if (totalSmall === 3) { return index === 2 ? 'lg:col-span-2' : ''; } return ''; } function TileBackground({ tile, isHero }: { tile: BentoTile; isHero: boolean; }) { if (!tile.image) return null; const fallbackWidth = isHero ? 1200 : 800; const fallbackHeight = isHero ? 1500 : 800; return ( 0 ? tile.imageWidth : fallbackWidth } height={ tile.imageHeight && tile.imageHeight > 0 ? tile.imageHeight : fallbackHeight } objectFit="cover" sizes={ isHero ? '(max-width: 1023px) 100vw, 50vw' : '(max-width: 1023px) 50vw, 25vw' } className="evershop-bento-grid__image absolute inset-0 h-full w-full transition-transform duration-500 ease-out group-hover:scale-[1.06]" // `height: 100%` defeats the shared 's inline `height: auto`, // which otherwise renders the img at its intrinsic aspect height — // a few px shorter than the tile — exposing the tile's backgroundColor // as a thin bar at the bottom. `aspectRatio: auto` clears its inline // aspect so `object-cover` can fill the whole tile. style={{ aspectRatio: 'auto', height: '100%' }} /> ); } function TileContent({ tile, isHero, originalIndex }: { tile: BentoTile; isHero: boolean; originalIndex: number; }) { const textClass = tile.textColor === 'light' ? 'text-white' : 'text-foreground'; const base = `settings.tiles.${originalIndex}`; return (
{/* Legibility scrim. Render it over a background image, and ALSO whenever the tile uses light text with no image — otherwise white copy sits on the raw (often light) background color at ~1.6:1. A bottom-anchored dark gradient gives the text a dark backing either way. */} {(tile.image || tile.textColor === 'light') && ( ); } export default function BentoGrid({ bentoGridWidget }: BentoGridProps) { const { tiles = [], gap, minHeight } = bentoGridWidget; // Track the source index alongside the filter so inline edits write back // to `settings.tiles.${originalIndex}.{eyebrow|heading|body}`. const enriched = (tiles ?? []) .map((tile, originalIndex) => ({ tile, originalIndex })) .filter(({ tile }) => tile && tile.heading && tile.link?.url); if (enriched.length === 0) return null; const hero = enriched[0]; const smalls = enriched.slice(1, 5); const totalSmall = smalls.length; const gapClass = GAP_CLASS[gap ?? 'md']; return (
{/* Hero */} {/* Smalls */} {smalls.map(({ tile, originalIndex }, i) => ( ))}
); } export const query = ` query Query($tiles: JSON, $gap: String, $minHeight: Float) { bentoGridWidget(tiles: $tiles, gap: $gap, minHeight: $minHeight) { tiles gap minHeight } } `; export const variables = `{ tiles: getWidgetSetting("tiles", []), gap: getWidgetSetting("gap", "md"), minHeight: getWidgetSetting("minHeight", 360) }`;