Skip to content
EspañolEnglish
All components (283)

Cookie notice

Layers · CookieBanner · .amset-cookies

What it is and when to use it

The cookie consent bar, at the bottom and without the usual traps: accept and reject weigh the same, with the same size and the same kind of button, side by side. Making "Accept" big and green and "Reject" small and gray is exactly what the AEPD forbids.

When to use it

  • On the first visit, while there is no saved decision: visible is decided by the application.
  • link for the cookie policy, inside the notice and not hidden in the footer.
  • categories adds the "Customize" button with its preferences panel: one switch per category (necessary, preferences, statistics and advertising by default, or your own with label and description), the necessary ones fixed on "Always on", and "Reject all", "Accept all" and "Save my choice". onConfigure still works for settings of your own and, if present, takes precedence.
  • mode is opt-in (the default: anything optional starts off, which is what is required in Spain and the EU) or opt-out (it starts on and is turned off by rejecting; only where the law allows it).
  • onDecide receives accepted, rejected or custom and the record with the choice for each category.
  • With useCookieConsent and consent={…} it manages itself: it reads the decision saved in a cookie (name, duration, domain, SameSite and Secure as you like through storage), shows the notice only when it has to ask, saves the choice and tells you whether each category is allowed (allowed('analytics')), which is what your code checks before loading a tag. revision is the version of your policy: when you raise it, whoever had already decided sees the notice again (and also if you add a category they had not seen). reopen() opens it again from a footer link, and reset() deletes the decision.
  • What it does not do: load third-party tags. The application does that, because it is the one that knows what is being loaded.

When not to

  • A notice for the whole application that does not ask for any decision: GlobalAlert.
  • A complete cookie policy (the list of each cookie with its duration and its provider): that is a page of yours, which link points to.

Keyboard: the preferences panel is a real dialog: it makes the page inert, moves focus inside, gives it back to the "Customize" button, and Escape closes it without deciding anything. When the notice appears it takes focus, so someone navigating by keyboard does not have to look for it at the end of the page; Tab reaches the link and the buttons. It does not trap focus. When the application hides it (visible={false}), focus returns to where it was.

Accessibility: it is a non-modal dialog with the title as its name: it does not cover the page. The icon is decoration. In the panel, each switch carries its explanation as its description, and the necessary ones can be read and focused but do not change.

Fine-tuning: CSS variables --amset-cookies-width (48 rem at the bottom, 24 in the corner), --amset-cookies-margin and --amset-cookies-padding. It sits in the --amset-layer-consent layer: above the page and below anything modal. position="corner" turns it into a narrow card, with the two buttons still weighing the same.

What it looks like

The notice is at the very bottom of the page.

<CookieBanner onDecide={(decision) => guardar(decision)} />

Props

Import it with import { CookieBanner } from '@amset/ui'. Required props are marked.

PropTypeWhat it does
acceptTextstring—
categoriesreadonly CookieCategory[]The categories of the preferences panel opened by “Customize”, with one switch each. Without `consent`, the usual four by default. If there is an `onConfigure`, that one takes precedence and the panel does not open.
classNamestringMerged with the library classes; it does not replace them.
configureTextstring—
consentCookieConsentControllerManaged consent: what `useCookieConsent` returns. With it, the notice appears on its own only when there is something to ask (no valid decision, or one from another version of the policy), saves the choice in a cookie and carries the categories and the mode of the hook. Without it, `visible` and `onDecide` are handled by the application.
link{ readonly text: string; readonly href: string; }Link to the policy. It goes inside the notice, not hidden in the footer.
modeCookieConsentMode`opt-in` (the default) or `opt-out`: what the switches of the panel start with. With `consent`, the one of the hook.
onConfigure() => voidA third button to open settings of your own. Without it, and with `categories` or `consent`, the button opens the preferences panel.
onDecide(decision: CookieDecision, record: CookieConsentRecord) => voidCalled with what was decided (`accepted`, `rejected` or `custom`, if it was chosen category by category) and with the whole record, which carries the choice for each category. With `consent` it is already saved on its own; without it, saving it is up to the application.
positionCookieBannerPosition`bottom` (the default) takes up the full width; `corner` leaves it as a card.
rejectTextstring—
textReactNode—
titlestring—
visiblebooleanWith `false` it is not painted: the application decides whether it was already answered. With `consent`, it decides.

It also accepts the attributes of the element it renders: className, style, data-*, aria-* and its events.

CSS variables

These CSS variables are how you adapt it. Declare them on the component's selector, not on :root: the stylesheet redeclares them in the rule itself, and a declaration on the same element always wins.

VariableDefault
--amset-cookies-width48rem
--amset-cookies-marginvar(--amset-space-4)
--amset-cookies-paddingvar(--amset-space-4)

How to change it

.amset-cookies {
  --amset-cookies-width: ...;
  --amset-cookies-margin: ...;
}

In the test bench

Every state and variant, to try one at a time, on its page at storybook.amsetui.com: