Koroflow
Beta
Components

Consent Solution

A customizable cookie consent solution for web applications

Loading...

Features

  • 🎯 All-in-one consent management - just listen to the consent hooks for your business logic
  • 🌍 Out-of-the-box support for global privacy regulations (GDPR, CCPA, LGPD, US State Privacy)
  • ⚡ Intelligent geolocation-based compliance handling
  • 🔒 Flexible integration options:
    • Use our complete consent management system
    • Or bring your own consent logic with our raw components
  • 🎨 Fully customizable:
    • Built with Tailwind CSS and shadcn/ui
    • Themeable to match your brand
    • Responsive by default
  • 📝 Comprehensive tooling:
    • Automated consent persistence
    • Server and client components

Before implementing cookie consent, it's important to understand the key legal requirements:

GDPR Requirements

  • Explicit, granular consent must be obtained before processing any non-essential cookies
  • Users must be able to withdraw consent as easily as they gave it
  • Consent must be freely given, specific, informed, and unambiguous
  • Pre-ticked boxes or implicit consent are not valid

CCPA/CPRA Requirements

  • Users must be able to opt-out of the sale or sharing of their personal information
  • A "Do Not Sell My Personal Information" link must be prominently displayed
  • Businesses must honor Global Privacy Control (GPC) signals
  • Users must be informed about the categories of personal information collected

LGPD Requirements

  • Explicit consent must be obtained for data processing activities
  • Users must be informed about the purpose of data collection
  • Consent must be specific to each processing purpose
  • Users must have easy access to their privacy rights

Installation

There are two ways to install the component:

Usage

Basic Usage

The simplest implementation with only necessary cookies:

"use client";
 
import { CookieBanner } from "@/components/components/consent/cookie-banner";
import {
	ConsentManagerProvider,
	useConsentManager,
} from "@koroflow/core-react";
import { Cookie, Lock, RefreshCw } from "lucide-react";
import { useCallback } from "react";
import { Button } from "../components/button";
import { ConsentCustomizationDialog } from "../components/consent/consent-customization-dialog";
 
export default function PrivacyPopupMinimalDemo() {
	return (
		<ConsentManagerProvider
			initialGdprTypes={[
				"necessary",
				"marketing",
				"functionality",
				"measurement",
			]}
			// This namespace is used specifically for demonstration purposes,
			// allowing multiple instances of the consent manager to coexist on the same page.
			// It helps in isolating consent states for different demos or components.
			namespace="MinimalDemo"
		>
			<DemoWidget />
			<CookieBanner />
		</ConsentManagerProvider>
	);
}
 
export function DemoWidget() {
	const { clearAllData, setShowPopup } = useConsentManager();
	const handleResetConsent = useCallback(() => {
		clearAllData();
	}, [clearAllData]);
 
	const handleOpenCookiePopup = useCallback(() => {
		setShowPopup(true);
	}, [setShowPopup]);
 
	return (
		<div className="flex flex-col gap-4 py-8 lg:py-0">
			<Button onClick={handleOpenCookiePopup}>
				<Cookie className="h-4 w-4 mr-2" />
				Open Cookie Banner
			</Button>
			<ConsentCustomizationDialog>
				<Button>
					<Lock className="h-4 w-4 mr-2" />
					Open Consent Customization{" "}
				</Button>
			</ConsentCustomizationDialog>
			<Button onClick={handleResetConsent}>
				<RefreshCw className="h-4 w-4 mr-2" />
				Reset Local Storage Consent
			</Button>
		</div>
	);
}
 

Event Callbacks

Track user interactions with the consent system:

"use client";
 
import { ConsentCustomizationDialog } from "@/components/components/consent/consent-customization-dialog";
import { CookieBanner } from "@/registry/default/components/consent/cookie-banner";
import {
	ConsentManagerProvider,
	useConsentManager,
} from "@koroflow/core-react";
import { Cookie, Lock, RefreshCw } from "lucide-react";
import { useCallback, useEffect } from "react";
import { Button } from "../components/button";
 
export default function PrivacyPopupMinimalDemo() {
	return (
		<ConsentManagerProvider
			initialGdprTypes={[
				"necessary",
				"marketing",
				"functionality",
				"measurement",
			]}
			// This namespace is used specifically for demonstration purposes,
			// allowing multiple instances of the consent manager to coexist on the same page.
			// It helps in isolating consent states for different demos or components.
			namespace="CallbackDemo"
		>
			<DemoWidget />
			<CookieBanner />
		</ConsentManagerProvider>
	);
}
 
export function DemoWidget() {
	const { clearAllData, setShowPopup, setCallback } = useConsentManager();
 
	const handleResetConsent = useCallback(() => {
		clearAllData();
	}, [clearAllData]);
 
	const handleOpenCookiePopup = useCallback(() => {
		setShowPopup(true);
	}, [setShowPopup]);
 
	useEffect(() => {
		setCallback("onBannerShown", () => {
			console.log("Banner displayed");
		});
 
		setCallback("onConsentGiven", () => {
			console.log("User gave consent");
		});
 
		setCallback("onConsentRejected", () => {
			console.log("User rejected consent");
		});
 
		setCallback("onBannerClosed", () => {
			console.log("Banner closed");
		});
	}, [setCallback]);
	return (
		<div className="flex flex-col gap-4 py-8 lg:py-0">
			<Button onClick={handleOpenCookiePopup}>
				<Cookie className="h-4 w-4 mr-2" />
				Open Cookie Banner
			</Button>
			<ConsentCustomizationDialog>
				<Button>
					<Lock className="h-4 w-4 mr-2" />
					Open Consent Customization{" "}
				</Button>
			</ConsentCustomizationDialog>
			<Button onClick={handleResetConsent}>
				<RefreshCw className="h-4 w-4 mr-2" />
				Reset Local Storage Consent
			</Button>
		</div>
	);
}
 

API Reference

ConsentManagerProvider

PropTypeDefault
initialGdprTypes
allConsentNames[]
["necessary"]
initialComplianceSettings
Record<ComplianceRegion, ComplianceSettings>
-
initialPrivacyPolicyUrl
string
-
initialCookiePolicyUrl
string
-

CookiePopup

PropTypeDefault
bannerDescription
string
-
bannerTitle
string
-
className
string
-
horizontalPosition
'left' | 'center' | 'right'
center
verticalPosition
'top' | 'center' | 'bottom'
bottom
enableScrollLock
boolean
false

PrivacyConsentDialog

PropTypeDefault
children
React.ReactNode
-
className
string
-

ConsentCustomizationWidget

PropTypeDefault
onSave
() => void
-
className
string
-

useConsentManager

A hook for accessing the privacy consent context.

PropTypeDefault
consents
ConsentState
-
setConsent
(name: allConsentNames, value: boolean) => void
-
saveConsents
() => void
-
resetConsents
() => void
-
setCallback
(name: keyof Callbacks, callback: CallbackFunction) => void
-
setShowPopup
(show: boolean) => void
-
setIsPrivacyDialogOpen
(open: boolean) => void
-

Accessibility

The cookie consent components are built with accessibility in mind:

  • Full keyboard navigation support
  • ARIA labels and roles
  • Focus management
  • Screen reader announcements for consent changes
  • High contrast mode support

Best Practices

  1. Always include necessary cookies as required
  2. Provide clear descriptions for each consent type
  3. Include links to privacy and cookie policies
  4. Implement proper consent persistence
  5. Handle consent changes appropriately
  6. Consider regional privacy regulations
  7. Use appropriate callbacks to track user interactions
  8. Provide multiple ways to access privacy settings
  9. Ensure consistent styling across components

Resources