AI store generator for ecommerce, Malaysia first. Laravel 13 + React + TypeScript.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

featured-product.tsx 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import { Check } from 'lucide-react';
  2. import { cn } from '@/lib/utils';
  3. import { useStorefront } from '../context';
  4. import { ProductImage } from '../product-card';
  5. import { storefrontText } from '../text';
  6. import { formatPrice } from '../theme';
  7. import type { FeaturedProductSection } from '../types';
  8. import { Container, Eyebrow, SfButton } from '../ui';
  9. /**
  10. * One product, shown large.
  11. *
  12. * - Linked to a real product: its real name, price, photo and page are used. The AI's words stay as the description.
  13. * - Not linked, store has real products: no price is shown, because the AI's price is only an example.
  14. * - Not linked, store has no products yet: the AI's example name and price are shown, so a new store never looks empty.
  15. */
  16. export function FeaturedProduct({
  17. section,
  18. }: {
  19. section: FeaturedProductSection;
  20. }) {
  21. const { eyebrow, description, bullets, cta, productSlug } = section.content;
  22. const { featuredProducts, products, language } = useStorefront();
  23. const t = storefrontText(language);
  24. const product = productSlug ? featuredProducts[productSlug] : undefined;
  25. const showExamplePrice = !product && products.length === 0;
  26. const name = product?.name ?? section.content.name;
  27. const href = product ? `/products/${product.slug}` : cta.href;
  28. // stacked: a wide photo on top, the words centred under it.
  29. const stacked = section.variant === 'stacked';
  30. return (
  31. <section id={section.id} className="scroll-mt-20 bg-(--sf-surface)">
  32. <Container
  33. className={cn(
  34. 'sf-section grid items-center gap-10 py-16 md:py-20',
  35. stacked
  36. ? 'justify-items-center text-center'
  37. : 'md:grid-cols-2',
  38. )}
  39. >
  40. <div
  41. className={cn(
  42. 'relative',
  43. stacked && 'w-full',
  44. section.variant === 'image-right' && 'md:order-last',
  45. )}
  46. >
  47. <ProductImage
  48. src={product?.image ?? null}
  49. alt={name}
  50. seed={2}
  51. className={cn(
  52. 'w-full',
  53. stacked
  54. ? 'aspect-[4/3] md:aspect-[21/9]'
  55. : 'aspect-square',
  56. )}
  57. />
  58. {product && !product.in_stock && (
  59. <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)">
  60. {t.soldOut}
  61. </span>
  62. )}
  63. </div>
  64. <div
  65. className={cn(
  66. stacked && 'flex max-w-2xl flex-col items-center',
  67. )}
  68. >
  69. {eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
  70. <h2 className="sf-heading mt-3 text-3xl leading-tight font-semibold sm:text-4xl">
  71. {name}
  72. </h2>
  73. {product && (
  74. <p
  75. className="mt-3 text-2xl font-semibold tabular-nums"
  76. data-test="featured-price"
  77. >
  78. {product.price_varies
  79. ? t.from(formatPrice(product.price))
  80. : formatPrice(product.price)}
  81. {!product.price_varies &&
  82. product.compare_at_price !== null && (
  83. <s className="ml-3 text-base font-normal text-(--sf-muted)">
  84. {formatPrice(product.compare_at_price)}
  85. </s>
  86. )}
  87. </p>
  88. )}
  89. {showExamplePrice && (
  90. <p className="mt-3 text-2xl font-semibold tabular-nums">
  91. {formatPrice(section.content.price)}
  92. </p>
  93. )}
  94. <p className="mt-4 max-w-md text-(--sf-muted)">
  95. {description}
  96. </p>
  97. {bullets.length > 0 && (
  98. <ul
  99. className={cn(
  100. 'mt-6 text-sm',
  101. stacked
  102. ? 'flex flex-wrap justify-center gap-x-6 gap-y-2.5'
  103. : 'space-y-2.5',
  104. )}
  105. >
  106. {bullets.map((bullet) => (
  107. <li key={bullet} className="flex gap-2.5">
  108. <Check
  109. aria-hidden
  110. className="mt-0.5 size-4 shrink-0 text-(--sf-primary)"
  111. />
  112. {bullet}
  113. </li>
  114. ))}
  115. </ul>
  116. )}
  117. <SfButton href={href} className="mt-8">
  118. {product && !product.in_stock
  119. ? t.viewProduct
  120. : cta.label}
  121. </SfButton>
  122. </div>
  123. </Container>
  124. </section>
  125. );
  126. }