121 Pro components and page blocks

Get Pro

Updated

Cookie Consent

New

Preview

Customize

Bottom left
Duration0.45s

Installation

npx shadcn@latest add https://uibrik.com/r/cookie-consent.json
Adds the files to components/uibrik/cookie-consent and installs motion and react-use-measure. With the @uibrik namespace set up: npx shadcn@latest add @uibrik/cookie-consent.

Usage

import { CookieConsent } from "@/components/uibrik/cookie-consent/cookie-consent";​const message = "We use cookies to keep the site working and, with your consent, to understand how it's used.";​const categories = [  { id: "necessary", label: "Necessary", description: "Sign-in, security and your cookie choice.", required: true },  { id: "preferences", label: "Preferences", description: "Language, theme and other settings." },  // …2 more];​<CookieConsent  position="bottom-left"  title="We use cookies"  message={message}  policyHref="#"  duration={0.45}  categories={categories}  storageKey={null}  delay={600}  strategy="absolute"  policyLabel="Cookie policy"  onConsent={(preferences) => {}}  // open={false}  // onOpenChange={(open) => {}}  // getCookieConsent={(storageKey) => {}}/>

Where to use Cookie Consent

  • Cookie banners

    A banner sliding up after load and growing into category switches covers GDPR consent.

    Pairs with Checkbox

  • Privacy settings

    Remembering the visitor's choice and reopening to saved settings saves users time.

  • Marketing opt-ins

    Per-category switches let visitors allow analytics but block ads.

    Pairs with Tactile Toggles

Props

CookieConsent
position
Type "bottom-left" | "bottom" | "bottom-right"
"bottom-left"
Corner of the window the card sits in.
title
Type string
"We use cookies"
Heading of the card.
message
Type string
"We use cookies to keep the site working and, with your consent, to understand how it's used."
Text under the heading.
policyHref
Type string
"#"
Link to your cookie or privacy policy. Empty to leave it out.
duration
Type number
0.45
How long the card takes to move and grow.
open / onOpenChange
Type boolean / (open) => void
–
Controlled visibility. Uncontrolled, the card shows itself after `delay` when no choice is saved.
onConsent
Type (preferences: Record<string, boolean>) => void
–
Called with every category's state once the visitor chooses.
categories
Type { id; label; description?; required?; defaultOn? }[]
Necessary, Preferences, Analytics, Marketing
Categories in the customize view. Required ones are always on.
storageKey
Type string | null
"cookie-consent"
localStorage key for the choice. null keeps nothing.
delay
Type number
600
Milliseconds after mount before the card shows itself.
strategy
Type "fixed" | "absolute"
"fixed"
Pin it to the window, or to the nearest positioned parent.
policyLabel
Type string
"Cookie policy"
Text of the policy link.
getCookieConsent
Type (storageKey?) => preferences | null
–
Reads the saved choice anywhere in your app, e.g. before loading analytics.
className
Type string
–
Classes for the card.