All blocks
[41] Feedback
Cookie Consent
A card pinned to the bottom with Accept, Reject and Choose; Choose opens a dialog with a switch per kind of cookie.
1280px
Copy the code
One file with one component and its sample data. It needs @vaneui/ui and its stylesheet, set up as in the installation guide. It passes an onClick handler, so in the Next.js App Router add "use client" at the top of its file.
cookie.tsx
import { useState } from "react";import { Button, Card, Col, Label, Link, Modal, ModalBody, ModalCloseButton, ModalFooter, ModalHeader, Row, Section, Switch, Text, Title } from "@vaneui/ui";
const kinds = [ { id: "necessary", label: "Necessary", text: "Sign-in, security and your cart. These are always on.", locked: true }, { id: "preferences", label: "Preferences", text: "Language, theme and other settings you choose." }, { id: "analytics", label: "Analytics", text: "Anonymous counts of visits, so we see which pages help." }, { id: "marketing", label: "Marketing", text: "Measuring ads on other sites. We never sell your data." },];
export function CookieConsent() { const [answered, setAnswered] = useState(false); const [choicesOpen, setChoicesOpen] = useState(false); const [allowed, setAllowed] = useState<string[]>(["necessary", "preferences"]); if (answered) return null;
const toggle = (id: string) => setAllowed((a) => (a.includes(id) ? a.filter((x) => x !== id) : [...a, id])); const close = () => { setChoicesOpen(false); setAnswered(true); };
return ( <Section fixed pointerEventsNone className="bottom-0 z-40"> <Card tag="section" aria-labelledby="cookie-title" shadow wFull pointerEventsAuto className="max-w-md"> <Col xs> <Title id="cookie-title" tag="h2">We use cookies</Title> <Text secondary> Some keep the site working, others show us how it is used. Pick what you allow. <Link href="/cookies">Cookie policy</Link> </Text> </Col> <Row justifyBetween flexWrap> <Button type="button" ghost secondary onClick={() => setChoicesOpen(true)}>Choose</Button> <Row sm> <Button type="button" onClick={close}>Reject all</Button> <Button type="button" onClick={close}>Accept all</Button> </Row> </Row> </Card>
<Modal open={choicesOpen} onClose={() => setChoicesOpen(false)} className="max-w-lg"> <ModalHeader> <Title>Cookie choices</Title> <ModalCloseButton /> </ModalHeader> <ModalBody> {kinds.map((k) => ( <Label key={k.id} row justifyBetween itemsCenter> <Col noGap> <Text fontMedium>{k.label}</Text> <Text sm secondary>{k.text}</Text> </Col> <Switch checked={k.locked || allowed.includes(k.id)} disabled={k.locked} onChange={() => toggle(k.id)} /> </Label> ))} </ModalBody> <ModalFooter> <Button type="button" secondary onClick={close}>Accept all</Button> <Button type="button" filled onClick={close}>Save choices</Button> </ModalFooter> </Modal> </Section> );}Components in this block
Adapt it with your coding agent
Add the VaneUI MCP server, and your agent reads the component docs and prop tables while it changes the block: the copy, the sample data or the layout.
$ claude mcp add vaneui -- npx -y @vaneui/mcp
Setup for other editors is in the AI assistants guide.