@peax/consent-banner-react 0.3.0 → 0.5.0
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 +15 -3
- package/dist/index.js +175 -171
- package/package.json +31 -24
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ A React cookie banner with compact and stacked layouts, built-in preferences, an
|
|
|
14
14
|
npm install @peax/consent-banner-react @peax/consent-banner-theme
|
|
15
15
|
```
|
|
16
16
|
|
|
17
|
-
Import the stylesheet once in your application entry.
|
|
17
|
+
Import the stylesheet once in your application entry. English defaults work without locales. Install the optional `@peax/consent-banner-locales` package and pass its dictionaries through `locales` when needed; message types live in `@peax/consent-banner-shared`.
|
|
18
18
|
|
|
19
19
|
The example below uses the three default categories. Supply previously saved choices as `initialPreferences` (`null` for a new visitor), and connect `onCommit` to your consent storage and service controls.
|
|
20
20
|
|
|
@@ -102,7 +102,8 @@ All `BannerProps` fields are optional, but `floatingButtonPosition` requires `sh
|
|
|
102
102
|
|
|
103
103
|
| Prop | Default | Purpose |
|
|
104
104
|
| --- | --- | --- |
|
|
105
|
-
| `locale` | `'en'` | Select
|
|
105
|
+
| `locale` | `'en'` | Select a configured dictionary; exact tags precede base-language matches |
|
|
106
|
+
| `locales` | Omitted | Readonly map of `{ banner, preferences }` dictionaries; omitted means shared English fallback |
|
|
106
107
|
| `cookiePolicyUrl` | Omitted | Destination for policy links; without it, labels are plain text |
|
|
107
108
|
| `bannerContent` | Locale dictionary | Partial `BannerMessages` overrides for banner and preferences copy |
|
|
108
109
|
| `preferencesSections` | `['essential', 'analytics', 'marketing']` | Ordered visible section IDs; `[]` displays no sections |
|
|
@@ -197,7 +198,7 @@ Keyboard order follows visual order where `reading-flow` is supported; otherwise
|
|
|
197
198
|
| --- | --- | --- |
|
|
198
199
|
| Colors, spacing, radii, theme mode | Public `--pxc-*` variables on the root | [Theme package](https://github.com/peaxco/consent/blob/main/packages/consent-banner-theme/README.md) |
|
|
199
200
|
| Body/heading fonts and text size | Typography tokens; load fonts in your application | [Typography guide](https://github.com/peaxco/consent/blob/main/docs/typography.md) |
|
|
200
|
-
| Language and button text | `locale`, `bannerContent` | [Locales package](https://github.com/peaxco/consent/blob/main/packages/consent-banner-locales/README.md) |
|
|
201
|
+
| Language and button text | `locale`, `locales`, `bannerContent` | [Locales package](https://github.com/peaxco/consent/blob/main/packages/consent-banner-locales/README.md) |
|
|
201
202
|
| Section titles/descriptions | `preferencesContent` | [Preferences guide](https://github.com/peaxco/consent/blob/main/docs/preferences.md) |
|
|
202
203
|
| A translated policy link | `<cookiePolicy>label</cookiePolicy>` plus `cookiePolicyUrl` | [Localized links](https://github.com/peaxco/consent/blob/main/docs/localization.md#localized-links) |
|
|
203
204
|
|
|
@@ -215,3 +216,14 @@ Run `yarn workspace @peax/consent-banner-react dev` from the repository. The dem
|
|
|
215
216
|
See [Banner verification](https://github.com/peaxco/consent/blob/main/docs/engineering/banner-verification.md) for browser setup and snapshot checks, and [Contributing](https://github.com/peaxco/consent/blob/main/CONTRIBUTING.md) for repository commands.
|
|
216
217
|
|
|
217
218
|
The adapter shares pure presentation contracts and UI state helpers with `@peax/consent-banner-shared`. Existing React exports and callback behavior remain unchanged. See [Vue integration](../../docs/vue.md) for the equivalent Vue package.
|
|
219
|
+
|
|
220
|
+
## Optional translations
|
|
221
|
+
|
|
222
|
+
```tsx
|
|
223
|
+
import { de } from '@peax/consent-banner-locales/de'
|
|
224
|
+
import { fr } from '@peax/consent-banner-locales/fr'
|
|
225
|
+
|
|
226
|
+
<Banner isOpen locale="de-AT" locales={{ de, fr }} />
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
For all 25 languages, use `import locales from '@peax/consent-banner-locales'` and pass `locales={locales}`. Applications can also provide custom/partial dictionaries or use only content props with no locale package. Missing fields fall back to shared English; content props have final precedence. See [localization and migration](https://github.com/peaxco/consent/blob/main/docs/localization.md).
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import e from "clsx";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { Switch as L } from "@base-ui/react/switch";
|
|
2
|
+
import { defaultPreferencesSections as t, entranceDuration as n, entranceEase as r, mergeBannerContent as i, normalizeAppearanceDelay as a, parseMessage as o, reconcileDraft as s, resolveFloatingPosition as c, resolveLocaleContent as l, resolveSections as u, resolveSlideFrom as d, safeHref as f, safeHref as p, transitionPreferencesView as m } from "@peax/consent-banner-shared";
|
|
3
|
+
import { forwardRef as h, memo as g, useCallback as _, useEffect as v, useId as y, useMemo as b, useRef as x, useState as S } from "react";
|
|
4
|
+
import { AnimatePresence as C, LazyMotion as w, domAnimation as T, useIsPresent as E, usePresenceData as D, useReducedMotion as O } from "framer-motion";
|
|
5
|
+
import * as k from "framer-motion/m";
|
|
6
|
+
import { Fragment as A, jsx as j, jsxs as M } from "react/jsx-runtime";
|
|
7
|
+
import { Button as N } from "@base-ui/react/button";
|
|
8
|
+
import { ScrollArea as P } from "@base-ui/react/scroll-area";
|
|
9
|
+
import { Switch as F } from "@base-ui/react/switch";
|
|
11
10
|
//#region src/hooks/usePreferencesView.ts
|
|
12
|
-
function
|
|
13
|
-
let [a, o] =
|
|
14
|
-
return
|
|
15
|
-
o((t) =>
|
|
11
|
+
function I({ isOpen: e, showFloatingButton: t, showCustomizePreferences: n, floatingPosition: r, onMsg: i }) {
|
|
12
|
+
let [a, o] = S(null), [s, c] = S(!1), l = x(null);
|
|
13
|
+
return v(() => {
|
|
14
|
+
o((t) => m(t, {
|
|
16
15
|
type: "sync",
|
|
17
16
|
isOpen: e
|
|
18
17
|
})), (e || !t) && (l.current = null);
|
|
@@ -20,14 +19,14 @@ function R({ isOpen: e, showFloatingButton: t, showCustomizePreferences: n, floa
|
|
|
20
19
|
view: a,
|
|
21
20
|
hasPanel: s,
|
|
22
21
|
setHasPanel: c,
|
|
23
|
-
triggerRef:
|
|
22
|
+
triggerRef: _((e) => {
|
|
24
23
|
if (!e) return;
|
|
25
24
|
let t = l.current;
|
|
26
25
|
l.current = null, t && (document.activeElement === t || document.activeElement === document.body) && e.focus();
|
|
27
26
|
}, []),
|
|
28
|
-
onExitFocus:
|
|
27
|
+
onExitFocus: _(() => (t && (l.current = document.activeElement), t), [t]),
|
|
29
28
|
openPreferences: (e) => {
|
|
30
|
-
o((t) =>
|
|
29
|
+
o((t) => m(t, {
|
|
31
30
|
type: "open",
|
|
32
31
|
source: e,
|
|
33
32
|
position: r
|
|
@@ -37,7 +36,7 @@ function R({ isOpen: e, showFloatingButton: t, showCustomizePreferences: n, floa
|
|
|
37
36
|
});
|
|
38
37
|
},
|
|
39
38
|
closePreferences: () => {
|
|
40
|
-
a && (a.source === "banner" && (l.current = n ? document.activeElement : null, o((e) =>
|
|
39
|
+
a && (a.source === "banner" && (l.current = n ? document.activeElement : null, o((e) => m(e, { type: "close" }))), i?.({
|
|
41
40
|
type: "on_close_preferences",
|
|
42
41
|
source: a.source
|
|
43
42
|
}));
|
|
@@ -46,42 +45,42 @@ function R({ isOpen: e, showFloatingButton: t, showCustomizePreferences: n, floa
|
|
|
46
45
|
}
|
|
47
46
|
//#endregion
|
|
48
47
|
//#region src/components/Container/ContainerWrapper.tsx
|
|
49
|
-
var
|
|
50
|
-
let
|
|
51
|
-
|
|
48
|
+
var L = ({ position: t, slideFrom: i, onPresenceChange: a, children: o }) => {
|
|
49
|
+
let s = E(), c = D(), l = O(), u = x(null), f = x(null);
|
|
50
|
+
v(() => (a?.(!0), () => a?.(!1)), [a]), v(() => {
|
|
52
51
|
let e = u.current;
|
|
53
52
|
if (e) {
|
|
54
|
-
if (
|
|
53
|
+
if (s) {
|
|
55
54
|
e.removeAttribute("inert");
|
|
56
55
|
let t = document.activeElement;
|
|
57
|
-
t instanceof HTMLElement && !e.contains(t) && (
|
|
56
|
+
t instanceof HTMLElement && !e.contains(t) && (f.current = t);
|
|
58
57
|
return;
|
|
59
58
|
}
|
|
60
59
|
if (e.contains(document.activeElement) && !c?.()) {
|
|
61
|
-
let e =
|
|
60
|
+
let e = f.current;
|
|
62
61
|
e?.isConnected && e.focus({ preventScroll: !0 });
|
|
63
62
|
}
|
|
64
63
|
e.setAttribute("inert", "");
|
|
65
64
|
}
|
|
66
|
-
}, [
|
|
67
|
-
let
|
|
68
|
-
return /* @__PURE__ */
|
|
65
|
+
}, [s, c]);
|
|
66
|
+
let p = d(t, i), m = { transform: p === "bottom" ? "translateY(100%)" : `translateX(${p === "left" ? "-100%" : "100%"})` };
|
|
67
|
+
return /* @__PURE__ */ j(k.div, {
|
|
69
68
|
ref: u,
|
|
70
69
|
exit: { transform: "none" },
|
|
71
70
|
initial: m,
|
|
72
71
|
animate: { transform: "none" },
|
|
73
|
-
"aria-hidden": !
|
|
74
|
-
"data-state":
|
|
72
|
+
"aria-hidden": !s || void 0,
|
|
73
|
+
"data-state": s ? "open" : "closing",
|
|
75
74
|
className: e("pxc-wrapper", `pxc-wrapper--${t}`),
|
|
76
75
|
transition: {
|
|
77
|
-
duration:
|
|
78
|
-
ease: [...
|
|
76
|
+
duration: s && !l ? n : 0,
|
|
77
|
+
ease: [...r]
|
|
79
78
|
},
|
|
80
|
-
children:
|
|
79
|
+
children: o
|
|
81
80
|
});
|
|
82
|
-
},
|
|
83
|
-
let p =
|
|
84
|
-
return
|
|
81
|
+
}, R = h(function({ isOpen: t = !0, appearanceDelay: n = 0, position: r = "right", slideFrom: i = "bottom", onPresenceChange: o, onExitFocus: s, className: c, children: l, actions: u, ...d }, f) {
|
|
82
|
+
let p = a(n), [m, h] = S(p === 0);
|
|
83
|
+
return v(() => {
|
|
85
84
|
if (m || !t) return;
|
|
86
85
|
let e = window.setTimeout(() => h(!0), p);
|
|
87
86
|
return () => window.clearTimeout(e);
|
|
@@ -89,24 +88,24 @@ var z = ({ position: t, slideFrom: n, onPresenceChange: r, children: i }) => {
|
|
|
89
88
|
p,
|
|
90
89
|
t,
|
|
91
90
|
m
|
|
92
|
-
]), /* @__PURE__ */
|
|
93
|
-
features:
|
|
91
|
+
]), /* @__PURE__ */ j(w, {
|
|
92
|
+
features: T,
|
|
94
93
|
strict: !0,
|
|
95
|
-
children: /* @__PURE__ */
|
|
96
|
-
custom:
|
|
97
|
-
children: t && m && /* @__PURE__ */
|
|
94
|
+
children: /* @__PURE__ */ j(C, {
|
|
95
|
+
custom: s,
|
|
96
|
+
children: t && m && /* @__PURE__ */ j(L, {
|
|
98
97
|
position: r,
|
|
99
98
|
slideFrom: i,
|
|
100
|
-
onPresenceChange:
|
|
101
|
-
children: /* @__PURE__ */
|
|
99
|
+
onPresenceChange: o,
|
|
100
|
+
children: /* @__PURE__ */ j("div", {
|
|
102
101
|
ref: f,
|
|
103
|
-
className: e("pxc-container", u != null && "pxc-container--with-actions",
|
|
102
|
+
className: e("pxc-container", u != null && "pxc-container--with-actions", c),
|
|
104
103
|
...d,
|
|
105
|
-
children: u == null ?
|
|
104
|
+
children: u == null ? l : /* @__PURE__ */ M(A, { children: [/* @__PURE__ */ j("div", {
|
|
106
105
|
className: "pxc-container__content",
|
|
107
106
|
"data-container-content": !0,
|
|
108
|
-
children:
|
|
109
|
-
}), /* @__PURE__ */
|
|
107
|
+
children: l
|
|
108
|
+
}), /* @__PURE__ */ j("div", {
|
|
110
109
|
className: "pxc-container__actions",
|
|
111
110
|
"data-container-actions": !0,
|
|
112
111
|
children: u
|
|
@@ -115,7 +114,7 @@ var z = ({ position: t, slideFrom: n, onPresenceChange: r, children: i }) => {
|
|
|
115
114
|
}, "container")
|
|
116
115
|
})
|
|
117
116
|
});
|
|
118
|
-
}),
|
|
117
|
+
}), z = () => /* @__PURE__ */ M("svg", {
|
|
119
118
|
width: "24",
|
|
120
119
|
height: "24",
|
|
121
120
|
viewBox: "0 0 24 24",
|
|
@@ -128,14 +127,14 @@ var z = ({ position: t, slideFrom: n, onPresenceChange: r, children: i }) => {
|
|
|
128
127
|
"aria-hidden": "true",
|
|
129
128
|
focusable: "false",
|
|
130
129
|
children: [
|
|
131
|
-
/* @__PURE__ */
|
|
132
|
-
/* @__PURE__ */
|
|
133
|
-
/* @__PURE__ */
|
|
134
|
-
/* @__PURE__ */
|
|
135
|
-
/* @__PURE__ */
|
|
136
|
-
/* @__PURE__ */
|
|
130
|
+
/* @__PURE__ */ j("path", { d: "M11 17H11.01" }),
|
|
131
|
+
/* @__PURE__ */ j("path", { d: "M12.025 2.61499C12.054 2.29199 11.82 1.98399 11.496 1.99999C9.02138 2.12561 6.68155 3.16546 4.92997 4.91799C3.0533 6.79479 1.99905 9.34023 1.99915 11.9943C1.99924 14.6484 3.05367 17.1938 4.93047 19.0705C6.80728 20.9472 9.35272 22.0014 12.0068 22.0013C14.6609 22.0012 17.2063 20.9468 19.083 19.07C20.8344 17.3179 21.8732 14.9782 21.998 12.504C22.014 12.181 21.707 11.947 21.384 11.977C20.8082 12.0311 20.2276 11.9597 19.6821 11.7677C19.1366 11.5757 18.6392 11.2678 18.2242 10.865C17.8092 10.4623 17.4864 9.97436 17.2782 9.43485C17.07 8.89535 16.9812 8.31711 17.018 7.73999C17.0244 7.63881 17.0093 7.53742 16.9734 7.44257C16.9376 7.34773 16.882 7.26161 16.8103 7.18997C16.7385 7.11833 16.6523 7.06281 16.5574 7.02712C16.4626 6.99143 16.3611 6.97638 16.26 6.98299C15.6828 7.01952 15.1046 6.93048 14.5652 6.72199C14.0258 6.51351 13.538 6.19054 13.1355 5.77535C12.7329 5.36015 12.4252 4.86261 12.2335 4.31701C12.0417 3.77141 11.9706 3.19073 12.025 2.61499Z" }),
|
|
132
|
+
/* @__PURE__ */ j("path", { d: "M12 12H12.01" }),
|
|
133
|
+
/* @__PURE__ */ j("path", { d: "M16 16H16.01" }),
|
|
134
|
+
/* @__PURE__ */ j("path", { d: "M7 14H7.01" }),
|
|
135
|
+
/* @__PURE__ */ j("path", { d: "M9 8H9.01" })
|
|
137
136
|
]
|
|
138
|
-
}),
|
|
137
|
+
}), B = () => /* @__PURE__ */ M("svg", {
|
|
139
138
|
xmlns: "http://www.w3.org/2000/svg",
|
|
140
139
|
width: "24",
|
|
141
140
|
height: "24",
|
|
@@ -148,40 +147,40 @@ var z = ({ position: t, slideFrom: n, onPresenceChange: r, children: i }) => {
|
|
|
148
147
|
"aria-hidden": "true",
|
|
149
148
|
focusable: "false",
|
|
150
149
|
children: [
|
|
151
|
-
/* @__PURE__ */
|
|
152
|
-
/* @__PURE__ */
|
|
153
|
-
/* @__PURE__ */
|
|
150
|
+
/* @__PURE__ */ j("path", { d: "M14 17H5" }),
|
|
151
|
+
/* @__PURE__ */ j("path", { d: "M19 7h-9" }),
|
|
152
|
+
/* @__PURE__ */ j("circle", {
|
|
154
153
|
cx: "17",
|
|
155
154
|
cy: "17",
|
|
156
155
|
r: "3"
|
|
157
156
|
}),
|
|
158
|
-
/* @__PURE__ */
|
|
157
|
+
/* @__PURE__ */ j("circle", {
|
|
159
158
|
cx: "7",
|
|
160
159
|
cy: "7",
|
|
161
160
|
r: "3"
|
|
162
161
|
})
|
|
163
162
|
]
|
|
164
|
-
}),
|
|
165
|
-
return /* @__PURE__ */ N
|
|
163
|
+
}), V = h(function({ variant: t, className: n, children: r, ...i }, a) {
|
|
164
|
+
return /* @__PURE__ */ j(N, {
|
|
166
165
|
ref: a,
|
|
167
166
|
className: (r) => e("pxc-button", `pxc-button--${t}`, typeof n == "function" ? n(r) : n),
|
|
168
167
|
...i,
|
|
169
168
|
focusableWhenDisabled: !1,
|
|
170
169
|
children: r
|
|
171
170
|
});
|
|
172
|
-
}),
|
|
173
|
-
return /* @__PURE__ */
|
|
171
|
+
}), H = h(function({ label: e, position: t, onMsg: n }, r) {
|
|
172
|
+
return /* @__PURE__ */ j(V, {
|
|
174
173
|
ref: r,
|
|
175
174
|
variant: "iconed",
|
|
176
175
|
className: `pxc-floating-button pxc-floating-button--${t}`,
|
|
177
176
|
"aria-label": e,
|
|
178
177
|
onClick: () => n({ type: "on_open_preferences" }),
|
|
179
|
-
children: /* @__PURE__ */
|
|
178
|
+
children: /* @__PURE__ */ j(z, {})
|
|
180
179
|
});
|
|
181
|
-
}),
|
|
180
|
+
}), U = () => /* @__PURE__ */ j("div", {
|
|
182
181
|
className: "pxc-lead-icon",
|
|
183
|
-
children: /* @__PURE__ */
|
|
184
|
-
}),
|
|
182
|
+
children: /* @__PURE__ */ j(z, {})
|
|
183
|
+
}), W = () => /* @__PURE__ */ j("svg", {
|
|
185
184
|
viewBox: "0 0 24 24",
|
|
186
185
|
fill: "none",
|
|
187
186
|
stroke: "currentColor",
|
|
@@ -189,36 +188,36 @@ var z = ({ position: t, slideFrom: n, onPresenceChange: r, children: i }) => {
|
|
|
189
188
|
strokeLinecap: "round",
|
|
190
189
|
"aria-hidden": "true",
|
|
191
190
|
focusable: "false",
|
|
192
|
-
children: /* @__PURE__ */
|
|
191
|
+
children: /* @__PURE__ */ j("path", { d: "m6 6 12 12M6 18 18 6" })
|
|
193
192
|
});
|
|
194
193
|
//#endregion
|
|
195
194
|
//#region src/utils/notReachable.ts
|
|
196
|
-
function
|
|
195
|
+
function G(e, t = { throwError: !0 }) {
|
|
197
196
|
let n = `Should not be reached ${e}`;
|
|
198
197
|
if (t.throwError) throw Error(n);
|
|
199
198
|
}
|
|
200
199
|
//#endregion
|
|
201
200
|
//#region src/components/Text/RichText.tsx
|
|
202
|
-
var
|
|
201
|
+
var K = ({ message: e, links: t }) => b(() => o(e, Object.keys(t)), [e, t]).map((e) => {
|
|
203
202
|
if (e.type === "text") return e.value;
|
|
204
|
-
let n =
|
|
205
|
-
return n && e.value.trim() ? /* @__PURE__ */
|
|
203
|
+
let n = f(t[e.name]);
|
|
204
|
+
return n && e.value.trim() ? /* @__PURE__ */ j("a", {
|
|
206
205
|
className: "pxc-link",
|
|
207
206
|
href: n,
|
|
208
207
|
children: e.value
|
|
209
208
|
}, e.offset) : e.value;
|
|
210
|
-
}),
|
|
211
|
-
let i =
|
|
212
|
-
return /* @__PURE__ */
|
|
209
|
+
}), q = ({ section: e, checked: t, links: n, onMsg: r }) => {
|
|
210
|
+
let i = y();
|
|
211
|
+
return /* @__PURE__ */ M("section", {
|
|
213
212
|
className: "pxc-preferences__section",
|
|
214
213
|
"aria-labelledby": `${i}-title`,
|
|
215
|
-
children: [/* @__PURE__ */
|
|
214
|
+
children: [/* @__PURE__ */ M("div", {
|
|
216
215
|
className: "pxc-preferences__section-heading",
|
|
217
|
-
children: [/* @__PURE__ */
|
|
216
|
+
children: [/* @__PURE__ */ j("h4", {
|
|
218
217
|
id: `${i}-title`,
|
|
219
218
|
className: "pxc-text--h4",
|
|
220
219
|
children: e.title
|
|
221
|
-
}), /* @__PURE__ */
|
|
220
|
+
}), /* @__PURE__ */ j(F.Root, {
|
|
222
221
|
className: "pxc-switch",
|
|
223
222
|
checked: t,
|
|
224
223
|
disabled: e.disabled ?? !1,
|
|
@@ -229,208 +228,213 @@ var J = ({ message: e, links: t }) => S(() => r(e, Object.keys(t)), [e, t]).map(
|
|
|
229
228
|
sectionId: e.id,
|
|
230
229
|
checked: t
|
|
231
230
|
}),
|
|
232
|
-
children: /* @__PURE__ */
|
|
231
|
+
children: /* @__PURE__ */ j(F.Thumb, { className: "pxc-switch__thumb" })
|
|
233
232
|
})]
|
|
234
|
-
}), e.text && /* @__PURE__ */
|
|
233
|
+
}), e.text && /* @__PURE__ */ j("p", {
|
|
235
234
|
id: `${i}-text`,
|
|
236
235
|
className: "pxc-text--paragraph pxc-preferences__description",
|
|
237
|
-
children: /* @__PURE__ */
|
|
236
|
+
children: /* @__PURE__ */ j(K, {
|
|
238
237
|
message: e.text,
|
|
239
238
|
links: n
|
|
240
239
|
})
|
|
241
240
|
})]
|
|
242
241
|
});
|
|
243
|
-
},
|
|
244
|
-
let i =
|
|
245
|
-
(o.size !==
|
|
242
|
+
}, J = ({ sections: e, content: t, links: n, onMsg: r }) => {
|
|
243
|
+
let i = y(), a = x(null), [o, c] = S(() => s(e)), l = s(e, o);
|
|
244
|
+
(o.size !== l.size || [...l].some(([e, t]) => o.get(e) !== t)) && c(l), v(() => {
|
|
246
245
|
a.current?.focus({ preventScroll: !0 });
|
|
247
246
|
}, []);
|
|
248
|
-
let
|
|
249
|
-
return /* @__PURE__ */
|
|
247
|
+
let u = p(n.cookiePolicy);
|
|
248
|
+
return /* @__PURE__ */ M("section", {
|
|
250
249
|
className: "pxc-preferences",
|
|
251
250
|
"aria-labelledby": i,
|
|
252
251
|
onKeyDown: (e) => {
|
|
253
252
|
e.key === "Escape" && (e.preventDefault(), e.stopPropagation(), r({ type: "on_close_preferences" }));
|
|
254
253
|
},
|
|
255
254
|
children: [
|
|
256
|
-
/* @__PURE__ */
|
|
255
|
+
/* @__PURE__ */ M("header", {
|
|
257
256
|
className: "pxc-preferences__header",
|
|
258
|
-
children: [/* @__PURE__ */
|
|
257
|
+
children: [/* @__PURE__ */ j("h3", {
|
|
259
258
|
id: i,
|
|
260
259
|
ref: a,
|
|
261
260
|
tabIndex: -1,
|
|
262
261
|
className: "pxc-text--h3",
|
|
263
262
|
children: t.preferencesTitle
|
|
264
|
-
}), /* @__PURE__ */
|
|
263
|
+
}), /* @__PURE__ */ j(V, {
|
|
265
264
|
variant: "iconed",
|
|
266
265
|
"aria-label": t.closePreferencesLabel,
|
|
267
266
|
onClick: () => r({ type: "on_close_preferences" }),
|
|
268
|
-
children: /* @__PURE__ */
|
|
267
|
+
children: /* @__PURE__ */ j(W, {})
|
|
269
268
|
})]
|
|
270
269
|
}),
|
|
271
|
-
/* @__PURE__ */ P
|
|
270
|
+
/* @__PURE__ */ M(P.Root, {
|
|
272
271
|
className: "pxc-preferences__scroll-area",
|
|
273
|
-
children: [/* @__PURE__ */
|
|
272
|
+
children: [/* @__PURE__ */ j(P.Viewport, {
|
|
274
273
|
className: "pxc-preferences__body",
|
|
275
274
|
role: "group",
|
|
276
275
|
"aria-labelledby": i,
|
|
277
|
-
children: /* @__PURE__ */ P
|
|
276
|
+
children: /* @__PURE__ */ M(P.Content, {
|
|
278
277
|
className: "pxc-preferences__content",
|
|
279
|
-
children: [t.preferencesText && /* @__PURE__ */
|
|
278
|
+
children: [t.preferencesText && /* @__PURE__ */ j("p", {
|
|
280
279
|
className: "pxc-text--paragraph pxc-preferences__introduction",
|
|
281
|
-
children: /* @__PURE__ */
|
|
280
|
+
children: /* @__PURE__ */ j(K, {
|
|
282
281
|
message: t.preferencesText,
|
|
283
282
|
links: n
|
|
284
283
|
})
|
|
285
|
-
}), e.map((e) => /* @__PURE__ */
|
|
284
|
+
}), e.map((e) => /* @__PURE__ */ j(q, {
|
|
286
285
|
section: e,
|
|
287
|
-
checked:
|
|
286
|
+
checked: l.get(e.id) ?? e.checked,
|
|
288
287
|
links: n,
|
|
289
288
|
onMsg: (e) => {
|
|
290
289
|
switch (e.type) {
|
|
291
290
|
case "on_change_preference":
|
|
292
|
-
|
|
291
|
+
c((t) => new Map(t).set(e.sectionId, e.checked)), r(e);
|
|
293
292
|
break;
|
|
294
|
-
default:
|
|
293
|
+
default: G(e.type);
|
|
295
294
|
}
|
|
296
295
|
}
|
|
297
296
|
}, e.id))]
|
|
298
297
|
})
|
|
299
|
-
}), /* @__PURE__ */
|
|
298
|
+
}), /* @__PURE__ */ j(P.Scrollbar, {
|
|
300
299
|
className: "pxc-preferences__scrollbar",
|
|
301
|
-
children: /* @__PURE__ */
|
|
300
|
+
children: /* @__PURE__ */ j(P.Thumb, {
|
|
302
301
|
className: "pxc-preferences__scroll-thumb",
|
|
303
|
-
children: /* @__PURE__ */
|
|
302
|
+
children: /* @__PURE__ */ j("span", { className: "pxc-preferences__scroll-indicator" })
|
|
304
303
|
})
|
|
305
304
|
})]
|
|
306
305
|
}),
|
|
307
|
-
/* @__PURE__ */
|
|
306
|
+
/* @__PURE__ */ M("footer", {
|
|
308
307
|
className: "pxc-preferences__footer",
|
|
309
|
-
children: [/* @__PURE__ */
|
|
308
|
+
children: [/* @__PURE__ */ j(V, {
|
|
310
309
|
variant: "primary",
|
|
311
310
|
onClick: () => r({
|
|
312
311
|
type: "on_apply_preferences",
|
|
313
|
-
preferences: Object.fromEntries(
|
|
312
|
+
preferences: Object.fromEntries(l)
|
|
314
313
|
}),
|
|
315
314
|
children: t.applyPreferencesLabel
|
|
316
|
-
}),
|
|
315
|
+
}), u ? /* @__PURE__ */ j("a", {
|
|
317
316
|
className: "pxc-link pxc-preferences__policy",
|
|
318
|
-
href:
|
|
317
|
+
href: u,
|
|
319
318
|
children: t.cookiePolicyLabel
|
|
320
|
-
}) : /* @__PURE__ */
|
|
319
|
+
}) : /* @__PURE__ */ j("span", {
|
|
321
320
|
className: "pxc-preferences__policy",
|
|
322
321
|
children: t.cookiePolicyLabel
|
|
323
322
|
})]
|
|
324
323
|
})
|
|
325
324
|
]
|
|
326
325
|
});
|
|
327
|
-
},
|
|
326
|
+
}, Y = ({ variant: e, tag: t, children: n }) => {
|
|
328
327
|
switch (e) {
|
|
329
|
-
case "label": return /* @__PURE__ */
|
|
328
|
+
case "label": return /* @__PURE__ */ j(t, {
|
|
330
329
|
className: "pxc-text--label",
|
|
331
330
|
children: n
|
|
332
331
|
});
|
|
333
|
-
case "heading": return /* @__PURE__ */
|
|
332
|
+
case "heading": return /* @__PURE__ */ j(t, {
|
|
334
333
|
className: `pxc-text--${t}`,
|
|
335
334
|
children: n
|
|
336
335
|
});
|
|
337
|
-
case "paragraph": return /* @__PURE__ */
|
|
336
|
+
case "paragraph": return /* @__PURE__ */ j("p", {
|
|
338
337
|
className: "pxc-text--paragraph",
|
|
339
338
|
children: n
|
|
340
339
|
});
|
|
341
|
-
default: return
|
|
340
|
+
default: return G(e);
|
|
342
341
|
}
|
|
343
|
-
},
|
|
342
|
+
}, X = ({ variant: e, content: t, equalWeight: n, showCustomizePreferences: r, preferencesRef: i, onMsg: a }) => /* @__PURE__ */ M(A, { children: [/* @__PURE__ */ M("div", {
|
|
344
343
|
className: "pxc-banner__choices",
|
|
345
|
-
children: [/* @__PURE__ */
|
|
344
|
+
children: [/* @__PURE__ */ j(V, {
|
|
346
345
|
variant: n ? "secondary" : "primary",
|
|
347
346
|
onClick: () => a({ type: "on_accept_all" }),
|
|
348
347
|
children: t.acceptAllLabel
|
|
349
|
-
}), /* @__PURE__ */
|
|
348
|
+
}), /* @__PURE__ */ j(V, {
|
|
350
349
|
variant: "secondary",
|
|
351
350
|
onClick: () => a({ type: "on_reject_all" }),
|
|
352
351
|
children: t.rejectAllLabel
|
|
353
352
|
})]
|
|
354
|
-
}), r && /* @__PURE__ */
|
|
353
|
+
}), r && /* @__PURE__ */ j("div", {
|
|
355
354
|
className: "pxc-banner__preferences",
|
|
356
|
-
children: /* @__PURE__ */
|
|
355
|
+
children: /* @__PURE__ */ j(V, {
|
|
357
356
|
ref: i,
|
|
358
357
|
variant: "inline",
|
|
359
358
|
className: e === "compact" ? "pxc-button--iconed" : void 0,
|
|
360
359
|
"aria-label": t.customizePreferencesLabel,
|
|
361
360
|
onClick: () => a({ type: "on_open_preferences" }),
|
|
362
|
-
children: e === "compact" ? /* @__PURE__ */
|
|
361
|
+
children: e === "compact" ? /* @__PURE__ */ M(A, { children: [/* @__PURE__ */ j(B, {}), /* @__PURE__ */ j("span", { children: t.customizePreferencesLabel })] }) : t.customizePreferencesLabel
|
|
363
362
|
})
|
|
364
|
-
})] }),
|
|
365
|
-
let
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
363
|
+
})] }), Z = g(function({ bannerContent: n, cookiePolicyUrl: r, isOpen: a = !1, appearanceDelay: o = 0, preferencesSections: s = t, preferencesContent: d, hasAcceptRejectEqualWeight: f = !1, showCustomizePreferences: p = !0, showFloatingButton: m = !0, floatingButtonPosition: h, variant: g = "compact", theme: _ = "auto", locale: v = "en", locales: y, onMsg: x, className: S, style: C, ...w }) {
|
|
364
|
+
let T = b(() => l(v, y, n !== void 0 || d !== void 0), [
|
|
365
|
+
v,
|
|
366
|
+
y,
|
|
367
|
+
n,
|
|
368
|
+
d
|
|
369
|
+
]), E = i(T.banner, n), D = b(() => ({ cookiePolicy: r }), [r]), O = b(() => u(s, d, T.preferences), [
|
|
370
|
+
s,
|
|
371
|
+
d,
|
|
372
|
+
T.preferences
|
|
373
|
+
]), k = c(w.position, h), N = I({
|
|
374
|
+
isOpen: a,
|
|
375
|
+
showFloatingButton: m,
|
|
376
|
+
showCustomizePreferences: p,
|
|
377
|
+
floatingPosition: k,
|
|
374
378
|
onMsg: x
|
|
375
|
-
}),
|
|
376
|
-
...
|
|
377
|
-
position:
|
|
379
|
+
}), P = N.view !== null, F = N.view?.source === "floating-button" ? {
|
|
380
|
+
...w,
|
|
381
|
+
position: N.view.position,
|
|
378
382
|
slideFrom: "bottom"
|
|
379
|
-
} :
|
|
380
|
-
if (e.type === "on_open_preferences") return
|
|
381
|
-
if (e.type === "on_close_preferences") return
|
|
383
|
+
} : w, L = (e) => {
|
|
384
|
+
if (e.type === "on_open_preferences") return N.openPreferences("banner");
|
|
385
|
+
if (e.type === "on_close_preferences") return N.closePreferences();
|
|
382
386
|
x?.(e);
|
|
383
387
|
};
|
|
384
|
-
return /* @__PURE__ */
|
|
385
|
-
"data-theme":
|
|
386
|
-
"data-banner-variant":
|
|
387
|
-
className: e("pxc",
|
|
388
|
+
return /* @__PURE__ */ M("div", {
|
|
389
|
+
"data-theme": _,
|
|
390
|
+
"data-banner-variant": g,
|
|
391
|
+
className: e("pxc", S),
|
|
388
392
|
style: {
|
|
389
393
|
fontFamily: "var(--pxc-font-family)",
|
|
390
|
-
...
|
|
394
|
+
...C
|
|
391
395
|
},
|
|
392
|
-
lang:
|
|
393
|
-
children: [/* @__PURE__ */
|
|
394
|
-
...
|
|
395
|
-
isOpen:
|
|
396
|
-
onExitFocus:
|
|
397
|
-
onPresenceChange:
|
|
398
|
-
appearanceDelay:
|
|
399
|
-
className:
|
|
400
|
-
actions:
|
|
401
|
-
variant:
|
|
402
|
-
content:
|
|
403
|
-
equalWeight:
|
|
404
|
-
showCustomizePreferences:
|
|
405
|
-
preferencesRef:
|
|
406
|
-
onMsg:
|
|
396
|
+
lang: T.locale,
|
|
397
|
+
children: [/* @__PURE__ */ j(R, {
|
|
398
|
+
...F,
|
|
399
|
+
isOpen: a,
|
|
400
|
+
onExitFocus: N.onExitFocus,
|
|
401
|
+
onPresenceChange: N.setHasPanel,
|
|
402
|
+
appearanceDelay: o,
|
|
403
|
+
className: P ? "pxc-container--preferences" : void 0,
|
|
404
|
+
actions: P ? null : /* @__PURE__ */ j(X, {
|
|
405
|
+
variant: g,
|
|
406
|
+
content: E,
|
|
407
|
+
equalWeight: f,
|
|
408
|
+
showCustomizePreferences: p,
|
|
409
|
+
preferencesRef: N.triggerRef,
|
|
410
|
+
onMsg: L
|
|
407
411
|
}),
|
|
408
|
-
children:
|
|
409
|
-
links:
|
|
410
|
-
content:
|
|
411
|
-
sections:
|
|
412
|
-
onMsg:
|
|
413
|
-
}) : /* @__PURE__ */
|
|
412
|
+
children: P ? /* @__PURE__ */ j(J, {
|
|
413
|
+
links: D,
|
|
414
|
+
content: E,
|
|
415
|
+
sections: O,
|
|
416
|
+
onMsg: L
|
|
417
|
+
}) : /* @__PURE__ */ M(A, { children: [g === "stacked" ? /* @__PURE__ */ M("div", {
|
|
414
418
|
className: "pxc-banner__heading",
|
|
415
|
-
children: [/* @__PURE__ */
|
|
419
|
+
children: [/* @__PURE__ */ j(U, {}), /* @__PURE__ */ j(Y, {
|
|
416
420
|
variant: "heading",
|
|
417
421
|
tag: "h3",
|
|
418
|
-
children:
|
|
422
|
+
children: E.title
|
|
419
423
|
})]
|
|
420
|
-
}) : /* @__PURE__ */
|
|
424
|
+
}) : /* @__PURE__ */ j(U, {}), /* @__PURE__ */ j(Y, {
|
|
421
425
|
variant: "paragraph",
|
|
422
|
-
children: /* @__PURE__ */
|
|
423
|
-
message:
|
|
424
|
-
links:
|
|
426
|
+
children: /* @__PURE__ */ j(K, {
|
|
427
|
+
message: E.collapsedText,
|
|
428
|
+
links: D
|
|
425
429
|
})
|
|
426
430
|
})] })
|
|
427
|
-
}),
|
|
428
|
-
ref:
|
|
429
|
-
position:
|
|
430
|
-
label:
|
|
431
|
-
onMsg: () =>
|
|
431
|
+
}), m && !a && !N.hasPanel && /* @__PURE__ */ j(H, {
|
|
432
|
+
ref: N.triggerRef,
|
|
433
|
+
position: k,
|
|
434
|
+
label: E.customizePreferencesLabel.trim() || T.banner.customizePreferencesLabel,
|
|
435
|
+
onMsg: () => N.openPreferences("floating-button")
|
|
432
436
|
})]
|
|
433
437
|
});
|
|
434
438
|
});
|
|
435
439
|
//#endregion
|
|
436
|
-
export {
|
|
440
|
+
export { Z as Banner };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peax/consent-banner-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Accessible React bindings and components for Peax Consent.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"consent-management",
|
|
@@ -45,44 +45,51 @@
|
|
|
45
45
|
"build": "vite build",
|
|
46
46
|
"dev": "vite src/demo --config vite.config.ts",
|
|
47
47
|
"test": "vitest run",
|
|
48
|
-
"test:browser": "
|
|
48
|
+
"test:browser": "node ../../scripts/test-browser.mjs react",
|
|
49
|
+
"test:browser:native": "vitest run --config vitest.browser.config.ts --testTimeout 30000",
|
|
49
50
|
"typecheck": "tsc --noEmit"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
53
|
+
"@peax/consent-banner-locales": "^0.5.0",
|
|
52
54
|
"react": "^18.2.0 || ^19.0.0",
|
|
53
55
|
"react-dom": "^18.2.0 || ^19.0.0"
|
|
54
56
|
},
|
|
55
57
|
"dependencies": {
|
|
56
|
-
"@base-ui/react": "^1.
|
|
57
|
-
"@peax/consent-banner-
|
|
58
|
-
"@peax/consent-banner-
|
|
59
|
-
"@peax/consent-banner-theme": "^0.3.0",
|
|
58
|
+
"@base-ui/react": "^1.8.0",
|
|
59
|
+
"@peax/consent-banner-shared": "^0.5.0",
|
|
60
|
+
"@peax/consent-banner-theme": "^0.5.0",
|
|
60
61
|
"clsx": "^2.1.1",
|
|
61
|
-
"framer-motion": "^13.
|
|
62
|
+
"framer-motion": "^13.4.1"
|
|
62
63
|
},
|
|
63
64
|
"devDependencies": {
|
|
64
65
|
"@axe-core/playwright": "^4.13.0",
|
|
65
66
|
"@fontsource/figtree": "^5.3.0",
|
|
66
67
|
"@fontsource/poppins": "^5.3.0",
|
|
67
|
-
"@
|
|
68
|
+
"@peax/consent-banner-locales": "^0.5.0",
|
|
69
|
+
"@testing-library/dom": "^10.4.2",
|
|
68
70
|
"@testing-library/jest-dom": "^7.0.1",
|
|
69
|
-
"@testing-library/react": "^16.3.
|
|
70
|
-
"@testing-library/user-event": "^14.6.
|
|
71
|
-
"@types/jest-image-snapshot": "^6.4.
|
|
72
|
-
"@types/node": "^26.
|
|
73
|
-
"@types/react": "^19.
|
|
74
|
-
"@types/react-dom": "^19.
|
|
75
|
-
"@unocss/reset": "^66.
|
|
76
|
-
"@vitejs/plugin-react": "^6.1.
|
|
71
|
+
"@testing-library/react": "^16.3.3",
|
|
72
|
+
"@testing-library/user-event": "^14.6.7",
|
|
73
|
+
"@types/jest-image-snapshot": "^6.4.2",
|
|
74
|
+
"@types/node": "^26.6.2",
|
|
75
|
+
"@types/react": "^19.3.0",
|
|
76
|
+
"@types/react-dom": "^19.3.0",
|
|
77
|
+
"@unocss/reset": "^66.10.5",
|
|
78
|
+
"@vitejs/plugin-react": "^6.1.1",
|
|
77
79
|
"jest-image-snapshot": "^6.5.2",
|
|
78
|
-
"jsdom": "30.
|
|
79
|
-
"playwright": "^1.
|
|
80
|
-
"playwright-core": "1.
|
|
81
|
-
"react": "^19.
|
|
82
|
-
"react-dom": "^19.
|
|
80
|
+
"jsdom": "30.1.1",
|
|
81
|
+
"playwright": "^1.63.0",
|
|
82
|
+
"playwright-core": "1.63.0",
|
|
83
|
+
"react": "^19.3.0",
|
|
84
|
+
"react-dom": "^19.3.0",
|
|
83
85
|
"typescript": "5.9.3",
|
|
84
|
-
"vite": "^8.
|
|
85
|
-
"vite-plugin-dts": "^5.
|
|
86
|
-
"vitest": "^
|
|
86
|
+
"vite": "^8.3.0",
|
|
87
|
+
"vite-plugin-dts": "^5.1.1",
|
|
88
|
+
"vitest": "^5.0.1"
|
|
89
|
+
},
|
|
90
|
+
"peerDependenciesMeta": {
|
|
91
|
+
"@peax/consent-banner-locales": {
|
|
92
|
+
"optional": true
|
|
93
|
+
}
|
|
87
94
|
}
|
|
88
95
|
}
|