11"use client"
22
3- import React from "react"
4- import { CookieConsent } from "./CookieConsent"
3+ import React , { useState , useEffect } from "react"
4+ import ReactCookieConsent from "react-cookie-consent"
5+ import { Cookie } from "lucide-react"
6+ import { getDomain } from "tldts"
7+ import { CONSENT_COOKIE_NAME } from "@/lib/constants"
58import { dispatchConsentEvent } from "@/lib/analytics/consent-manager"
69
710/**
8- * Wrapper component for CookieConsent that handles consent callbacks
9- * This is needed because we can't pass event handlers from server components
11+ * GDPR-compliant cookie consent banner component
12+ * Handles both the UI and consent event dispatching
1013 */
1114export function CookieConsentWrapper ( ) {
15+ const [ cookieDomain , setCookieDomain ] = useState < string | null > ( null )
16+
17+ useEffect ( ( ) => {
18+ // Get the appropriate domain using tldts
19+ if ( typeof window !== "undefined" ) {
20+ const domain = getDomain ( window . location . hostname )
21+ setCookieDomain ( domain )
22+ }
23+ } , [ ] )
24+
1225 const handleAccept = ( ) => {
1326 dispatchConsentEvent ( true )
1427 }
@@ -17,5 +30,82 @@ export function CookieConsentWrapper() {
1730 dispatchConsentEvent ( false )
1831 }
1932
20- return < CookieConsent onAccept = { handleAccept } onDecline = { handleDecline } enableDeclineButton = { true } />
33+ const extraCookieOptions = cookieDomain
34+ ? {
35+ domain : cookieDomain ,
36+ }
37+ : { }
38+
39+ const containerClasses = `
40+ fixed bottom-2 left-2 right-2 z-[999]
41+ bg-black/95 dark:bg-white/95
42+ text-white dark:text-black
43+ border-t-neutral-800 dark:border-t-gray-200
44+ backdrop-blur-xl
45+ border-t
46+ font-semibold
47+ rounded-t-lg
48+ px-4 py-4 md:px-8 md:py-4
49+ flex flex-wrap items-center justify-between gap-4
50+ text-sm font-sans
51+ ` . trim ( )
52+
53+ const buttonWrapperClasses = `
54+ flex
55+ flex-row-reverse
56+ items-center
57+ gap-2
58+ ` . trim ( )
59+
60+ const acceptButtonClasses = `
61+ bg-white text-black border-neutral-800
62+ dark:bg-black dark:text-white dark:border-gray-200
63+ hover:opacity-50
64+ transition-opacity
65+ rounded-md
66+ px-4 py-2 mr-2
67+ text-sm font-bold
68+ cursor-pointer
69+ focus:outline-none focus:ring-2 focus:ring-offset-2
70+ ` . trim ( )
71+
72+ const declineButtonClasses = `
73+ dark:bg-white dark:text-black dark:border-gray-200
74+ bg-black text-white border-neutral-800
75+ hover:opacity-50
76+ border border-border
77+ transition-opacity
78+ rounded-md
79+ px-4 py-2
80+ text-sm font-bold
81+ cursor-pointer
82+ focus:outline-none focus:ring-2 focus:ring-offset-2
83+ ` . trim ( )
84+
85+ return (
86+ < div role = "banner" aria-label = "Cookie consent banner" aria-live = "polite" >
87+ < ReactCookieConsent
88+ location = "bottom"
89+ buttonText = "Accept"
90+ declineButtonText = "Decline"
91+ cookieName = { CONSENT_COOKIE_NAME }
92+ expires = { 365 }
93+ enableDeclineButton = { true }
94+ onAccept = { handleAccept }
95+ onDecline = { handleDecline }
96+ containerClasses = { containerClasses }
97+ buttonClasses = { acceptButtonClasses }
98+ buttonWrapperClasses = { buttonWrapperClasses }
99+ declineButtonClasses = { declineButtonClasses }
100+ extraCookieOptions = { extraCookieOptions }
101+ disableStyles = { true }
102+ ariaAcceptLabel = { `Accept` }
103+ ariaDeclineLabel = { `Decline` } >
104+ < div className = "flex items-center gap-2" >
105+ < Cookie className = "size-5 hidden md:block" />
106+ < span > Like most of the internet, we use cookies. Are you OK with that?</ span >
107+ </ div >
108+ </ ReactCookieConsent >
109+ </ div >
110+ )
21111}
0 commit comments