|
| 1 | +import React, { useState } from "react"; |
| 2 | + |
| 3 | +type PopupWhatsAppProps = { |
| 4 | + phoneNumber: string; |
| 5 | + message?: string; |
| 6 | +}; |
| 7 | + |
| 8 | +const PopupWhatsApp: React.FC<PopupWhatsAppProps> = ({ |
| 9 | + phoneNumber, |
| 10 | + message = "Hello GoBuild! I need some information regarding your services.", |
| 11 | +}) => { |
| 12 | + const [open, setOpen] = useState(false); |
| 13 | + |
| 14 | + const whatsappLink = `https://wa.me/${8899310111}?text=${encodeURIComponent( |
| 15 | + message |
| 16 | + )}`; |
| 17 | + |
| 18 | + return ( |
| 19 | + <> |
| 20 | + {/* Floating Button */} |
| 21 | + <div |
| 22 | + onClick={() => setOpen(!open)} |
| 23 | + style={{ |
| 24 | + position: "fixed", |
| 25 | + bottom: "20px", |
| 26 | + right: "20px", |
| 27 | + backgroundColor: "#25D366", |
| 28 | + width: "60px", |
| 29 | + height: "60px", |
| 30 | + borderRadius: "50%", |
| 31 | + display: "flex", |
| 32 | + alignItems: "center", |
| 33 | + justifyContent: "center", |
| 34 | + cursor: "pointer", |
| 35 | + boxShadow: "0 4px 10px rgba(0,0,0,0.3)", |
| 36 | + zIndex: 9999, |
| 37 | + animation: "bounce 1.5s infinite", |
| 38 | + transition: "0.3s ease", |
| 39 | + }} |
| 40 | + > |
| 41 | + {/* WhatsApp icon when closed */} |
| 42 | + {!open && ( |
| 43 | + <img |
| 44 | + src="https://upload.wikimedia.org/wikipedia/commons/6/6b/WhatsApp.svg" |
| 45 | + alt="whatsapp" |
| 46 | + style={{ width: "32px", height: "32px" }} |
| 47 | + /> |
| 48 | + )} |
| 49 | + |
| 50 | + {/* DOWN ARROW when popup is open */} |
| 51 | + {open && ( |
| 52 | + <img |
| 53 | + src="https://cdn-icons-png.flaticon.com/512/2985/2985150.png" |
| 54 | + alt="down arrow" |
| 55 | + style={{ |
| 56 | + width: "26px", |
| 57 | + height: "26px", |
| 58 | + filter: "brightness(0) invert(1)", // forces clean white |
| 59 | + }} |
| 60 | + /> |
| 61 | +)} |
| 62 | + |
| 63 | + </div> |
| 64 | + |
| 65 | + {/* Popup */} |
| 66 | + <div |
| 67 | + style={{ |
| 68 | + position: "fixed", |
| 69 | + bottom: open ? "100px" : "-300px", |
| 70 | + right: "20px", |
| 71 | + width: "260px", |
| 72 | + background: "white", |
| 73 | + borderRadius: "12px", |
| 74 | + padding: "16px", |
| 75 | + boxShadow: "0 4px 20px rgba(0,0,0,0.2)", |
| 76 | + zIndex: 999, |
| 77 | + transition: "bottom 0.35s ease", |
| 78 | + }} |
| 79 | + > |
| 80 | + <p style={{ fontWeight: "bold", marginBottom: "4px" }}>Hi there!</p> |
| 81 | + |
| 82 | + <a |
| 83 | + href={whatsappLink} |
| 84 | + target="_blank" |
| 85 | + rel="noopener noreferrer" |
| 86 | + style={{ |
| 87 | + display: "flex", |
| 88 | + alignItems: "center", |
| 89 | + gap: "8px", |
| 90 | + background: "#25D366", |
| 91 | + color: "white", |
| 92 | + padding: "10px 16px", |
| 93 | + borderRadius: "8px", |
| 94 | + textDecoration: "none", |
| 95 | + justifyContent: "center", |
| 96 | + fontSize: "14px", |
| 97 | + boxShadow: "0 2px 6px rgba(0,0,0,0.2)", |
| 98 | + }} |
| 99 | + > |
| 100 | + <img |
| 101 | + src="https://upload.wikimedia.org/wikipedia/commons/6/6b/WhatsApp.svg" |
| 102 | + style={{ width: "20px" }} |
| 103 | + /> |
| 104 | + Chat with us |
| 105 | + </a> |
| 106 | + </div> |
| 107 | + |
| 108 | + {/* Bounce Animation */} |
| 109 | + <style> |
| 110 | + {` |
| 111 | + @keyframes bounce { |
| 112 | + 0%, 100% { transform: translateY(0); } |
| 113 | + 50% { transform: translateY(-8px); } |
| 114 | + } |
| 115 | + `} |
| 116 | + </style> |
| 117 | + </> |
| 118 | + ); |
| 119 | +}; |
| 120 | + |
| 121 | +export default PopupWhatsApp; |
0 commit comments