Cookie banner
Consent prompt. 2 layouts.
We use cookies
We use a few cookies to remember your cart. Nothing is shared with advertisers.
import * as React from "react";
import { Button } from "@/components/ui/button";
import { CookieBanner } from "@/components/ui/cookie-banner";
export default function Example() {
const [done, setDone] = React.useState("");
if (done) return <span className="text-body-medium text-fg-secondary">You chose: {done}. <Button variant="link" onClick={() => setDone("")}>Ask again</Button></span>;
return (
<div style={{ width: "100%" }}>
<CookieBanner layout="bar" onAccept={() => setDone("accept all")} onReject={() => setDone("reject all")} onSettings={() => setDone("custom settings")}>
We use a few cookies to remember your cart. Nothing is shared with advertisers.
</CookieBanner>
</div>
);
}
Installation
$ npx uix-ui@latest add cookie-bannerThis copies the file into components/ui/cookie-banner.tsx in your project. npx shadcn@latest add @uix/cookie-banner works too.
Usage
import { CookieBanner } from "@/components/ui/cookie-banner";
<div style={{ width: "100%" }}>
<CookieBanner layout="bar" onAccept={() => setDone("accept all")} onReject={() => setDone("reject all")} onSettings={() => setDone("custom settings")}>
We use a few cookies to remember your cart. Nothing is shared with advertisers.
</CookieBanner>
</div>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
layout | bar | card | "bar" | |
title | React.ReactNode | "We use cookies" | |
icon | React.ReactNode | – | Replaces the cookie icon. |
acceptLabel | React.ReactNode | "Accept all" | |
rejectLabel | React.ReactNode | "Reject all" | |
settingsLabel | React.ReactNode | "Cookie settings" | |
onAccept | () => void | – | |
onReject | () => void | – | |
onSettings | () => void | – |
Everything else is passed to the root element, so className, aria-* and event handlers work as usual.
Dependencies
Installed for you by the CLI.
class-variance-authorityclsxtailwind-merge
lib/utils.tscomponents/ui/icons.tsx