Skip to content
StackD
Bot cookies, the StackD component

Notifications · Free

Bot cookies

A cookie banner where the cookie is the consent: chips for each kind you allow, the Bot eats it on Accept all; jelly switches, remembers the choice and calls onChoice.

Free on Gumroad: the download arrives in your inbox.

Details

Category
Notifications
Plan
Free
Code
React + Tailwind, TypeScript · 275 lines
Files
BotCookies.tsx
Needs
The Bot (installed with it)
Agents
MCP server and shadcn registry

About

A cookie banner where the Bot holds the cookie, and the cookie is the consent. Every kind of cookie you allow adds its chocolate chips; every one you turn off takes them away. Accept all and the Bot eats it, bite by bite, happy. Only the necessary ones and it keeps a plain biscuit and nods. Customize opens a jelly switch for each kind.

It remembers the choice (localStorage), so it doesn't ask again, and tells your code with onChoice.

Install

With the shadcn CLI:

npx shadcn@latest add https://www.stackd.codes/r/bot-cookies.json

Or let your agent add it through the StackD MCP server:

claude mcp add --transport http stackd https://www.stackd.codes/mcp

Prompt for your agent

Paste it into Claude Code, Cursor, Codex or VS Code once the MCP server is connected.

Add the StackD Bot cookies component to this project. Use the StackD MCP server: call get_component with { "name": "bot-cookies" }, write the files at the paths it gives and install any npm packages it lists. Then use it where it fits, following its README for the props, and keep its own styles.

What's inside

FileWhat it is
BotCookies.tsxThe banner
Bot.tsxThe Bot that holds the cookie

Use

  1. Copy both files into the same folder of your project (for example components/).
  2. Put it once in your layout:
import { BotCookies } from './components/BotCookies'

<BotCookies
  policyHref="/cookies"
  onChoice={(choice) => {
    // { necessary: true, analytics: boolean, marketing: boolean, preferences: boolean }
    if (choice.analytics) startAnalytics()
  }}
/>

On later visits, read the saved choice yourself before loading anything:

const saved = JSON.parse(localStorage.getItem('stackd-cookies') ?? 'null')

In Next.js the files already start with 'use client'. In other React setups that line does nothing.

Options

PropDefaultWhat it does
title'We use cookies'The heading
bodya short sentenceThe text under it
policyHrefYour cookie policy. Without it there's no link
kindsfour kindsNames and descriptions of necessary, analytics, marketing, preferences
onChoiceCalled with the choice, after the Bot's little scene
storageKey'stackd-cookies'Where the choice is kept. null: not kept, it asks every time
alwaysShowfalseShow it even if a choice is kept (for a settings page or a demo)
defaultOpenfalseStart with the switches open
defaultChoiceall onThe switches as they start, e.g. { marketing: false }
floatingtrueFixed in the bottom-left corner. false puts it where you place it
theme'light''light' or 'dark'
classNameExtra classes

Good to know

The banner records the choice; it doesn't block scripts by itself. Load analytics or ads only when onChoice (or the saved choice) says yes. Check what your country's rules ask for; this gives people a clear, equal choice between accepting and refusing.

Works with

Mouse, touch and keyboard. It's a dialog with a heading, and the kinds are real switches (role="switch"), so screen readers say on or off. With reduced motion on, the Bot doesn't animate: the choice is made straight away.

More in Notifications