shadcn.io is not affiliated with official shadcn/ui
Cookie Inventory Account Block for React
The cookies on a person's own browser as a table of eleven typed cookies with name, provider, purpose and dates, four category switches that clear what they cover, a search and a delete that asks first.
Installation
Overview
Show people the cookies a site has set on their browser, with this cookie inventory for React with Base UI. A hairline frame with a plus mark on each corner opens with four category cells on shared hairlines: Necessary is always on, and Functional, Analytics and Advertising each have a Switch and say how many of their cookies are held. Under them a search over name, provider and purpose, a count ("8 of 11 held") and a Clear analytics cookies Button that asks first in an Alert Dialog. The table has a row per cookie: its name in mono, the provider and category, what it is for, the day it was set and the day it ends, and a state as a word with an icon (Held, Not set, Blocked). Turning a category off clears its cookies; each optional cookie also deletes in two steps in place, Delete then Confirm or Cancel. A line at the foot says what happened and Undo walks back one change at a time. From the large breakpoint down each cookie is a card. It's built from Switch, Alert Dialog, Input, Badge, Empty, Button and Guides, with a native table and a CSS entrance only. For the privacy page of any site that sets cookies.
FAQ
How do I list the real cookies?
Edit COOKIES. Each has an id, a name, its provider, its category, a one-line purpose, the ISO day it was set and its life in days (0 for a cookie that ends with the visit). The end day is worked out from those, and every date and count comes from the one AS_OF constant, never the clock. The cookie names here are made up. A browser page cannot read cookies set by other origins or marked HttpOnly, so a real inventory comes from your server or your consent tool, not from document.cookie.
What stays local, and how do I make it real?
Everything: nothing here reads or writes a real cookie or any storage, and the status line says "in this demo". To make it real, have your server clear the cookies of a category when its switch goes off (a browser can only delete cookies the page itself can see), keep the person's choice in your consent record, and update the table from what comes back. Undo then needs its own reverse call, or should be removed.
What do Held, Not set and Blocked mean?
Held is a cookie the browser has now. Not set is a cookie that was deleted while its category is still allowed, so it can come back on a later visit. Blocked is a cookie whose category is off, so it will not be set at all. Turning a category on again does not bring its cookies back: they return when the site sets them. A row that is not held is tinted and its text stays at full strength, so the state is never only a tint.
How do deleting and clearing work?
Delete swaps that button, in place, for Confirm and Cancel, with focus on Confirm; Escape cancels and returns focus to Delete, and confirming moves focus to the next row's Delete, or to Undo when none is left. Necessary cookies show "Needed" with a lock instead of a button, because deleting them would sign the person out. Clear analytics cookies opens an alert dialog with focus on Keep them; it removes the held analytics cookies and leaves Analytics allowed. Both are single undo steps.
How does it look on a phone?
The category cells are two by two, and each cookie is a card of three fixed lines (name and state, what it is for, provider and end day) with its action beside them, so searching, deleting and switching never change the card heights. The foot with the status line and Undo stays pinned to the bottom of the screen. The table and the cards are one list in the markup that the large breakpoint swaps; keyboard and screen reader users get whichever is on screen.
Is it accessible?
The table has a caption, column heads and a row header per cookie; each switch is named "Allow Analytics cookies"; Delete, Confirm and Cancel name their cookie. State is a word with an icon, and the result of each action is spoken once by a polite status line that exists from the start. Names and dates keep their reading order in a right-to-left page.
Related
- Pro
Cookie Consent Settings
Privacy and consentA cookie preferences page with four purpose cells on shared hairlines: necessary locked on in words, three switches, and under each the exact cookies it covers, kept for how long, set or blocked.
- Pro
Cookie Consent Notification
Asks and consentA news site's corner cookie card: Reject all and Accept all as equal buttons, a Customize that opens a switch for each optional kind with the cookies it sets, and a one-line receipt you can change.
- Pro
A person's consent choices as an accordion of purposes with switches beside a consent receipt, an ordered log that gains a line for each choice and saves as a real PDF or JSON file.
- Pro
A person's record of who their data went to: a row per recipient with the kinds of data it received, the day it last did and why, and a switch that stops the sharing where consent is the reason.
- Pro
Cookie Settings Dialog
Confirm and consentA newspaper's cookie preference centre shown open over its front page: four categories with switches and counts, Essential locked on, and for the chosen one a sentence and a table of its actual cookies, then Reject non-essential, Accept all and Save choices.
- Pro
Export Table
Select and actA sales table with a search and row checkboxes and an Export dialog that asks which rows (visible, selected or all, with counts), whether to include hidden columns and a file name, then downloads a real CSV, shown open in place.