@escape-game-over/atlas 0.1.38 → 0.1.40

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.
@@ -51,7 +51,9 @@ answer is two, one per category: `analytics` (Google's `analytics_storage`) and
51
51
  markup marks its buttons `data-consent="grant"` and `data-consent="deny"` for
52
52
  everything at once, and `data-consent="save"` for the answer its checkboxes
53
53
  give — `data-consent-category="analytics"` and `"marketing"`, never ticked by
54
- default. The control that brings it back is `data-consent-reopen hidden`.
54
+ default. Those can wait in a `data-consent-choices hidden` panel that a
55
+ `data-consent-choose` button shows and hides, keeping its `aria-expanded` in
56
+ step. The control that brings it back is `data-consent-reopen hidden`.
55
57
 
56
58
  `Document` ships one more: scroll restoration, on unless `restoreScroll={false}`.
57
59
  WebKit restores a page's position only at `load`, after every image, so a page
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escape-game-over/atlas",
3
- "version": "0.1.38",
3
+ "version": "0.1.40",
4
4
  "type": "module",
5
5
  "description": "Typed, data-driven machinery for static multi-locale, multi-deployment Astro sites.",
6
6
  "private": false,
@@ -7,7 +7,7 @@ import {
7
7
  recordConsent,
8
8
  } from "./consent.ts";
9
9
  import { element } from "./element.ts";
10
- import { data, refs } from "./ref.ts";
10
+ import { data, ref, refs } from "./ref.ts";
11
11
 
12
12
  /**
13
13
  * The banner's behaviour. Its own module, and not re-exported from `client.ts`,
@@ -25,6 +25,13 @@ import { data, refs } from "./ref.ts";
25
25
  * The checkboxes are never ticked by default; they show an answer already
26
26
  * given, and nothing else.
27
27
  *
28
+ * To keep them out of sight until asked for, put them in a
29
+ * `data-consent-choices hidden` panel and add a `data-consent-choose` button:
30
+ * it shows and hides the panel, and keeps its own `aria-expanded` in step. The
31
+ * panel can sit anywhere in the banner — below the buttons, not only inside
32
+ * the control, which is what a `<details>` would force. It starts closed each
33
+ * time the banner is shown.
34
+ *
28
35
  * The control that brings it back — usually in the footer — is
29
36
  * `data-consent-reopen hidden`: it stays hidden until there is an answer to
30
37
  * withdraw.
@@ -53,12 +60,31 @@ export const consentBanner = element("atlas-consent", ({ root, signal }) => {
53
60
  };
54
61
  };
55
62
 
63
+ const toggles = refs<HTMLButtonElement>(root, "[data-consent-choose]");
64
+ const panel =
65
+ toggles.length > 0 ? ref(root, "[data-consent-choices]") : undefined;
66
+
67
+ const expand = (open: boolean): void => {
68
+ if (panel === undefined) return;
69
+ panel.hidden = !open;
70
+ for (const toggle of toggles) {
71
+ toggle.setAttribute("aria-expanded", String(open));
72
+ }
73
+ };
74
+
75
+ for (const toggle of toggles) {
76
+ toggle.addEventListener("click", () => expand(panel?.hidden === true), {
77
+ signal,
78
+ });
79
+ }
80
+
56
81
  const show = (): void => {
57
82
  // Only an answer already given ticks a box.
58
83
  const stored = readConsent();
59
84
  for (const { box, category } of boxes) {
60
85
  box.checked = stored?.[category] === "granted";
61
86
  }
87
+ expand(false);
62
88
  root.hidden = false;
63
89
  };
64
90
 
package/src/index.ts CHANGED
@@ -12,6 +12,12 @@
12
12
  * ```
13
13
  */
14
14
 
15
+ export {
16
+ CONSENT_CATEGORIES,
17
+ type ConsentCategory,
18
+ type ConsentChoice,
19
+ type ConsentChoices,
20
+ } from "./analytics/consent-storage.ts";
15
21
  export {
16
22
  type AnalyticsSettings,
17
23
  type AnalyticsTags,