@peax/consent-banner-react 0.4.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.
Files changed (3) hide show
  1. package/README.md +15 -3
  2. package/dist/index.js +175 -171
  3. package/package.json +29 -23
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. Locales are already a dependency; install `@peax/consent-banner-locales` directly if your application imports its dictionaries or types.
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 English/German; regional tags fall back to their base language |
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 { getMessages as t, getPreferencesMessages as n, parseMessage as r, resolveLocale as i } from "@peax/consent-banner-locales";
3
- import { defaultPreferencesSections as a, entranceDuration as o, entranceEase as s, mergeBannerContent as c, normalizeAppearanceDelay as l, reconcileDraft as u, resolveFloatingPosition as d, resolveSections as f, resolveSlideFrom as p, safeHref as m, safeHref as h, transitionPreferencesView as g } from "@peax/consent-banner-shared";
4
- import { forwardRef as _, memo as v, useCallback as y, useEffect as b, useId as x, useMemo as S, useRef as C, useState as w } from "react";
5
- import { AnimatePresence as T, LazyMotion as E, domAnimation as D, useIsPresent as O, usePresenceData as k, useReducedMotion as A } from "framer-motion";
6
- import * as j from "framer-motion/m";
7
- import { Fragment as M, jsx as N, jsxs as P } from "react/jsx-runtime";
8
- import { Button as F } from "@base-ui/react/button";
9
- import { ScrollArea as I } from "@base-ui/react/scroll-area";
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 R({ isOpen: e, showFloatingButton: t, showCustomizePreferences: n, floatingPosition: r, onMsg: i }) {
13
- let [a, o] = w(null), [s, c] = w(!1), l = C(null);
14
- return b(() => {
15
- o((t) => g(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: y((e) => {
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: y(() => (t && (l.current = document.activeElement), t), [t]),
27
+ onExitFocus: _(() => (t && (l.current = document.activeElement), t), [t]),
29
28
  openPreferences: (e) => {
30
- o((t) => g(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) => g(e, { type: "close" }))), i?.({
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 z = ({ position: t, slideFrom: n, onPresenceChange: r, children: i }) => {
50
- let a = O(), c = k(), l = A(), u = C(null), d = C(null);
51
- b(() => (r?.(!0), () => r?.(!1)), [r]), b(() => {
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 (a) {
53
+ if (s) {
55
54
  e.removeAttribute("inert");
56
55
  let t = document.activeElement;
57
- t instanceof HTMLElement && !e.contains(t) && (d.current = 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 = d.current;
60
+ let e = f.current;
62
61
  e?.isConnected && e.focus({ preventScroll: !0 });
63
62
  }
64
63
  e.setAttribute("inert", "");
65
64
  }
66
- }, [a, c]);
67
- let f = p(t, n), m = { transform: l ? "none" : f === "bottom" ? "translateY(100%)" : `translateX(${f === "left" ? "-100%" : "100%"})` };
68
- return /* @__PURE__ */ N(j.div, {
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": !a || void 0,
74
- "data-state": a ? "open" : "closing",
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: a && !l ? o : 0,
78
- ease: [...s]
76
+ duration: s && !l ? n : 0,
77
+ ease: [...r]
79
78
  },
80
- children: i
79
+ children: o
81
80
  });
82
- }, B = _(function({ isOpen: t = !0, appearanceDelay: n = 0, position: r = "right", slideFrom: i = "bottom", onPresenceChange: a, onExitFocus: o, className: s, children: c, actions: u, ...d }, f) {
83
- let p = l(n), [m, h] = w(p === 0);
84
- return b(() => {
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__ */ N(E, {
93
- features: D,
91
+ ]), /* @__PURE__ */ j(w, {
92
+ features: T,
94
93
  strict: !0,
95
- children: /* @__PURE__ */ N(T, {
96
- custom: o,
97
- children: t && m && /* @__PURE__ */ N(z, {
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: a,
101
- children: /* @__PURE__ */ N("div", {
99
+ onPresenceChange: o,
100
+ children: /* @__PURE__ */ j("div", {
102
101
  ref: f,
103
- className: e("pxc-container", u != null && "pxc-container--with-actions", s),
102
+ className: e("pxc-container", u != null && "pxc-container--with-actions", c),
104
103
  ...d,
105
- children: u == null ? c : /* @__PURE__ */ P(M, { children: [/* @__PURE__ */ N("div", {
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: c
109
- }), /* @__PURE__ */ N("div", {
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
- }), V = () => /* @__PURE__ */ P("svg", {
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__ */ N("path", { d: "M11 17H11.01" }),
132
- /* @__PURE__ */ N("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" }),
133
- /* @__PURE__ */ N("path", { d: "M12 12H12.01" }),
134
- /* @__PURE__ */ N("path", { d: "M16 16H16.01" }),
135
- /* @__PURE__ */ N("path", { d: "M7 14H7.01" }),
136
- /* @__PURE__ */ N("path", { d: "M9 8H9.01" })
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
- }), H = () => /* @__PURE__ */ P("svg", {
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__ */ N("path", { d: "M14 17H5" }),
152
- /* @__PURE__ */ N("path", { d: "M19 7h-9" }),
153
- /* @__PURE__ */ N("circle", {
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__ */ N("circle", {
157
+ /* @__PURE__ */ j("circle", {
159
158
  cx: "7",
160
159
  cy: "7",
161
160
  r: "3"
162
161
  })
163
162
  ]
164
- }), U = _(function({ variant: t, className: n, children: r, ...i }, a) {
165
- return /* @__PURE__ */ N(F, {
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
- }), W = _(function({ label: e, position: t, onMsg: n }, r) {
173
- return /* @__PURE__ */ N(U, {
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__ */ N(V, {})
178
+ children: /* @__PURE__ */ j(z, {})
180
179
  });
181
- }), G = () => /* @__PURE__ */ N("div", {
180
+ }), U = () => /* @__PURE__ */ j("div", {
182
181
  className: "pxc-lead-icon",
183
- children: /* @__PURE__ */ N(V, {})
184
- }), K = () => /* @__PURE__ */ N("svg", {
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__ */ N("path", { d: "m6 6 12 12M6 18 18 6" })
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 q(e, t = { throwError: !0 }) {
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 J = ({ message: e, links: t }) => S(() => r(e, Object.keys(t)), [e, t]).map((e) => {
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 = m(t[e.name]);
205
- return n && e.value.trim() ? /* @__PURE__ */ N("a", {
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
- }), Y = ({ section: e, checked: t, links: n, onMsg: r }) => {
211
- let i = x();
212
- return /* @__PURE__ */ P("section", {
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__ */ P("div", {
214
+ children: [/* @__PURE__ */ M("div", {
216
215
  className: "pxc-preferences__section-heading",
217
- children: [/* @__PURE__ */ N("h4", {
216
+ children: [/* @__PURE__ */ j("h4", {
218
217
  id: `${i}-title`,
219
218
  className: "pxc-text--h4",
220
219
  children: e.title
221
- }), /* @__PURE__ */ N(L.Root, {
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__ */ N(L.Thumb, { className: "pxc-switch__thumb" })
231
+ children: /* @__PURE__ */ j(F.Thumb, { className: "pxc-switch__thumb" })
233
232
  })]
234
- }), e.text && /* @__PURE__ */ N("p", {
233
+ }), e.text && /* @__PURE__ */ j("p", {
235
234
  id: `${i}-text`,
236
235
  className: "pxc-text--paragraph pxc-preferences__description",
237
- children: /* @__PURE__ */ N(J, {
236
+ children: /* @__PURE__ */ j(K, {
238
237
  message: e.text,
239
238
  links: n
240
239
  })
241
240
  })]
242
241
  });
243
- }, X = ({ sections: e, content: t, links: n, onMsg: r }) => {
244
- let i = x(), a = C(null), [o, s] = w(() => u(e)), c = u(e, o);
245
- (o.size !== c.size || [...c].some(([e, t]) => o.get(e) !== t)) && s(c), b(() => {
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 l = h(n.cookiePolicy);
249
- return /* @__PURE__ */ P("section", {
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__ */ P("header", {
255
+ /* @__PURE__ */ M("header", {
257
256
  className: "pxc-preferences__header",
258
- children: [/* @__PURE__ */ N("h3", {
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__ */ N(U, {
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__ */ N(K, {})
267
+ children: /* @__PURE__ */ j(W, {})
269
268
  })]
270
269
  }),
271
- /* @__PURE__ */ P(I.Root, {
270
+ /* @__PURE__ */ M(P.Root, {
272
271
  className: "pxc-preferences__scroll-area",
273
- children: [/* @__PURE__ */ N(I.Viewport, {
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(I.Content, {
276
+ children: /* @__PURE__ */ M(P.Content, {
278
277
  className: "pxc-preferences__content",
279
- children: [t.preferencesText && /* @__PURE__ */ N("p", {
278
+ children: [t.preferencesText && /* @__PURE__ */ j("p", {
280
279
  className: "pxc-text--paragraph pxc-preferences__introduction",
281
- children: /* @__PURE__ */ N(J, {
280
+ children: /* @__PURE__ */ j(K, {
282
281
  message: t.preferencesText,
283
282
  links: n
284
283
  })
285
- }), e.map((e) => /* @__PURE__ */ N(Y, {
284
+ }), e.map((e) => /* @__PURE__ */ j(q, {
286
285
  section: e,
287
- checked: c.get(e.id) ?? e.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
- s((t) => new Map(t).set(e.sectionId, e.checked)), r(e);
291
+ c((t) => new Map(t).set(e.sectionId, e.checked)), r(e);
293
292
  break;
294
- default: q(e.type);
293
+ default: G(e.type);
295
294
  }
296
295
  }
297
296
  }, e.id))]
298
297
  })
299
- }), /* @__PURE__ */ N(I.Scrollbar, {
298
+ }), /* @__PURE__ */ j(P.Scrollbar, {
300
299
  className: "pxc-preferences__scrollbar",
301
- children: /* @__PURE__ */ N(I.Thumb, {
300
+ children: /* @__PURE__ */ j(P.Thumb, {
302
301
  className: "pxc-preferences__scroll-thumb",
303
- children: /* @__PURE__ */ N("span", { className: "pxc-preferences__scroll-indicator" })
302
+ children: /* @__PURE__ */ j("span", { className: "pxc-preferences__scroll-indicator" })
304
303
  })
305
304
  })]
306
305
  }),
307
- /* @__PURE__ */ P("footer", {
306
+ /* @__PURE__ */ M("footer", {
308
307
  className: "pxc-preferences__footer",
309
- children: [/* @__PURE__ */ N(U, {
308
+ children: [/* @__PURE__ */ j(V, {
310
309
  variant: "primary",
311
310
  onClick: () => r({
312
311
  type: "on_apply_preferences",
313
- preferences: Object.fromEntries(c)
312
+ preferences: Object.fromEntries(l)
314
313
  }),
315
314
  children: t.applyPreferencesLabel
316
- }), l ? /* @__PURE__ */ N("a", {
315
+ }), u ? /* @__PURE__ */ j("a", {
317
316
  className: "pxc-link pxc-preferences__policy",
318
- href: l,
317
+ href: u,
319
318
  children: t.cookiePolicyLabel
320
- }) : /* @__PURE__ */ N("span", {
319
+ }) : /* @__PURE__ */ j("span", {
321
320
  className: "pxc-preferences__policy",
322
321
  children: t.cookiePolicyLabel
323
322
  })]
324
323
  })
325
324
  ]
326
325
  });
327
- }, Z = ({ variant: e, tag: t, children: n }) => {
326
+ }, Y = ({ variant: e, tag: t, children: n }) => {
328
327
  switch (e) {
329
- case "label": return /* @__PURE__ */ N(t, {
328
+ case "label": return /* @__PURE__ */ j(t, {
330
329
  className: "pxc-text--label",
331
330
  children: n
332
331
  });
333
- case "heading": return /* @__PURE__ */ N(t, {
332
+ case "heading": return /* @__PURE__ */ j(t, {
334
333
  className: `pxc-text--${t}`,
335
334
  children: n
336
335
  });
337
- case "paragraph": return /* @__PURE__ */ N("p", {
336
+ case "paragraph": return /* @__PURE__ */ j("p", {
338
337
  className: "pxc-text--paragraph",
339
338
  children: n
340
339
  });
341
- default: return q(e);
340
+ default: return G(e);
342
341
  }
343
- }, Q = ({ variant: e, content: t, equalWeight: n, showCustomizePreferences: r, preferencesRef: i, onMsg: a }) => /* @__PURE__ */ P(M, { children: [/* @__PURE__ */ P("div", {
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__ */ N(U, {
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__ */ N(U, {
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__ */ N("div", {
353
+ }), r && /* @__PURE__ */ j("div", {
355
354
  className: "pxc-banner__preferences",
356
- children: /* @__PURE__ */ N(U, {
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__ */ P(M, { children: [/* @__PURE__ */ N(H, {}), /* @__PURE__ */ N("span", { children: t.customizePreferencesLabel })] }) : t.customizePreferencesLabel
361
+ children: e === "compact" ? /* @__PURE__ */ M(A, { children: [/* @__PURE__ */ j(B, {}), /* @__PURE__ */ j("span", { children: t.customizePreferencesLabel })] }) : t.customizePreferencesLabel
363
362
  })
364
- })] }), $ = v(function({ bannerContent: r, cookiePolicyUrl: o, isOpen: s = !1, appearanceDelay: l = 0, preferencesSections: u = a, preferencesContent: p, hasAcceptRejectEqualWeight: m = !1, showCustomizePreferences: h = !0, showFloatingButton: g = !0, floatingButtonPosition: _, variant: v = "compact", theme: y = "auto", locale: b = "en", onMsg: x, className: C, style: w, ...T }) {
365
- let E = i(b), D = t(E), O = c(D, r), k = S(() => ({ cookiePolicy: o }), [o]), A = S(() => f(u, p, n(E)), [
366
- u,
367
- p,
368
- E
369
- ]), j = d(T.position, _), F = R({
370
- isOpen: s,
371
- showFloatingButton: g,
372
- showCustomizePreferences: h,
373
- floatingPosition: j,
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
- }), I = F.view !== null, L = F.view?.source === "floating-button" ? {
376
- ...T,
377
- position: F.view.position,
379
+ }), P = N.view !== null, F = N.view?.source === "floating-button" ? {
380
+ ...w,
381
+ position: N.view.position,
378
382
  slideFrom: "bottom"
379
- } : T, z = (e) => {
380
- if (e.type === "on_open_preferences") return F.openPreferences("banner");
381
- if (e.type === "on_close_preferences") return F.closePreferences();
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__ */ P("div", {
385
- "data-theme": y,
386
- "data-banner-variant": v,
387
- className: e("pxc", C),
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
- ...w
394
+ ...C
391
395
  },
392
- lang: E,
393
- children: [/* @__PURE__ */ N(B, {
394
- ...L,
395
- isOpen: s,
396
- onExitFocus: F.onExitFocus,
397
- onPresenceChange: F.setHasPanel,
398
- appearanceDelay: l,
399
- className: I ? "pxc-container--preferences" : void 0,
400
- actions: I ? null : /* @__PURE__ */ N(Q, {
401
- variant: v,
402
- content: O,
403
- equalWeight: m,
404
- showCustomizePreferences: h,
405
- preferencesRef: F.triggerRef,
406
- onMsg: z
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: I ? /* @__PURE__ */ N(X, {
409
- links: k,
410
- content: O,
411
- sections: A,
412
- onMsg: z
413
- }) : /* @__PURE__ */ P(M, { children: [v === "stacked" ? /* @__PURE__ */ P("div", {
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__ */ N(G, {}), /* @__PURE__ */ N(Z, {
419
+ children: [/* @__PURE__ */ j(U, {}), /* @__PURE__ */ j(Y, {
416
420
  variant: "heading",
417
421
  tag: "h3",
418
- children: O.title
422
+ children: E.title
419
423
  })]
420
- }) : /* @__PURE__ */ N(G, {}), /* @__PURE__ */ N(Z, {
424
+ }) : /* @__PURE__ */ j(U, {}), /* @__PURE__ */ j(Y, {
421
425
  variant: "paragraph",
422
- children: /* @__PURE__ */ N(J, {
423
- message: O.collapsedText,
424
- links: k
426
+ children: /* @__PURE__ */ j(K, {
427
+ message: E.collapsedText,
428
+ links: D
425
429
  })
426
430
  })] })
427
- }), g && !s && !F.hasPanel && /* @__PURE__ */ N(W, {
428
- ref: F.triggerRef,
429
- position: j,
430
- label: O.customizePreferencesLabel.trim() || D.customizePreferencesLabel,
431
- onMsg: () => F.openPreferences("floating-button")
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 { $ as Banner };
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.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Accessible React bindings and components for Peax Consent.",
5
5
  "keywords": [
6
6
  "consent-management",
@@ -50,40 +50,46 @@
50
50
  "typecheck": "tsc --noEmit"
51
51
  },
52
52
  "peerDependencies": {
53
+ "@peax/consent-banner-locales": "^0.5.0",
53
54
  "react": "^18.2.0 || ^19.0.0",
54
55
  "react-dom": "^18.2.0 || ^19.0.0"
55
56
  },
56
57
  "dependencies": {
57
- "@base-ui/react": "^1.7.0",
58
- "@peax/consent-banner-locales": "^0.4.0",
59
- "@peax/consent-banner-shared": "^0.4.0",
60
- "@peax/consent-banner-theme": "^0.4.0",
58
+ "@base-ui/react": "^1.8.0",
59
+ "@peax/consent-banner-shared": "^0.5.0",
60
+ "@peax/consent-banner-theme": "^0.5.0",
61
61
  "clsx": "^2.1.1",
62
- "framer-motion": "^13.1.1"
62
+ "framer-motion": "^13.4.1"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@axe-core/playwright": "^4.13.0",
66
66
  "@fontsource/figtree": "^5.3.0",
67
67
  "@fontsource/poppins": "^5.3.0",
68
- "@testing-library/dom": "^10.4.1",
68
+ "@peax/consent-banner-locales": "^0.5.0",
69
+ "@testing-library/dom": "^10.4.2",
69
70
  "@testing-library/jest-dom": "^7.0.1",
70
- "@testing-library/react": "^16.3.2",
71
- "@testing-library/user-event": "^14.6.6",
72
- "@types/jest-image-snapshot": "^6.4.1",
73
- "@types/node": "^26.3.0",
74
- "@types/react": "^19.2.18",
75
- "@types/react-dom": "^19.2.5",
76
- "@unocss/reset": "^66.8.1",
77
- "@vitejs/plugin-react": "^6.1.0",
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",
78
79
  "jest-image-snapshot": "^6.5.2",
79
- "jsdom": "30.0.1",
80
- "playwright": "^1.62.1",
81
- "playwright-core": "1.62.1",
82
- "react": "^19.2.8",
83
- "react-dom": "^19.2.8",
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",
84
85
  "typescript": "5.9.3",
85
- "vite": "^8.2.2",
86
- "vite-plugin-dts": "^5.0.3",
87
- "vitest": "^4.1.11"
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
+ }
88
94
  }
89
95
  }