@htmlbricks/hb-cookie-law-banner 0.71.34 → 0.71.36
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/README.md +145 -22
- package/manifest.json +29 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,40 +1,127 @@
|
|
|
1
|
-
|
|
1
|
+
# `hb-cookie-law-banner`
|
|
2
2
|
|
|
3
|
-
**Category:** layout
|
|
3
|
+
**Category:** layout · **Tags:** layout, compliance
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Fixed bottom cookie/consent bar built with Bulma (`notification is-dark`, columns, buttons). It stays visible until the visitor chooses **Accept** or (optionally) **Decline**, then hides and persists the choice in **`localStorage`** so repeat visits do not show the bar again.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
---
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
## Behavior and logic
|
|
10
|
+
|
|
11
|
+
1. **Persistence** — On **Accept** or **Decline**, the component writes `localStorage.setItem("cookielaw", "yes" | "no")` (`"yes"` for accept, `"no"` for decline). On load, if that key exists, the banner is treated as dismissed and does not show the visible state.
|
|
12
|
+
|
|
13
|
+
2. **Visibility** — The outer bar uses CSS (see [Styling](#styling)) to sit fixed at the bottom of the viewport. When a stored choice exists, the `is-visible` class is omitted so the bar animates to hidden (opacity / translate). When there is no stored choice, `is-visible` is applied so the bar appears (with a short transition delay).
|
|
14
|
+
|
|
15
|
+
3. **`allowdecline`** — Only the string `"yes"` enables the decline button. Any other value (including missing) is normalized to **`"no"`** in an effect: accept-only flow with a single primary button.
|
|
16
|
+
|
|
17
|
+
4. **`cookielawuri4more`** — The “Learn more” anchor is rendered when this attribute is **not** the literal string `"no"`. If the URL is empty, the link still appears and points to `https://wikipedia.org/wiki/HTTP_cookie`. Set `cookielawuri4more="no"` to hide the link entirely.
|
|
18
|
+
|
|
19
|
+
5. **`capabilities`** — If passed as a JSON string (typical from HTML attributes), the component parses it in an effect. The current markup **does not render** group/item toggles or lists from `capabilities`; the shape exists in typings and metadata for integrators who may read the prop or extend the host app. The visible UI remains title, body, link, and buttons.
|
|
20
|
+
|
|
21
|
+
6. **Internationalization** — `i18nlang` selects entries from the built-in dictionary (`"en"`, `"it"`). Strings include title, body, “Learn more”, “Accept”, and “Decline”. Override copy with slots when you need full control. (As shipped, the default body string under `en` may still be Italian; use the `text` slot for guaranteed locale-specific copy.)
|
|
22
|
+
|
|
23
|
+
7. **Host logging** — Choosing an option logs an informational message to the console (`accept cookie law`).
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Layout
|
|
28
|
+
|
|
29
|
+
- **Shell:** Bulma `notification is-dark is-radiusless mb-0` with `role="alert"`.
|
|
30
|
+
- **Grid:** `columns is-mobile is-vcentered is-multiline` — on mobile the text column is full width (`is-12-mobile`); from tablet up, copy uses `is-8-tablet` and actions `is-4-tablet`.
|
|
31
|
+
- **Actions column:** Flex row with wrap, end justification, centered cross-axis, and gap between the optional link and buttons.
|
|
32
|
+
- **Fixed positioning:** Implemented in `styles/webcomponent.scss` (bottom edge, full width, `z-index: 40`), with horizontal column margins reset so the bar does not widen the document scroll width.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Custom element
|
|
10
37
|
|
|
11
38
|
`hb-cookie-law-banner`
|
|
12
39
|
|
|
13
|
-
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Attributes / properties (snake_case, string-oriented)
|
|
43
|
+
|
|
44
|
+
Web component attributes are strings. Booleans use **`yes`** / **`no`**. Complex values such as `capabilities` are JSON strings.
|
|
45
|
+
|
|
46
|
+
| Attribute / prop | Type (logical) | Description |
|
|
47
|
+
| --- | --- | --- |
|
|
48
|
+
| `id` | `string` (optional) | Optional element id (standard host usage). |
|
|
49
|
+
| `style` | `string` (optional) | Inline styles on the host (standard). |
|
|
50
|
+
| `allowdecline` | `"yes"` \| `"no"` (optional, default `"no"`) | `"yes"` shows **Decline**; anything else behaves as `"no"`. |
|
|
51
|
+
| `i18nlang` | `string` (optional) | Language key, e.g. `en`, `it`. |
|
|
52
|
+
| `cookielawuri4more` | `string` (optional) | Policy URL for “Learn more”. Omit or leave empty for the Wikipedia cookie fallback. Use the literal **`no`** to hide the link. |
|
|
53
|
+
| `capabilities` | `ICapabilities` as JSON string (optional) | Structured groups/items for cookie metadata; parsed when provided as a string. Not used by the default UI (see [Behavior](#behavior-and-logic)). |
|
|
54
|
+
|
|
55
|
+
---
|
|
14
56
|
|
|
15
|
-
|
|
57
|
+
## Events
|
|
58
|
+
|
|
59
|
+
| Event | `detail` | When |
|
|
16
60
|
| --- | --- | --- |
|
|
17
|
-
| `
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
61
|
+
| `acceptCookieLaw` | `{ accepted: boolean }` | After the user clicks **Accept** (`true`) or **Decline** (`false`, only if decline is enabled). The choice is written to `localStorage` before the event is dispatched. |
|
|
62
|
+
|
|
63
|
+
**Note:** `types/webcomponent.type.d.ts` currently types `accepted` as `"yes" \| "no"`; at runtime the component dispatches a **boolean**. Prefer listening for `true` / `false` in vanilla JS; align the declaration file with runtime if you rely on strict typings.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Slots
|
|
68
|
+
|
|
69
|
+
| Slot | Purpose |
|
|
70
|
+
| --- | --- |
|
|
71
|
+
| `title` | Replaces the default translated heading inside `title is-5`. |
|
|
72
|
+
| `text` | Replaces the default translated paragraph inside `content is-size-6`. |
|
|
73
|
+
|
|
74
|
+
Default slot content comes from the i18n dictionary for the active `i18nlang`.
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
## Styling
|
|
79
|
+
|
|
80
|
+
### Bulma and host tokens
|
|
81
|
+
|
|
82
|
+
The component forwards Bulma Sass with theme variables on `:host`. Documented CSS custom properties (from metadata / `extra/docs.ts`):
|
|
83
|
+
|
|
84
|
+
| Variable | Role |
|
|
85
|
+
| --- | --- |
|
|
86
|
+
| `--bulma-scheme-main` | Scheme / surface for the dark notification bar. |
|
|
87
|
+
| `--bulma-text` | Primary text (title and body). |
|
|
88
|
+
| `--bulma-link` | “Learn more” link color on the inverted bar. |
|
|
89
|
+
| `--bulma-border` | Useful if you extend the layout with extra separators. |
|
|
90
|
+
|
|
91
|
+
See [Bulma CSS variables](https://bulma.io/documentation/features/css-variables/) for the full token set available where Bulma is forwarded.
|
|
92
|
+
|
|
93
|
+
### Component SCSS
|
|
23
94
|
|
|
24
|
-
|
|
95
|
+
`styles/webcomponent.scss` pins the bar to the bottom (`position: fixed`, `inset-inline: 0`, `bottom: 0`), hides it by default (`opacity: 0`, `visibility: hidden`, `translateY(100%)`), and reveals it with `.hb-cookie-law.is-visible` including transition timing.
|
|
25
96
|
|
|
26
|
-
###
|
|
97
|
+
### CSS parts
|
|
27
98
|
|
|
28
|
-
|
|
99
|
+
None (`::part` not exposed).
|
|
29
100
|
|
|
30
|
-
|
|
101
|
+
---
|
|
31
102
|
|
|
32
|
-
|
|
33
|
-
- Fullscreen layout size hint in metadata for Storybook-style hosts.
|
|
34
|
-
- Shadow DOM; override copy via `title` and `text` slots.
|
|
35
|
-
- Set `i18nlang` to match declared languages.
|
|
103
|
+
## TypeScript typings
|
|
36
104
|
|
|
37
|
-
|
|
105
|
+
Authoring types live in `types/webcomponent.type.d.ts`.
|
|
106
|
+
|
|
107
|
+
**`ICapabilities`** — Cookie catalog shape:
|
|
108
|
+
|
|
109
|
+
- **`groups`:** `{ _id, label, type }[]`
|
|
110
|
+
- **`items`:** entries with `groupId`, `title`, `scope`, `_id`, `cookieName`, and optional fields such as `description`, `descriptionUrl`, `thirdCompanyName`, `isMandatory`, `isTechnical`, `isMarketing`, `isThirdPartyOwned`, `isSessionCookie`, `cookieExpirationInSeconds`
|
|
111
|
+
|
|
112
|
+
**`Component`** (props):
|
|
113
|
+
|
|
114
|
+
- `id?`, `style?`, `allowdecline?`, `i18nlang?`, `cookielawuri4more?`, `capabilities?` (typed as `ICapabilities` in TS; from HTML pass JSON string)
|
|
115
|
+
|
|
116
|
+
**`Events`:**
|
|
117
|
+
|
|
118
|
+
- `acceptCookieLaw`: `{ accepted: "yes" | "no" }` in the type file — see [Events](#events) for runtime `boolean` behavior.
|
|
119
|
+
|
|
120
|
+
---
|
|
121
|
+
|
|
122
|
+
## Example
|
|
123
|
+
|
|
124
|
+
Minimal host page with English copy, optional policy URL, and decline enabled:
|
|
38
125
|
|
|
39
126
|
```html
|
|
40
127
|
<hb-cookie-law-banner
|
|
@@ -42,4 +129,40 @@ Bootstrap alert cookie notice until the user accepts or declines; the choice is
|
|
|
42
129
|
i18nlang="en"
|
|
43
130
|
cookielawuri4more="https://example.com/cookies"
|
|
44
131
|
></hb-cookie-law-banner>
|
|
132
|
+
|
|
133
|
+
<script>
|
|
134
|
+
document.querySelector("hb-cookie-law-banner").addEventListener("acceptCookieLaw", (e) => {
|
|
135
|
+
console.log(e.detail.accepted); // true = accept, false = decline
|
|
136
|
+
});
|
|
137
|
+
</script>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
Accept-only (no decline button):
|
|
141
|
+
|
|
142
|
+
```html
|
|
143
|
+
<hb-cookie-law-banner allowdecline="no"></hb-cookie-law-banner>
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
Hide “Learn more”:
|
|
147
|
+
|
|
148
|
+
```html
|
|
149
|
+
<hb-cookie-law-banner cookielawuri4more="no"></hb-cookie-law-banner>
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Custom title and body via slots (shadow DOM slot API depends on how you mount the bundle; with declarative shadow DOM or frameworks, use the same slot names):
|
|
153
|
+
|
|
154
|
+
```html
|
|
155
|
+
<hb-cookie-law-banner allowdecline="yes">
|
|
156
|
+
<span slot="title">Cookies on this site</span>
|
|
157
|
+
<span slot="text">We use cookies to run the site and measure usage. See our policy for details.</span>
|
|
158
|
+
</hb-cookie-law-banner>
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Optional `capabilities` JSON string (for hosts that store or forward metadata; default UI unchanged):
|
|
162
|
+
|
|
163
|
+
```html
|
|
164
|
+
<hb-cookie-law-banner
|
|
165
|
+
allowdecline="yes"
|
|
166
|
+
capabilities='{"groups":[{"_id":"essential","label":"Essential","type":"technical"}],"items":[{"groupId":"essential","title":"Session","scope":"strictly_necessary","_id":"1","cookieName":"sid","isTechnical":true,"isMandatory":true}]}'
|
|
167
|
+
></hb-cookie-law-banner>
|
|
45
168
|
```
|
package/manifest.json
CHANGED
|
@@ -184,18 +184,43 @@
|
|
|
184
184
|
}
|
|
185
185
|
},
|
|
186
186
|
"styleSetup": {
|
|
187
|
-
"vars": [
|
|
187
|
+
"vars": [
|
|
188
|
+
{
|
|
189
|
+
"name": "--bulma-scheme-main",
|
|
190
|
+
"valueType": "color",
|
|
191
|
+
"defaultValue": "(theme)",
|
|
192
|
+
"description": "Dark notification (`notification is-dark`) maps surface colors through the active scheme; set on `:host` or document for bar contrast."
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
"name": "--bulma-text",
|
|
196
|
+
"valueType": "color",
|
|
197
|
+
"defaultValue": "(theme)",
|
|
198
|
+
"description": "Primary text on the bar (title and body copy)."
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"name": "--bulma-link",
|
|
202
|
+
"valueType": "color",
|
|
203
|
+
"defaultValue": "(theme)",
|
|
204
|
+
"description": "“Learn more” link color on the inverted bar."
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"name": "--bulma-border",
|
|
208
|
+
"valueType": "color",
|
|
209
|
+
"defaultValue": "(theme)",
|
|
210
|
+
"description": "Subtle separators if you extend the layout with extra rules."
|
|
211
|
+
}
|
|
212
|
+
],
|
|
188
213
|
"parts": []
|
|
189
214
|
},
|
|
190
215
|
"contributors": [],
|
|
191
216
|
"htmlSlots": [
|
|
192
217
|
{
|
|
193
218
|
"name": "title",
|
|
194
|
-
"description": ""
|
|
219
|
+
"description": "Replace the default translated cookie title inside the `title is-5` heading."
|
|
195
220
|
},
|
|
196
221
|
{
|
|
197
222
|
"name": "text",
|
|
198
|
-
"description": ""
|
|
223
|
+
"description": "Replace the default translated explanatory paragraph inside the `content` block."
|
|
199
224
|
}
|
|
200
225
|
],
|
|
201
226
|
"i18n": [
|
|
@@ -297,5 +322,5 @@
|
|
|
297
322
|
},
|
|
298
323
|
"iifePath": "main.iife.js",
|
|
299
324
|
"repoName": "@htmlbricks/hb-cookie-law-banner",
|
|
300
|
-
"version": "0.71.
|
|
325
|
+
"version": "0.71.36"
|
|
301
326
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@htmlbricks/hb-cookie-law-banner",
|
|
3
|
-
"version": "0.71.
|
|
3
|
+
"version": "0.71.36",
|
|
4
4
|
"contributors": [],
|
|
5
5
|
"description": "Bootstrap alert cookie notice shown until the user chooses accept or decline; the choice is stored in `localStorage` under `cookielaw` so the banner stays hidden on return visits. Supports i18n via `i18nlang`, optional `cookielawuri4more` link, JSON `capabilities` for extended consent, slots to override title/text, and dispatches `acceptCookieLaw` with `{ accepted: boolean }`.",
|
|
6
6
|
"licenses": [
|