| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- import { cn } from '@/lib/utils';
- import { useStorefront } from '../context';
- import { ProductCard } from '../product-card';
- import { storefrontText } from '../text';
- import type { StoreCollection, StoreProduct } from '../types';
- import { Container, SfLink } from '../ui';
-
- /** The full shop: every product shoppers may see. Built by us, in the store's colours and fonts. */
- export function ShopPage() {
- const { products, language } = useStorefront();
- const t = storefrontText(language);
-
- return (
- <ProductList
- title={t.allProducts}
- description={null}
- products={products}
- current={null}
- />
- );
- }
-
- /** One collection's page: its products, with links to the other collections. */
- export function CollectionPage({
- collection,
- products,
- }: {
- collection: StoreCollection;
- products: StoreProduct[];
- }) {
- return (
- <ProductList
- title={collection.name}
- description={collection.description}
- products={products}
- current={collection.slug}
- />
- );
- }
-
- function ProductList({
- title,
- description,
- products,
- current,
- }: {
- title: string;
- description: string | null;
- products: StoreProduct[];
- current: string | null;
- }) {
- const { shop, language } = useStorefront();
- const t = storefrontText(language);
- const chip =
- 'inline-flex rounded-full border px-4 py-1.5 text-sm transition-colors';
-
- return (
- <main className="py-12 md:py-16">
- <Container>
- <h1 className="sf-heading text-4xl font-semibold sm:text-5xl">
- {title}
- </h1>
- {description && (
- <p className="mt-3 max-w-2xl text-(--sf-muted)">
- {description}
- </p>
- )}
- <p className="mt-3 text-sm text-(--sf-muted)">
- {products.length > 0
- ? t.productCount(products.length)
- : t.noProducts}
- </p>
-
- {shop.collections.length > 0 && (
- <nav
- aria-label={t.collections}
- className="mt-6 flex flex-wrap gap-2"
- data-test="collection-links"
- >
- <SfLink
- href="/shop"
- className={cn(
- chip,
- current === null
- ? 'border-(--sf-fg) bg-(--sf-fg) text-(--sf-bg)'
- : 'border-(--sf-border) hover:bg-(--sf-surface)',
- )}
- >
- {t.allProducts}
- </SfLink>
- {shop.collections.map((collection) => (
- <SfLink
- key={collection.slug}
- href={`/collections/${collection.slug}`}
- className={cn(
- chip,
- current === collection.slug
- ? 'border-(--sf-fg) bg-(--sf-fg) text-(--sf-bg)'
- : 'border-(--sf-border) hover:bg-(--sf-surface)',
- )}
- >
- {collection.name}
- </SfLink>
- ))}
- </nav>
- )}
-
- {products.length > 0 && (
- <ul className="mt-10 grid grid-cols-2 gap-x-5 gap-y-10 md:grid-cols-3 lg:grid-cols-4">
- {products.map((product, index) => (
- <li key={product.id}>
- <ProductCard product={product} seed={index} />
- </li>
- ))}
- </ul>
- )}
- </Container>
- </main>
- );
- }
|