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.

trust-bar.tsx 6.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import type { LucideIcon } from 'lucide-react';
  2. import {
  3. Award,
  4. Clock,
  5. Gift,
  6. Heart,
  7. Leaf,
  8. MapPin,
  9. MessageCircle,
  10. Package,
  11. RefreshCw,
  12. ShieldCheck,
  13. Star,
  14. Truck,
  15. } from 'lucide-react';
  16. import { useStorefront } from '../context';
  17. import { storefrontText } from '../text';
  18. import { formatPrice } from '../theme';
  19. import type { TrustBarSection, TrustIcon, TrustItem } from '../types';
  20. import { Container } from '../ui';
  21. import { cn } from '@/lib/utils';
  22. const icons: Record<TrustIcon, LucideIcon> = {
  23. truck: Truck,
  24. shield: ShieldCheck,
  25. chat: MessageCircle,
  26. refresh: RefreshCw,
  27. leaf: Leaf,
  28. star: Star,
  29. gift: Gift,
  30. clock: Clock,
  31. heart: Heart,
  32. award: Award,
  33. 'map-pin': MapPin,
  34. package: Package,
  35. };
  36. type Shown = { icon: LucideIcon; title: string; text: string | null };
  37. /**
  38. * Short reassurances, such as free shipping and secure payment.
  39. * Shipping, payment and WhatsApp items are written from the store's real settings, so they are always true.
  40. */
  41. export function TrustBar({ section }: { section: TrustBarSection }) {
  42. const { shop, language } = useStorefront();
  43. const t = storefrontText(language);
  44. function show(item: TrustItem): Shown | null {
  45. const icon = item.icon ? icons[item.icon] : undefined;
  46. switch (item.kind) {
  47. case 'shipping': {
  48. const free = shop.free_shipping_over;
  49. return {
  50. icon: icon ?? Truck,
  51. title:
  52. free === 0
  53. ? t.trustFreeShipping
  54. : free !== null
  55. ? t.trustFreeShippingOver(formatPrice(free))
  56. : t.trustShippingFrom(
  57. formatPrice(shop.shipping_from),
  58. ),
  59. text: t.trustShippingText,
  60. };
  61. }
  62. case 'payment':
  63. return {
  64. icon: icon ?? ShieldCheck,
  65. title: t.trustPayment,
  66. text: t.trustPaymentText,
  67. };
  68. case 'whatsapp':
  69. return shop.whatsapp
  70. ? {
  71. icon: icon ?? MessageCircle,
  72. title: t.trustWhatsApp,
  73. text: t.trustWhatsAppText,
  74. }
  75. : null;
  76. default:
  77. return item.title
  78. ? {
  79. icon: icon ?? Star,
  80. title: item.title,
  81. text: item.text ?? null,
  82. }
  83. : null;
  84. }
  85. }
  86. const items = section.content.items
  87. .map(show)
  88. .filter((item): item is Shown => item !== null);
  89. if (items.length === 0) {
  90. return null;
  91. }
  92. const columns =
  93. items.length >= 4
  94. ? 'md:grid-cols-4'
  95. : items.length === 3
  96. ? 'md:grid-cols-3'
  97. : 'md:grid-cols-2';
  98. if (section.variant === 'boxed') {
  99. return (
  100. <section id={section.id} className="scroll-mt-20 py-10">
  101. <Container>
  102. <ul className={cn('grid grid-cols-2 gap-3', columns)}>
  103. {items.map((item) => (
  104. <li
  105. key={item.title}
  106. className="flex flex-col gap-3 rounded-(--sf-radius-card) border border-(--sf-border) p-5"
  107. >
  108. <item.icon
  109. className="size-6 text-(--sf-primary)"
  110. aria-hidden="true"
  111. />
  112. <div>
  113. <p className="font-semibold">
  114. {item.title}
  115. </p>
  116. {item.text && (
  117. <p className="mt-1 text-sm text-(--sf-muted)">
  118. {item.text}
  119. </p>
  120. )}
  121. </div>
  122. </li>
  123. ))}
  124. </ul>
  125. </Container>
  126. </section>
  127. );
  128. }
  129. return (
  130. <section
  131. id={section.id}
  132. className="scroll-mt-20 border-y border-(--sf-border) bg-(--sf-surface)"
  133. >
  134. <Container>
  135. <ul
  136. className={cn(
  137. 'grid grid-cols-2 gap-x-4 gap-y-5 py-6',
  138. columns,
  139. )}
  140. >
  141. {items.map((item) => (
  142. <li
  143. key={item.title}
  144. className="flex items-start gap-3 sm:items-center"
  145. >
  146. <span className="grid size-10 shrink-0 place-items-center rounded-full bg-(--sf-bg) text-(--sf-primary)">
  147. <item.icon
  148. className="size-5"
  149. aria-hidden="true"
  150. />
  151. </span>
  152. <div className="min-w-0">
  153. <p className="text-sm font-semibold">
  154. {item.title}
  155. </p>
  156. {item.text && (
  157. <p className="text-xs text-(--sf-muted) sm:text-sm">
  158. {item.text}
  159. </p>
  160. )}
  161. </div>
  162. </li>
  163. ))}
  164. </ul>
  165. </Container>
  166. </section>
  167. );
  168. }