|
| 1 | +import React, { useState, useEffect } from 'react'; |
| 2 | +import { motion, AnimatePresence } from 'framer-motion'; |
| 3 | +import { Cookie, X } from 'lucide-react'; |
| 4 | +import { Button } from '@/components/ui/button'; |
| 5 | +import { Link } from 'react-router-dom'; |
| 6 | + |
| 7 | +const CookieConsent = () => { |
| 8 | + const [showBanner, setShowBanner] = useState(false); |
| 9 | + |
| 10 | + useEffect(() => { |
| 11 | + const consent = localStorage.getItem('cookie-consent'); |
| 12 | + if (!consent) { |
| 13 | + // Show banner after a short delay |
| 14 | + setTimeout(() => setShowBanner(true), 1000); |
| 15 | + } |
| 16 | + }, []); |
| 17 | + |
| 18 | + const handleAccept = () => { |
| 19 | + localStorage.setItem('cookie-consent', 'accepted'); |
| 20 | + setShowBanner(false); |
| 21 | + }; |
| 22 | + |
| 23 | + const handleDecline = () => { |
| 24 | + localStorage.setItem('cookie-consent', 'declined'); |
| 25 | + setShowBanner(false); |
| 26 | + }; |
| 27 | + |
| 28 | + return ( |
| 29 | + <AnimatePresence> |
| 30 | + {showBanner && ( |
| 31 | + <motion.div |
| 32 | + initial={{ y: 100, opacity: 0 }} |
| 33 | + animate={{ y: 0, opacity: 1 }} |
| 34 | + exit={{ y: 100, opacity: 0 }} |
| 35 | + transition={{ duration: 0.3 }} |
| 36 | + className="fixed bottom-0 left-0 right-0 z-50 p-4" |
| 37 | + > |
| 38 | + <div className="container mx-auto max-w-6xl"> |
| 39 | + <div className="bg-alien-space-dark/95 backdrop-blur-md border-2 border-alien-gold/30 rounded-xl p-6 shadow-2xl"> |
| 40 | + <div className="flex flex-col lg:flex-row items-start lg:items-center gap-4"> |
| 41 | + {/* Icon and Message */} |
| 42 | + <div className="flex items-start gap-4 flex-1"> |
| 43 | + <div className="p-2 bg-alien-gold/20 rounded-lg flex-shrink-0"> |
| 44 | + <Cookie className="h-6 w-6 text-alien-gold" /> |
| 45 | + </div> |
| 46 | + <div className="flex-1"> |
| 47 | + <h3 className="text-alien-gold font-bold font-nasalization mb-2"> |
| 48 | + Cookie Notice |
| 49 | + </h3> |
| 50 | + <p className="text-gray-200 text-sm font-[Exo] leading-relaxed"> |
| 51 | + We use cookies to enhance your experience, analyze site traffic, and provide |
| 52 | + personalized content. By clicking "Accept", you consent to our use of cookies.{' '} |
| 53 | + <Link |
| 54 | + to="/privacy-policy" |
| 55 | + className="text-alien-gold hover:text-alien-gold-light underline" |
| 56 | + onClick={() => setShowBanner(false)} |
| 57 | + > |
| 58 | + Learn more |
| 59 | + </Link> |
| 60 | + </p> |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + |
| 64 | + {/* Action Buttons */} |
| 65 | + <div className="flex gap-3 w-full lg:w-auto lg:flex-shrink-0"> |
| 66 | + <Button |
| 67 | + onClick={handleDecline} |
| 68 | + variant="outline" |
| 69 | + className="flex-1 lg:flex-none border-alien-gold/50 text-alien-gold hover:bg-alien-gold/10 hover:border-alien-gold font-[Exo]" |
| 70 | + > |
| 71 | + Decline |
| 72 | + </Button> |
| 73 | + <Button |
| 74 | + onClick={handleAccept} |
| 75 | + className="flex-1 lg:flex-none bg-alien-gold text-alien-space-dark hover:bg-alien-gold-light font-[Exo] font-semibold" |
| 76 | + > |
| 77 | + Accept |
| 78 | + </Button> |
| 79 | + </div> |
| 80 | + |
| 81 | + {/* Close Button */} |
| 82 | + <button |
| 83 | + onClick={handleDecline} |
| 84 | + className="absolute top-3 right-3 lg:relative lg:top-0 lg:right-0 p-1 text-gray-400 hover:text-alien-gold transition-colors" |
| 85 | + aria-label="Close" |
| 86 | + > |
| 87 | + <X className="h-5 w-5" /> |
| 88 | + </button> |
| 89 | + </div> |
| 90 | + </div> |
| 91 | + </div> |
| 92 | + </motion.div> |
| 93 | + )} |
| 94 | + </AnimatePresence> |
| 95 | + ); |
| 96 | +}; |
| 97 | + |
| 98 | +export default CookieConsent; |
0 commit comments