Black Friday is here 🔥 Get Wensity Pro for 20% less with

Cookie Banner

React cookie banner with accept, reject and per-category switches, a saved choice and a cookie that takes a bite.

cookie bannercookie consentcookie popupconsent bannergdpr banner
Cookie Banner component preview

Overview

Cookie Banner is a React and Tailwind CSS cookie consent banner with accept, reject and per-category choices, in Next.js or any React app. It ships as a corner card or a bottom bar, with Reject all beside Accept all. Customize opens a switch for each category, and Necessary stays locked on. The choice is saved to localStorage with a version and a 180 day expiry, so returning visitors see no flash. The banner records consent but blocks nothing itself: start analytics inside onConsent, or read useCookieConsent. It is a non-modal dialog, and reduced motion removes the slide.

Installation

Run the following command

~/your-project
pnpm dlx wensity@latest add cookie-banner

Usage

Import CookieBanner from @/components/wensity/cookie-banner and render it anywhere in your React or Next.js app. The source lands in your own repo, so every prop, class and animation below is yours to edit.

app/example.tsx
import { CookieBanner, useCookieConsent } from "@/components/wensity/cookie-banner";
// Once, in your root layout.
export function Consent() {
return (
<CookieBanner
policyHref="/cookies"
onConsent={(consent) => {
if (consent.analytics) startAnalytics();
}}
/>
);
}
// Anywhere else: read the choice, or bring the banner back.
export function CookieSettingsLink() {
const { reset } = useCookieConsent();
return <button onClick={reset}>Cookie settings</button>;
}

Props

PropTypeDefaultDescription
variant"card" | "bar""card"A compact corner card or a wide strip along the bottom.
position"bottom-left" | "bottom-center" | "bottom-right""bottom-left"Corner the card sits in. The bar is always centred.
placement"fixed" | "inline""fixed"Pin it to the viewport, or render it in the page flow.
tone"neutral" | "blue" | "emerald" | "orange""neutral"Colour of the main button and the switches.
titlestring"We use cookies"Heading of the banner.
descriptionReactNode-Text under the heading.
policyHrefstring-Adds a link to your cookie policy after the description.
categoriesCookieCategory[]4 built inRows in the options panel: id, label, description, required and defaultValue.
onConsent(consent, action: "accept" | "reject" | "save") => void-Runs once the visitor has chosen, with each category id mapped to true or false.
storageKeystring | null"cookie-consent"localStorage key for the saved choice. Pass null to keep nothing.
versionstring-Change it to ask every visitor again.
expiresDaysnumber180Days before the saved choice expires and the banner returns.
openboolean-Control visibility yourself. Leave unset to follow the saved choice.
onOpenChange(open: boolean) => void-Called when the banner closes after a choice.
bitebooleantrueThe cookie loses a bite when the pointer rests on Accept and two more as the banner leaves.
acceptLabelstring"Accept all"Button text. rejectLabel, customizeLabel, saveLabel and requiredLabel work the same way.
  • macOS Floating Dock component preview

    macOS Floating Dock

    A magnetic dock where icons inflate near the cursor and push their siblings aside.

  • Multi-Select Tag Input component preview

    Multi-Select Tag Input

    A tag input where pills pop in as you add them and slide out on remove, closing the gap without snapping the layout.

  • Shimmering Skeleton Wrapper component preview

    Shimmering Skeleton Wrapper

    One angled GPU sweep that travels across any placeholder geometry you wrap, never a separate shimmer stuttering per row.

  • Cool Button component preview

    Cool Button

    A dual-layer orbit glow that soft-spins around the edge of any button or link you wrap it around, at zero layout cost.