@krysmalskipl/astro-consent-mode 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/README.md +51 -0
- package/dist/client.js +27 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +4 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## 0.1.2 - 2026-10-12
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- Added floating cookie preference badge (`badge` and `badgePosition` options) allowing visitors to reopen consent preferences at any time.
|
|
10
|
+
- Added `hideFromBots: false` option to ensure cookie banner functions properly in CI environments, headless browser automations, and testing suites.
|
|
11
|
+
- Added documentation screenshots showing all 8 banner layouts with overlay variations and floating badge.
|
|
12
|
+
|
|
13
|
+
## 0.1.1 - 2026-10-12
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Updated npm scope to `@krysmalskipl/astro-consent-mode`.
|
|
18
|
+
|
|
5
19
|
## 0.1.0 - 2026-10-12
|
|
6
20
|
|
|
7
21
|
### Features
|
package/README.md
CHANGED
|
@@ -157,6 +157,32 @@ Choose a ready-made layout using the `banner` option:
|
|
|
157
157
|
| `'bar-top'` | Full-width bar anchored to the top edge |
|
|
158
158
|
| `'modal'` | Centered modal window with a dimmed page backdrop (sets `overlay: true` automatically) |
|
|
159
159
|
|
|
160
|
+
### Layout Previews
|
|
161
|
+
|
|
162
|
+
#### 1. `banner: 'box-left'` *(Default)*
|
|
163
|
+

|
|
164
|
+
|
|
165
|
+
#### 2. `banner: 'box-right'` *(shown with `overlay: true`)*
|
|
166
|
+

|
|
167
|
+
|
|
168
|
+
#### 3. `banner: 'box-center'`
|
|
169
|
+

|
|
170
|
+
|
|
171
|
+
#### 4. `banner: 'box-wide'` *(shown with `overlay: true`)*
|
|
172
|
+

|
|
173
|
+
|
|
174
|
+
#### 5. `banner: 'cloud'`
|
|
175
|
+

|
|
176
|
+
|
|
177
|
+
#### 6. `banner: 'bar-bottom'`
|
|
178
|
+

|
|
179
|
+
|
|
180
|
+
#### 7. `banner: 'bar-top'` *(shown with `overlay: true`)*
|
|
181
|
+

|
|
182
|
+
|
|
183
|
+
#### 8. `banner: 'modal'` *(Centered dialog, `overlay: true` by default)*
|
|
184
|
+

|
|
185
|
+
|
|
160
186
|
You can also dim the page background and prevent page interactions for any layout by setting `overlay: true`:
|
|
161
187
|
|
|
162
188
|
```ts
|
|
@@ -167,6 +193,31 @@ consent({
|
|
|
167
193
|
})
|
|
168
194
|
```
|
|
169
195
|
|
|
196
|
+
## Floating Badge (Cookie Icon)
|
|
197
|
+
|
|
198
|
+
Allow visitors to reopen cookie preferences at any time with a floating button:
|
|
199
|
+
|
|
200
|
+
```ts
|
|
201
|
+
consent({
|
|
202
|
+
gtmId: 'GTM-XXXXXX',
|
|
203
|
+
badge: true, // Displays '🍪' in the bottom-left corner
|
|
204
|
+
badgePosition: 'bottom-left', // 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right'
|
|
205
|
+
})
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
You can customize the badge content by passing a string (e.g. emoji, text, or both):
|
|
209
|
+
|
|
210
|
+
```ts
|
|
211
|
+
consent({
|
|
212
|
+
gtmId: 'GTM-XXXXXX',
|
|
213
|
+
badge: '🍪 Cookies',
|
|
214
|
+
badgePosition: 'bottom-left',
|
|
215
|
+
})
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
#### Floating Badge Preview
|
|
219
|
+

|
|
220
|
+
|
|
170
221
|
## Styling
|
|
171
222
|
|
|
172
223
|
The banner is styled using vanilla-cookieconsent v3 CSS variables. You can override colors, fonts, and border radius in your global CSS stylesheet:
|
package/dist/client.js
CHANGED
|
@@ -57,6 +57,7 @@ if (typeof window !== "undefined") {
|
|
|
57
57
|
// Resolved at build time from the `banner` preset merged with `gui`.
|
|
58
58
|
guiOptions: config.gui,
|
|
59
59
|
disablePageInteraction: config.overlay,
|
|
60
|
+
hideFromBots: false,
|
|
60
61
|
categories,
|
|
61
62
|
language: {
|
|
62
63
|
default: config.lang,
|
|
@@ -65,6 +66,32 @@ if (typeof window !== "undefined") {
|
|
|
65
66
|
onConsent: syncConsent,
|
|
66
67
|
onChange: syncConsent
|
|
67
68
|
});
|
|
69
|
+
if (config.badge) {
|
|
70
|
+
const badgeLabel = typeof config.badge === "string" ? config.badge : "\u{1F36A}";
|
|
71
|
+
const pos = config.badgePosition || "bottom-left";
|
|
72
|
+
const btn = document.createElement("button");
|
|
73
|
+
btn.type = "button";
|
|
74
|
+
btn.setAttribute("data-cc", "show-preferencesModal");
|
|
75
|
+
btn.setAttribute("aria-label", config.lang === "pl" ? "Ustawienia cookies" : "Cookie settings");
|
|
76
|
+
btn.innerHTML = badgeLabel;
|
|
77
|
+
const baseStyle = "position:fixed;z-index:9999;display:inline-flex;align-items:center;justify-content:center;cursor:pointer;background:var(--cc-btn-secondary-bg, #ffffff);color:var(--cc-btn-secondary-text, #132a5e);border:1px solid var(--cc-btn-secondary-border, rgba(0,0,0,0.12));border-radius:9999px;padding:8px 14px;font-size:14px;font-weight:600;font-family:inherit;box-shadow:0 4px 14px rgba(0,0,0,0.1);transition:transform 0.15s ease,box-shadow 0.15s ease;";
|
|
78
|
+
const posStyles = {
|
|
79
|
+
"bottom-left": "bottom:16px;left:16px;",
|
|
80
|
+
"bottom-right": "bottom:16px;right:16px;",
|
|
81
|
+
"top-left": "top:16px;left:16px;",
|
|
82
|
+
"top-right": "top:16px;right:16px;"
|
|
83
|
+
};
|
|
84
|
+
btn.style.cssText = baseStyle + (posStyles[pos] || posStyles["bottom-left"]);
|
|
85
|
+
btn.addEventListener("mouseenter", () => {
|
|
86
|
+
btn.style.transform = "scale(1.05)";
|
|
87
|
+
btn.style.boxShadow = "0 6px 20px rgba(0,0,0,0.16)";
|
|
88
|
+
});
|
|
89
|
+
btn.addEventListener("mouseleave", () => {
|
|
90
|
+
btn.style.transform = "scale(1)";
|
|
91
|
+
btn.style.boxShadow = "0 4px 14px rgba(0,0,0,0.1)";
|
|
92
|
+
});
|
|
93
|
+
document.body.appendChild(btn);
|
|
94
|
+
}
|
|
68
95
|
}
|
|
69
96
|
export {
|
|
70
97
|
showPreferences2 as showPreferences
|
package/dist/index.d.ts
CHANGED
|
@@ -148,6 +148,21 @@ interface ConsentOptions {
|
|
|
148
148
|
* Defaults to true for the 'modal' preset, false otherwise.
|
|
149
149
|
*/
|
|
150
150
|
overlay?: boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Floating button / badge allowing users to reopen cookie preferences anytime:
|
|
153
|
+
* - `false` (default): disabled (preference reopening handled via footer link or [data-cc="show-preferencesModal"])
|
|
154
|
+
* - `true`: displays standard badge with cookie emoji 🍪
|
|
155
|
+
* - `string`: custom label or icon, e.g. '🍪', 'Cookies', '🍪 Ustawienia cookies'
|
|
156
|
+
*/
|
|
157
|
+
badge?: boolean | string;
|
|
158
|
+
/**
|
|
159
|
+
* Position of the floating preferences badge:
|
|
160
|
+
* - 'bottom-left' (default)
|
|
161
|
+
* - 'bottom-right'
|
|
162
|
+
* - 'top-left'
|
|
163
|
+
* - 'top-right'
|
|
164
|
+
*/
|
|
165
|
+
badgePosition?: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right';
|
|
151
166
|
/**
|
|
152
167
|
* Low-level UI configuration for consent and preferences modals.
|
|
153
168
|
* Merged on top of the `banner` preset, so you can fine-tune any of its values.
|
|
@@ -216,6 +231,8 @@ interface ClientConfig {
|
|
|
216
231
|
translations: Record<string, Translation>;
|
|
217
232
|
gui: GuiOptions;
|
|
218
233
|
overlay: boolean;
|
|
234
|
+
badge: boolean | string;
|
|
235
|
+
badgePosition: 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right';
|
|
219
236
|
revision: number;
|
|
220
237
|
mode: 'basic' | 'advanced';
|
|
221
238
|
}
|
package/dist/index.js
CHANGED
|
@@ -449,6 +449,8 @@ function consent(options = {}) {
|
|
|
449
449
|
);
|
|
450
450
|
const banner = options.banner ?? "box-left";
|
|
451
451
|
const overlay = options.overlay ?? banner === "modal";
|
|
452
|
+
const badge = options.badge ?? false;
|
|
453
|
+
const badgePosition = options.badgePosition ?? "bottom-left";
|
|
452
454
|
const preset = BANNER_PRESETS[banner];
|
|
453
455
|
const gui = {
|
|
454
456
|
consentModal: { ...preset.consentModal, ...options.gui?.consentModal },
|
|
@@ -464,6 +466,8 @@ function consent(options = {}) {
|
|
|
464
466
|
translations,
|
|
465
467
|
gui,
|
|
466
468
|
overlay,
|
|
469
|
+
badge,
|
|
470
|
+
badgePosition,
|
|
467
471
|
revision,
|
|
468
472
|
mode
|
|
469
473
|
};
|
package/package.json
CHANGED