Cookie Consent
A compact cookie card with Accept / Reject and a Customise view where each category has its own switch.
$
View as Markdownnpx shadcn@latest add https://sundaeui.dev/r/cookie-consent.jsonOverview
Accept all and Reject all are equal weight, as regulators expect. Customise expands the card in place into category switches with one-line explanations; Necessary is locked on.
Saving collapses it to a small confirmation that fades away.
When to use
- First visit on sites that set non-essential cookies.
When not to use
- Sites with only essential cookies: no banner is needed.
Installation
$
pnpm dlx shadcn@latest add https://sundaeui.dev/r/cookie-consent.json$
npx shadcn@latest add https://sundaeui.dev/r/cookie-consent.json$
yarn dlx shadcn@latest add https://sundaeui.dev/r/cookie-consent.json$
bunx --bun shadcn@latest add https://sundaeui.dev/r/cookie-consent.jsonWorks in any React project. Files are written to components/sundae/. Read the source in the stage’s Code view.
- No dependencies beyond React 18 or later.
- Copy cookie-consent.tsx and cookie-consent.css into components/sundae/.
- The CSS file is imported by the component, so no extra configuration is needed.
- Import the component and use it as shown below.
Usage
import { CookieConsent } from '@/components/sundae/cookie-consent'
<CookieConsent />Props
| Prop | Type | Default |
|---|---|---|
categories*Categories. | { id: string; label: string; hint: string; locked?: boolean }[] | — |
onSaveCalled with enabled category ids. | (enabled: string[]) => void | — |
fillSurface: dark or light. | 'dark' | 'light' | 'dark' |
Accessibility
- A labelled region (not a modal) so it never traps focus.
- Switches are role="switch" buttons with aria-checked; the locked one is aria-disabled.
- Reduced motion removes the movement and keeps every state change.
Customization
- Colours are CSS custom properties on .sd-cks; override them in your own stylesheet.
- fill="light" switches the built-in light palette.
FAQ
- Is Cookie Consent free?
- Yes. Cookie Consent is free for personal and commercial projects, with full source on this page.
- How do I install Cookie Consent?
- Run npx shadcn@latest add https://sundaeui.dev/r/cookie-consent.json. The files are written to components/sundae/. It has no dependencies beyond React 18 or later.
- Does Cookie Consent support keyboard and screen readers?
- A labelled region (not a modal) so it never traps focus. Switches are role="switch" buttons with aria-checked; the locked one is aria-disabled.
- Does Cookie Consent respect reduced motion?
- Reduced motion removes the movement and keeps every state change.
More like this
All components →Announcement Bar
Components · RefinedInline Alert
Components · RefinedPermission Prompt
Components · Refined- Pro
Glass Control Center
Components · Refined Toast Stack
Components · Refined- Pro
Sheet Drawer
Components · Refined