| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- import type { LucideIcon } from 'lucide-react';
- import {
- Award,
- Clock,
- Gift,
- Heart,
- Leaf,
- MapPin,
- MessageCircle,
- Package,
- RefreshCw,
- ShieldCheck,
- Star,
- Truck,
- } from 'lucide-react';
- import { useStorefront } from '../context';
- import { storefrontText } from '../text';
- import { formatPrice } from '../theme';
- import type { TrustBarSection, TrustIcon, TrustItem } from '../types';
- import { Container } from '../ui';
- import { cn } from '@/lib/utils';
-
- const icons: Record<TrustIcon, LucideIcon> = {
- truck: Truck,
- shield: ShieldCheck,
- chat: MessageCircle,
- refresh: RefreshCw,
- leaf: Leaf,
- star: Star,
- gift: Gift,
- clock: Clock,
- heart: Heart,
- award: Award,
- 'map-pin': MapPin,
- package: Package,
- };
-
- type Shown = { icon: LucideIcon; title: string; text: string | null };
-
- /**
- * Short reassurances, such as free shipping and secure payment.
- * Shipping, payment and WhatsApp items are written from the store's real settings, so they are always true.
- */
- export function TrustBar({ section }: { section: TrustBarSection }) {
- const { shop, language } = useStorefront();
- const t = storefrontText(language);
-
- function show(item: TrustItem): Shown | null {
- const icon = item.icon ? icons[item.icon] : undefined;
-
- switch (item.kind) {
- case 'shipping': {
- const free = shop.free_shipping_over;
-
- return {
- icon: icon ?? Truck,
- title:
- free === 0
- ? t.trustFreeShipping
- : free !== null
- ? t.trustFreeShippingOver(formatPrice(free))
- : t.trustShippingFrom(
- formatPrice(shop.shipping_from),
- ),
- text: t.trustShippingText,
- };
- }
- case 'payment':
- return {
- icon: icon ?? ShieldCheck,
- title: t.trustPayment,
- text: t.trustPaymentText,
- };
- case 'whatsapp':
- return shop.whatsapp
- ? {
- icon: icon ?? MessageCircle,
- title: t.trustWhatsApp,
- text: t.trustWhatsAppText,
- }
- : null;
- default:
- return item.title
- ? {
- icon: icon ?? Star,
- title: item.title,
- text: item.text ?? null,
- }
- : null;
- }
- }
-
- const items = section.content.items
- .map(show)
- .filter((item): item is Shown => item !== null);
-
- if (items.length === 0) {
- return null;
- }
-
- const columns =
- items.length >= 4
- ? 'md:grid-cols-4'
- : items.length === 3
- ? 'md:grid-cols-3'
- : 'md:grid-cols-2';
-
- if (section.variant === 'boxed') {
- return (
- <section id={section.id} className="sf-section scroll-mt-20 py-10">
- <Container>
- <ul className={cn('grid grid-cols-2 gap-3', columns)}>
- {items.map((item) => (
- <li
- key={item.title}
- className="sf-card flex flex-col gap-3 rounded-(--sf-radius-card) border border-(--sf-border) p-5"
- >
- <item.icon
- className="size-6 text-(--sf-primary)"
- aria-hidden="true"
- />
- <div>
- <p className="font-semibold">
- {item.title}
- </p>
- {item.text && (
- <p className="mt-1 text-sm text-(--sf-muted)">
- {item.text}
- </p>
- )}
- </div>
- </li>
- ))}
- </ul>
- </Container>
- </section>
- );
- }
-
- return (
- <section
- id={section.id}
- className="scroll-mt-20 border-y border-(--sf-border) bg-(--sf-surface)"
- >
- <Container>
- <ul
- className={cn(
- 'grid grid-cols-2 gap-x-4 gap-y-5 py-6',
- columns,
- )}
- >
- {items.map((item) => (
- <li
- key={item.title}
- className="flex items-start gap-3 sm:items-center"
- >
- <span className="grid size-10 shrink-0 place-items-center rounded-full bg-(--sf-bg) text-(--sf-primary)">
- <item.icon
- className="size-5"
- aria-hidden="true"
- />
- </span>
- <div className="min-w-0">
- <p className="text-sm font-semibold">
- {item.title}
- </p>
- {item.text && (
- <p className="text-xs text-(--sf-muted) sm:text-sm">
- {item.text}
- </p>
- )}
- </div>
- </li>
- ))}
- </ul>
- </Container>
- </section>
- );
- }
|