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.

product-grid.tsx 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { useStorefront } from '../context';
  2. import { ProductCard } from '../product-card';
  3. import { storefrontText } from '../text';
  4. import { formatPrice } from '../theme';
  5. import type { ProductGridSection } from '../types';
  6. import { Container, ImagePlaceholder, SectionHeading, SfButton } from '../ui';
  7. /** How many real products the home page shows before "View all". */
  8. const maxShown = 8;
  9. /**
  10. * Shows the merchant's real products when there are any.
  11. * Until then it shows the example items the AI wrote, so a new store never looks empty.
  12. */
  13. export function ProductGrid({ section }: { section: ProductGridSection }) {
  14. const { heading, subheading, items } = section.content;
  15. const minimal = section.variant === 'minimal';
  16. const { products, language } = useStorefront();
  17. const t = storefrontText(language);
  18. const hasProducts = products.length > 0;
  19. return (
  20. <section
  21. id={section.id}
  22. className="sf-section scroll-mt-20 py-16 md:py-20"
  23. >
  24. <Container>
  25. <div
  26. className={
  27. minimal
  28. ? ''
  29. : 'flex flex-wrap items-end justify-between gap-4'
  30. }
  31. >
  32. <SectionHeading
  33. heading={heading}
  34. subheading={subheading}
  35. align={minimal ? 'center' : 'left'}
  36. />
  37. {hasProducts && !minimal && (
  38. <SfButton href="/shop" variant="outline">
  39. {t.viewAll}
  40. </SfButton>
  41. )}
  42. </div>
  43. <ul className="mt-10 grid grid-cols-2 gap-x-5 gap-y-9 lg:grid-cols-4">
  44. {hasProducts
  45. ? products.slice(0, maxShown).map((product, index) => (
  46. <li key={product.id}>
  47. <ProductCard
  48. product={product}
  49. seed={index}
  50. centered={minimal}
  51. />
  52. </li>
  53. ))
  54. : items.map((item, index) => (
  55. <li key={item.name + index}>
  56. <div className="relative">
  57. <ImagePlaceholder
  58. seed={index}
  59. label={item.name}
  60. className="aspect-[4/5] w-full"
  61. />
  62. {item.badge && (
  63. <span className="absolute top-3 left-3 rounded-(--sf-radius) bg-(--sf-fg) px-2.5 py-1 text-xs font-semibold text-(--sf-bg)">
  64. {item.badge}
  65. </span>
  66. )}
  67. </div>
  68. <div
  69. className={
  70. minimal
  71. ? 'mt-4 text-center'
  72. : 'mt-4 flex flex-col gap-1 sm:flex-row sm:items-baseline sm:justify-between sm:gap-3'
  73. }
  74. >
  75. <h3 className="font-medium">
  76. {item.name}
  77. </h3>
  78. <p className="text-sm text-(--sf-muted) tabular-nums">
  79. {formatPrice(item.price)}
  80. </p>
  81. </div>
  82. </li>
  83. ))}
  84. </ul>
  85. {hasProducts && minimal && (
  86. <div className="mt-10 text-center">
  87. <SfButton href="/shop" variant="outline">
  88. {t.viewAll}
  89. </SfButton>
  90. </div>
  91. )}
  92. </Container>
  93. </section>
  94. );
  95. }