Overview
TheWhatsappButton component is a floating action button that appears after scrolling, providing users with quick access to WhatsApp contact. It features smooth animations, hover effects, and route-based visibility control.
Features
- Scroll-Based Visibility: Appears after scrolling 300px down the page
- Route-Aware: Automatically hidden on the
/loginpage - Smooth Animations: Fade and slide animations for appearance/disappearance
- Hover Effects: Scale and shadow effects on hover
- Pre-filled Message: Opens WhatsApp with a default greeting message
- Fixed Positioning: Stays in the bottom-right corner of the viewport
Component Structure
The WhatsappButton component is a client-side component that doesn’t accept any props.Implementation
Basic Usage
State Management
The component manages two pieces of state:visible: Controls whether the button is shown based on scroll positionpathname: Used to hide the button on specific routes
Scroll Detection
The component listens for scroll events and shows the button after 300px:Route-Based Visibility
The button is automatically hidden on the login page:WhatsApp Configuration
Phone Number
Pre-filled Message
The button opens WhatsApp with a friendly greeting:WhatsApp Link
Styling
Button Appearance
- Size: 56px x 56px on mobile, 64px x 64px on desktop
- Color: WhatsApp green (
#25D366) - Shape: Circular with
rounded-full - Icon: WhatsApp icon from
react-icons/fa
Animation Classes
Visibility States
Visible
opacity-100: Fully visibletranslate-y-0: Original position- Pointer events enabled
Hidden
opacity-0: Invisibletranslate-y-10: Moved 40px downpointer-events-none: No interaction possible
Hover Effects
hover:scale-110: Grows to 110% sizehover:shadow-[0_0_25px_rgba(37,211,102,0.6)]: Glowing green shadow effect
Responsive Sizing
Positioning
Animation Duration
All transitions use a 500ms duration for smooth animations:Accessibility
The link opens in a new tab with WhatsApp’s web interface:The button uses
pointer-events-none when hidden to prevent accidental clicks on the invisible element.Dependencies
Design Tokens
Colors
- Background:
#25D366(WhatsApp brand color) - Text: White
- Hover Shadow:
rgba(37,211,102,0.6)(Semi-transparent green)
Timing
- Scroll Threshold: 300px
- Transition Duration: 500ms
Sizes
- Mobile: 56px x 56px
- Desktop: 64px x 64px
- Hover Scale: 110%
Customization Examples
Change Scroll Threshold
Change Phone Number
Change Default Message
Hide on Additional Routes
Source Code Location
/app/components/WhatsappButton.tsx
Related Components
- ScrollToTop - Companion button for scrolling to page top