@htmlbricks/hb-cookie-law-banner 0.71.35 → 0.71.37

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 CHANGED
@@ -1,40 +1,125 @@
1
- ## `hb-cookie-law-banner` — cookie-law-banner
1
+ # `hb-cookie-law-banner`
2
2
 
3
- **Category:** layout | **Tags:** layout, compliance
3
+ **Category:** layout · **Tags:** layout, compliance
4
4
 
5
- ### What it does
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
- Bootstrap alert cookie notice until the user accepts or declines; the choice is stored in `localStorage` under `cookielaw`. Supports i18n via `i18nlang`, optional `cookielawuri4more` link, JSON `capabilities` for extended consent, slots to override title/text, and dispatches `acceptCookieLaw` with `{ accepted: "yes" | "no" }`.
7
+ ---
8
8
 
9
- ### Custom element
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
- ### Attributes / props (snake_case)
40
+ ---
14
41
 
15
- | Property | Type | Notes |
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 |
16
47
  | --- | --- | --- |
17
- | `id` | string (optional) | Element identifier. |
18
- | `style` | string (optional) | Inline style string. |
19
- | `allowdecline` | union (optional) | `"yes"` \| `"no"` show decline action. |
20
- | `i18nlang` | string (optional) | Language key (e.g. `en`, `it`). |
21
- | `capabilities` | object (optional) | JSON `ICapabilities`: cookie groups and items with scopes, mandatory flags, etc. |
22
- | `cookielawuri4more` | string (optional) | “Learn more” URL. |
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
+ ---
56
+
57
+ ## Events
58
+
59
+ | Event | `detail` | When |
60
+ | --- | --- | --- |
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
+ ---
64
+
65
+ ## Slots
66
+
67
+ | Slot | Purpose |
68
+ | --- | --- |
69
+ | `title` | Replaces the default translated heading inside `title is-5`. |
70
+ | `text` | Replaces the default translated paragraph inside `content is-size-6`. |
71
+
72
+ Default slot content comes from the i18n dictionary for the active `i18nlang`.
73
+
74
+ ---
75
+
76
+ ## Styling
77
+
78
+ ### Bulma and host tokens
79
+
80
+ The component forwards Bulma Sass with theme variables on `:host`. Documented CSS custom properties (from metadata / `extra/docs.ts`):
81
+
82
+ | Variable | Role |
83
+ | --- | --- |
84
+ | `--bulma-scheme-main` | Scheme / surface for the dark notification bar. |
85
+ | `--bulma-text` | Primary text (title and body). |
86
+ | `--bulma-link` | “Learn more” link color on the inverted bar. |
87
+ | `--bulma-border` | Useful if you extend the layout with extra separators. |
88
+
89
+ See [Bulma CSS variables](https://bulma.io/documentation/features/css-variables/) for the full token set available where Bulma is forwarded.
90
+
91
+ ### Component SCSS
23
92
 
24
- **Slots:** `title`, `text`. **i18n:** Italian and English in metadata.
93
+ `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
94
 
26
- ### Events (`CustomEvent` names)
95
+ ### CSS parts
27
96
 
28
- - **`acceptCookieLaw`** — `{ accepted: "yes" | "no" }`
97
+ None (`::part` not exposed).
29
98
 
30
- ### Usage notes
99
+ ---
31
100
 
32
- - Uses Bootstrap alert styling patterns.
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.
101
+ ## TypeScript typings
36
102
 
37
- ### Minimal HTML example
103
+ Authoring types live in `types/webcomponent.type.d.ts`.
104
+
105
+ **`ICapabilities`** — Cookie catalog shape:
106
+
107
+ - **`groups`:** `{ _id, label, type }[]`
108
+ - **`items`:** entries with `groupId`, `title`, `scope`, `_id`, `cookieName`, and optional fields such as `description`, `descriptionUrl`, `thirdCompanyName`, `isMandatory`, `isTechnical`, `isMarketing`, `isThirdPartyOwned`, `isSessionCookie`, `cookieExpirationInSeconds`
109
+
110
+ **`Component`** (props):
111
+
112
+ - `id?`, `style?`, `allowdecline?`, `i18nlang?`, `cookielawuri4more?`, `capabilities?` (typed as `ICapabilities` in TS; from HTML pass JSON string)
113
+
114
+ **`Events`:**
115
+
116
+ - `acceptCookieLaw`: `{ accepted: boolean }`
117
+
118
+ ---
119
+
120
+ ## Example
121
+
122
+ Minimal host page with English copy, optional policy URL, and decline enabled:
38
123
 
39
124
  ```html
40
125
  <hb-cookie-law-banner
@@ -42,4 +127,40 @@ Bootstrap alert cookie notice until the user accepts or declines; the choice is
42
127
  i18nlang="en"
43
128
  cookielawuri4more="https://example.com/cookies"
44
129
  ></hb-cookie-law-banner>
130
+
131
+ <script>
132
+ document.querySelector("hb-cookie-law-banner").addEventListener("acceptCookieLaw", (e) => {
133
+ console.log(e.detail.accepted); // true = accept, false = decline
134
+ });
135
+ </script>
136
+ ```
137
+
138
+ Accept-only (no decline button):
139
+
140
+ ```html
141
+ <hb-cookie-law-banner allowdecline="no"></hb-cookie-law-banner>
142
+ ```
143
+
144
+ Hide “Learn more”:
145
+
146
+ ```html
147
+ <hb-cookie-law-banner cookielawuri4more="no"></hb-cookie-law-banner>
148
+ ```
149
+
150
+ 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):
151
+
152
+ ```html
153
+ <hb-cookie-law-banner allowdecline="yes">
154
+ <span slot="title">Cookies on this site</span>
155
+ <span slot="text">We use cookies to run the site and measure usage. See our policy for details.</span>
156
+ </hb-cookie-law-banner>
157
+ ```
158
+
159
+ Optional `capabilities` JSON string (for hosts that store or forward metadata; default UI unchanged):
160
+
161
+ ```html
162
+ <hb-cookie-law-banner
163
+ allowdecline="yes"
164
+ capabilities='{"groups":[{"_id":"essential","label":"Essential","type":"technical"}],"items":[{"groupId":"essential","title":"Session","scope":"strictly_necessary","_id":"1","cookieName":"sid","isTechnical":true,"isMandatory":true}]}'
165
+ ></hb-cookie-law-banner>
45
166
  ```
package/manifest.json CHANGED
@@ -11,11 +11,7 @@
11
11
  "additionalProperties": false,
12
12
  "properties": {
13
13
  "accepted": {
14
- "enum": [
15
- "yes",
16
- "no"
17
- ],
18
- "type": "string"
14
+ "type": "boolean"
19
15
  }
20
16
  },
21
17
  "required": [
@@ -184,18 +180,43 @@
184
180
  }
185
181
  },
186
182
  "styleSetup": {
187
- "vars": [],
183
+ "vars": [
184
+ {
185
+ "name": "--bulma-scheme-main",
186
+ "valueType": "color",
187
+ "defaultValue": "(theme)",
188
+ "description": "Dark notification (`notification is-dark`) maps surface colors through the active scheme; set on `:host` or document for bar contrast."
189
+ },
190
+ {
191
+ "name": "--bulma-text",
192
+ "valueType": "color",
193
+ "defaultValue": "(theme)",
194
+ "description": "Primary text on the bar (title and body copy)."
195
+ },
196
+ {
197
+ "name": "--bulma-link",
198
+ "valueType": "color",
199
+ "defaultValue": "(theme)",
200
+ "description": "“Learn more” link color on the inverted bar."
201
+ },
202
+ {
203
+ "name": "--bulma-border",
204
+ "valueType": "color",
205
+ "defaultValue": "(theme)",
206
+ "description": "Subtle separators if you extend the layout with extra rules."
207
+ }
208
+ ],
188
209
  "parts": []
189
210
  },
190
211
  "contributors": [],
191
212
  "htmlSlots": [
192
213
  {
193
214
  "name": "title",
194
- "description": ""
215
+ "description": "Replace the default translated cookie title inside the `title is-5` heading."
195
216
  },
196
217
  {
197
218
  "name": "text",
198
- "description": ""
219
+ "description": "Replace the default translated explanatory paragraph inside the `content` block."
199
220
  }
200
221
  ],
201
222
  "i18n": [
@@ -297,5 +318,5 @@
297
318
  },
298
319
  "iifePath": "main.iife.js",
299
320
  "repoName": "@htmlbricks/hb-cookie-law-banner",
300
- "version": "0.71.35"
321
+ "version": "0.71.37"
301
322
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@htmlbricks/hb-cookie-law-banner",
3
- "version": "0.71.35",
3
+ "version": "0.71.37",
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": [
@@ -32,5 +32,5 @@ export type Component = {
32
32
  };
33
33
 
34
34
  export type Events = {
35
- acceptCookieLaw: { accepted: "yes" | "no" };
35
+ acceptCookieLaw: { accepted: boolean };
36
36
  };
@@ -9,11 +9,7 @@
9
9
  "additionalProperties": false,
10
10
  "properties": {
11
11
  "accepted": {
12
- "enum": [
13
- "yes",
14
- "no"
15
- ],
16
- "type": "string"
12
+ "type": "boolean"
17
13
  }
18
14
  },
19
15
  "required": [