"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(null); const restoreRef = useRef(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 (
{visible ? ( setPolicyOpen(true) }, }} detail={ preferencesOpen ? (
Optional choices
) : null } actions={actions} /> ) : (
Local sample {choice}
)}
Sample policy

{policyOpen ? "What each choice means here" : "Policy details"}

{policyOpen ? (

Essential keeps the preview usable. Optional choices change only the visible receipt and reset when the preview reloads.

) : (

Open the policy link to review the supplied choices.

)}
Sample choices. No cookie or preference is stored.
); } export default function AgentExample() { return (
); }