README / w-312356-main /src /components /FloatingContactButton.tsx
TAShaikhh's picture
Upload 159 files
d3b533c verified
import { MessageSquare } from "lucide-react";
import { useState, useEffect } from "react";
import { Button } from "@/components/ui/button";
const FloatingContactButton = () => {
const [isVisible, setIsVisible] = useState(false);
// Show the button after scrolling down a bit
useEffect(() => {
const handleScroll = () => {
const scrollY = window.scrollY;
if (scrollY > 500) {
setIsVisible(true);
} else {
setIsVisible(false);
}
};
window.addEventListener("scroll", handleScroll);
return () => window.removeEventListener("scroll", handleScroll);
}, []);
const scrollToContact = (e: React.MouseEvent) => {
e.preventDefault();
const contactSection = document.getElementById('contact-info');
if (contactSection) {
contactSection.scrollIntoView({
behavior: 'smooth'
});
}
};
if (!isVisible) return null;
return (
<Button
onClick={scrollToContact}
className="fixed bottom-6 right-6 z-50 bg-gray-800 hover:bg-gray-700 text-white rounded-full p-3 shadow-lg hover:shadow-xl transition-all"
size="icon"
aria-label="Contact Us"
>
<MessageSquare className="h-6 w-6" />
</Button>
);
};
export default FloatingContactButton;