Cookie Consent
jarvis-ui/cookie-consentFreeComponent
A compact cookie consent card with pluggable accept and decline handlers.
Live preview
live · rendered by the registry
Rendered by jarvis-ui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://ui.jarv.is/r/cookie-consent.jsonSource
1"use client";23import * as React from "react";45import { Button } from "@/components/ui/button";6import { cn } from "@/lib/utils";78type CookieConsentDecision = "accepted" | "declined";910type CookieConsentProps = React.ComponentProps<"div"> & {11 acceptLabel?: React.ReactNode;12 defaultOpen?: boolean;13 declineLabel?: React.ReactNode;14 dismissOnConsent?: boolean;15 learnMoreHref?: string;16 learnMoreLabel?: React.ReactNode;17 onAccept?: (event: React.MouseEvent<HTMLButtonElement>) => void;18 onConsentChange?: (19 decision: CookieConsentDecision,20 event: React.MouseEvent<HTMLButtonElement>,21 ) => void;22 onDecline?: (event: React.MouseEvent<HTMLButtonElement>) => void;23 onOpenChange?: (open: boolean) => void;24 open?: boolean;25};2627function CookieConsent({28 acceptLabel = "Accept",29 defaultOpen = true,30 declineLabel = "Decline",31 dismissOnConsent = true,32 learnMoreHref = "#",33 learnMoreLabel = "Learn more.",34 onAccept,35 onConsentChange,36 onDecline,37 onOpenChange,38 open,39 className,40 children,41 ...props42}: CookieConsentProps) {43 const [uncontrolledOpen, setUncontrolledOpen] = React.useState(defaultOpen);44 const isControlled = open !== undefined;45 const isOpen = isControlled ? open : uncontrolledOpen;4647 const setOpen = React.useCallback(48 (nextOpen: boolean) => {49 if (!isControlled) {50 setUncontrolledOpen(nextOpen);51 }5253 onOpenChange?.(nextOpen);54 },55 [isControlled, onOpenChange],56 );5758 const handleConsent = React.useCallback(59 (decision: CookieConsentDecision, event: React.MouseEvent<HTMLButtonElement>) => {60 if (decision === "accepted") {61 onAccept?.(event);62 } else {63 onDecline?.(event);64 }6566 onConsentChange?.(decision, event);6768 if (dismissOnConsent && !event.defaultPrevented) {69 setOpen(false);70 }71 },72 [dismissOnConsent, onAccept, onConsentChange, onDecline, setOpen],73 );7475 if (!isOpen) {76 return null;77 }7879 return (80 <div81 role="dialog"82 aria-label="Cookie consent"83 data-slot="cookie-consent"84 className={cn("max-w-[260px] rounded-lg border bg-card p-3 shadow-md", className)}85 {...props}86 >87 <p className="text-xs leading-relaxed text-pretty text-muted-foreground">88 {children ?? (89 <>90 We use cookies to understand how you use our service.{" "}91 <a92 href={learnMoreHref}93// … truncated
What it pulls in
Other registry items
Files it writes
More from jarvis-ui
All 10 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Browser Windowbrowser-window | jarvis-ui | Components | Free | no deps | |
| Copy Buttoncopy-button | jarvis-ui | Components | Free | 1 dep | |
| Copyable Fieldcopyable-field | jarvis-ui | Components | Free | no deps | |
| Parallax Cardparallax-card | jarvis-ui | Components | Free | 1 dep | |
| Scroll Areascroll-area | jarvis-ui | Components | Free | 1 dep | |
| Stepperstepper | jarvis-ui | Components | Free | 1 dep | |
| Tipovertipover | jarvis-ui | Components | Free | 1 dep · 2 files | |
| Toasttoast | jarvis-ui | Components | Free | 2 deps |
