Vanilla
@vscookies/vanilla is the Web Component runtime. It bundles React,
@vscookies/core, @vscookies/tokens and the headless provider, so it has
no dependencies and needs no React install. Banners arrive as separate
skin packages, for example @vscookies/skin-minimalist-vanilla.
# Download from https://vs-goods.store/ and unzip into vendor/:# vscookies-vanilla-v0.2.0.zip -> vendor/vscookies/vanilla/# vscookies-skin-minimalist-vanilla-v0.2.0.zip -> vendor/vscookies/skin-minimalist-vanilla/That is the whole vanilla install: one runtime zip + one skin zip, with zero npm installs. See Installing from the zip for the import map and bundler setup.
Define the elements
Section titled “Define the elements”Import the skin (it self-registers), then define the loaded elements once, early in your app:
<script type="module"> import { defineAll } from "@vscookies/vanilla/define"; import "@vscookies/skin-minimalist-vanilla"; defineAll();</script>| Export | Registers |
|---|---|
defineAll(config?) | Every loaded skin’s custom element, optionally under your own consent rules. |
defineSkin(slug, name?, config?) | One skin by slug, e.g. defineSkin("minimalist"), with an optional custom tag name and consent config. |
registerSkin(definition) | Register a custom skin descriptor (idempotent by slug). |
getSkin(slug) / getSkins() | Look up or list registered skins. |
Every define* call is idempotent — an already-registered tag is left as-is.
defineSkin("minimalist", "my-consent") mounts that element under a custom tag.
import { defineSkin } from "@vscookies/vanilla/define";defineSkin("minimalist", "my-consent");Add your own tags and cookies
Section titled “Add your own tags and cookies”Pass a consent config once to defineAll() (or defineSkin()) and every
element runs under your rules. Local (/vendor/x.js) and online
(https://…) scripts are declared identically in scripts: [{ src }] —
execution: "async" for isolated tags, defer (default) for ordered ones.
Cookies support per-cookie title/description (shown in the manage view) and
server: true + serverEndpoint for long-lived cookies (Safari ITP):
import { defineAll } from "@vscookies/vanilla/define";import { DEFAULT_CATEGORY_RULES } from "@vscookies/core";import "@vscookies/skin-minimalist-vanilla";
defineAll({ serverEndpoint: "/api/consent-cookies", categories: { ...DEFAULT_CATEGORY_RULES, analytics: { ...DEFAULT_CATEGORY_RULES.analytics, scripts: [ { src: "https://www.googletagmanager.com/gtm.js?id=GTM-XXXX", title: "Google Tag Manager", description: "Analytics and ads.", setsCookies: ["_ga", "_gid"], // purged automatically when denied }, { src: "/vendor/local-vendor.js", execution: "defer", title: "Local vendor" }, ], }, marketing: { ...DEFAULT_CATEGORY_RULES.marketing, cookies: [ { name: "campaign", title: "Campaign ID", description: "Remembers which campaign brought you here.", value: () => new URLSearchParams(location.search).get("utm_campaign") ?? "", options: { maxAge: 604800 }, }, ], }, },});The config is captured at define time (first config wins; later conflicting calls warn and are ignored), so pass it in the same call that defines the elements. Tags are injected only while their category is allowed and removed on revocation; cookies are written while allowed and purged on revocation.
Elements
Section titled “Elements”<vscookies-minimalist mode="blur"></vscookies-minimalist><vscookies-edito mode="ticket"></vscookies-edito>| Element | Skin |
|---|---|
<vscookies-minimalist> | minimalist |
<vscookies-edito> | edito |
Attributes
Section titled “Attributes”Both elements observe the same attributes:
| Attribute | Type | Default | Description |
|---|---|---|---|
mode | light | dark | blur (minimalist) / default | ticket (edito) | light / default | Visual mode. |
title | string | component default | Heading text. |
description | string | component default | Body copy. |
accept-label | string | "Accept all cookies" | Accept button label. |
reject-label | string | "Decline cookies" | Reject button label. |
manage-label | string | "Manage cookies" | Manage button label. |
show-reject | "false" / "0" | shown | Hide the reject button. |
Attributes are reactive: changing one re-renders the element.
Properties
Section titled “Properties”For programmatic control, mode (typed) and showReject (boolean) are exposed
as JS properties:
const banner = document.querySelector("vscookies-minimalist");banner.mode = "dark";banner.showReject = false;Manage cookies signal
Section titled “Manage cookies signal”The vanilla runtime exposes the same UI-only signal as React. manageCookies()
emits the event; onPreferencesChange() subscribes and returns an unsubscribe
function. Neither changes consent state — the preferences UI decides what to do.
The shared open-state is also available as setPreferencesOpen(open),
isPreferencesOpen() and onPreferencesChange(listener) (React wrappers:
usePreferencesOpen()).
import { manageCookies, onPreferencesChange, setPreferencesOpen, isPreferencesOpen, cmp } from "@vscookies/vanilla";
document.querySelector("#cookie-settings").addEventListener("click", manageCookies);
const off = onPreferencesChange((open) => open && openPreferences());// off(); // unsubscribe
setPreferencesOpen(false); // close the preferences UIisPreferencesOpen(); // -> boolean
// The CMP SDK itself remains exactly three methods.cmp.on("consentUpdated", (record) => console.log(record.categories, record.cookies));In React, call useCookieConsent().manageCookies() from a footer link instead;
the two runtimes share the same signal within a page.
Styling
Section titled “Styling”Each skin injects its own CSS into the element’s shadow root; the runtime adds
the tokens to document.head when the first element is defined. To link CSS
explicitly instead, use @vscookies/vanilla/tokens.css and
@vscookies/vanilla/style.css.
The runtime’s :root layer contains only shared --vsc-state-* tokens; each
skin injects its own UI tokens and sets data-vsc-skin="<slug>" on the host, so
both custom properties inherit into the shadow tree. The runtime also exports
the token contract for runtime overrides:
import { GLOBAL_TOKEN_MANIFEST, GLOBAL_TOKEN_NAMES, setTokenOverrides, clearTokenOverrides, clearAllTokenOverrides,} from "@vscookies/vanilla";
setTokenOverrides({ "--vsc-global-radius-xl": "0.5rem" });setTokenOverrides({ "--vsc-min-color-accent": "#7c3aed" }, { skin: "minimalist" });clearTokenOverrides({ skin: "minimalist" });clearAllTokenOverrides();Use these to build your own live token editor — there is no built-in editor.
Shadow DOM and events
Section titled “Shadow DOM and events”Each element uses an open shadow root, so the banner markup lives inside it
and is isolated from page styles. Global state tokens are defined on :root;
each skin’s UI tokens are defined on its host element. Both inherit into the
shadow tree, which is why overrides still restyle the banners.
Plain HTML example
Section titled “Plain HTML example”No bundler or CSS <link> is needed — an import map points at the unzipped
files and the tokens are injected at runtime. The internal/react and
internal/headless mappings let the skin share the runtime’s React and provider.
<!doctype html><html> <head> <meta charset="utf-8" /> <title>My site</title> <script type="importmap"> { "imports": { "@vscookies/vanilla": "./vendor/vscookies/vanilla/dist/index.js", "@vscookies/vanilla/define": "./vendor/vscookies/vanilla/dist/define.js", "@vscookies/vanilla/internal/react": "./vendor/vscookies/vanilla/dist/internal/react.js", "@vscookies/vanilla/internal/headless": "./vendor/vscookies/vanilla/dist/internal/headless.js", "@vscookies/skin-minimalist-vanilla": "./vendor/vscookies/skin-minimalist-vanilla/dist/index.js" } } </script> </head> <body> <vscookies-minimalist title="Cookies"></vscookies-minimalist>
<script type="module"> import { defineAll } from "@vscookies/vanilla/define"; import "@vscookies/skin-minimalist-vanilla"; defineAll(); </script> </body></html>Serve the folder over HTTP (module scripts do not run from file://), e.g.
npx serve .. See Installing from the zip for the
bundler-based setup.
Try it live
Section titled “Try it live”Run pnpm storybook and open Skins/Minimalist/WebComponent or
Skins/Edito/WebComponent. Skins/Playground shows the active skin counts.