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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 id={section.id} className="scroll-mt-20 py-16 md:py-20">
  21. <Container>
  22. <div
  23. className={
  24. minimal
  25. ? ''
  26. : 'flex flex-wrap items-end justify-between gap-4'
  27. }
  28. >
  29. <SectionHeading
  30. heading={heading}
  31. subheading={subheading}
  32. align={minimal ? 'center' : 'left'}
  33. />
  34. {hasProducts && !minimal && (
  35. <SfButton href="/shop" variant="outline">
  36. {t.viewAll}
  37. </SfButton>
  38. )}
  39. </div>
  40. <ul className="mt-10 grid grid-cols-2 gap-x-5 gap-y-9 lg:grid-cols-4">
  41. {hasProducts
  42. ? products.slice(0, maxShown).map((product, index) => (
  43. <li key={product.id}>
  44. <ProductCard
  45. product={product}
  46. seed={index}
  47. centered={minimal}
  48. />
  49. </li>
  50. ))
  51. : items.map((item, index) => (
  52. <li key={item.name + index}>
  53. <div className="relative">
  54. <ImagePlaceholder
  55. seed={index}
  56. label={item.name}
  57. className="aspect-[4/5] w-full"
  58. />
  59. {item.badge && (
  60. <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)">
  61. {item.badge}
  62. </span>
  63. )}
  64. </div>
  65. <div
  66. className={
  67. minimal
  68. ? 'mt-4 text-center'
  69. : 'mt-4 flex flex-col gap-1 sm:flex-row sm:items-baseline sm:justify-between sm:gap-3'
  70. }
  71. >
  72. <h3 className="font-medium">
  73. {item.name}
  74. </h3>
  75. <p className="text-sm text-(--sf-muted) tabular-nums">
  76. {formatPrice(item.price)}
  77. </p>
  78. </div>
  79. </li>
  80. ))}
  81. </ul>
  82. {hasProducts && minimal && (
  83. <div className="mt-10 text-center">
  84. <SfButton href="/shop" variant="outline">
  85. {t.viewAll}
  86. </SfButton>
  87. </div>
  88. )}
  89. </Container>
  90. </section>
  91. );
  92. }