import { useStorefront } from '../context'; import type { ShopBySection, StoreCollection } from '../types'; import { Container, ImagePlaceholder, SectionHeading, SfLink } from '../ui'; /** * "Shop by": the store's collections as round photos (circles) or larger photo tiles (tiles). * Shows the collections the design names, in that order, or every collection when it names none. * Nothing shows until the merchant has a collection with products. */ export function ShopBy({ section }: { section: ShopBySection }) { const { shop } = useStorefront(); const { heading, subheading, collections: wanted } = section.content; const shown: StoreCollection[] = wanted.length > 0 ? wanted .map((slug) => shop.collections.find((item) => item.slug === slug), ) .filter((item): item is StoreCollection => Boolean(item)) : shop.collections; if (shown.length === 0) { return null; } if (section.variant === 'tiles') { return (
    {shown.map((collection, index) => (
  • {collection.image ? ( ) : ( )} {collection.name} {collection.count}
  • ))}
); } return (
    {shown.map((collection, index) => (
  • {collection.image ? ( ) : ( )} {collection.name}
  • ))}
); }