Skip to content

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.

Terminal window
# 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.

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>
ExportRegisters
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");

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.

<vscookies-minimalist mode="blur"></vscookies-minimalist>
<vscookies-edito mode="ticket"></vscookies-edito>
ElementSkin
<vscookies-minimalist>minimalist
<vscookies-edito>edito

Both elements observe the same attributes:

AttributeTypeDefaultDescription
modelight | dark | blur (minimalist) / default | ticket (edito)light / defaultVisual mode.
titlestringcomponent defaultHeading text.
descriptionstringcomponent defaultBody copy.
accept-labelstring"Accept all cookies"Accept button label.
reject-labelstring"Decline cookies"Reject button label.
manage-labelstring"Manage cookies"Manage button label.
show-reject"false" / "0"shownHide the reject button.

Attributes are reactive: changing one re-renders the element.

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;

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 UI
isPreferencesOpen(); // -> 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.

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.

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.

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.

index.html
<!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.

Run pnpm storybook and open Skins/Minimalist/WebComponent or Skins/Edito/WebComponent. Skins/Playground shows the active skin counts.