react-lgpd-consent 0.1.6 → 0.1.8
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 +1 -9
- package/dist/{PreferencesModal-LWZAP5OT.js → PreferencesModal-4FDYT7VE.js} +1 -1
- package/dist/{chunk-K3EVSUMQ.js → chunk-Y4XEAQXV.js} +41 -8
- package/dist/index.cjs +42 -9
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
# react-lgpd-consent 🍪
|
|
2
2
|
|
|
3
|
-
[](https://www.
|
|
4
|
-
if (consented && preferences.analytics) {
|
|
5
|
-
loadScript(
|
|
6
|
-
'ga',
|
|
7
|
-
'https://www.googletagmanager.com/gtag/js?id=GA_ID',
|
|
8
|
-
'analytics' // Aguarda consentimento finalizado
|
|
9
|
-
)
|
|
10
|
-
}
|
|
11
|
-
}, [preferences, consented])package/react-lgpd-consent)
|
|
3
|
+
[](https://www.npmjs.com/package/react-lgpd-consent)
|
|
12
4
|
[](https://github.com/lucianoedipo/react-lgpd-consent/blob/main/LICENSE)
|
|
13
5
|
[](https://www.typescriptlang.org/)
|
|
14
6
|
[](https://reactjs.org/)
|
|
@@ -8,6 +8,7 @@ import FormControlLabel from "@mui/material/FormControlLabel";
|
|
|
8
8
|
import FormGroup from "@mui/material/FormGroup";
|
|
9
9
|
import Switch from "@mui/material/Switch";
|
|
10
10
|
import Typography from "@mui/material/Typography";
|
|
11
|
+
import { useState, useEffect as useEffect2 } from "react";
|
|
11
12
|
|
|
12
13
|
// src/context/ConsentContext.tsx
|
|
13
14
|
import * as React from "react";
|
|
@@ -122,7 +123,7 @@ var defaultConsentTheme = createTheme({
|
|
|
122
123
|
// src/context/ConsentContext.tsx
|
|
123
124
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
124
125
|
var PreferencesModal = React.lazy(
|
|
125
|
-
() => import("./PreferencesModal-
|
|
126
|
+
() => import("./PreferencesModal-4FDYT7VE.js").then((m) => ({
|
|
126
127
|
default: m.PreferencesModal
|
|
127
128
|
}))
|
|
128
129
|
);
|
|
@@ -163,6 +164,13 @@ function reducer(state, action) {
|
|
|
163
164
|
[action.category]: action.value
|
|
164
165
|
}
|
|
165
166
|
};
|
|
167
|
+
case "SET_PREFERENCES":
|
|
168
|
+
return {
|
|
169
|
+
...state,
|
|
170
|
+
consented: true,
|
|
171
|
+
preferences: action.preferences,
|
|
172
|
+
isModalOpen: false
|
|
173
|
+
};
|
|
166
174
|
case "OPEN_MODAL":
|
|
167
175
|
return { ...state, isModalOpen: true };
|
|
168
176
|
case "CLOSE_MODAL":
|
|
@@ -238,6 +246,7 @@ function ConsentProvider({
|
|
|
238
246
|
const acceptAll = () => dispatch({ type: "ACCEPT_ALL" });
|
|
239
247
|
const rejectAll = () => dispatch({ type: "REJECT_ALL" });
|
|
240
248
|
const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
|
|
249
|
+
const setPreferences = (preferences) => dispatch({ type: "SET_PREFERENCES", preferences });
|
|
241
250
|
const openPreferences = () => dispatch({ type: "OPEN_MODAL" });
|
|
242
251
|
const closePreferences = () => dispatch({ type: "CLOSE_MODAL" });
|
|
243
252
|
const resetConsent = () => {
|
|
@@ -251,6 +260,7 @@ function ConsentProvider({
|
|
|
251
260
|
acceptAll,
|
|
252
261
|
rejectAll,
|
|
253
262
|
setPreference,
|
|
263
|
+
setPreferences,
|
|
254
264
|
openPreferences,
|
|
255
265
|
closePreferences,
|
|
256
266
|
resetConsent
|
|
@@ -289,6 +299,7 @@ function useConsent() {
|
|
|
289
299
|
acceptAll: actions.acceptAll,
|
|
290
300
|
rejectAll: actions.rejectAll,
|
|
291
301
|
setPreference: actions.setPreference,
|
|
302
|
+
setPreferences: actions.setPreferences,
|
|
292
303
|
openPreferences: actions.openPreferences,
|
|
293
304
|
closePreferences: actions.closePreferences,
|
|
294
305
|
resetConsent: actions.resetConsent
|
|
@@ -303,15 +314,28 @@ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
|
303
314
|
function PreferencesModal2({
|
|
304
315
|
DialogProps: DialogProps2
|
|
305
316
|
}) {
|
|
306
|
-
const { preferences,
|
|
317
|
+
const { preferences, setPreferences, closePreferences, isModalOpen } = useConsent();
|
|
307
318
|
const texts = useConsentTexts();
|
|
319
|
+
const [tempPreferences, setTempPreferences] = useState(preferences);
|
|
320
|
+
useEffect2(() => {
|
|
321
|
+
if (isModalOpen) {
|
|
322
|
+
setTempPreferences(preferences);
|
|
323
|
+
}
|
|
324
|
+
}, [isModalOpen, preferences]);
|
|
308
325
|
const open = DialogProps2?.open ?? isModalOpen ?? false;
|
|
326
|
+
const handleSave = () => {
|
|
327
|
+
setPreferences(tempPreferences);
|
|
328
|
+
};
|
|
329
|
+
const handleCancel = () => {
|
|
330
|
+
setTempPreferences(preferences);
|
|
331
|
+
closePreferences();
|
|
332
|
+
};
|
|
309
333
|
return /* @__PURE__ */ jsxs2(
|
|
310
334
|
Dialog,
|
|
311
335
|
{
|
|
312
336
|
"aria-labelledby": "cookie-pref-title",
|
|
313
337
|
open,
|
|
314
|
-
onClose:
|
|
338
|
+
onClose: handleCancel,
|
|
315
339
|
...DialogProps2,
|
|
316
340
|
children: [
|
|
317
341
|
/* @__PURE__ */ jsx2(DialogTitle, { id: "cookie-pref-title", children: texts.modalTitle }),
|
|
@@ -324,8 +348,11 @@ function PreferencesModal2({
|
|
|
324
348
|
control: /* @__PURE__ */ jsx2(
|
|
325
349
|
Switch,
|
|
326
350
|
{
|
|
327
|
-
checked:
|
|
328
|
-
onChange: (e) =>
|
|
351
|
+
checked: tempPreferences.analytics,
|
|
352
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
353
|
+
...prev,
|
|
354
|
+
analytics: e.target.checked
|
|
355
|
+
}))
|
|
329
356
|
}
|
|
330
357
|
),
|
|
331
358
|
label: "Cookies Anal\xEDticos (medem uso do site)"
|
|
@@ -337,8 +364,11 @@ function PreferencesModal2({
|
|
|
337
364
|
control: /* @__PURE__ */ jsx2(
|
|
338
365
|
Switch,
|
|
339
366
|
{
|
|
340
|
-
checked:
|
|
341
|
-
onChange: (e) =>
|
|
367
|
+
checked: tempPreferences.marketing,
|
|
368
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
369
|
+
...prev,
|
|
370
|
+
marketing: e.target.checked
|
|
371
|
+
}))
|
|
342
372
|
}
|
|
343
373
|
),
|
|
344
374
|
label: "Cookies de Marketing/Publicidade"
|
|
@@ -353,7 +383,10 @@ function PreferencesModal2({
|
|
|
353
383
|
)
|
|
354
384
|
] })
|
|
355
385
|
] }),
|
|
356
|
-
/* @__PURE__ */
|
|
386
|
+
/* @__PURE__ */ jsxs2(DialogActions, { children: [
|
|
387
|
+
/* @__PURE__ */ jsx2(Button, { variant: "outlined", onClick: handleCancel, children: "Cancelar" }),
|
|
388
|
+
/* @__PURE__ */ jsx2(Button, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
389
|
+
] })
|
|
357
390
|
]
|
|
358
391
|
}
|
|
359
392
|
);
|
package/dist/index.cjs
CHANGED
|
@@ -156,15 +156,28 @@ __export(PreferencesModal_exports, {
|
|
|
156
156
|
function PreferencesModal({
|
|
157
157
|
DialogProps: DialogProps2
|
|
158
158
|
}) {
|
|
159
|
-
const { preferences,
|
|
159
|
+
const { preferences, setPreferences, closePreferences, isModalOpen } = useConsent();
|
|
160
160
|
const texts = useConsentTexts();
|
|
161
|
+
const [tempPreferences, setTempPreferences] = (0, import_react.useState)(preferences);
|
|
162
|
+
(0, import_react.useEffect)(() => {
|
|
163
|
+
if (isModalOpen) {
|
|
164
|
+
setTempPreferences(preferences);
|
|
165
|
+
}
|
|
166
|
+
}, [isModalOpen, preferences]);
|
|
161
167
|
const open = DialogProps2?.open ?? isModalOpen ?? false;
|
|
168
|
+
const handleSave = () => {
|
|
169
|
+
setPreferences(tempPreferences);
|
|
170
|
+
};
|
|
171
|
+
const handleCancel = () => {
|
|
172
|
+
setTempPreferences(preferences);
|
|
173
|
+
closePreferences();
|
|
174
|
+
};
|
|
162
175
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
163
176
|
import_Dialog.default,
|
|
164
177
|
{
|
|
165
178
|
"aria-labelledby": "cookie-pref-title",
|
|
166
179
|
open,
|
|
167
|
-
onClose:
|
|
180
|
+
onClose: handleCancel,
|
|
168
181
|
...DialogProps2,
|
|
169
182
|
children: [
|
|
170
183
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_DialogTitle.default, { id: "cookie-pref-title", children: texts.modalTitle }),
|
|
@@ -177,8 +190,11 @@ function PreferencesModal({
|
|
|
177
190
|
control: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
178
191
|
import_Switch.default,
|
|
179
192
|
{
|
|
180
|
-
checked:
|
|
181
|
-
onChange: (e) =>
|
|
193
|
+
checked: tempPreferences.analytics,
|
|
194
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
195
|
+
...prev,
|
|
196
|
+
analytics: e.target.checked
|
|
197
|
+
}))
|
|
182
198
|
}
|
|
183
199
|
),
|
|
184
200
|
label: "Cookies Anal\xEDticos (medem uso do site)"
|
|
@@ -190,8 +206,11 @@ function PreferencesModal({
|
|
|
190
206
|
control: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
191
207
|
import_Switch.default,
|
|
192
208
|
{
|
|
193
|
-
checked:
|
|
194
|
-
onChange: (e) =>
|
|
209
|
+
checked: tempPreferences.marketing,
|
|
210
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
211
|
+
...prev,
|
|
212
|
+
marketing: e.target.checked
|
|
213
|
+
}))
|
|
195
214
|
}
|
|
196
215
|
),
|
|
197
216
|
label: "Cookies de Marketing/Publicidade"
|
|
@@ -206,12 +225,15 @@ function PreferencesModal({
|
|
|
206
225
|
)
|
|
207
226
|
] })
|
|
208
227
|
] }),
|
|
209
|
-
/* @__PURE__ */ (0, import_jsx_runtime.
|
|
228
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_DialogActions.default, { children: [
|
|
229
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.default, { variant: "outlined", onClick: handleCancel, children: "Cancelar" }),
|
|
230
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Button.default, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
231
|
+
] })
|
|
210
232
|
]
|
|
211
233
|
}
|
|
212
234
|
);
|
|
213
235
|
}
|
|
214
|
-
var import_Button, import_Dialog, import_DialogActions, import_DialogContent, import_DialogTitle, import_FormControlLabel, import_FormGroup, import_Switch, import_Typography, import_jsx_runtime;
|
|
236
|
+
var import_Button, import_Dialog, import_DialogActions, import_DialogContent, import_DialogTitle, import_FormControlLabel, import_FormGroup, import_Switch, import_Typography, import_react, import_jsx_runtime;
|
|
215
237
|
var init_PreferencesModal = __esm({
|
|
216
238
|
"src/components/PreferencesModal.tsx"() {
|
|
217
239
|
"use strict";
|
|
@@ -224,6 +246,7 @@ var init_PreferencesModal = __esm({
|
|
|
224
246
|
import_FormGroup = __toESM(require("@mui/material/FormGroup"), 1);
|
|
225
247
|
import_Switch = __toESM(require("@mui/material/Switch"), 1);
|
|
226
248
|
import_Typography = __toESM(require("@mui/material/Typography"), 1);
|
|
249
|
+
import_react = require("react");
|
|
227
250
|
init_useConsent();
|
|
228
251
|
import_jsx_runtime = require("react/jsx-runtime");
|
|
229
252
|
}
|
|
@@ -252,6 +275,13 @@ function reducer(state, action) {
|
|
|
252
275
|
[action.category]: action.value
|
|
253
276
|
}
|
|
254
277
|
};
|
|
278
|
+
case "SET_PREFERENCES":
|
|
279
|
+
return {
|
|
280
|
+
...state,
|
|
281
|
+
consented: true,
|
|
282
|
+
preferences: action.preferences,
|
|
283
|
+
isModalOpen: false
|
|
284
|
+
};
|
|
255
285
|
case "OPEN_MODAL":
|
|
256
286
|
return { ...state, isModalOpen: true };
|
|
257
287
|
case "CLOSE_MODAL":
|
|
@@ -324,6 +354,7 @@ function ConsentProvider({
|
|
|
324
354
|
const acceptAll = () => dispatch({ type: "ACCEPT_ALL" });
|
|
325
355
|
const rejectAll = () => dispatch({ type: "REJECT_ALL" });
|
|
326
356
|
const setPreference = (category, value) => dispatch({ type: "SET_CATEGORY", category, value });
|
|
357
|
+
const setPreferences = (preferences) => dispatch({ type: "SET_PREFERENCES", preferences });
|
|
327
358
|
const openPreferences = () => dispatch({ type: "OPEN_MODAL" });
|
|
328
359
|
const closePreferences = () => dispatch({ type: "CLOSE_MODAL" });
|
|
329
360
|
const resetConsent = () => {
|
|
@@ -337,6 +368,7 @@ function ConsentProvider({
|
|
|
337
368
|
acceptAll,
|
|
338
369
|
rejectAll,
|
|
339
370
|
setPreference,
|
|
371
|
+
setPreferences,
|
|
340
372
|
openPreferences,
|
|
341
373
|
closePreferences,
|
|
342
374
|
resetConsent
|
|
@@ -409,6 +441,7 @@ function useConsent() {
|
|
|
409
441
|
acceptAll: actions.acceptAll,
|
|
410
442
|
rejectAll: actions.rejectAll,
|
|
411
443
|
setPreference: actions.setPreference,
|
|
444
|
+
setPreferences: actions.setPreferences,
|
|
412
445
|
openPreferences: actions.openPreferences,
|
|
413
446
|
closePreferences: actions.closePreferences,
|
|
414
447
|
resetConsent: actions.resetConsent
|
|
@@ -569,7 +602,7 @@ function loadScript(id, src, category = null, attrs = {}) {
|
|
|
569
602
|
}
|
|
570
603
|
try {
|
|
571
604
|
const consent = JSON.parse(decodeURIComponent(consentCookie));
|
|
572
|
-
if (!consent.consented) {
|
|
605
|
+
if (!consent.consented || consent.isModalOpen) {
|
|
573
606
|
setTimeout(checkConsent, 100);
|
|
574
607
|
return;
|
|
575
608
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -111,6 +111,8 @@ interface ConsentContextValue {
|
|
|
111
111
|
rejectAll: () => void;
|
|
112
112
|
/** Define a preferência para uma categoria específica. */
|
|
113
113
|
setPreference: (cat: Category, value: boolean) => void;
|
|
114
|
+
/** Define múltiplas preferências de uma vez e salva. */
|
|
115
|
+
setPreferences: (preferences: ConsentPreferences) => void;
|
|
114
116
|
/** Abre o modal de preferências. */
|
|
115
117
|
openPreferences: () => void;
|
|
116
118
|
/** Fecha o modal de preferências. */
|
package/dist/index.d.ts
CHANGED
|
@@ -111,6 +111,8 @@ interface ConsentContextValue {
|
|
|
111
111
|
rejectAll: () => void;
|
|
112
112
|
/** Define a preferência para uma categoria específica. */
|
|
113
113
|
setPreference: (cat: Category, value: boolean) => void;
|
|
114
|
+
/** Define múltiplas preferências de uma vez e salva. */
|
|
115
|
+
setPreferences: (preferences: ConsentPreferences) => void;
|
|
114
116
|
/** Abre o modal de preferências. */
|
|
115
117
|
openPreferences: () => void;
|
|
116
118
|
/** Fecha o modal de preferências. */
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
defaultConsentTheme,
|
|
5
5
|
useConsent,
|
|
6
6
|
useConsentTexts
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-Y4XEAQXV.js";
|
|
8
8
|
|
|
9
9
|
// src/components/CookieBanner.tsx
|
|
10
10
|
import Button from "@mui/material/Button";
|
|
@@ -130,7 +130,7 @@ function loadScript(id, src, category = null, attrs = {}) {
|
|
|
130
130
|
}
|
|
131
131
|
try {
|
|
132
132
|
const consent = JSON.parse(decodeURIComponent(consentCookie));
|
|
133
|
-
if (!consent.consented) {
|
|
133
|
+
if (!consent.consented || consent.isModalOpen) {
|
|
134
134
|
setTimeout(checkConsent, 100);
|
|
135
135
|
return;
|
|
136
136
|
}
|
package/package.json
CHANGED