Cookie consent centered dialog — Legal block

Free

legal-cookie-consent-centered-dialog · for all pages

Cookie consent centered dialog

A small centred dialog over a dimmed page that waits for an answer, the categories swapped in place behind a link: when the shop wants an explicit choice before use

Documentation

Installation

One command copies the block into your project with the shadcn CLI (the registry is set once: Installation).

pnpm dlx shadcn-vue@latest add @trame/legal-cookie-consent-centered-dialog

Usage

Its demo data, shortened (Using blocks).

<script setup lang="ts">
import LegalCookieConsentCenteredDialog from '@/components/trame/blocks/legal/legal-cookie-consent-centered-dialog.vue'

const props = {
title: "Your cookie choices",
text: "We use cookies to run the shop and, if you agree, to measure its traffic. Declining changes nothing about how you browse.",
policy: {
label: "Privacy policy",
action: "privacy"
},
categories: [
{
id: "necessary",
label: "Strictly necessary",
text: "Cart, sign-in and payment security. They can’t be turned off.",
required: true
},
{
id: "analytics",
label: "Analytics",
text: "We count visits to learn which pages actually help."
}
],
onChoice: "cookie-consent",
options: {
floating: false
}
}
</script>

<template>
<LegalCookieConsentCenteredDialog v-bind="props" />
</template>

Props

Each prop says who changes it: Words, Picture, Action, Design, Data.* required.

PropTypeDescription
title*stringWordswhat is asked, in a few words ("Your cookie choices")
text*stringWordsone or two sentences: what the shop uses cookies for, only what it really does
policyPolicythe link to the policy: its words and the page action it runs
categoriesCategory[]the cookie categories the visitor can accept or refuse
onChoice*stringActionthe action the choice is posted to: "choice" (accept, refuse or save) and the ticked "category" keys
optionsOptionsthe block’s settings: layout choices and secondary words, read by every variant
Policy policy · 2 props
PropTypeDescription
label*stringWordsthe policy’s link ("Privacy policy")
action*stringActiona named action of the page
Category categories[] · 4 props
PropTypeDescription
id*stringDesignthe category’s key, as the consent action receives it ("analytics")
label*stringWordsthe category’s name ("Audience measurement")
text*stringWordswhat the shop does with it, and which tool, in one sentence
requiredbooleanstrictly necessary: locked on, the only one ticked from the start
Options options · 6 props
PropTypeDescription
acceptLabelstringWordsthe accept-all button ("Accept all")
refuseLabelstringWordsthe refuse-all button ("Reject all")
saveLabelstringWordsthe button that saves the ticked categories ("Save my choices")
position'start' | 'end'the side a floating card sits on
floatingbooleanfixed to the screen (the default); false sets it in the page flow
mood'inverse' | 'brand' | 'warm' | 'tint' | stringa band of the page that redefines the theme surfaces inside it
What it asks your app for

The block never knows your app: it asks it, through one context provided once, where its links lead, what its actions do, how a price reads and which words to say (The host context).

MemberWhat it is for
hrefthe address an action leads to, or null to hide what leads there
actruns a change (subscribe, add to cart, save) and answers { ok } or { ok: false, error }
canwhether the page has this action
Linkyour router’s link component
cartCountthe cart badge’s number
cartDrawerwhether your app has a cart drawer
cartOpenwhether the cart drawer is open
labelyour word for an interface key, or undefined to keep the block’s own

The words it says itself, in English and French; label(key) replaces any of them:

KeyEnglishFrench
newsletter.alreadyYou are already subscribed.Vous êtes déjà inscrit.
newsletter.doneDone: you are subscribed.C’est noté : vous êtes inscrit.
newsletter.invalidCheck the email address.Vérifiez l’adresse e-mail.
newsletter.tooManyToo many attempts, try again in a moment.Trop de tentatives, réessayez dans un moment.

Features

  • Every word in the server HTML
  • Same markup in Vue and React
  • Theme tokens only: every theme, light and dark
  • Shows what you give it, invents nothing
  • No motion; still under reduced motion
  • Real buttons and links, a visible focus
  • Asks your app through actions: policy, onChoice

A legal section, for all pages; it uses @lucide/vue, class-variance-authority, clsx, reka-ui, tailwind-merge.

More legal blocks

  • Compliance statement: an accessibility or compliance statement: what works, what does not yet, and the date of the review.
  • Cookie preferences docked split: a panel docked at the bottom, the words, the policy and a count of the optional categories on at the left, the switches as a ruled list at the right: a more serious or regulated shop.
  • Cookie preferences modal prefs: a centered panel with every category and its switch: for shops with several tools to declare.
  • Cookie preferences sheet cards: a full-width bottom sheet where each category is a card with its switch: three or four categories, each worth a line.
  • Cookie strip bottom bar: a slim strip at the bottom: the question, two equal buttons, and the categories on demand.
  • Disclosures grouped: the notes under the product or topic they concern, the groups flowing in two columns on a wide screen: a financial or insurance site whose fine print covers several products; the merchant’s own wording only.
  • Disclosures ruled notes: the page’s fine print in a narrow measure, each note a row with its marker in a fixed gutter and a hairline between notes: a landing or product page whose figures, offers or claims carry a few notes; the merchant’s own wording only.
  • Policy summary numbered: the policy in numbered sentences with a link to the full text: a page that explains before it asks.

All 19 legal blocks