Cookie consent
Asks once and plainly: reject and accept carry the same weight, choices explain what they are for, and the preferences can be reopened later.
When to use
- Sites that set analytics or marketing cookies.
- A cookie settings link in the footer.
When not to use
- Only necessary cookies are used; no banner is needed, mention them in the policy.
Installation
terminal
pnpm dlx shadcn@latest add @caliper/cookie-consent
Adds its 7 files to components/ui/, each with its own stylesheet, and installs their packages. Pro installs with your access token, set up once per project. See Pro access. The first part also adds Caliper UI’s tokens; import them once as in Installation.
API reference
CookieConsent
9 props
PropTypeDefaultDescription
open *boolean—Show the banner, usually while no choice is stored.
categories *readonly CookieCategory[]—
valueCookieChoice—
onDecide *(choice: CookieChoice, decision: CookieDecision) => void—
titlestring"Cookies on this site"
descriptionstring"We use necessary cookies to make the site work. With your permission we would also like to measure visits and remember your settings."
policyHrefstring—
position"inline" | "fixed""fixed"`fixed` sits on the bottom of the viewport; `inline` stays where it is placed, e.g. in a preview.
classNamestring—
CookiePreferences
6 props
PropTypeDefaultDescription
open *boolean—
onOpenChange *(open: boolean) => void—
categories *readonly CookieCategory[]—
valueCookieChoice—The choice saved last time, if any.
onSave *(choice: CookieChoice, decision: CookieDecision) => void—
policyHrefstring—
Keyboard
- Keyboard and focus come from Radix dialog: arrow keys move through items, Enter and Space select, and Escape closes and returns focus.
Accessibility
It is built on native elements and keeps aria-describedby, aria-labelledby and aria-hidden in step with state.
Notes for AI
Give your coding assistant this page as Markdown instead of screenshots: the props, keyboard and examples in one file.
/docs/components/cookie-consent.mdThe index of every part is at /llms.txt.