ConsentBanner
Styled cookie/consent banner: fixed bottom bar with accept, decline and an optional manage-preferences action. Presentational only — wire it to useConsent (or your own store) and render it while the visitor is undecided.
Design intent
Every consumer app reinvents the same cookie banner and consent store. ConsentBanner owns the presentation (fixed bar, safe-area padding, labelled region, AA buttons); useConsent owns the headless state (per-purpose preferences, expiry, cross-tab sync) so neither side is coupled to the other.
npx @slipstream-ui/cli@latest add consent-bannerWe use cookies
Cookies
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| onAccept | () => void | required | Called on accept; typically consent.setAll(true). |
| onDecline | () => void | required | Called on decline; typically consent.setAll(false). |
| onManage | () => void | — | Optional manage-preferences action for granular consent dialogs. |
| title | ReactNode | — | Banner heading; omit for a single-line notice. |
| children | ReactNode | — | Body copy; put privacy-policy links here. |
| label | string | 'Cookie consent' | Accessible name for the banner region. |
| acceptLabel | ReactNode | 'Accept' | Accept button label. |
| declineLabel | ReactNode | 'Decline' | Decline button label. |
| manageLabel | ReactNode | 'Manage' | Manage-preferences button label. |
Anti-patterns
validate_usage is the MCP tool that rejects these mistakes: the same list agents see over MCP and in the canonical markdown.
Don't render before the decision is known
Render the banner only while consent.decided is false, and read preferences (not decided) to gate trackers — a denied purpose and an undecided visitor are different states.
tsx// Avoid{consent.decided && <Tracker />}// Prefer{consent.preferences?.analytics && <Tracker />}Don't block the page
ConsentBanner is non-modal by design; a modal consent wall hurts conversion and accessibility. Use Dialog only if your policy genuinely requires it.
tsx// Avoid<Dialog open={!consent.decided}>...</Dialog>
Accessibility
- Renders role=region with an aria-label (default "Cookie consent"); localize label and button labels.
- Accept and decline are equally prominent native Buttons with visible focus rings — no dark patterns.
- Bottom padding includes env(safe-area-inset-bottom) for notched devices.
Composition
Compose with useConsent: Headless hook exported from @slipstream-ui/core; wire onAccept/onDecline/onManage to setAll/set/clear
const consent = useConsent({ purposes: ['analytics', 'marketing'] });
Compose with SiteFooter: Re-open the banner or preferences dialog from a footer 'Cookie settings' link via consent.clear()
<SiteFooter contact={<button onClick={consent.clear}>Cookie settings</button>} />
Dependencies
What the registry installs alongside this component. Package imports already include these.
npm packages
- class-variance-authority
- clsx
- tailwind-merge
Browser support
| Browser | Tested versions |
|---|---|
| Chrome | 111+ (Mar 2023) |
| Edge | 111+ (Mar 2023) |
| Firefox | 121+ (Dec 2023) |
| Safari | 17.2+: macOS & iOS (Dec 2023) |
Slipstream components rely only on CSS custom properties, Flexbox/Grid, and ARIA, the everyday baseline of the last two years of evergreen releases. Anything newer is progressive enhancement: unsupported browsers keep full functionality with static behavior instead of animations.