| 12345678910111213141516171819202122232425262728293031323334 |
- import { MessageCircle } from 'lucide-react';
- import { useStorefront } from './context';
- import { storefrontText } from './text';
-
- export function whatsappLink(number: string, text: string): string {
- return `https://wa.me/${number}?text=${encodeURIComponent(text)}`;
- }
-
- /**
- * A round "chat on WhatsApp" button in the corner of every store page.
- * Shows only when the merchant has set a WhatsApp number.
- */
- export function WhatsAppButton() {
- const { shop, language, storeName } = useStorefront();
- const t = storefrontText(language);
-
- if (!shop.whatsapp) {
- return null;
- }
-
- return (
- <a
- href={whatsappLink(shop.whatsapp, t.whatsAppHello(storeName))}
- target="_blank"
- rel="noreferrer"
- className="fixed right-4 bottom-4 z-30 inline-flex items-center gap-2 rounded-full bg-[#25D366] px-4 py-3 text-sm font-semibold text-[#073B1C] shadow-lg transition-transform hover:scale-105 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-[#25D366] sm:right-6 sm:bottom-6"
- data-test="whatsapp-button"
- >
- <MessageCircle className="size-5" aria-hidden="true" />
- <span className="hidden sm:inline">{t.chatOnWhatsApp}</span>
- <span className="sr-only sm:hidden">{t.chatOnWhatsApp}</span>
- </a>
- );
- }
|