|
2 | 2 |
|
3 | 3 | import React from "react" |
4 | 4 | import ReactCookieConsent from "react-cookie-consent" |
5 | | -import { useTheme } from "next-themes" |
| 5 | +import { Cookie } from "lucide-react" |
6 | 6 |
|
7 | 7 | export interface CookieConsentProps { |
8 | | - /** |
9 | | - * The text to display in the cookie consent banner |
10 | | - */ |
11 | | - text?: string |
12 | | - /** |
13 | | - * The text for the accept button |
14 | | - */ |
15 | | - buttonText?: string |
16 | 8 | /** |
17 | 9 | * Callback when cookies are accepted |
18 | 10 | */ |
@@ -45,90 +37,85 @@ export interface CookieConsentProps { |
45 | 37 |
|
46 | 38 | /** |
47 | 39 | * GDPR-compliant cookie consent banner component |
48 | | - * Uses Tailwind classes for styling and next-themes for dark mode detection |
| 40 | + * Uses Tailwind classes for styling |
49 | 41 | */ |
50 | 42 | export function CookieConsent({ |
51 | | - text = "Like pretty much everyone else, we use cookies. We assume you're OK with it, but you can opt out if you want.", |
52 | | - buttonText = "Accept", |
53 | 43 | onAccept, |
54 | 44 | onDecline, |
55 | | - enableDeclineButton = true, |
56 | | - declineButtonText = "Decline", |
57 | 45 | className = "", |
58 | 46 | cookieName = "roo-code-cookie-consent", |
59 | 47 | debug = false, |
60 | 48 | }: CookieConsentProps) { |
61 | | - const { theme } = useTheme() |
62 | | - const isDarkMode = theme === "dark" |
63 | | - |
64 | | - // Tailwind classes for the container |
65 | 49 | const containerClasses = ` |
66 | | - fixed bottom-0 left-0 right-0 z-[999] |
67 | | - ${isDarkMode ? "bg-black/95" : "bg-white/95"} |
| 50 | + fixed bottom-2 left-2 right-2 z-[999] |
| 51 | + bg-black/95 dark:bg-white/95 |
| 52 | + text-white dark:text-black |
| 53 | + border-t-neutral-800 dark:border-t-gray-200 |
68 | 54 | backdrop-blur-xl |
69 | | - ${isDarkMode ? "border-t-neutral-800" : "border-t-gray-200"} |
70 | 55 | border-t |
| 56 | + font-semibold |
| 57 | + rounded-t-lg |
71 | 58 | px-4 py-4 md:px-8 md:py-4 |
72 | 59 | flex flex-wrap items-center justify-between gap-4 |
73 | 60 | text-sm font-sans |
74 | 61 | ${className} |
75 | 62 | `.trim() |
76 | 63 |
|
77 | | - // Tailwind classes for the accept button |
| 64 | + const buttonWrapperClasses = ` |
| 65 | + flex |
| 66 | + flex-row-reverse |
| 67 | + items-center |
| 68 | + gap-2 |
| 69 | + `.trim() |
| 70 | + |
78 | 71 | const acceptButtonClasses = ` |
79 | | - ${isDarkMode ? "bg-white text-black" : "bg-black text-white"} |
80 | | - hover:opacity-90 |
| 72 | + bg-white text-black border-neutral-800 |
| 73 | + dark:bg-black dark:text-white dark:border-gray-200 |
| 74 | + hover:opacity-50 |
81 | 75 | transition-opacity |
82 | 76 | rounded-md |
83 | | - px-4 py-2 |
84 | | - text-sm font-medium |
| 77 | + px-4 py-2 mr-2 |
| 78 | + text-sm font-bold |
85 | 79 | cursor-pointer |
86 | 80 | focus:outline-none focus:ring-2 focus:ring-offset-2 |
87 | | - ${isDarkMode ? "focus:ring-white" : "focus:ring-black"} |
88 | 81 | `.trim() |
89 | 82 |
|
90 | | - // Tailwind classes for the decline button |
91 | 83 | const declineButtonClasses = ` |
92 | | - bg-transparent |
93 | | - ${isDarkMode ? "text-white border-neutral-800" : "text-black border-gray-200"} |
94 | | - border |
95 | | - hover:opacity-90 |
| 84 | + dark:bg-white dark:text-black dark:border-gray-200 |
| 85 | + bg-black text-white border-neutral-800 |
| 86 | + hover:opacity-50 |
| 87 | + border border-border |
96 | 88 | transition-opacity |
97 | 89 | rounded-md |
98 | 90 | px-4 py-2 |
99 | | - text-sm font-medium |
| 91 | + text-sm font-bold |
100 | 92 | cursor-pointer |
101 | 93 | focus:outline-none focus:ring-2 focus:ring-offset-2 |
102 | | - ${isDarkMode ? "focus:ring-white" : "focus:ring-black"} |
103 | | - `.trim() |
104 | | - |
105 | | - // Tailwind classes for the content |
106 | | - const contentClasses = ` |
107 | | - flex-1 |
108 | | - ${isDarkMode ? "text-neutral-200" : "text-gray-700"} |
109 | | - mr-4 |
110 | 94 | `.trim() |
111 | 95 |
|
112 | 96 | return ( |
113 | 97 | <div role="banner" aria-label="Cookie consent banner" aria-live="polite"> |
114 | 98 | <ReactCookieConsent |
115 | 99 | location="bottom" |
116 | | - buttonText={buttonText} |
117 | | - declineButtonText={declineButtonText} |
| 100 | + buttonText="Accept" |
| 101 | + declineButtonText="Decline" |
118 | 102 | cookieName={cookieName} |
119 | 103 | expires={365} |
120 | | - enableDeclineButton={enableDeclineButton} |
| 104 | + enableDeclineButton={true} |
121 | 105 | onAccept={onAccept} |
122 | 106 | onDecline={onDecline} |
123 | 107 | debug={debug} |
124 | 108 | containerClasses={containerClasses} |
125 | 109 | buttonClasses={acceptButtonClasses} |
| 110 | + buttonWrapperClasses={buttonWrapperClasses} |
126 | 111 | declineButtonClasses={declineButtonClasses} |
127 | | - contentClasses={contentClasses} |
128 | 112 | disableStyles={true} |
129 | | - ariaAcceptLabel={`Accept ${buttonText}`} |
130 | | - ariaDeclineLabel={`Decline ${declineButtonText}`}> |
131 | | - {text} |
| 113 | + ariaAcceptLabel={`Accept`} |
| 114 | + ariaDeclineLabel={`Decline`}> |
| 115 | + <div className="flex items-center gap-2"> |
| 116 | + <Cookie className="size-5 hidden md:block" /> |
| 117 | + <span>Like most of the internet, we use cookies. Are you OK with that?</span> |
| 118 | + </div> |
132 | 119 | </ReactCookieConsent> |
133 | 120 | </div> |
134 | 121 | ) |
|
0 commit comments