| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import { ArrowUpRight } from 'lucide-react';
- import { cn } from '@/lib/utils';
- import { useStorefront } from '../context';
- import type { BentoSection, BentoTile } from '../types';
- import { Container, SectionHeading, SfLink } from '../ui';
-
- /**
- * Tile sizes for the mosaic layout on wide screens (4 columns), by how many tiles there are.
- * The first tile is always the big one. On phones the big and wide tiles take the full width.
- */
- const mosaic: Record<number, string[]> = {
- 3: ['big', 'wide', 'wide'],
- 4: ['big', 'wide', 'small', 'small'],
- 5: ['big', 'small', 'small', 'small', 'small'],
- 6: ['big', 'small', 'small', 'small', 'small', 'full'],
- };
-
- const sizeClass: Record<string, string> = {
- big: 'col-span-2 row-span-2',
- wide: 'col-span-2',
- small: 'col-span-1',
- full: 'col-span-2 md:col-span-4',
- };
-
- const toneClass: Record<string, string> = {
- primary: 'bg-(--sf-primary) text-(--sf-primary-fg)',
- accent: 'bg-(--sf-accent) text-(--sf-fg)',
- dark: 'bg-(--sf-fg) text-(--sf-bg)',
- surface: 'bg-(--sf-surface) text-(--sf-fg)',
- };
-
- /** Tiles of different sizes for products, collections, offers and stories, like a bento box. */
- export function Bento({ section }: { section: BentoSection }) {
- const { heading, tiles } = section.content;
- const even = section.variant === 'even';
- const sizes = mosaic[tiles.length] ?? [];
-
- return (
- <section
- id={section.id}
- className="sf-section scroll-mt-20 py-16 md:py-20"
- data-layout={section.variant}
- >
- <Container>
- {heading && <SectionHeading heading={heading} />}
- <ul
- className={cn(
- 'grid gap-4',
- heading && 'mt-10',
- even
- ? 'grid-cols-1 sm:grid-cols-2 lg:grid-cols-3'
- : 'auto-rows-[180px] grid-cols-2 md:auto-rows-[220px] md:grid-cols-4',
- )}
- >
- {tiles.map((tile, index) => (
- <li
- key={tile.title + index}
- className={cn(
- !even && sizeClass[sizes[index] ?? 'small'],
- even && 'aspect-[4/3]',
- )}
- >
- <Tile tile={tile} big={!even && index === 0} />
- </li>
- ))}
- </ul>
- </Container>
- </section>
- );
- }
-
- function Tile({ tile, big }: { tile: BentoTile; big: boolean }) {
- const { heroImages } = useStorefront();
- const photo = tile.image ? heroImages.refs[tile.image] : undefined;
-
- return (
- <SfLink
- href={tile.href}
- className={cn(
- 'sf-card group relative flex h-full flex-col justify-end overflow-hidden rounded-(--sf-radius-card) border border-(--sf-border) p-5',
- photo
- ? 'text-white'
- : (toneClass[tile.tone ?? 'surface'] ?? toneClass.surface),
- )}
- >
- {photo && (
- <>
- <img
- src={photo}
- alt=""
- loading="lazy"
- className="absolute inset-0 -z-0 h-full w-full object-cover transition-transform duration-500 motion-safe:group-hover:scale-[1.04]"
- />
- <span className="absolute inset-0 bg-linear-to-t from-black/70 via-black/20 to-transparent" />
- </>
- )}
- <ArrowUpRight
- className="absolute top-4 right-4 size-5 opacity-70 transition-transform group-hover:translate-x-0.5 group-hover:-translate-y-0.5"
- aria-hidden="true"
- />
- <span className="relative">
- <span
- className={cn(
- 'sf-heading block font-semibold text-balance',
- big ? 'text-2xl md:text-3xl' : 'text-lg',
- )}
- >
- {tile.title}
- </span>
- {tile.text && (
- <span className="mt-1 block text-sm opacity-85">
- {tile.text}
- </span>
- )}
- </span>
- </SfLink>
- );
- }
|