@react-lgpd-consent/mui 0.7.1 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/dist/index.cjs +92 -32
- package/dist/index.d.cts +55 -4
- package/dist/index.d.ts +55 -4
- package/dist/index.js +92 -32
- package/dist/ui.cjs +92 -32
- package/dist/ui.js +92 -32
- package/package.json +2 -2
package/dist/ui.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Link from '@mui/material/Link';
|
|
2
2
|
import Typography from '@mui/material/Typography';
|
|
3
|
-
import { useConsentTexts, useDesignTokens, useConsent, logger, useConsentHydration, useCategories, getCookiesInfoForCategory, ConsentProvider as ConsentProvider$1 } from '@react-lgpd-consent/core';
|
|
4
|
-
import * as
|
|
3
|
+
import { useConsentTexts, resolveTexts, useDesignTokens, useConsent, logger, useConsentHydration, useCategories, getCookiesInfoForCategory, ConsentProvider as ConsentProvider$1 } from '@react-lgpd-consent/core';
|
|
4
|
+
import * as React4 from 'react';
|
|
5
5
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
6
6
|
import { useTheme, ThemeProvider } from '@mui/material/styles';
|
|
7
7
|
import Box2 from '@mui/material/Box';
|
|
@@ -48,11 +48,22 @@ var linkStyles = {
|
|
|
48
48
|
textDecoration: "underline"
|
|
49
49
|
}
|
|
50
50
|
};
|
|
51
|
-
var Branding =
|
|
51
|
+
var Branding = React4.memo(function Branding2({
|
|
52
52
|
variant,
|
|
53
|
-
hidden = false
|
|
53
|
+
hidden = false,
|
|
54
|
+
texts: textsProp,
|
|
55
|
+
language,
|
|
56
|
+
textVariant
|
|
54
57
|
}) {
|
|
55
|
-
const
|
|
58
|
+
const baseTexts = useConsentTexts();
|
|
59
|
+
const mergedTexts = React4.useMemo(
|
|
60
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
61
|
+
[baseTexts, textsProp]
|
|
62
|
+
);
|
|
63
|
+
const texts = React4.useMemo(
|
|
64
|
+
() => resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
65
|
+
[mergedTexts, language, textVariant]
|
|
66
|
+
);
|
|
56
67
|
const designTokens = useDesignTokens();
|
|
57
68
|
if (hidden) return null;
|
|
58
69
|
return /* @__PURE__ */ jsxs(
|
|
@@ -90,10 +101,21 @@ function CookieBanner({
|
|
|
90
101
|
blocking = true,
|
|
91
102
|
hideBranding = false,
|
|
92
103
|
SnackbarProps,
|
|
93
|
-
PaperProps
|
|
104
|
+
PaperProps,
|
|
105
|
+
texts: textsProp,
|
|
106
|
+
language,
|
|
107
|
+
textVariant
|
|
94
108
|
}) {
|
|
95
109
|
const { consented, acceptAll, rejectAll, openPreferences } = useConsent();
|
|
96
|
-
const
|
|
110
|
+
const baseTexts = useConsentTexts();
|
|
111
|
+
const mergedTexts = React4.useMemo(
|
|
112
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
113
|
+
[baseTexts, textsProp]
|
|
114
|
+
);
|
|
115
|
+
const texts = React4.useMemo(
|
|
116
|
+
() => resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
117
|
+
[mergedTexts, language, textVariant]
|
|
118
|
+
);
|
|
97
119
|
const isHydrated = useConsentHydration();
|
|
98
120
|
const designTokens = useDesignTokens();
|
|
99
121
|
const open = debug ? true : isHydrated && !consented;
|
|
@@ -168,7 +190,15 @@ function CookieBanner({
|
|
|
168
190
|
}
|
|
169
191
|
)
|
|
170
192
|
] }),
|
|
171
|
-
!hideBranding && /* @__PURE__ */ jsx(
|
|
193
|
+
!hideBranding && /* @__PURE__ */ jsx(
|
|
194
|
+
Branding,
|
|
195
|
+
{
|
|
196
|
+
variant: "banner",
|
|
197
|
+
texts: textsProp,
|
|
198
|
+
language,
|
|
199
|
+
textVariant
|
|
200
|
+
}
|
|
201
|
+
)
|
|
172
202
|
] }) });
|
|
173
203
|
const resolveBannerZIndex = (theme) => designTokens?.layout?.zIndex?.banner ?? theme?.zIndex?.snackbar ?? 1400;
|
|
174
204
|
const positionStyle = (theme) => ({
|
|
@@ -268,13 +298,24 @@ function FloatingPreferencesButtonComponent({
|
|
|
268
298
|
icon = /* @__PURE__ */ jsx(CookieOutlined, {}),
|
|
269
299
|
tooltip,
|
|
270
300
|
FabProps,
|
|
271
|
-
hideWhenConsented = false
|
|
301
|
+
hideWhenConsented = false,
|
|
302
|
+
texts: textsProp,
|
|
303
|
+
language,
|
|
304
|
+
textVariant
|
|
272
305
|
}) {
|
|
273
306
|
const { openPreferences, consented } = useConsent();
|
|
274
|
-
const
|
|
307
|
+
const baseTexts = useConsentTexts();
|
|
308
|
+
const mergedTexts = React4.useMemo(
|
|
309
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
310
|
+
[baseTexts, textsProp]
|
|
311
|
+
);
|
|
312
|
+
const texts = React4.useMemo(
|
|
313
|
+
() => resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
314
|
+
[mergedTexts, language, textVariant]
|
|
315
|
+
);
|
|
275
316
|
const safeTheme = useThemeWithFallbacks();
|
|
276
317
|
const designTokens = useDesignTokens();
|
|
277
|
-
const positionStyles =
|
|
318
|
+
const positionStyles = React4.useMemo(() => {
|
|
278
319
|
const styles = {
|
|
279
320
|
position: "fixed",
|
|
280
321
|
zIndex: 1200
|
|
@@ -325,7 +366,7 @@ function FloatingPreferencesButtonComponent({
|
|
|
325
366
|
}
|
|
326
367
|
) });
|
|
327
368
|
}
|
|
328
|
-
var FloatingPreferencesButton =
|
|
369
|
+
var FloatingPreferencesButton = React4.memo(FloatingPreferencesButtonComponent);
|
|
329
370
|
FloatingPreferencesButton.displayName = "FloatingPreferencesButton";
|
|
330
371
|
function PreferencesModal({
|
|
331
372
|
DialogProps: DialogProps2,
|
|
@@ -333,26 +374,37 @@ function PreferencesModal({
|
|
|
333
374
|
isModalOpen: isModalOpenProp,
|
|
334
375
|
preferences: preferencesProp,
|
|
335
376
|
setPreferences: setPreferencesProp,
|
|
336
|
-
closePreferences: closePreferencesProp
|
|
377
|
+
closePreferences: closePreferencesProp,
|
|
378
|
+
texts: textsProp,
|
|
379
|
+
language,
|
|
380
|
+
textVariant
|
|
337
381
|
}) {
|
|
338
382
|
const hookValue = useConsent();
|
|
339
383
|
const preferences = preferencesProp ?? hookValue.preferences;
|
|
340
384
|
const setPreferences = setPreferencesProp ?? hookValue.setPreferences;
|
|
341
385
|
const closePreferences = closePreferencesProp ?? hookValue.closePreferences;
|
|
342
386
|
const isModalOpen = isModalOpenProp ?? hookValue.isModalOpen;
|
|
343
|
-
const
|
|
387
|
+
const baseTexts = useConsentTexts();
|
|
388
|
+
const mergedTexts = React4.useMemo(
|
|
389
|
+
() => ({ ...baseTexts, ...textsProp ?? {} }),
|
|
390
|
+
[baseTexts, textsProp]
|
|
391
|
+
);
|
|
392
|
+
const texts = React4.useMemo(
|
|
393
|
+
() => resolveTexts(mergedTexts, { language, variant: textVariant }),
|
|
394
|
+
[mergedTexts, language, textVariant]
|
|
395
|
+
);
|
|
344
396
|
const designTokens = useDesignTokens();
|
|
345
397
|
const { toggleableCategories, allCategories } = useCategories();
|
|
346
|
-
const getInitialPreferences =
|
|
398
|
+
const getInitialPreferences = React4.useCallback(() => {
|
|
347
399
|
const syncedPrefs = { necessary: true };
|
|
348
400
|
toggleableCategories.forEach((category) => {
|
|
349
401
|
syncedPrefs[category.id] = preferences[category.id] ?? false;
|
|
350
402
|
});
|
|
351
403
|
return syncedPrefs;
|
|
352
404
|
}, [preferences, toggleableCategories]);
|
|
353
|
-
const [tempPreferences, setTempPreferences] =
|
|
354
|
-
const wasOpenRef =
|
|
355
|
-
|
|
405
|
+
const [tempPreferences, setTempPreferences] = React4.useState(getInitialPreferences);
|
|
406
|
+
const wasOpenRef = React4.useRef(isModalOpen);
|
|
407
|
+
React4.useEffect(() => {
|
|
356
408
|
const justOpened = isModalOpen && !wasOpenRef.current;
|
|
357
409
|
wasOpenRef.current = isModalOpen;
|
|
358
410
|
if (justOpened) {
|
|
@@ -370,6 +422,7 @@ function PreferencesModal({
|
|
|
370
422
|
setTempPreferences(preferences);
|
|
371
423
|
closePreferences();
|
|
372
424
|
};
|
|
425
|
+
const descriptionId = "cookie-pref-description";
|
|
373
426
|
const modalTitleSx = (theme) => ({
|
|
374
427
|
fontSize: designTokens?.typography?.fontSize?.modal ?? void 0,
|
|
375
428
|
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
@@ -379,7 +432,7 @@ function PreferencesModal({
|
|
|
379
432
|
backgroundColor: designTokens?.colors?.background ?? theme.palette.background.paper,
|
|
380
433
|
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
381
434
|
});
|
|
382
|
-
const resolveModalZIndex =
|
|
435
|
+
const resolveModalZIndex = React4.useCallback(
|
|
383
436
|
(theme) => designTokens?.layout?.zIndex?.modal ?? (theme?.zIndex?.modal ?? 1300) + 10,
|
|
384
437
|
[designTokens?.layout?.zIndex?.modal]
|
|
385
438
|
);
|
|
@@ -394,11 +447,13 @@ function PreferencesModal({
|
|
|
394
447
|
...modalZIndexToken ? { style: { zIndex: modalZIndexToken } } : {},
|
|
395
448
|
"data-testid": dialogRest?.slotProps?.root?.["data-testid"] ?? "lgpd-preferences-modal-root"
|
|
396
449
|
};
|
|
450
|
+
const ariaDescribedBy = dialogRest["aria-describedby"] ?? descriptionId;
|
|
397
451
|
const mergedDialogProps = {
|
|
398
452
|
open,
|
|
399
453
|
fullWidth: true,
|
|
400
454
|
maxWidth: "sm",
|
|
401
455
|
...dialogRest,
|
|
456
|
+
"aria-describedby": ariaDescribedBy,
|
|
402
457
|
slotProps: {
|
|
403
458
|
...dialogRest?.slotProps,
|
|
404
459
|
root: rootSlotProps
|
|
@@ -410,6 +465,7 @@ function PreferencesModal({
|
|
|
410
465
|
/* @__PURE__ */ jsx(
|
|
411
466
|
Typography,
|
|
412
467
|
{
|
|
468
|
+
id: descriptionId,
|
|
413
469
|
variant: "body2",
|
|
414
470
|
sx: (theme) => ({
|
|
415
471
|
mb: 2,
|
|
@@ -425,6 +481,10 @@ function PreferencesModal({
|
|
|
425
481
|
const namesFromGuidance = full?.cookies ?? [];
|
|
426
482
|
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
427
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";
|
|
428
488
|
const enrichedDescriptors = descriptors.map((desc) => {
|
|
429
489
|
if (desc.purpose && desc.duration && desc.provider) {
|
|
430
490
|
return desc;
|
|
@@ -445,8 +505,8 @@ function PreferencesModal({
|
|
|
445
505
|
if (merged.length === 0) {
|
|
446
506
|
const gmap = globalThis.__LGPD_INTEGRATIONS_MAP__ || {};
|
|
447
507
|
const scriptRows = Object.entries(gmap).filter(([, cat]) => cat === category.id).map(([id]) => ({
|
|
448
|
-
name:
|
|
449
|
-
purpose:
|
|
508
|
+
name: `${scriptLabelPrefix}${id}`,
|
|
509
|
+
purpose: scriptPurpose,
|
|
450
510
|
duration: "-",
|
|
451
511
|
provider: "-"
|
|
452
512
|
}));
|
|
@@ -472,13 +532,13 @@ function PreferencesModal({
|
|
|
472
532
|
}
|
|
473
533
|
),
|
|
474
534
|
/* @__PURE__ */ jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
475
|
-
/* @__PURE__ */ jsx("summary", { children:
|
|
535
|
+
/* @__PURE__ */ jsx("summary", { children: toggleDetailsText }),
|
|
476
536
|
/* @__PURE__ */ jsx(Box2, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
477
537
|
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
478
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
479
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
480
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
481
|
-
/* @__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" })
|
|
482
542
|
] }) }),
|
|
483
543
|
/* @__PURE__ */ jsx("tbody", { children: mergedFinal.map((d, idx) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
484
544
|
/* @__PURE__ */ jsx("td", { children: d.name }),
|
|
@@ -492,13 +552,13 @@ function PreferencesModal({
|
|
|
492
552
|
}),
|
|
493
553
|
/* @__PURE__ */ jsx(FormControlLabel, { control: /* @__PURE__ */ jsx(Switch, { checked: true, disabled: true }), label: texts.necessaryAlwaysOn }),
|
|
494
554
|
/* @__PURE__ */ jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
495
|
-
/* @__PURE__ */ jsx("summary", { children: "Ver detalhes" }),
|
|
555
|
+
/* @__PURE__ */ jsx("summary", { children: texts.cookieDetails?.toggleDetails?.expand ?? "Ver detalhes" }),
|
|
496
556
|
/* @__PURE__ */ jsx(Box2, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
497
557
|
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
498
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
499
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
500
|
-
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
501
|
-
/* @__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" })
|
|
502
562
|
] }) }),
|
|
503
563
|
/* @__PURE__ */ jsx("tbody", { children: (() => {
|
|
504
564
|
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
@@ -521,7 +581,7 @@ function PreferencesModal({
|
|
|
521
581
|
/* @__PURE__ */ jsx(Button, { variant: "outlined", onClick: handleCancel, children: texts.close }),
|
|
522
582
|
/* @__PURE__ */ jsx(Button, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
523
583
|
] }),
|
|
524
|
-
!hideBranding && /* @__PURE__ */ jsx(Branding, { variant: "modal" })
|
|
584
|
+
!hideBranding && /* @__PURE__ */ jsx(Branding, { variant: "modal", texts: textsProp, language, textVariant })
|
|
525
585
|
] });
|
|
526
586
|
}
|
|
527
587
|
function ConsentProvider({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-lgpd-consent/mui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Componentes Material-UI prontos para gerenciamento de consentimento LGPD",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lgpd",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
}
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@react-lgpd-consent/core": "^0.
|
|
66
|
+
"@react-lgpd-consent/core": "^0.8.0"
|
|
67
67
|
},
|
|
68
68
|
"scripts": {
|
|
69
69
|
"clean": "rimraf dist",
|