# Cookie banner

A consumer-controlled cookie notice with native choice buttons, a real policy destination and no built-in persistence.

Access: pro. Category: Feedback. Kind: composite.

## When to use

- Use it when a page needs a consumer-controlled cookie notice with native choice buttons, a real policy destination and no built-in persistence.
- Choose it when the host application can supply the required state and keep business logic outside the presentation component.

## Alternatives

- Choose alert instead when inline notices with icons, actions and optional dismissal is the actual interface need, rather than cookie banner.

## Setup for agents

Use React 19 and TypeScript. Initialize shadcn for your framework, then merge this exact entry into components.json:

```json
{
  "registries": {
    "@tidal-pro": {
      "url": "https://tidalui.com/r/pro/{name}.json",
      "headers": {
        "Authorization": "Bearer ${TIDALUI_TOKEN}"
      }
    }
  }
}
```

The namespace must be named **@tidal-pro** because transitive Pro dependencies use that namespace. Obtain an agent key from your active Pro account at https://tidalui.com/account. Keep TIDALUI_TOKEN in your local environment, never in components.json, client code, Git or logs.

```sh
export TIDALUI_TOKEN='your-private-agent-key'
npx shadcn@latest add @tidal-pro/waitlist-form
npx shadcn@latest add https://tidalui.com/r/tidal-button.json
```

Free command: `npx shadcn@latest add https://tidalui.com/r/<name>.json`.
Pro command: `npx shadcn@latest add @tidal-pro/<name>`.

Import the base stylesheet and every stylesheet listed on the installed item's metadata. For example:

```tsx
import "./components/ui/tidal.css";
import "./components/ui/hero-section.css";
// Place installed components inside this wrapper:
<div className="tidal-scope" data-theme="dark">...</div>
```

Omit data-theme for the default light theme. Put the attribute on the same tidal-scope element for dark mode. Every component installs the shared free tidal-base dependency. After upgrading, run `npx shadcn@latest add https://tidalui.com/r/tidal-base.json --overwrite` to receive current tokens. Review local modifications before overwriting.

Vite: Use React + TypeScript. Map @/* to ./src/* in paths and Vite resolve.alias. Import tidal.css and each component stylesheet in your application entry.

Next.js 15 App Router: Next.js App Router: import tidal.css and component CSS in app/layout.tsx. Interactive examples belong in a client component with "use client". Map @/* to ./* or ./src/* to match your project.

TypeScript 6: use paths without baseUrl:

```json
{
  "compilerOptions": {
    "paths": {
      "@/*": [
        "./src/*"
      ]
    }
  }
}
```

Pro registry requests are server/CLI-only. Use the same-origin account interface in a browser; cross-origin Authorization preflights are intentionally unsupported.


## Install Cookie banner

```sh
npx shadcn@latest add @tidal-pro/cookie-banner
```

Stylesheets: `components/ui/tidal.css`, `components/ui/cookie-banner.css`.

## Minimal example

```tsx
import"./components/ui/tidal.css";
import"./components/ui/cookie-banner.css";
import{TidalCookieBanner}from"./components/ui/cookie-banner";
export default()=><div className="tidal-scope"><TidalCookieBanner actions={[{id:"example",label:"Demo",onAction:() => {}}]} description={"Demo"} title={"Demo"}/></div>;
```

## Structured props

- `TidalCookieBanner.actions: ReadonlyArray<TidalCookieBannerAction>`: Required actions value accepted by this exported component.
- `TidalCookieBanner.description: ReactNode`: Required description value accepted by this exported component.
- `TidalCookieBanner.title: ReactNode`: Required title value accepted by this exported component.
- `TidalCookieBanner.actionsLabel?: string | undefined` (default "Cookie choices"): Optional actions label value accepted by this exported component.
- `TidalCookieBanner.badge?: ReactNode`: Optional badge value accepted by this exported component.
- `TidalCookieBanner.detail?: ReactNode`: Optional detail value accepted by this exported component.
- `TidalCookieBanner.emptyActionsMessage?: ReactNode` (default "No cookie choices are available."): Optional empty actions message value accepted by this exported component.
- `TidalCookieBanner.headingLevel?: 2 | 3 | 4 | 5 | 6 | undefined` (default 2): Optional heading level value accepted by this exported component.
- `TidalCookieBanner.policyLink?: TidalCookieBannerPolicyLink | undefined`: Optional policy link value accepted by this exported component.

## Complete usage example

[Source](https://tidalui.com/examples/cookie-banner.tsx) | [Manifest](https://tidalui.com/examples/cookie-banner.json). Install the listed additional dependencies. Consumer fixture: TypeScript pass; Vite pass. This fixture check is distinct from the actual shadcn install receipt.

```tsx
"use client";

import "./components/ui/tidal.css";

import { useId, useLayoutEffect, useRef, useState } from "react";

import { TidalCookieBanner, type TidalCookieBannerAction } from "./components/ui/cookie-banner";

import "./components/ui/cookie-banner.css";



const tidalExampleStyles = ".tidal-scope .cookie-demo,\n.tidal-scope .cookie-demo * {\n  box-sizing: border-box;\n}\n\n.tidal-scope .cookie-demo {\n  width: 100%;\n  min-width: 0;\n  color: var(--t-ink);\n  container: cookie-demo / inline-size;\n  font-family: Inter, ui-sans-serif, system-ui, sans-serif;\n}\n\n.tidal-scope .cookie-demo-frame {\n  display: grid;\n  min-width: 0;\n  gap: 10px;\n  padding: clamp(8px, 2.8cqi, 28px);\n}\n\n.tidal-scope .cookie-demo-receipt {\n  display: flex;\n  min-width: 0;\n  min-height: 116px;\n  align-items: center;\n  justify-content: space-between;\n  gap: 18px;\n  padding: 20px;\n  border: 1px solid var(--t-ink);\n  border-radius: 22px;\n  background: var(--t-ink);\n  color: var(--t-surface);\n  animation: cookie-demo-receipt-in 360ms var(--t-ease-out) both;\n}\n\n.tidal-scope .cookie-demo-receipt > div {\n  display: grid;\n  min-width: 0;\n  gap: 6px;\n}\n\n.tidal-scope .cookie-demo-receipt span,\n.tidal-scope .cookie-demo-policy > span {\n  color: var(--t-muted);\n  font-size: 11px;\n  font-weight: 720;\n  letter-spacing: 0.09em;\n  line-height: 1.4;\n  text-transform: uppercase;\n}\n\n.tidal-scope .cookie-demo-receipt span {\n  color: var(--t-surface);\n  opacity: 0.66;\n}\n\n.tidal-scope .cookie-demo-receipt strong {\n  min-width: 0;\n  font-size: clamp(18px, 3cqi, 28px);\n  font-weight: 560;\n  letter-spacing: -0.035em;\n  line-height: 1.1;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .cookie-demo-receipt button {\n  min-width: 132px;\n  min-height: 44px;\n  flex: none;\n  padding: 8px 13px;\n  border: 1px solid var(--t-surface);\n  border-radius: 10px;\n  background: var(--t-surface);\n  color: var(--t-ink);\n  font: inherit;\n  font-size: 11px;\n  font-weight: 690;\n  cursor: pointer;\n  transition:\n    background 160ms,\n    color 160ms,\n    transform 140ms var(--t-ease-out);\n}\n\n.tidal-scope .cookie-demo-receipt button:hover {\n  background: var(--t-ink);\n  color: var(--t-surface);\n}\n\n.tidal-scope .cookie-demo-receipt button:active {\n  transform: scale(0.97);\n}\n\n.tidal-scope .cookie-demo-receipt button:focus-visible,\n.tidal-scope .cookie-demo-policy:focus-visible,\n.tidal-scope .cookie-demo-preferences input:focus-visible {\n  outline: 2px solid var(--t-accent);\n  outline-offset: 3px;\n}\n\n.tidal-scope .cookie-demo-preferences {\n  display: grid;\n  min-width: 0;\n  gap: 5px;\n  padding: 0;\n  margin: 0;\n  border: 0;\n}\n\n.tidal-scope .cookie-demo-preferences legend {\n  margin-bottom: 4px;\n  color: var(--t-ink);\n  font-size: 11px;\n  font-weight: 720;\n}\n\n.tidal-scope .cookie-demo-preferences label {\n  display: grid;\n  min-width: 0;\n  min-height: 48px;\n  grid-template-columns: minmax(0, 1fr) auto;\n  align-items: center;\n  gap: 10px;\n  padding: 6px 8px;\n  border: 1px solid var(--t-border);\n  border-radius: 9px;\n  background: var(--t-surface);\n  cursor: pointer;\n}\n\n.tidal-scope .cookie-demo-preferences label:has(input:disabled) {\n  cursor: default;\n}\n\n.tidal-scope .cookie-demo-preferences label > span {\n  display: grid;\n  min-width: 0;\n  gap: 2px;\n}\n\n.tidal-scope .cookie-demo-preferences strong,\n.tidal-scope .cookie-demo-preferences small {\n  min-width: 0;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .cookie-demo-preferences strong {\n  color: var(--t-ink);\n  font-size: 11px;\n}\n\n.tidal-scope .cookie-demo-preferences small {\n  font-size: 11px;\n  line-height: 1.35;\n}\n\n.tidal-scope .cookie-demo-preferences input {\n  width: 20px;\n  height: 20px;\n  accent-color: var(--t-ink);\n}\n\n.tidal-scope .cookie-demo-policy {\n  min-width: 0;\n  padding: 20px;\n  border: 1px solid var(--t-border);\n  border-radius: 18px;\n  background: var(--t-subtle);\n}\n\n.tidal-scope .cookie-demo-policy h2 {\n  margin: 9px 0 0;\n  font-size: 18px;\n  font-weight: 620;\n  letter-spacing: -0.04em;\n  line-height: 1.1;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .cookie-demo-policy p {\n  max-width: 68ch;\n  margin: 8px 0 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.6;\n  overflow-wrap: anywhere;\n}\n\n.tidal-scope .cookie-demo-footer {\n  padding: 3px 2px 0;\n  color: var(--t-muted);\n  font-size: 11px;\n  line-height: 1.5;\n  overflow-wrap: anywhere;\n}\n\n@container cookie-demo (max-width: 480px) {\n  .tidal-scope .cookie-demo-frame {\n    padding: 6px;\n  }\n\n  .tidal-scope .cookie-demo-receipt {\n    align-items: stretch;\n    flex-direction: column;\n    padding: 18px;\n  }\n\n  .tidal-scope .cookie-demo-receipt button {\n    width: 100%;\n    min-width: 0;\n    font-size: 16px;\n  }\n\n  .tidal-scope .cookie-demo-policy {\n    padding: 18px;\n  }\n\n  .tidal-scope .cookie-demo-preferences label {\n    min-height: 52px;\n  }\n}\n\n@media (hover: none) and (pointer: coarse) {\n  .tidal-scope .cookie-demo-receipt button {\n    font-size: 16px;\n  }\n}\n\n@media (prefers-reduced-motion: reduce) {\n  .tidal-scope .cookie-demo-receipt,\n  .tidal-scope .cookie-demo-receipt button {\n    animation: none;\n    transition: none;\n  }\n\n  .tidal-scope .cookie-demo-receipt button:active {\n    transform: none;\n  }\n}\n\n@keyframes cookie-demo-receipt-in {\n  from {\n    opacity: 0;\n    transform: translateY(7px);\n  }\n  to {\n    opacity: 1;\n    transform: none;\n  }\n}";

export function CookieBannerDemo() {
  const generatedId = useId().replace(/:/g, "");
  const preferencesId = `${generatedId}-sample-preferences`;
  const policyId = `${generatedId}-sample-policy`;
  const [visible, setVisible] = useState(true);
  const [preferencesOpen, setPreferencesOpen] = useState(false);
  const [policyOpen, setPolicyOpen] = useState(false);
  const [measurement, setMeasurement] = useState(false);
  const [personalization, setPersonalization] = useState(false);
  const [choice, setChoice] = useState("No sample choice yet.");
  const [focusIntent, setFocusIntent] = useState<"banner" | "receipt" | null>(
    null,
  );
  const primaryActionRef = useRef<HTMLButtonElement>(null);
  const restoreRef = useRef<HTMLButtonElement>(null);

  useLayoutEffect(() => {
    if (focusIntent === "banner" && visible)
      primaryActionRef.current?.focus({ preventScroll: true });
    if (focusIntent === "receipt" && !visible)
      restoreRef.current?.focus({ preventScroll: true });
    setFocusIntent(null);
  }, [focusIntent, visible]);

  function recordChoice(nextChoice: string) {
    setChoice(nextChoice);
    setVisible(false);
    setFocusIntent("receipt");
  }

  const actions: readonly TidalCookieBannerAction[] = [
    {
      id: "manage",
      label: preferencesOpen ? "Hide choices" : "Manage choices",
      buttonProps: {
        "aria-expanded": preferencesOpen,
        "aria-controls": preferencesOpen ? preferencesId : undefined,
      },
      onAction: () => setPreferencesOpen((current) => !current),
    },
    {
      id: "essential",
      label: "Essential only",
      onAction: () => {
        setMeasurement(false);
        setPersonalization(false);
        recordChoice("Sample choice: essential only.");
      },
    },
    preferencesOpen
      ? {
          id: "save",
          label: "Save sample choice",
          emphasis: "primary",
          buttonRef: primaryActionRef,
          onAction: () =>
            recordChoice(
              `Sample choice: ${measurement ? "measurement on" : "measurement off"}, ${personalization ? "personalization on" : "personalization off"}.`,
            ),
        }
      : {
          id: "all",
          label: "Allow all",
          emphasis: "primary",
          buttonRef: primaryActionRef,
          onAction: () => {
            setMeasurement(true);
            setPersonalization(true);
            recordChoice("Sample choice: all options allowed.");
          },
        },
  ];

  return (
    <section className="cookie-demo" aria-label="Cookie notice preview">
      <div className="cookie-demo-frame">
        {visible ? (
          <TidalCookieBanner
            title="Choose how this sample works"
            description="Essential items keep the preview usable. Optional choices can tailor the fictional workspace summary."
            badge="Privacy choices"
            policyLink={{
              label: "Read the sample policy",
              href: `#${policyId}`,
              linkProps: { onClick: () => setPolicyOpen(true) },
            }}
            detail={
              preferencesOpen ? (
                <fieldset
                  id={preferencesId}
                  className="cookie-demo-preferences"
                >
                  <legend>Optional choices</legend>
                  <label>
                    <span>
                      <strong>Essential</strong>
                      <small>Required for this preview</small>
                    </span>
                    <input type="checkbox" checked disabled />
                  </label>
                  <label>
                    <span>
                      <strong>Measurement</strong>
                      <small>Sample usage summary</small>
                    </span>
                    <input
                      type="checkbox"
                      checked={measurement}
                      onChange={(event) =>
                        setMeasurement(event.currentTarget.checked)
                      }
                    />
                  </label>
                  <label>
                    <span>
                      <strong>Personalization</strong>
                      <small>Sample layout choice</small>
                    </span>
                    <input
                      type="checkbox"
                      checked={personalization}
                      onChange={(event) =>
                        setPersonalization(event.currentTarget.checked)
                      }
                    />
                  </label>
                </fieldset>
              ) : null
            }
            actions={actions}
          />
        ) : (
          <div className="cookie-demo-receipt">
            <div>
              <span>Local sample</span>
              <strong>{choice}</strong>
            </div>
            <button
              ref={restoreRef}
              type="button"
              onClick={() => {
                setVisible(true);
                setFocusIntent("banner");
              }}
            >
              Review choices
            </button>
          </div>
        )}

        <article id={policyId} className="cookie-demo-policy" tabIndex={-1}>
          <span>Sample policy</span>
          <h2>
            {policyOpen ? "What each choice means here" : "Policy details"}
          </h2>
          {policyOpen ? (
            <p>
              Essential keeps the preview usable. Optional choices change only
              the visible receipt and reset when the preview reloads.
            </p>
          ) : (
            <p>Open the policy link to review the supplied choices.</p>
          )}
        </article>

        <footer className="cookie-demo-footer">
          Sample choices. No cookie or preference is stored.
        </footer>
      </div>
    </section>
  );
}

export default function AgentExample() {
  return (
    <div className="tidal-scope" data-theme="light" dir="ltr">
      <style>{tidalExampleStyles}</style>
      <CookieBannerDemo />
    </div>
  );
}

```

## Gotchas

- Install the declared registry dependencies and render inside a tidal-scope with the foundation stylesheet loaded.

## Theme and accessibility

{"tokens":["--t-accent","--t-border","--t-border-strong","--t-canvas","--t-danger","--t-display","--t-ease-out","--t-ease-spring","--t-faint","--t-font","--t-ink","--t-line","--t-muted","--t-primary","--t-primary-contrast","--t-radius-card","--t-radius-control","--t-radius-overlay","--t-radius-panel","--t-ring","--t-shadow-lg","--t-shadow-soft","--t-soft","--t-subtle","--t-surface","--t-wash"],"darkMode":true}

{"keyboard":["Tab and Shift+Tab follow the component's native focus order."],"aria":"The component wires labels and relationships from consumer-provided visible text or ARIA props; preserve those labels in production.","notes":"Verify focus visibility, text alternatives, contrast, and reduced motion in the final composition."}

title and description label the notice through generated stable IDs. Optional badge and detail preserve numeric zero; headingLevel defaults to h2. policyLink renders a real native anchor with consumer href, label, optional accessible label, disabled state, native attributes and ref. An action-disabled or aria-disabled policy link prevents navigation before its caller handler, while explicit aria-disabled=false is preserved. actions are ordered native buttons with unique IDs, consumer labels, optional accessible labels, primary or secondary emphasis, disabled state, native attributes, refs and required onAction callbacks. Native action clicks run first and prevention suppresses the higher callback. actionsLabel names the button group, and emptyActionsMessage covers an empty action list. Root native attributes/ref pass through. The component performs no cookie read or write, consent mutation, request, route, analytics, network, storage or persistence action.
