Cookie Consent

Cookie consent card that springs up after mount with Accept all, Reject non-essential and Customize, where Customize grows the card into Necessary (locked on), Analytics and Marketing switches with Save; the choice is reported through onConsentChange and can persist to localStorage, anchored bottom-left, bottom or bottom-right, fixed to the viewport or contained in a parent.

Preview

Cookie Consent preview width

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @karaui/cookie-consent
@karaui not found? Add it to components.json
{
  "registries": {
    "@karaui": "https://karaui.kamisama-v0.my.id/r/{name}.json"
  }
}

@karaui is in shadcn's public registry directory, so the latest CLI needs no setup. On an older CLI, merge this into the existing file once and every @karaui/… install resolves.

API Reference

onConsentChange?
((preferences: CookiePreferences) => void)

Called with the final preferences whenever the visitor decides.

—
storageKey?
string

Persist the choice to `localStorage` under this key. When a saved choice exists the banner stays hidden. Read after mount, so SSR output is stable.

—
position?
"bottom" | "bottom-left" | "bottom-right"
bottom-right
contained?
boolean

Position inside the nearest positioned ancestor (`absolute`) instead of the viewport (`fixed`). Use for previews and contained layouts.

false
delay?
number

Delay before sliding up, in ms. Default 500.

500
defaultPreferences?
Partial<Pick<CookiePreferences, OptionalCategory>>

Starting state of the optional toggles in the Customize panel.

—
title?
ReactNode
We use cookies
description?
ReactNode
Some are essential to run the site. Others help us understand usage and show relevant ads — only with your permission.
className?
string
—

Keep in mind

Some components on this site are inspired by or recreated from existing work across the web. I'm not here to take credit; just to learn, experiment, and sometimes push things a bit further. If something looks familiar and I forgot to mention you, reach out and I'll fix that right away.

Updated