| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- 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 (
- <section
- id={section.id}
- className="sf-section scroll-mt-20 py-16 md:py-20"
- data-layout="tiles"
- >
- <Container>
- <SectionHeading heading={heading} subheading={subheading} />
- <ul className="mt-10 grid grid-cols-2 gap-4 md:grid-cols-3">
- {shown.map((collection, index) => (
- <li key={collection.slug}>
- <SfLink
- href={`/collections/${collection.slug}`}
- className="group relative block overflow-hidden rounded-(--sf-radius-card)"
- >
- {collection.image ? (
- <img
- src={collection.image}
- alt=""
- loading="lazy"
- className="sf-card aspect-[4/5] w-full rounded-(--sf-radius-card) object-cover transition-transform duration-500 motion-safe:group-hover:scale-[1.04]"
- />
- ) : (
- <ImagePlaceholder
- seed={index}
- label={collection.name}
- className="aspect-[4/5] w-full"
- />
- )}
- <span className="absolute inset-x-0 bottom-0 rounded-b-(--sf-radius-card) bg-linear-to-t from-black/70 to-transparent p-4 pt-12 text-white">
- <span className="sf-heading block text-lg font-semibold">
- {collection.name}
- </span>
- <span className="text-sm text-white/80">
- {collection.count}
- </span>
- </span>
- </SfLink>
- </li>
- ))}
- </ul>
- </Container>
- </section>
- );
- }
-
- return (
- <section
- id={section.id}
- className="sf-section scroll-mt-20 py-14 md:py-16"
- data-layout="circles"
- >
- <Container>
- <SectionHeading
- heading={heading}
- subheading={subheading}
- align="center"
- />
- <ul className="-mx-5 mt-8 flex snap-x gap-6 overflow-x-auto px-5 pb-2 sm:mx-0 sm:flex-wrap sm:justify-center sm:overflow-visible sm:px-0">
- {shown.map((collection, index) => (
- <li
- key={collection.slug}
- className="w-24 shrink-0 snap-start sm:w-32"
- >
- <SfLink
- href={`/collections/${collection.slug}`}
- className="group flex flex-col items-center gap-3 text-center"
- >
- {collection.image ? (
- <img
- src={collection.image}
- alt=""
- loading="lazy"
- className="aspect-square w-full rounded-full object-cover ring-1 ring-(--sf-border) transition-transform duration-300 motion-safe:group-hover:scale-105"
- />
- ) : (
- <ImagePlaceholder
- seed={index}
- label={collection.name}
- className="aspect-square w-full rounded-full!"
- />
- )}
- <span className="text-sm font-medium group-hover:underline">
- {collection.name}
- </span>
- </SfLink>
- </li>
- ))}
- </ul>
- </Container>
- </section>
- );
- }
|