@peax/consent-banner-react 0.1.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/LICENSE +201 -0
- package/README.md +198 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.js +433 -0
- package/package.json +87 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# @peax/consent-banner-react
|
|
2
|
+
|
|
3
|
+
A React cookie banner with compact and stacked layouts, built-in preferences, and typed consent events.
|
|
4
|
+
|
|
5
|
+
[Peax Consent](https://github.com/peaxco/consent/blob/main/README.md) · [All guides](https://github.com/peaxco/consent/blob/main/docs/README.md) · [Theme](https://github.com/peaxco/consent/blob/main/packages/consent-banner-theme/README.md) · [Locales](https://github.com/peaxco/consent/blob/main/packages/consent-banner-locales/README.md)
|
|
6
|
+
|
|
7
|
+
[Quick start](#quick-start) · [Props](#props) · [Events](#events) · [Preferences](#preferences) · [Layouts](#layouts)
|
|
8
|
+
|
|
9
|
+
## Quick start
|
|
10
|
+
|
|
11
|
+
**Requires React 18.2+ (18.x) or 19.x, with matching React DOM.** ESM and TypeScript declarations are included.
|
|
12
|
+
|
|
13
|
+
```sh
|
|
14
|
+
npm install @peax/consent-banner-react @peax/consent-banner-theme
|
|
15
|
+
```
|
|
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.
|
|
18
|
+
|
|
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
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import { useState } from 'react'
|
|
23
|
+
import { Banner } from '@peax/consent-banner-react'
|
|
24
|
+
import '@peax/consent-banner-theme/styles.css'
|
|
25
|
+
|
|
26
|
+
type Preferences = Record<string, boolean>
|
|
27
|
+
|
|
28
|
+
type Props = {
|
|
29
|
+
initialPreferences: Preferences | null
|
|
30
|
+
onCommit: (preferences: Preferences) => void
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function CookieBanner({ initialPreferences, onCommit }: Props) {
|
|
34
|
+
const [open, setOpen] = useState(initialPreferences === null)
|
|
35
|
+
const [preferences, setPreferences] = useState(initialPreferences ?? {})
|
|
36
|
+
|
|
37
|
+
function commit(next: Preferences) {
|
|
38
|
+
onCommit(next) // Your application saves and enforces this decision.
|
|
39
|
+
setPreferences(next)
|
|
40
|
+
setOpen(false)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<>
|
|
45
|
+
<button type="button" onClick={() => setOpen(true)}>Cookie choices</button>
|
|
46
|
+
<Banner
|
|
47
|
+
isOpen={open}
|
|
48
|
+
cookiePolicyUrl="/cookies"
|
|
49
|
+
preferencesContent={Object.fromEntries(
|
|
50
|
+
Object.entries(preferences).map(([id, checked]) => [id, { checked }]),
|
|
51
|
+
)}
|
|
52
|
+
onMsg={msg => {
|
|
53
|
+
switch (msg.type) {
|
|
54
|
+
case 'on_accept_all':
|
|
55
|
+
commit({ essential: true, analytics: true, marketing: true })
|
|
56
|
+
break
|
|
57
|
+
case 'on_reject_all':
|
|
58
|
+
commit({ essential: true, analytics: false, marketing: false })
|
|
59
|
+
break
|
|
60
|
+
case 'on_apply_preferences':
|
|
61
|
+
commit(msg.preferences)
|
|
62
|
+
break
|
|
63
|
+
}
|
|
64
|
+
}}
|
|
65
|
+
/>
|
|
66
|
+
</>
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
**Your application completes the integration:**
|
|
72
|
+
|
|
73
|
+
1. Restore saved consent before initializing this wrapper; keep server and client initial props consistent.
|
|
74
|
+
2. Keep optional services blocked until the relevant consent is granted. Save and enforce decisions in `onCommit`, including later revocation.
|
|
75
|
+
3. Adapt the Accept/Reject maps if you change the selected categories or their behavior.
|
|
76
|
+
4. Keep the banner mounted and change `isOpen` to play its exit animation. The “Cookie choices” button above reopens it.
|
|
77
|
+
|
|
78
|
+
The banner manages UI and temporary drafts. It does not store consent, load trackers, or depend on `@peax/consent-core`.
|
|
79
|
+
|
|
80
|
+
## Props
|
|
81
|
+
|
|
82
|
+
All `BannerProps` fields are optional. **`isOpen` defaults to `false`**, so pass it to display the banner.
|
|
83
|
+
|
|
84
|
+
### Visibility and layout
|
|
85
|
+
|
|
86
|
+
| Prop | Default | Purpose |
|
|
87
|
+
| --- | --- | --- |
|
|
88
|
+
| `isOpen` | `false` | Show or hide the banner |
|
|
89
|
+
| `variant` | `'compact'` | `'compact'` or `'stacked'` |
|
|
90
|
+
| `showCustomizePreferences` | `true` | Show the preferences trigger, whether icon or text |
|
|
91
|
+
| `hasAcceptRejectEqualWeight` | `false` | Give Accept and Reject the same secondary button appearance |
|
|
92
|
+
| `position` | `'right'` | `'left'`, `'center'`, or `'right'` |
|
|
93
|
+
| `slideFrom` | `'bottom'` | Bottom, or the matching side for left/right positioning |
|
|
94
|
+
| `appearanceDelay` | `0` | Delay the first appearance, in milliseconds |
|
|
95
|
+
|
|
96
|
+
### Content and preferences
|
|
97
|
+
|
|
98
|
+
| Prop | Default | Purpose |
|
|
99
|
+
| --- | --- | --- |
|
|
100
|
+
| `locale` | `'en'` | Select English/German; regional tags fall back to their base language |
|
|
101
|
+
| `cookiePolicyUrl` | Omitted | Destination for policy links; without it, labels are plain text |
|
|
102
|
+
| `bannerContent` | Locale dictionary | Partial `BannerMessages` overrides for banner and preferences copy |
|
|
103
|
+
| `preferencesSections` | `['essential', 'analytics', 'marketing']` | Ordered visible section IDs; `[]` displays no sections |
|
|
104
|
+
| `preferencesContent` | Built-in section defaults | Overrides keyed by section ID; see [Preferences](#preferences) |
|
|
105
|
+
|
|
106
|
+
### Styling and events
|
|
107
|
+
|
|
108
|
+
| Prop | Default | Purpose |
|
|
109
|
+
| --- | --- | --- |
|
|
110
|
+
| `theme` | `'auto'` | Host theme: `'light'`, `'dark'`, or system preference |
|
|
111
|
+
| `className` | Omitted | Class on the banner's `.pxc` root |
|
|
112
|
+
| `style` | Omitted | Inline styles on that same root |
|
|
113
|
+
| `onMsg` | Omitted | `(msg: BannerMsg) => void`; see the event contract below |
|
|
114
|
+
|
|
115
|
+
## Events
|
|
116
|
+
|
|
117
|
+
All interactions use `onMsg`. The three decision events leave the banner open until your application changes `isOpen`.
|
|
118
|
+
|
|
119
|
+
| Message `type` | Additional payload | Integration behavior |
|
|
120
|
+
| --- | --- | --- |
|
|
121
|
+
| `on_accept_all` | None | Grant the applicable categories, save, enforce, and close |
|
|
122
|
+
| `on_reject_all` | None | Reject optional categories, save, enforce, and close |
|
|
123
|
+
| `on_apply_preferences` | `preferences: Record<string, boolean>` | Save and enforce the supplied selection, then close |
|
|
124
|
+
| `on_change_preference` | `sectionId`, `checked` | Observe a draft edit; do not treat it as applied consent |
|
|
125
|
+
| `on_open_preferences` | None | Notification; the panel opens internally |
|
|
126
|
+
| `on_close_preferences` | None | Notification; Close/Escape discards drafts and returns to the banner |
|
|
127
|
+
|
|
128
|
+
Apply includes every selected section ID, including disabled sections. Closing preferences never grants consent. External closure through `isOpen={false}` resets the draft without emitting `on_close_preferences`.
|
|
129
|
+
|
|
130
|
+
## Preferences
|
|
131
|
+
|
|
132
|
+
Select IDs, then override only the fields you need:
|
|
133
|
+
|
|
134
|
+
```tsx
|
|
135
|
+
<Banner
|
|
136
|
+
isOpen
|
|
137
|
+
preferencesSections={['essential', 'analytics', 'marketing']}
|
|
138
|
+
preferencesContent={{ essential: { title: 'Required cookies' } }}
|
|
139
|
+
/>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
This changes the Essential title while retaining its description and behavior. Analytics and Marketing retain all their defaults.
|
|
143
|
+
|
|
144
|
+
| Section ID | Checked | Disabled | Copy |
|
|
145
|
+
| --- | --- | --- | --- |
|
|
146
|
+
| `essential` | `true` | `true` | From the selected locale |
|
|
147
|
+
| `analytics` | `false` | `false` | From the selected locale |
|
|
148
|
+
| `marketing` | `false` | `false` | From the selected locale |
|
|
149
|
+
| Any custom string | `false` | `false` | ID as title; no description |
|
|
150
|
+
|
|
151
|
+
- `preferencesSections` controls visibility and order; an override alone does not add a section. Empty or whitespace-only IDs are omitted, other IDs are preserved exactly, and duplicate IDs appear once.
|
|
152
|
+
- Each override accepts `title`, `text`, `checked`, and `disabled`. Omitted/nullish fields retain defaults; `false` is respected and `text: ''` hides the description. Empty or whitespace-only titles fall back to the localized built-in title or custom ID to keep switches named.
|
|
153
|
+
- `PreferencesSectionId` suggests built-in IDs while accepting custom strings.
|
|
154
|
+
- `showCustomizePreferences={false}` removes the trigger in every layout. Changing it does not close an already open panel.
|
|
155
|
+
|
|
156
|
+
See [Cookie preferences](https://github.com/peaxco/consent/blob/main/docs/preferences.md) for custom categories, draft reconciliation, accessibility, and migration from the earlier array API.
|
|
157
|
+
|
|
158
|
+
## Layouts
|
|
159
|
+
|
|
160
|
+
| Variant | Presentation | Sizing |
|
|
161
|
+
| --- | --- | --- |
|
|
162
|
+
| `compact` | Cookie icon and paragraph; preferences icon becomes a centered text action when space is tight | Fills available width, up to an 800px outer limit including gutters |
|
|
163
|
+
| `stacked` | Cookie icon and heading, paragraph, decision buttons, then a centered preferences label | 420px card on desktop; fills the space inside gutters below 768px |
|
|
164
|
+
|
|
165
|
+
In compact mode, actions adapt to their actual label widths:
|
|
166
|
+
|
|
167
|
+
| Available space | Visible order |
|
|
168
|
+
| --- | --- |
|
|
169
|
+
| All three controls fit | Preferences icon → Reject → Accept |
|
|
170
|
+
| Only decisions fit together | Reject + Accept, then Customize preferences |
|
|
171
|
+
| Decisions need separate rows | Accept → Reject → Customize preferences |
|
|
172
|
+
|
|
173
|
+
Both variants support wrapping labels and scrolling on short viewports. Preferences opens the same nonmodal panel, with a scrolling body and fixed header/footer. Close/Escape restores focus to the visible trigger.
|
|
174
|
+
|
|
175
|
+
Keyboard order follows visual order where `reading-flow` is supported; otherwise compact controls retain Accept → Reject → Preferences DOM order. The preferences panel does not trap focus.
|
|
176
|
+
|
|
177
|
+
## Styling and localization
|
|
178
|
+
|
|
179
|
+
| Change | Use | Details |
|
|
180
|
+
| --- | --- | --- |
|
|
181
|
+
| 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) |
|
|
182
|
+
| 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) |
|
|
183
|
+
| Language and button text | `locale`, `bannerContent` | [Locales package](https://github.com/peaxco/consent/blob/main/packages/consent-banner-locales/README.md) |
|
|
184
|
+
| Section titles/descriptions | `preferencesContent` | [Preferences guide](https://github.com/peaxco/consent/blob/main/docs/preferences.md) |
|
|
185
|
+
| A translated policy link | `<cookiePolicy>label</cookiePolicy>` plus `cookiePolicyUrl` | [Localized links](https://github.com/peaxco/consent/blob/main/docs/localization.md#localized-links) |
|
|
186
|
+
|
|
187
|
+
## Runtime and public exports
|
|
188
|
+
|
|
189
|
+
- Import `Banner` and types `BannerProps`, `BannerMsg`, `PreferencesSection`, and `PreferencesSectionId` from the package root. Deep imports are unsupported.
|
|
190
|
+
- The JavaScript entry is safe for SSR and does not import CSS. Load `@peax/consent-banner-theme/styles.css` separately; there is no React CSS entry.
|
|
191
|
+
- In an application with React Server Components, render the interactive banner through a client component. Locale selection is explicit, so use matching initial props during hydration.
|
|
192
|
+
- Mount outside restrictive ancestor stacking contexts. The wrapper's default z-index is `1000`; override `--pxc-z-index` when needed.
|
|
193
|
+
|
|
194
|
+
## Development
|
|
195
|
+
|
|
196
|
+
Run `yarn workspace @peax/consent-banner-react dev` from the repository. The demo supports `?variant=stacked`, `?locale=de`, and `?showCustomizePreferences=false`. Theme edits update live from source.
|
|
197
|
+
|
|
198
|
+
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.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { BannerMessages } from '@peax/consent-banner-locales';
|
|
2
|
+
import { BuiltInPreferencesSectionId } from '@peax/consent-banner-locales';
|
|
3
|
+
import { NamedExoticComponent } from 'react';
|
|
4
|
+
|
|
5
|
+
export declare const Banner: NamedExoticComponent<BannerProps>;
|
|
6
|
+
|
|
7
|
+
export declare type BannerMsg = {
|
|
8
|
+
type: 'on_accept_all' | 'on_reject_all' | 'on_open_preferences' | 'on_close_preferences';
|
|
9
|
+
} | {
|
|
10
|
+
type: 'on_apply_preferences';
|
|
11
|
+
preferences: Record<string, boolean>;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'on_change_preference';
|
|
14
|
+
sectionId: PreferencesSectionId;
|
|
15
|
+
checked: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export declare type BannerProps = Placement & {
|
|
19
|
+
isOpen?: boolean;
|
|
20
|
+
appearanceDelay?: number;
|
|
21
|
+
hasAcceptRejectEqualWeight?: boolean;
|
|
22
|
+
showCustomizePreferences?: boolean;
|
|
23
|
+
variant?: 'compact' | 'stacked';
|
|
24
|
+
locale?: string;
|
|
25
|
+
cookiePolicyUrl?: string;
|
|
26
|
+
bannerContent?: Partial<BannerMessages>;
|
|
27
|
+
preferencesSections?: readonly PreferencesSectionId[];
|
|
28
|
+
preferencesContent?: Readonly<Partial<Record<PreferencesSectionId, PreferencesSection>>>;
|
|
29
|
+
className?: string;
|
|
30
|
+
style?: React.CSSProperties;
|
|
31
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
32
|
+
onMsg?: (msg: BannerMsg) => void;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
declare type Placement = {
|
|
36
|
+
position?: 'right';
|
|
37
|
+
slideFrom?: 'bottom' | 'right';
|
|
38
|
+
} | {
|
|
39
|
+
position: 'left';
|
|
40
|
+
slideFrom?: 'bottom' | 'left';
|
|
41
|
+
} | {
|
|
42
|
+
position: 'center';
|
|
43
|
+
slideFrom?: 'bottom';
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export declare type PreferencesSection = Readonly<{
|
|
47
|
+
title?: string;
|
|
48
|
+
text?: string;
|
|
49
|
+
checked?: boolean;
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
}>;
|
|
52
|
+
|
|
53
|
+
export declare type PreferencesSectionId = BuiltInPreferencesSectionId | (string & Record<never, never>);
|
|
54
|
+
|
|
55
|
+
export { }
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,433 @@
|
|
|
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 { forwardRef as a, memo as o, useCallback as s, useEffect as c, useId as l, useMemo as u, useRef as d, useState as f } from "react";
|
|
4
|
+
import { AnimatePresence as p, LazyMotion as m, domAnimation as h, useIsPresent as g, useReducedMotion as _ } from "framer-motion";
|
|
5
|
+
import * as v from "framer-motion/m";
|
|
6
|
+
import { Fragment as y, jsx as b, jsxs as x } from "react/jsx-runtime";
|
|
7
|
+
import { ScrollArea as S } from "@base-ui/react/scroll-area";
|
|
8
|
+
import { Button as C } from "@base-ui/react/button";
|
|
9
|
+
import { Switch as w } from "@base-ui/react/switch";
|
|
10
|
+
//#region src/utils/notReachable.ts
|
|
11
|
+
function T(e, t = { throwError: !0 }) {
|
|
12
|
+
let n = `Should not be reached ${e}`;
|
|
13
|
+
if (t.throwError) throw Error(n);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/components/Container/ContainerWrapper.tsx
|
|
17
|
+
var E = ({ position: t, slideFrom: n, children: r }) => {
|
|
18
|
+
let i = g(), a = _(), o = d(null), s = d(null);
|
|
19
|
+
c(() => {
|
|
20
|
+
let e = o.current;
|
|
21
|
+
if (e) {
|
|
22
|
+
if (i) {
|
|
23
|
+
e.removeAttribute("inert");
|
|
24
|
+
let t = document.activeElement;
|
|
25
|
+
t instanceof HTMLElement && !e.contains(t) && (s.current = t);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (e.contains(document.activeElement)) {
|
|
29
|
+
let e = s.current;
|
|
30
|
+
e?.isConnected && e.focus({ preventScroll: !0 });
|
|
31
|
+
}
|
|
32
|
+
e.setAttribute("inert", "");
|
|
33
|
+
}
|
|
34
|
+
}, [i]);
|
|
35
|
+
let l = n === t ? n : "bottom", u = { transform: a ? "none" : l === "bottom" ? "translateY(100%)" : `translateX(${l === "left" ? "-100%" : "100%"})` };
|
|
36
|
+
return /* @__PURE__ */ b(v.div, {
|
|
37
|
+
ref: o,
|
|
38
|
+
exit: u,
|
|
39
|
+
initial: u,
|
|
40
|
+
animate: { transform: "none" },
|
|
41
|
+
"aria-hidden": !i || void 0,
|
|
42
|
+
"data-state": i ? "open" : "closing",
|
|
43
|
+
className: e("pxc-wrapper", `pxc-wrapper--${t}`),
|
|
44
|
+
transition: {
|
|
45
|
+
duration: a ? 0 : i ? .36 : .28,
|
|
46
|
+
ease: i ? [
|
|
47
|
+
.16,
|
|
48
|
+
1,
|
|
49
|
+
.3,
|
|
50
|
+
1
|
|
51
|
+
] : [
|
|
52
|
+
.4,
|
|
53
|
+
0,
|
|
54
|
+
.2,
|
|
55
|
+
1
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
children: r
|
|
59
|
+
});
|
|
60
|
+
}, D = a(function({ isOpen: t = !0, appearanceDelay: n = 0, position: r = "right", slideFrom: i = "bottom", className: a, children: o, actions: s, ...l }, u) {
|
|
61
|
+
let d = Number.isFinite(n) ? Math.max(0, n) : 0, [g, _] = f(d === 0);
|
|
62
|
+
return c(() => {
|
|
63
|
+
if (g || !t) return;
|
|
64
|
+
let e = window.setTimeout(() => _(!0), d);
|
|
65
|
+
return () => window.clearTimeout(e);
|
|
66
|
+
}, [
|
|
67
|
+
d,
|
|
68
|
+
t,
|
|
69
|
+
g
|
|
70
|
+
]), /* @__PURE__ */ b(m, {
|
|
71
|
+
features: h,
|
|
72
|
+
strict: !0,
|
|
73
|
+
children: /* @__PURE__ */ b(p, { children: t && g && /* @__PURE__ */ b(E, {
|
|
74
|
+
position: r,
|
|
75
|
+
slideFrom: i,
|
|
76
|
+
children: /* @__PURE__ */ b("div", {
|
|
77
|
+
ref: u,
|
|
78
|
+
className: e("pxc-container", s != null && "pxc-container--with-actions", a),
|
|
79
|
+
...l,
|
|
80
|
+
children: s == null ? o : /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ b("div", {
|
|
81
|
+
className: "pxc-container__content",
|
|
82
|
+
"data-container-content": !0,
|
|
83
|
+
children: o
|
|
84
|
+
}), /* @__PURE__ */ b("div", {
|
|
85
|
+
className: "pxc-container__actions",
|
|
86
|
+
"data-container-actions": !0,
|
|
87
|
+
children: s
|
|
88
|
+
})] })
|
|
89
|
+
})
|
|
90
|
+
}, "container") })
|
|
91
|
+
});
|
|
92
|
+
}), O = () => /* @__PURE__ */ x("svg", {
|
|
93
|
+
width: "24",
|
|
94
|
+
height: "24",
|
|
95
|
+
viewBox: "0 0 24 24",
|
|
96
|
+
fill: "none",
|
|
97
|
+
stroke: "currentColor",
|
|
98
|
+
strokeWidth: "2",
|
|
99
|
+
strokeLinecap: "round",
|
|
100
|
+
strokeLinejoin: "round",
|
|
101
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
102
|
+
"aria-hidden": "true",
|
|
103
|
+
focusable: "false",
|
|
104
|
+
children: [
|
|
105
|
+
/* @__PURE__ */ b("path", { d: "M11 17H11.01" }),
|
|
106
|
+
/* @__PURE__ */ b("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" }),
|
|
107
|
+
/* @__PURE__ */ b("path", { d: "M12 12H12.01" }),
|
|
108
|
+
/* @__PURE__ */ b("path", { d: "M16 16H16.01" }),
|
|
109
|
+
/* @__PURE__ */ b("path", { d: "M7 14H7.01" }),
|
|
110
|
+
/* @__PURE__ */ b("path", { d: "M9 8H9.01" })
|
|
111
|
+
]
|
|
112
|
+
}), k = () => /* @__PURE__ */ x("svg", {
|
|
113
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
114
|
+
width: "24",
|
|
115
|
+
height: "24",
|
|
116
|
+
viewBox: "0 0 24 24",
|
|
117
|
+
fill: "none",
|
|
118
|
+
stroke: "currentColor",
|
|
119
|
+
strokeWidth: "2",
|
|
120
|
+
strokeLinecap: "round",
|
|
121
|
+
strokeLinejoin: "round",
|
|
122
|
+
"aria-hidden": "true",
|
|
123
|
+
focusable: "false",
|
|
124
|
+
children: [
|
|
125
|
+
/* @__PURE__ */ b("path", { d: "M14 17H5" }),
|
|
126
|
+
/* @__PURE__ */ b("path", { d: "M19 7h-9" }),
|
|
127
|
+
/* @__PURE__ */ b("circle", {
|
|
128
|
+
cx: "17",
|
|
129
|
+
cy: "17",
|
|
130
|
+
r: "3"
|
|
131
|
+
}),
|
|
132
|
+
/* @__PURE__ */ b("circle", {
|
|
133
|
+
cx: "7",
|
|
134
|
+
cy: "7",
|
|
135
|
+
r: "3"
|
|
136
|
+
})
|
|
137
|
+
]
|
|
138
|
+
}), A = () => /* @__PURE__ */ b("div", {
|
|
139
|
+
className: "pxc-lead-icon",
|
|
140
|
+
children: /* @__PURE__ */ b(O, {})
|
|
141
|
+
}), j = () => /* @__PURE__ */ b("svg", {
|
|
142
|
+
viewBox: "0 0 24 24",
|
|
143
|
+
fill: "none",
|
|
144
|
+
stroke: "currentColor",
|
|
145
|
+
strokeWidth: "2",
|
|
146
|
+
strokeLinecap: "round",
|
|
147
|
+
"aria-hidden": "true",
|
|
148
|
+
focusable: "false",
|
|
149
|
+
children: /* @__PURE__ */ b("path", { d: "m6 6 12 12M6 18 18 6" })
|
|
150
|
+
}), M = a(function({ variant: t, className: n, children: r, ...i }, a) {
|
|
151
|
+
return /* @__PURE__ */ b(C, {
|
|
152
|
+
ref: a,
|
|
153
|
+
className: (r) => e("pxc-button", `pxc-button--${t}`, typeof n == "function" ? n(r) : n),
|
|
154
|
+
...i,
|
|
155
|
+
focusableWhenDisabled: !1,
|
|
156
|
+
children: r
|
|
157
|
+
});
|
|
158
|
+
}), N = (e) => {
|
|
159
|
+
if (e?.trim()) try {
|
|
160
|
+
let t = new URL(e, "https://consent.invalid");
|
|
161
|
+
return t.protocol === "http:" || t.protocol === "https:" ? e : void 0;
|
|
162
|
+
} catch {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
}, P = ({ message: e, links: t }) => u(() => r(e, Object.keys(t)), [e, t]).map((e) => {
|
|
166
|
+
if (e.type === "text") return e.value;
|
|
167
|
+
let n = N(t[e.name]);
|
|
168
|
+
return n && e.value.trim() ? /* @__PURE__ */ b("a", {
|
|
169
|
+
className: "pxc-link",
|
|
170
|
+
href: n,
|
|
171
|
+
children: e.value
|
|
172
|
+
}, e.offset) : e.value;
|
|
173
|
+
}), F = ({ section: e, checked: t, links: n, onMsg: r }) => {
|
|
174
|
+
let i = l();
|
|
175
|
+
return /* @__PURE__ */ x("section", {
|
|
176
|
+
className: "pxc-preferences__section",
|
|
177
|
+
"aria-labelledby": `${i}-title`,
|
|
178
|
+
children: [/* @__PURE__ */ x("div", {
|
|
179
|
+
className: "pxc-preferences__section-heading",
|
|
180
|
+
children: [/* @__PURE__ */ b("h4", {
|
|
181
|
+
id: `${i}-title`,
|
|
182
|
+
className: "pxc-text--h4",
|
|
183
|
+
children: e.title
|
|
184
|
+
}), /* @__PURE__ */ b(w.Root, {
|
|
185
|
+
className: "pxc-switch",
|
|
186
|
+
checked: t,
|
|
187
|
+
disabled: e.disabled ?? !1,
|
|
188
|
+
"aria-labelledby": `${i}-title`,
|
|
189
|
+
"aria-describedby": e.text ? `${i}-text` : void 0,
|
|
190
|
+
onCheckedChange: (t) => r({
|
|
191
|
+
type: "on_change_preference",
|
|
192
|
+
sectionId: e.id,
|
|
193
|
+
checked: t
|
|
194
|
+
}),
|
|
195
|
+
children: /* @__PURE__ */ b(w.Thumb, { className: "pxc-switch__thumb" })
|
|
196
|
+
})]
|
|
197
|
+
}), e.text && /* @__PURE__ */ b("p", {
|
|
198
|
+
id: `${i}-text`,
|
|
199
|
+
className: "pxc-text--paragraph pxc-preferences__description",
|
|
200
|
+
children: /* @__PURE__ */ b(P, {
|
|
201
|
+
message: e.text,
|
|
202
|
+
links: n
|
|
203
|
+
})
|
|
204
|
+
})]
|
|
205
|
+
});
|
|
206
|
+
}, I = ({ sections: e, content: t, links: n, onMsg: r }) => {
|
|
207
|
+
let i = l(), a = d(null), [o, s] = f(() => new Map(e.map((e) => [e.id, e.checked]))), u = new Map(e.map((e) => [e.id, e.disabled ? e.checked : o.get(e.id) ?? e.checked]));
|
|
208
|
+
(o.size !== u.size || [...u].some(([e, t]) => o.get(e) !== t)) && s(u), c(() => {
|
|
209
|
+
a.current?.focus({ preventScroll: !0 });
|
|
210
|
+
}, []);
|
|
211
|
+
let p = N(n.cookiePolicy);
|
|
212
|
+
return /* @__PURE__ */ x("section", {
|
|
213
|
+
className: "pxc-preferences",
|
|
214
|
+
"aria-labelledby": i,
|
|
215
|
+
onKeyDown: (e) => {
|
|
216
|
+
e.key === "Escape" && (e.preventDefault(), e.stopPropagation(), r({ type: "on_close_preferences" }));
|
|
217
|
+
},
|
|
218
|
+
children: [
|
|
219
|
+
/* @__PURE__ */ x("header", {
|
|
220
|
+
className: "pxc-preferences__header",
|
|
221
|
+
children: [/* @__PURE__ */ b("h3", {
|
|
222
|
+
id: i,
|
|
223
|
+
ref: a,
|
|
224
|
+
tabIndex: -1,
|
|
225
|
+
className: "pxc-text--h3",
|
|
226
|
+
children: t.preferencesTitle
|
|
227
|
+
}), /* @__PURE__ */ b(M, {
|
|
228
|
+
variant: "iconed",
|
|
229
|
+
"aria-label": t.closePreferencesLabel,
|
|
230
|
+
onClick: () => r({ type: "on_close_preferences" }),
|
|
231
|
+
children: /* @__PURE__ */ b(j, {})
|
|
232
|
+
})]
|
|
233
|
+
}),
|
|
234
|
+
/* @__PURE__ */ x(S.Root, {
|
|
235
|
+
className: "pxc-preferences__scroll-area",
|
|
236
|
+
children: [/* @__PURE__ */ b(S.Viewport, {
|
|
237
|
+
className: "pxc-preferences__body",
|
|
238
|
+
role: "group",
|
|
239
|
+
"aria-labelledby": i,
|
|
240
|
+
children: /* @__PURE__ */ x(S.Content, {
|
|
241
|
+
className: "pxc-preferences__content",
|
|
242
|
+
children: [t.preferencesText && /* @__PURE__ */ b("p", {
|
|
243
|
+
className: "pxc-text--paragraph pxc-preferences__introduction",
|
|
244
|
+
children: /* @__PURE__ */ b(P, {
|
|
245
|
+
message: t.preferencesText,
|
|
246
|
+
links: n
|
|
247
|
+
})
|
|
248
|
+
}), e.map((e) => /* @__PURE__ */ b(F, {
|
|
249
|
+
section: e,
|
|
250
|
+
checked: u.get(e.id) ?? e.checked,
|
|
251
|
+
links: n,
|
|
252
|
+
onMsg: (e) => {
|
|
253
|
+
switch (e.type) {
|
|
254
|
+
case "on_change_preference":
|
|
255
|
+
s((t) => new Map(t).set(e.sectionId, e.checked)), r(e);
|
|
256
|
+
break;
|
|
257
|
+
default: T(e.type);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}, e.id))]
|
|
261
|
+
})
|
|
262
|
+
}), /* @__PURE__ */ b(S.Scrollbar, {
|
|
263
|
+
className: "pxc-preferences__scrollbar",
|
|
264
|
+
children: /* @__PURE__ */ b(S.Thumb, {
|
|
265
|
+
className: "pxc-preferences__scroll-thumb",
|
|
266
|
+
children: /* @__PURE__ */ b("span", { className: "pxc-preferences__scroll-indicator" })
|
|
267
|
+
})
|
|
268
|
+
})]
|
|
269
|
+
}),
|
|
270
|
+
/* @__PURE__ */ x("footer", {
|
|
271
|
+
className: "pxc-preferences__footer",
|
|
272
|
+
children: [/* @__PURE__ */ b(M, {
|
|
273
|
+
variant: "primary",
|
|
274
|
+
onClick: () => r({
|
|
275
|
+
type: "on_apply_preferences",
|
|
276
|
+
preferences: Object.fromEntries(u)
|
|
277
|
+
}),
|
|
278
|
+
children: t.applyPreferencesLabel
|
|
279
|
+
}), p ? /* @__PURE__ */ b("a", {
|
|
280
|
+
className: "pxc-link pxc-preferences__policy",
|
|
281
|
+
href: p,
|
|
282
|
+
children: t.cookiePolicyLabel
|
|
283
|
+
}) : /* @__PURE__ */ b("span", {
|
|
284
|
+
className: "pxc-preferences__policy",
|
|
285
|
+
children: t.cookiePolicyLabel
|
|
286
|
+
})]
|
|
287
|
+
})
|
|
288
|
+
]
|
|
289
|
+
});
|
|
290
|
+
}, L = [
|
|
291
|
+
"essential",
|
|
292
|
+
"analytics",
|
|
293
|
+
"marketing"
|
|
294
|
+
];
|
|
295
|
+
function R(e, t, n) {
|
|
296
|
+
let r = new Map(Object.entries(n));
|
|
297
|
+
return [...new Set(e.filter((e) => e.trim()))].map((e) => {
|
|
298
|
+
let n = r.get(e), i = t && Object.hasOwn(t, e) ? t[e] : void 0;
|
|
299
|
+
return {
|
|
300
|
+
id: e,
|
|
301
|
+
title: i?.title?.trim() ? i.title : n?.title ?? e,
|
|
302
|
+
text: i?.text ?? n?.text ?? "",
|
|
303
|
+
checked: i?.checked ?? e === "essential",
|
|
304
|
+
disabled: i?.disabled ?? e === "essential"
|
|
305
|
+
};
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
//#endregion
|
|
309
|
+
//#region src/components/Text/Text.tsx
|
|
310
|
+
var z = ({ variant: e, tag: t, children: n }) => {
|
|
311
|
+
switch (e) {
|
|
312
|
+
case "label": return /* @__PURE__ */ b(t, {
|
|
313
|
+
className: "pxc-text--label",
|
|
314
|
+
children: n
|
|
315
|
+
});
|
|
316
|
+
case "heading": return /* @__PURE__ */ b(t, {
|
|
317
|
+
className: `pxc-text--${t}`,
|
|
318
|
+
children: n
|
|
319
|
+
});
|
|
320
|
+
case "paragraph": return /* @__PURE__ */ b("p", {
|
|
321
|
+
className: "pxc-text--paragraph",
|
|
322
|
+
children: n
|
|
323
|
+
});
|
|
324
|
+
default: return T(e);
|
|
325
|
+
}
|
|
326
|
+
}, B = ({ variant: e, content: t, equalWeight: n, showCustomizePreferences: r, preferencesRef: i, onMsg: a }) => /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ x("div", {
|
|
327
|
+
className: "pxc-banner__choices",
|
|
328
|
+
children: [/* @__PURE__ */ b(M, {
|
|
329
|
+
variant: n ? "secondary" : "primary",
|
|
330
|
+
onClick: () => a({ type: "on_accept_all" }),
|
|
331
|
+
children: t.acceptAllLabel
|
|
332
|
+
}), /* @__PURE__ */ b(M, {
|
|
333
|
+
variant: "secondary",
|
|
334
|
+
onClick: () => a({ type: "on_reject_all" }),
|
|
335
|
+
children: t.rejectAllLabel
|
|
336
|
+
})]
|
|
337
|
+
}), r && /* @__PURE__ */ b("div", {
|
|
338
|
+
className: "pxc-banner__preferences",
|
|
339
|
+
children: /* @__PURE__ */ b(M, {
|
|
340
|
+
ref: i,
|
|
341
|
+
variant: "inline",
|
|
342
|
+
className: e === "compact" ? "pxc-button--iconed" : void 0,
|
|
343
|
+
"aria-label": t.customizePreferencesLabel,
|
|
344
|
+
onClick: () => a({ type: "on_open_preferences" }),
|
|
345
|
+
children: e === "compact" ? /* @__PURE__ */ x(y, { children: [/* @__PURE__ */ b(k, {}), /* @__PURE__ */ b("span", { children: t.customizePreferencesLabel })] }) : t.customizePreferencesLabel
|
|
346
|
+
})
|
|
347
|
+
})] }), V = o(function({ bannerContent: r, cookiePolicyUrl: a, isOpen: o = !1, appearanceDelay: l = 0, preferencesSections: p = L, preferencesContent: m, hasAcceptRejectEqualWeight: h = !1, showCustomizePreferences: g = !0, variant: _ = "compact", theme: v = "auto", locale: S = "en", onMsg: C, className: w, style: E, ...O }) {
|
|
348
|
+
let k = i(S), j = t(k), M = Object.fromEntries(Object.entries(r ?? {}).filter(([, e]) => e != null)), N = {
|
|
349
|
+
...j,
|
|
350
|
+
...M
|
|
351
|
+
}, F = u(() => ({ cookiePolicy: a }), [a]), V = u(() => R(p, m, n(k)), [
|
|
352
|
+
p,
|
|
353
|
+
m,
|
|
354
|
+
k
|
|
355
|
+
]), [H, U] = f(!1), W = d(!1), G = s((e) => {
|
|
356
|
+
e && W.current && (W.current = !1, e.focus());
|
|
357
|
+
}, []);
|
|
358
|
+
c(() => {
|
|
359
|
+
o || (W.current = !1, U(!1));
|
|
360
|
+
}, [o]);
|
|
361
|
+
let K = () => {
|
|
362
|
+
U(!0), C?.({ type: "on_open_preferences" });
|
|
363
|
+
}, q = () => {
|
|
364
|
+
W.current = g, U(!1), C?.({ type: "on_close_preferences" });
|
|
365
|
+
};
|
|
366
|
+
return /* @__PURE__ */ b("div", {
|
|
367
|
+
"data-theme": v,
|
|
368
|
+
"data-banner-variant": _,
|
|
369
|
+
className: e("pxc", w),
|
|
370
|
+
style: {
|
|
371
|
+
fontFamily: "var(--pxc-font-family)",
|
|
372
|
+
...E
|
|
373
|
+
},
|
|
374
|
+
lang: k,
|
|
375
|
+
children: /* @__PURE__ */ b(D, {
|
|
376
|
+
...O,
|
|
377
|
+
isOpen: !!o,
|
|
378
|
+
appearanceDelay: l,
|
|
379
|
+
className: H ? "pxc-container--preferences" : void 0,
|
|
380
|
+
actions: H ? null : /* @__PURE__ */ b(B, {
|
|
381
|
+
variant: _,
|
|
382
|
+
content: N,
|
|
383
|
+
equalWeight: h,
|
|
384
|
+
showCustomizePreferences: g,
|
|
385
|
+
preferencesRef: G,
|
|
386
|
+
onMsg: (e) => {
|
|
387
|
+
switch (e.type) {
|
|
388
|
+
case "on_open_preferences":
|
|
389
|
+
K();
|
|
390
|
+
break;
|
|
391
|
+
case "on_accept_all":
|
|
392
|
+
case "on_reject_all":
|
|
393
|
+
C?.(e);
|
|
394
|
+
break;
|
|
395
|
+
default: T(e.type);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}),
|
|
399
|
+
children: H ? /* @__PURE__ */ b(I, {
|
|
400
|
+
links: F,
|
|
401
|
+
content: N,
|
|
402
|
+
sections: V,
|
|
403
|
+
onMsg: (e) => {
|
|
404
|
+
switch (e.type) {
|
|
405
|
+
case "on_close_preferences":
|
|
406
|
+
q();
|
|
407
|
+
break;
|
|
408
|
+
case "on_apply_preferences":
|
|
409
|
+
case "on_change_preference":
|
|
410
|
+
C?.(e);
|
|
411
|
+
break;
|
|
412
|
+
default: T(e);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}) : /* @__PURE__ */ x(y, { children: [_ === "stacked" ? /* @__PURE__ */ x("div", {
|
|
416
|
+
className: "pxc-banner__heading",
|
|
417
|
+
children: [/* @__PURE__ */ b(A, {}), /* @__PURE__ */ b(z, {
|
|
418
|
+
variant: "heading",
|
|
419
|
+
tag: "h3",
|
|
420
|
+
children: N.title
|
|
421
|
+
})]
|
|
422
|
+
}) : /* @__PURE__ */ b(A, {}), /* @__PURE__ */ b(z, {
|
|
423
|
+
variant: "paragraph",
|
|
424
|
+
children: /* @__PURE__ */ b(P, {
|
|
425
|
+
message: N.collapsedText,
|
|
426
|
+
links: F
|
|
427
|
+
})
|
|
428
|
+
})] })
|
|
429
|
+
})
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
//#endregion
|
|
433
|
+
export { V as Banner };
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@peax/consent-banner-react",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Accessible React bindings and components for Peax Consent.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"consent-management",
|
|
7
|
+
"cookie-consent",
|
|
8
|
+
"privacy",
|
|
9
|
+
"gdpr",
|
|
10
|
+
"react",
|
|
11
|
+
"accessibility",
|
|
12
|
+
"components"
|
|
13
|
+
],
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"homepage": "https://github.com/peaxco/consent",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/peaxco/consent.git",
|
|
19
|
+
"directory": "packages/consent-banner-react"
|
|
20
|
+
},
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/peaxco/consent/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"main": "./dist/index.js",
|
|
30
|
+
"module": "./dist/index.js",
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"exports": {
|
|
33
|
+
".": {
|
|
34
|
+
"types": "./dist/index.d.ts",
|
|
35
|
+
"import": "./dist/index.js",
|
|
36
|
+
"default": "./dist/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public",
|
|
41
|
+
"provenance": true,
|
|
42
|
+
"registry": "https://registry.npmjs.org"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "vite build",
|
|
46
|
+
"dev": "vite src/demo --config vite.config.ts",
|
|
47
|
+
"test": "vitest run",
|
|
48
|
+
"test:browser": "vitest run --config vitest.browser.config.ts",
|
|
49
|
+
"typecheck": "tsc --noEmit"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
53
|
+
"react-dom": "^18.2.0 || ^19.0.0"
|
|
54
|
+
},
|
|
55
|
+
"dependencies": {
|
|
56
|
+
"@base-ui/react": "^1.7.0",
|
|
57
|
+
"@peax/consent-banner-locales": "^0.1.0",
|
|
58
|
+
"@peax/consent-banner-theme": "^0.1.0",
|
|
59
|
+
"clsx": "^2.1.1",
|
|
60
|
+
"framer-motion": "^13.1.1"
|
|
61
|
+
},
|
|
62
|
+
"devDependencies": {
|
|
63
|
+
"@axe-core/playwright": "^4.13.0",
|
|
64
|
+
"@fontsource/figtree": "^5.3.0",
|
|
65
|
+
"@fontsource/poppins": "^5.3.0",
|
|
66
|
+
"@testing-library/dom": "^10.4.1",
|
|
67
|
+
"@testing-library/jest-dom": "^7.0.1",
|
|
68
|
+
"@testing-library/react": "^16.3.2",
|
|
69
|
+
"@testing-library/user-event": "^14.6.6",
|
|
70
|
+
"@types/jest-image-snapshot": "^6.4.1",
|
|
71
|
+
"@types/node": "^26.3.0",
|
|
72
|
+
"@types/react": "^19.2.18",
|
|
73
|
+
"@types/react-dom": "^19.2.5",
|
|
74
|
+
"@unocss/reset": "^66.8.1",
|
|
75
|
+
"@vitejs/plugin-react": "^6.1.0",
|
|
76
|
+
"jest-image-snapshot": "^6.5.2",
|
|
77
|
+
"jsdom": "30.0.1",
|
|
78
|
+
"playwright": "^1.62.1",
|
|
79
|
+
"playwright-core": "1.62.1",
|
|
80
|
+
"react": "^19.2.8",
|
|
81
|
+
"react-dom": "^19.2.8",
|
|
82
|
+
"typescript": "5.9.3",
|
|
83
|
+
"vite": "^8.2.2",
|
|
84
|
+
"vite-plugin-dts": "^5.0.3",
|
|
85
|
+
"vitest": "^4.1.11"
|
|
86
|
+
}
|
|
87
|
+
}
|