AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

shop.tsx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { cn } from '@/lib/utils';
  2. import { useStorefront } from '../context';
  3. import { ProductCard } from '../product-card';
  4. import { storefrontText } from '../text';
  5. import type { StoreCollection, StoreProduct } from '../types';
  6. import { Container, SfLink } from '../ui';
  7. /** The full shop: every product shoppers may see. Built by us, in the store's colours and fonts. */
  8. export function ShopPage() {
  9. const { products, language } = useStorefront();
  10. const t = storefrontText(language);
  11. return (
  12. <ProductList
  13. title={t.allProducts}
  14. description={null}
  15. products={products}
  16. current={null}
  17. />
  18. );
  19. }
  20. /** One collection's page: its products, with links to the other collections. */
  21. export function CollectionPage({
  22. collection,
  23. products,
  24. }: {
  25. collection: StoreCollection;
  26. products: StoreProduct[];
  27. }) {
  28. return (
  29. <ProductList
  30. title={collection.name}
  31. description={collection.description}
  32. products={products}
  33. current={collection.slug}
  34. />
  35. );
  36. }
  37. function ProductList({
  38. title,
  39. description,
  40. products,
  41. current,
  42. }: {
  43. title: string;
  44. description: string | null;
  45. products: StoreProduct[];
  46. current: string | null;
  47. }) {
  48. const { shop, language } = useStorefront();
  49. const t = storefrontText(language);
  50. const chip =
  51. 'inline-flex rounded-full border px-4 py-1.5 text-sm transition-colors';
  52. return (
  53. <main className="py-12 md:py-16">
  54. <Container>
  55. <h1 className="sf-heading text-4xl font-semibold sm:text-5xl">
  56. {title}
  57. </h1>
  58. {description && (
  59. <p className="mt-3 max-w-2xl text-(--sf-muted)">
  60. {description}
  61. </p>
  62. )}
  63. <p className="mt-3 text-sm text-(--sf-muted)">
  64. {products.length > 0
  65. ? t.productCount(products.length)
  66. : t.noProducts}
  67. </p>
  68. {shop.collections.length > 0 && (
  69. <nav
  70. aria-label={t.collections}
  71. className="mt-6 flex flex-wrap gap-2"
  72. data-test="collection-links"
  73. >
  74. <SfLink
  75. href="/shop"
  76. className={cn(
  77. chip,
  78. current === null
  79. ? 'border-(--sf-fg) bg-(--sf-fg) text-(--sf-bg)'
  80. : 'border-(--sf-border) hover:bg-(--sf-surface)',
  81. )}
  82. >
  83. {t.allProducts}
  84. </SfLink>
  85. {shop.collections.map((collection) => (
  86. <SfLink
  87. key={collection.slug}
  88. href={`/collections/${collection.slug}`}
  89. className={cn(
  90. chip,
  91. current === collection.slug
  92. ? 'border-(--sf-fg) bg-(--sf-fg) text-(--sf-bg)'
  93. : 'border-(--sf-border) hover:bg-(--sf-surface)',
  94. )}
  95. >
  96. {collection.name}
  97. </SfLink>
  98. ))}
  99. </nav>
  100. )}
  101. {products.length > 0 && (
  102. <ul className="mt-10 grid grid-cols-2 gap-x-5 gap-y-10 md:grid-cols-3 lg:grid-cols-4">
  103. {products.map((product, index) => (
  104. <li key={product.id}>
  105. <ProductCard product={product} seed={index} />
  106. </li>
  107. ))}
  108. </ul>
  109. )}
  110. </Container>
  111. </main>
  112. );
  113. }