@react-lgpd-consent/mui 0.7.0 → 0.7.2
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 +6 -1
- package/dist/index.cjs +90 -32
- package/dist/index.d.cts +57 -4
- package/dist/index.d.ts +57 -4
- package/dist/index.js +90 -32
- package/dist/ui.cjs +673 -0
- package/dist/ui.d.cts +9 -0
- package/dist/ui.d.ts +9 -0
- package/dist/ui.js +628 -0
- package/package.json +10 -5
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { useConsentTexts, useDesignTokens, useConsent, logger, useConsentHydration, useCategories, getCookiesInfoForCategory, ConsentProvider as ConsentProvider$1 } from '@react-lgpd-consent/core';
|
|
1
|
+
import { useConsentTexts, resolveTexts, useDesignTokens, useConsent, logger, useConsentHydration, useCategories, getCookiesInfoForCategory, ConsentProvider as ConsentProvider$1 } from '@react-lgpd-consent/core';
|
|
2
2
|
export * from '@react-lgpd-consent/core';
|
|
3
|
+
import * as core from '@react-lgpd-consent/core';
|
|
4
|
+
export { core as headless };
|
|
3
5
|
export { ConsentProvider as ConsentProviderHeadless } from '@react-lgpd-consent/core';
|
|
4
6
|
import Link from '@mui/material/Link';
|
|
5
7
|
import Typography from '@mui/material/Typography';
|
|
6
|
-
import * as
|
|
8
|
+
import * as React4 from 'react';
|
|
7
9
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
8
10
|
import { useTheme, ThemeProvider } from '@mui/material/styles';
|
|
9
11
|
import Box2 from '@mui/material/Box';
|
|
@@ -50,11 +52,22 @@ var linkStyles = {
|
|
|
50
52
|
textDecoration: "underline"
|
|
51
53
|
}
|
|
52
54
|
};
|
|
53
|
-
var Branding =
|
|
55
|
+
var Branding = React4.memo(function Branding2({
|
|
54
56
|
variant,
|
|
55
|
-
hidden = false
|
|
57
|
+
hidden = false,
|
|
58
|
+
texts: textsProp,
|
|
59
|
+
language,
|
|
60
|
+
textVariant
|
|
56
61
|
}) {
|
|
57
|
-
const
|
|
62
|
+
const baseTexts = useConsentTexts();
|
|
63
|
+
const mergedTexts = React4.useMemo(
|
|
64
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
65
|
+
[baseTexts, textsProp]
|
|
66
|
+
);
|
|
67
|
+
const texts = React4.useMemo(
|
|
68
|
+
() => resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
69
|
+
[mergedTexts, language, textVariant]
|
|
70
|
+
);
|
|
58
71
|
const designTokens = useDesignTokens();
|
|
59
72
|
if (hidden) return null;
|
|
60
73
|
return /* @__PURE__ */ jsxs(
|
|
@@ -92,10 +105,21 @@ function CookieBanner({
|
|
|
92
105
|
blocking = true,
|
|
93
106
|
hideBranding = false,
|
|
94
107
|
SnackbarProps,
|
|
95
|
-
PaperProps
|
|
108
|
+
PaperProps,
|
|
109
|
+
texts: textsProp,
|
|
110
|
+
language,
|
|
111
|
+
textVariant
|
|
96
112
|
}) {
|
|
97
113
|
const { consented, acceptAll, rejectAll, openPreferences } = useConsent();
|
|
98
|
-
const
|
|
114
|
+
const baseTexts = useConsentTexts();
|
|
115
|
+
const mergedTexts = React4.useMemo(
|
|
116
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
117
|
+
[baseTexts, textsProp]
|
|
118
|
+
);
|
|
119
|
+
const texts = React4.useMemo(
|
|
120
|
+
() => resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
121
|
+
[mergedTexts, language, textVariant]
|
|
122
|
+
);
|
|
99
123
|
const isHydrated = useConsentHydration();
|
|
100
124
|
const designTokens = useDesignTokens();
|
|
101
125
|
const open = debug ? true : isHydrated && !consented;
|
|
@@ -170,7 +194,15 @@ function CookieBanner({
|
|
|
170
194
|
}
|
|
171
195
|
)
|
|
172
196
|
] }),
|
|
173
|
-
!hideBranding && /* @__PURE__ */ jsx(
|
|
197
|
+
!hideBranding && /* @__PURE__ */ jsx(
|
|
198
|
+
Branding,
|
|
199
|
+
{
|
|
200
|
+
variant: "banner",
|
|
201
|
+
texts: textsProp,
|
|
202
|
+
language,
|
|
203
|
+
textVariant
|
|
204
|
+
}
|
|
205
|
+
)
|
|
174
206
|
] }) });
|
|
175
207
|
const resolveBannerZIndex = (theme) => designTokens?.layout?.zIndex?.banner ?? theme?.zIndex?.snackbar ?? 1400;
|
|
176
208
|
const positionStyle = (theme) => ({
|
|
@@ -270,13 +302,24 @@ function FloatingPreferencesButtonComponent({
|
|
|
270
302
|
icon = /* @__PURE__ */ jsx(CookieOutlined, {}),
|
|
271
303
|
tooltip,
|
|
272
304
|
FabProps,
|
|
273
|
-
hideWhenConsented = false
|
|
305
|
+
hideWhenConsented = false,
|
|
306
|
+
texts: textsProp,
|
|
307
|
+
language,
|
|
308
|
+
textVariant
|
|
274
309
|
}) {
|
|
275
310
|
const { openPreferences, consented } = useConsent();
|
|
276
|
-
const
|
|
311
|
+
const baseTexts = useConsentTexts();
|
|
312
|
+
const mergedTexts = React4.useMemo(
|
|
313
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
314
|
+
[baseTexts, textsProp]
|
|
315
|
+
);
|
|
316
|
+
const texts = React4.useMemo(
|
|
317
|
+
() => resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
318
|
+
[mergedTexts, language, textVariant]
|
|
319
|
+
);
|
|
277
320
|
const safeTheme = useThemeWithFallbacks();
|
|
278
321
|
const designTokens = useDesignTokens();
|
|
279
|
-
const positionStyles =
|
|
322
|
+
const positionStyles = React4.useMemo(() => {
|
|
280
323
|
const styles = {
|
|
281
324
|
position: "fixed",
|
|
282
325
|
zIndex: 1200
|
|
@@ -327,7 +370,7 @@ function FloatingPreferencesButtonComponent({
|
|
|
327
370
|
}
|
|
328
371
|
) });
|
|
329
372
|
}
|
|
330
|
-
var FloatingPreferencesButton =
|
|
373
|
+
var FloatingPreferencesButton = React4.memo(FloatingPreferencesButtonComponent);
|
|
331
374
|
FloatingPreferencesButton.displayName = "FloatingPreferencesButton";
|
|
332
375
|
function PreferencesModal({
|
|
333
376
|
DialogProps: DialogProps2,
|
|
@@ -335,26 +378,37 @@ function PreferencesModal({
|
|
|
335
378
|
isModalOpen: isModalOpenProp,
|
|
336
379
|
preferences: preferencesProp,
|
|
337
380
|
setPreferences: setPreferencesProp,
|
|
338
|
-
closePreferences: closePreferencesProp
|
|
381
|
+
closePreferences: closePreferencesProp,
|
|
382
|
+
texts: textsProp,
|
|
383
|
+
language,
|
|
384
|
+
textVariant
|
|
339
385
|
}) {
|
|
340
386
|
const hookValue = useConsent();
|
|
341
387
|
const preferences = preferencesProp ?? hookValue.preferences;
|
|
342
388
|
const setPreferences = setPreferencesProp ?? hookValue.setPreferences;
|
|
343
389
|
const closePreferences = closePreferencesProp ?? hookValue.closePreferences;
|
|
344
390
|
const isModalOpen = isModalOpenProp ?? hookValue.isModalOpen;
|
|
345
|
-
const
|
|
391
|
+
const baseTexts = useConsentTexts();
|
|
392
|
+
const mergedTexts = React4.useMemo(
|
|
393
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
394
|
+
[baseTexts, textsProp]
|
|
395
|
+
);
|
|
396
|
+
const texts = React4.useMemo(
|
|
397
|
+
() => resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
398
|
+
[mergedTexts, language, textVariant]
|
|
399
|
+
);
|
|
346
400
|
const designTokens = useDesignTokens();
|
|
347
401
|
const { toggleableCategories, allCategories } = useCategories();
|
|
348
|
-
const getInitialPreferences =
|
|
402
|
+
const getInitialPreferences = React4.useCallback(() => {
|
|
349
403
|
const syncedPrefs = { necessary: true };
|
|
350
404
|
toggleableCategories.forEach((category) => {
|
|
351
405
|
syncedPrefs[category.id] = preferences[category.id] ?? false;
|
|
352
406
|
});
|
|
353
407
|
return syncedPrefs;
|
|
354
408
|
}, [preferences, toggleableCategories]);
|
|
355
|
-
const [tempPreferences, setTempPreferences] =
|
|
356
|
-
const wasOpenRef =
|
|
357
|
-
|
|
409
|
+
const [tempPreferences, setTempPreferences] = React4.useState(getInitialPreferences);
|
|
410
|
+
const wasOpenRef = React4.useRef(isModalOpen);
|
|
411
|
+
React4.useEffect(() => {
|
|
358
412
|
const justOpened = isModalOpen && !wasOpenRef.current;
|
|
359
413
|
wasOpenRef.current = isModalOpen;
|
|
360
414
|
if (justOpened) {
|
|
@@ -381,7 +435,7 @@ function PreferencesModal({
|
|
|
381
435
|
backgroundColor: designTokens?.colors?.background ?? theme.palette.background.paper,
|
|
382
436
|
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
383
437
|
});
|
|
384
|
-
const resolveModalZIndex =
|
|
438
|
+
const resolveModalZIndex = React4.useCallback(
|
|
385
439
|
(theme) => designTokens?.layout?.zIndex?.modal ?? (theme?.zIndex?.modal ?? 1300) + 10,
|
|
386
440
|
[designTokens?.layout?.zIndex?.modal]
|
|
387
441
|
);
|
|
@@ -427,6 +481,10 @@ function PreferencesModal({
|
|
|
427
481
|
const namesFromGuidance = full?.cookies ?? [];
|
|
428
482
|
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
429
483
|
const descriptors = getCookiesInfoForCategory(category.id, used);
|
|
484
|
+
const tableHeaders = texts.cookieDetails?.tableHeaders;
|
|
485
|
+
const toggleDetailsText = texts.cookieDetails?.toggleDetails?.expand ?? "Ver detalhes";
|
|
486
|
+
const scriptLabelPrefix = texts.cookieDetails?.scriptLabelPrefix ?? "(script) ";
|
|
487
|
+
const scriptPurpose = texts.cookieDetails?.scriptPurpose ?? "Script de integra\xE7\xE3o ativo";
|
|
430
488
|
const enrichedDescriptors = descriptors.map((desc) => {
|
|
431
489
|
if (desc.purpose && desc.duration && desc.provider) {
|
|
432
490
|
return desc;
|
|
@@ -447,8 +505,8 @@ function PreferencesModal({
|
|
|
447
505
|
if (merged.length === 0) {
|
|
448
506
|
const gmap = globalThis.__LGPD_INTEGRATIONS_MAP__ || {};
|
|
449
507
|
const scriptRows = Object.entries(gmap).filter(([, cat]) => cat === category.id).map(([id]) => ({
|
|
450
|
-
name:
|
|
451
|
-
purpose:
|
|
508
|
+
name: `${scriptLabelPrefix}${id}`,
|
|
509
|
+
purpose: scriptPurpose,
|
|
452
510
|
duration: "-",
|
|
453
511
|
provider: "-"
|
|
454
512
|
}));
|
|
@@ -474,13 +532,13 @@ function PreferencesModal({
|
|
|
474
532
|
}
|
|
475
533
|
),
|
|
476
534
|
/* @__PURE__ */ jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
477
|
-
/* @__PURE__ */ jsx("summary", { children:
|
|
535
|
+
/* @__PURE__ */ jsx("summary", { children: toggleDetailsText }),
|
|
478
536
|
/* @__PURE__ */ jsx(Box2, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
479
537
|
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
480
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
481
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
482
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
483
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Fornecedor" })
|
|
538
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: tableHeaders?.name ?? "Cookie" }),
|
|
539
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: tableHeaders?.purpose ?? "Finalidade" }),
|
|
540
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: tableHeaders?.duration ?? "Dura\xE7\xE3o" }),
|
|
541
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: tableHeaders?.provider ?? "Fornecedor" })
|
|
484
542
|
] }) }),
|
|
485
543
|
/* @__PURE__ */ jsx("tbody", { children: mergedFinal.map((d, idx) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
486
544
|
/* @__PURE__ */ jsx("td", { children: d.name }),
|
|
@@ -494,13 +552,13 @@ function PreferencesModal({
|
|
|
494
552
|
}),
|
|
495
553
|
/* @__PURE__ */ jsx(FormControlLabel, { control: /* @__PURE__ */ jsx(Switch, { checked: true, disabled: true }), label: texts.necessaryAlwaysOn }),
|
|
496
554
|
/* @__PURE__ */ jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
497
|
-
/* @__PURE__ */ jsx("summary", { children: "Ver detalhes" }),
|
|
555
|
+
/* @__PURE__ */ jsx("summary", { children: texts.cookieDetails?.toggleDetails?.expand ?? "Ver detalhes" }),
|
|
498
556
|
/* @__PURE__ */ jsx(Box2, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
499
557
|
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
500
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
501
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
502
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
503
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Fornecedor" })
|
|
558
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: texts.cookieDetails?.tableHeaders?.name ?? "Cookie" }),
|
|
559
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: texts.cookieDetails?.tableHeaders?.purpose ?? "Finalidade" }),
|
|
560
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: texts.cookieDetails?.tableHeaders?.duration ?? "Dura\xE7\xE3o" }),
|
|
561
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: texts.cookieDetails?.tableHeaders?.provider ?? "Fornecedor" })
|
|
504
562
|
] }) }),
|
|
505
563
|
/* @__PURE__ */ jsx("tbody", { children: (() => {
|
|
506
564
|
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
@@ -523,7 +581,7 @@ function PreferencesModal({
|
|
|
523
581
|
/* @__PURE__ */ jsx(Button, { variant: "outlined", onClick: handleCancel, children: texts.close }),
|
|
524
582
|
/* @__PURE__ */ jsx(Button, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
525
583
|
] }),
|
|
526
|
-
!hideBranding && /* @__PURE__ */ jsx(Branding, { variant: "modal" })
|
|
584
|
+
!hideBranding && /* @__PURE__ */ jsx(Branding, { variant: "modal", texts: textsProp, language, textVariant })
|
|
527
585
|
] });
|
|
528
586
|
}
|
|
529
587
|
function ConsentProvider({
|