@react-lgpd-consent/mui 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +138 -0
- package/dist/index.cjs +597 -0
- package/dist/index.d.cts +469 -0
- package/dist/index.d.ts +469 -0
- package/dist/index.js +544 -0
- package/package.json +73 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,544 @@
|
|
|
1
|
+
import { useConsentTexts, useDesignTokens, useConsent, logger, useConsentHydration, useCategories, getCookiesInfoForCategory, ConsentProvider as ConsentProvider$1 } from '@react-lgpd-consent/core';
|
|
2
|
+
export * from '@react-lgpd-consent/core';
|
|
3
|
+
export { ConsentProvider as ConsentProviderHeadless } from '@react-lgpd-consent/core';
|
|
4
|
+
import Link from '@mui/material/Link';
|
|
5
|
+
import Typography from '@mui/material/Typography';
|
|
6
|
+
import * as React3 from 'react';
|
|
7
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
8
|
+
import { useTheme, ThemeProvider } from '@mui/material/styles';
|
|
9
|
+
import Box2 from '@mui/material/Box';
|
|
10
|
+
import Button from '@mui/material/Button';
|
|
11
|
+
import Paper from '@mui/material/Paper';
|
|
12
|
+
import Snackbar from '@mui/material/Snackbar';
|
|
13
|
+
import Stack from '@mui/material/Stack';
|
|
14
|
+
import CookieOutlined from '@mui/icons-material/CookieOutlined';
|
|
15
|
+
import Fab from '@mui/material/Fab';
|
|
16
|
+
import Tooltip from '@mui/material/Tooltip';
|
|
17
|
+
import Dialog from '@mui/material/Dialog';
|
|
18
|
+
import DialogActions from '@mui/material/DialogActions';
|
|
19
|
+
import DialogContent from '@mui/material/DialogContent';
|
|
20
|
+
import DialogTitle from '@mui/material/DialogTitle';
|
|
21
|
+
import FormControlLabel from '@mui/material/FormControlLabel';
|
|
22
|
+
import FormGroup from '@mui/material/FormGroup';
|
|
23
|
+
import Switch from '@mui/material/Switch';
|
|
24
|
+
|
|
25
|
+
// @react-lgpd-consent/mui - proxy build
|
|
26
|
+
|
|
27
|
+
var brandingStyles = {
|
|
28
|
+
banner: {
|
|
29
|
+
fontSize: "0.65rem",
|
|
30
|
+
textAlign: "right",
|
|
31
|
+
mt: 1,
|
|
32
|
+
opacity: 0.7,
|
|
33
|
+
fontStyle: "italic",
|
|
34
|
+
width: "100%"
|
|
35
|
+
},
|
|
36
|
+
modal: {
|
|
37
|
+
fontSize: "0.65rem",
|
|
38
|
+
textAlign: "right",
|
|
39
|
+
px: 3,
|
|
40
|
+
pb: 1,
|
|
41
|
+
opacity: 0.7,
|
|
42
|
+
fontStyle: "italic",
|
|
43
|
+
width: "100%"
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
var linkStyles = {
|
|
47
|
+
textDecoration: "none",
|
|
48
|
+
fontWeight: 500,
|
|
49
|
+
"&:hover": {
|
|
50
|
+
textDecoration: "underline"
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var Branding = React3.memo(function Branding2({
|
|
54
|
+
variant,
|
|
55
|
+
hidden = false
|
|
56
|
+
}) {
|
|
57
|
+
const texts = useConsentTexts();
|
|
58
|
+
const designTokens = useDesignTokens();
|
|
59
|
+
if (hidden) return null;
|
|
60
|
+
return /* @__PURE__ */ jsxs(
|
|
61
|
+
Typography,
|
|
62
|
+
{
|
|
63
|
+
variant: "caption",
|
|
64
|
+
sx: (theme) => ({
|
|
65
|
+
...brandingStyles[variant],
|
|
66
|
+
color: designTokens?.colors?.text ?? theme.palette.text.secondary
|
|
67
|
+
}),
|
|
68
|
+
children: [
|
|
69
|
+
texts.brandingPoweredBy || "fornecido por",
|
|
70
|
+
" ",
|
|
71
|
+
/* @__PURE__ */ jsx(
|
|
72
|
+
Link,
|
|
73
|
+
{
|
|
74
|
+
href: "https://www.ledipo.eti.br",
|
|
75
|
+
target: "_blank",
|
|
76
|
+
rel: "noopener noreferrer",
|
|
77
|
+
sx: (theme) => ({
|
|
78
|
+
...linkStyles,
|
|
79
|
+
color: designTokens?.colors?.primary ?? theme.palette.primary.main
|
|
80
|
+
}),
|
|
81
|
+
children: "L\xC9dipO.eti.br"
|
|
82
|
+
}
|
|
83
|
+
)
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
});
|
|
88
|
+
function CookieBanner({
|
|
89
|
+
policyLinkUrl,
|
|
90
|
+
termsLinkUrl,
|
|
91
|
+
debug,
|
|
92
|
+
blocking = true,
|
|
93
|
+
hideBranding = false,
|
|
94
|
+
SnackbarProps,
|
|
95
|
+
PaperProps
|
|
96
|
+
}) {
|
|
97
|
+
const { consented, acceptAll, rejectAll, openPreferences } = useConsent();
|
|
98
|
+
const texts = useConsentTexts();
|
|
99
|
+
const isHydrated = useConsentHydration();
|
|
100
|
+
const designTokens = useDesignTokens();
|
|
101
|
+
const open = debug ? true : isHydrated && !consented;
|
|
102
|
+
logger.componentRender("CookieBanner", {
|
|
103
|
+
open,
|
|
104
|
+
consented,
|
|
105
|
+
isHydrated,
|
|
106
|
+
blocking,
|
|
107
|
+
hideBranding
|
|
108
|
+
});
|
|
109
|
+
if (!open) return null;
|
|
110
|
+
const bannerStyle = (theme) => ({
|
|
111
|
+
p: designTokens?.spacing?.padding?.banner ?? 2,
|
|
112
|
+
maxWidth: 720,
|
|
113
|
+
mx: "auto",
|
|
114
|
+
backgroundColor: designTokens?.colors?.background ?? theme.palette.background?.paper,
|
|
115
|
+
color: designTokens?.colors?.text ?? theme.palette.text?.primary,
|
|
116
|
+
borderRadius: designTokens?.spacing?.borderRadius?.banner,
|
|
117
|
+
fontFamily: designTokens?.typography?.fontFamily
|
|
118
|
+
});
|
|
119
|
+
const bannerContent = /* @__PURE__ */ jsx(Paper, { elevation: 3, sx: bannerStyle, ...PaperProps, children: /* @__PURE__ */ jsxs(Stack, { spacing: 1, children: [
|
|
120
|
+
/* @__PURE__ */ jsxs(Typography, { variant: "body2", sx: { fontSize: designTokens?.typography?.fontSize?.banner }, children: [
|
|
121
|
+
texts.bannerMessage,
|
|
122
|
+
" ",
|
|
123
|
+
policyLinkUrl && /* @__PURE__ */ jsx(
|
|
124
|
+
Link,
|
|
125
|
+
{
|
|
126
|
+
href: policyLinkUrl,
|
|
127
|
+
underline: "hover",
|
|
128
|
+
target: "_blank",
|
|
129
|
+
rel: "noopener noreferrer",
|
|
130
|
+
sx: { color: designTokens?.colors?.primary },
|
|
131
|
+
children: texts.policyLink ?? "Saiba mais"
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
] }),
|
|
135
|
+
/* @__PURE__ */ jsxs(Stack, { direction: { xs: "column", sm: "row" }, spacing: 1, justifyContent: "flex-end", children: [
|
|
136
|
+
/* @__PURE__ */ jsx(
|
|
137
|
+
Button,
|
|
138
|
+
{
|
|
139
|
+
variant: "outlined",
|
|
140
|
+
onClick: () => {
|
|
141
|
+
logger.apiUsage("rejectAll", { source: "banner" });
|
|
142
|
+
rejectAll();
|
|
143
|
+
},
|
|
144
|
+
sx: { color: designTokens?.colors?.secondary },
|
|
145
|
+
children: texts.declineAll
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
/* @__PURE__ */ jsx(
|
|
149
|
+
Button,
|
|
150
|
+
{
|
|
151
|
+
variant: "contained",
|
|
152
|
+
onClick: () => {
|
|
153
|
+
logger.apiUsage("acceptAll", { source: "banner" });
|
|
154
|
+
acceptAll();
|
|
155
|
+
},
|
|
156
|
+
sx: { backgroundColor: designTokens?.colors?.primary },
|
|
157
|
+
children: texts.acceptAll
|
|
158
|
+
}
|
|
159
|
+
),
|
|
160
|
+
/* @__PURE__ */ jsx(
|
|
161
|
+
Button,
|
|
162
|
+
{
|
|
163
|
+
variant: "text",
|
|
164
|
+
onClick: () => {
|
|
165
|
+
logger.apiUsage("openPreferences", { source: "banner" });
|
|
166
|
+
openPreferences();
|
|
167
|
+
},
|
|
168
|
+
sx: { color: designTokens?.colors?.text },
|
|
169
|
+
children: texts.preferences
|
|
170
|
+
}
|
|
171
|
+
)
|
|
172
|
+
] }),
|
|
173
|
+
!hideBranding && /* @__PURE__ */ jsx(Branding, { variant: "banner" })
|
|
174
|
+
] }) });
|
|
175
|
+
const positionStyle = {
|
|
176
|
+
position: "fixed",
|
|
177
|
+
zIndex: 1300,
|
|
178
|
+
...designTokens?.layout?.position === "top" ? { top: 0 } : { bottom: 0 },
|
|
179
|
+
left: 0,
|
|
180
|
+
right: 0,
|
|
181
|
+
width: designTokens?.layout?.width?.desktop ?? "100%",
|
|
182
|
+
p: 2
|
|
183
|
+
};
|
|
184
|
+
const backdropToken = designTokens?.layout?.backdrop;
|
|
185
|
+
const resolveBackdropColor = (theme) => {
|
|
186
|
+
if (backdropToken === false) return "transparent";
|
|
187
|
+
if (typeof backdropToken === "string") {
|
|
188
|
+
if (backdropToken.toLowerCase() === "auto") {
|
|
189
|
+
const isDark2 = theme?.palette?.mode === "dark";
|
|
190
|
+
return isDark2 ? "rgba(255, 255, 255, 0.12)" : "rgba(0, 0, 0, 0.4)";
|
|
191
|
+
}
|
|
192
|
+
return backdropToken;
|
|
193
|
+
}
|
|
194
|
+
const isDark = theme?.palette?.mode === "dark";
|
|
195
|
+
return isDark ? "rgba(255, 255, 255, 0.12)" : "rgba(0, 0, 0, 0.4)";
|
|
196
|
+
};
|
|
197
|
+
const isSafeRoute = (() => {
|
|
198
|
+
try {
|
|
199
|
+
if (typeof window === "undefined") return false;
|
|
200
|
+
const current = new URL(window.location.href);
|
|
201
|
+
const safeUrls = [policyLinkUrl, termsLinkUrl].filter(Boolean);
|
|
202
|
+
return safeUrls.some((u) => {
|
|
203
|
+
try {
|
|
204
|
+
const target = new URL(u, current.origin);
|
|
205
|
+
return target.pathname === current.pathname;
|
|
206
|
+
} catch {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
} catch {
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
})();
|
|
214
|
+
const effectiveBlocking = blocking && !isSafeRoute;
|
|
215
|
+
if (effectiveBlocking) {
|
|
216
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
217
|
+
/* @__PURE__ */ jsx(
|
|
218
|
+
Box2,
|
|
219
|
+
{
|
|
220
|
+
sx: (theme) => ({
|
|
221
|
+
position: "fixed",
|
|
222
|
+
top: 0,
|
|
223
|
+
left: 0,
|
|
224
|
+
right: 0,
|
|
225
|
+
bottom: 0,
|
|
226
|
+
backgroundColor: resolveBackdropColor(theme),
|
|
227
|
+
zIndex: 1299
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
/* @__PURE__ */ jsx(Box2, { sx: positionStyle, children: bannerContent })
|
|
232
|
+
] });
|
|
233
|
+
}
|
|
234
|
+
return /* @__PURE__ */ jsx(
|
|
235
|
+
Snackbar,
|
|
236
|
+
{
|
|
237
|
+
open,
|
|
238
|
+
anchorOrigin: {
|
|
239
|
+
vertical: designTokens?.layout?.position === "top" ? "top" : "bottom",
|
|
240
|
+
horizontal: "center"
|
|
241
|
+
},
|
|
242
|
+
...SnackbarProps,
|
|
243
|
+
children: bannerContent
|
|
244
|
+
}
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
function useThemeWithFallbacks() {
|
|
248
|
+
const theme = useTheme();
|
|
249
|
+
logger.themeCompatibility(theme);
|
|
250
|
+
return {
|
|
251
|
+
palette: {
|
|
252
|
+
primary: {
|
|
253
|
+
main: theme?.palette?.primary?.main || "#1976d2",
|
|
254
|
+
dark: theme?.palette?.primary?.dark || "#1565c0"
|
|
255
|
+
}
|
|
256
|
+
},
|
|
257
|
+
transitions: {
|
|
258
|
+
duration: {
|
|
259
|
+
shortest: theme?.transitions?.duration?.shortest || 150,
|
|
260
|
+
short: theme?.transitions?.duration?.short || 250
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
var FloatingPreferencesButton = React3.memo(function FloatingPreferencesButton2({
|
|
266
|
+
position = "bottom-right",
|
|
267
|
+
offset = 24,
|
|
268
|
+
icon = /* @__PURE__ */ jsx(CookieOutlined, {}),
|
|
269
|
+
tooltip,
|
|
270
|
+
FabProps,
|
|
271
|
+
hideWhenConsented = false
|
|
272
|
+
}) {
|
|
273
|
+
const { openPreferences, consented } = useConsent();
|
|
274
|
+
const texts = useConsentTexts();
|
|
275
|
+
const safeTheme = useThemeWithFallbacks();
|
|
276
|
+
const designTokens = useDesignTokens();
|
|
277
|
+
const positionStyles = React3.useMemo(() => {
|
|
278
|
+
const styles = {
|
|
279
|
+
position: "fixed",
|
|
280
|
+
zIndex: 1200
|
|
281
|
+
};
|
|
282
|
+
switch (position) {
|
|
283
|
+
case "bottom-left":
|
|
284
|
+
return { ...styles, bottom: offset, left: offset };
|
|
285
|
+
case "bottom-right":
|
|
286
|
+
return { ...styles, bottom: offset, right: offset };
|
|
287
|
+
case "top-left":
|
|
288
|
+
return { ...styles, top: offset, left: offset };
|
|
289
|
+
case "top-right":
|
|
290
|
+
return { ...styles, top: offset, right: offset };
|
|
291
|
+
default:
|
|
292
|
+
return { ...styles, bottom: offset, right: offset };
|
|
293
|
+
}
|
|
294
|
+
}, [position, offset]);
|
|
295
|
+
logger.componentRender("FloatingPreferencesButton", {
|
|
296
|
+
position,
|
|
297
|
+
offset,
|
|
298
|
+
hideWhenConsented,
|
|
299
|
+
consented
|
|
300
|
+
});
|
|
301
|
+
if (hideWhenConsented && consented) {
|
|
302
|
+
logger.debug(
|
|
303
|
+
"FloatingPreferencesButton: Hidden due to hideWhenConsented=true and consented=true"
|
|
304
|
+
);
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
const tooltipText = tooltip ?? texts.preferencesButton ?? "Gerenciar Prefer\xEAncias de Cookies";
|
|
308
|
+
return /* @__PURE__ */ jsx(Tooltip, { title: tooltipText, placement: "top", children: /* @__PURE__ */ jsx(
|
|
309
|
+
Fab,
|
|
310
|
+
{
|
|
311
|
+
size: "medium",
|
|
312
|
+
color: "primary",
|
|
313
|
+
onClick: openPreferences,
|
|
314
|
+
sx: {
|
|
315
|
+
...positionStyles,
|
|
316
|
+
backgroundColor: designTokens?.colors?.primary ?? safeTheme.palette.primary.main,
|
|
317
|
+
"&:hover": {
|
|
318
|
+
backgroundColor: designTokens?.colors?.primary ? designTokens?.colors?.primary : safeTheme.palette.primary.dark
|
|
319
|
+
},
|
|
320
|
+
transition: `all ${safeTheme.transitions.duration.short}ms`
|
|
321
|
+
},
|
|
322
|
+
"aria-label": tooltipText,
|
|
323
|
+
...FabProps,
|
|
324
|
+
children: icon
|
|
325
|
+
}
|
|
326
|
+
) });
|
|
327
|
+
});
|
|
328
|
+
function PreferencesModal({
|
|
329
|
+
DialogProps: DialogProps2,
|
|
330
|
+
hideBranding = false,
|
|
331
|
+
isModalOpen: isModalOpenProp,
|
|
332
|
+
preferences: preferencesProp,
|
|
333
|
+
setPreferences: setPreferencesProp,
|
|
334
|
+
closePreferences: closePreferencesProp
|
|
335
|
+
}) {
|
|
336
|
+
const hookValue = useConsent();
|
|
337
|
+
const preferences = preferencesProp ?? hookValue.preferences;
|
|
338
|
+
const setPreferences = setPreferencesProp ?? hookValue.setPreferences;
|
|
339
|
+
const closePreferences = closePreferencesProp ?? hookValue.closePreferences;
|
|
340
|
+
const isModalOpen = isModalOpenProp ?? hookValue.isModalOpen;
|
|
341
|
+
const texts = useConsentTexts();
|
|
342
|
+
const designTokens = useDesignTokens();
|
|
343
|
+
const { toggleableCategories, allCategories } = useCategories();
|
|
344
|
+
const getInitialPreferences = React3.useCallback(() => {
|
|
345
|
+
const syncedPrefs = { necessary: true };
|
|
346
|
+
toggleableCategories.forEach((category) => {
|
|
347
|
+
syncedPrefs[category.id] = preferences[category.id] ?? false;
|
|
348
|
+
});
|
|
349
|
+
return syncedPrefs;
|
|
350
|
+
}, [preferences, toggleableCategories]);
|
|
351
|
+
const [tempPreferences, setTempPreferences] = React3.useState(getInitialPreferences);
|
|
352
|
+
const wasOpenRef = React3.useRef(isModalOpen);
|
|
353
|
+
React3.useEffect(() => {
|
|
354
|
+
const justOpened = isModalOpen && !wasOpenRef.current;
|
|
355
|
+
wasOpenRef.current = isModalOpen;
|
|
356
|
+
if (justOpened) {
|
|
357
|
+
queueMicrotask(() => {
|
|
358
|
+
setTempPreferences(getInitialPreferences());
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}, [isModalOpen, getInitialPreferences]);
|
|
362
|
+
const open = DialogProps2?.open ?? isModalOpen ?? false;
|
|
363
|
+
const handleSave = () => {
|
|
364
|
+
setPreferences(tempPreferences);
|
|
365
|
+
};
|
|
366
|
+
const handleCancel = () => {
|
|
367
|
+
setTempPreferences(preferences);
|
|
368
|
+
closePreferences();
|
|
369
|
+
};
|
|
370
|
+
const modalTitleSx = (theme) => ({
|
|
371
|
+
fontSize: designTokens?.typography?.fontSize?.modal ?? void 0,
|
|
372
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
373
|
+
});
|
|
374
|
+
const modalContentSx = (theme) => ({
|
|
375
|
+
p: designTokens?.spacing?.padding?.modal ?? void 0,
|
|
376
|
+
backgroundColor: designTokens?.colors?.background ?? theme.palette.background.paper,
|
|
377
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
378
|
+
});
|
|
379
|
+
return /* @__PURE__ */ jsxs(Dialog, { "aria-labelledby": "cookie-pref-title", open, onClose: handleCancel, ...DialogProps2, children: [
|
|
380
|
+
/* @__PURE__ */ jsx(DialogTitle, { id: "cookie-pref-title", sx: modalTitleSx, children: texts.modalTitle }),
|
|
381
|
+
/* @__PURE__ */ jsxs(DialogContent, { dividers: true, sx: modalContentSx, children: [
|
|
382
|
+
/* @__PURE__ */ jsx(
|
|
383
|
+
Typography,
|
|
384
|
+
{
|
|
385
|
+
variant: "body2",
|
|
386
|
+
sx: (theme) => ({
|
|
387
|
+
mb: 2,
|
|
388
|
+
fontSize: designTokens?.typography?.fontSize?.modal ?? void 0,
|
|
389
|
+
color: designTokens?.colors?.text ?? theme.palette.text.primary
|
|
390
|
+
}),
|
|
391
|
+
children: texts.modalIntro
|
|
392
|
+
}
|
|
393
|
+
),
|
|
394
|
+
/* @__PURE__ */ jsxs(FormGroup, { children: [
|
|
395
|
+
toggleableCategories.map((category) => {
|
|
396
|
+
const full = allCategories.find((c) => c.id === category.id);
|
|
397
|
+
const namesFromGuidance = full?.cookies ?? [];
|
|
398
|
+
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
399
|
+
const descriptors = getCookiesInfoForCategory(category.id, used);
|
|
400
|
+
const enrichedDescriptors = descriptors.map((desc) => {
|
|
401
|
+
if (desc.purpose && desc.duration && desc.provider) {
|
|
402
|
+
return desc;
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
name: desc.name,
|
|
406
|
+
purpose: desc.purpose || "-",
|
|
407
|
+
duration: desc.duration || "-",
|
|
408
|
+
provider: desc.provider || "-"
|
|
409
|
+
};
|
|
410
|
+
});
|
|
411
|
+
const merged = [
|
|
412
|
+
...enrichedDescriptors,
|
|
413
|
+
...namesFromGuidance.filter((n) => !enrichedDescriptors.find((d) => d.name === n)).map((n) => ({ name: n, purpose: "-", duration: "-", provider: "-" }))
|
|
414
|
+
];
|
|
415
|
+
let mergedFinal = merged;
|
|
416
|
+
try {
|
|
417
|
+
if (merged.length === 0) {
|
|
418
|
+
const gmap = globalThis.__LGPD_INTEGRATIONS_MAP__ || {};
|
|
419
|
+
const scriptRows = Object.entries(gmap).filter(([, cat]) => cat === category.id).map(([id]) => ({
|
|
420
|
+
name: `(script) ${id}`,
|
|
421
|
+
purpose: "Script de integra\xE7\xE3o ativo",
|
|
422
|
+
duration: "-",
|
|
423
|
+
provider: "-"
|
|
424
|
+
}));
|
|
425
|
+
if (scriptRows.length > 0) mergedFinal = scriptRows;
|
|
426
|
+
}
|
|
427
|
+
} catch {
|
|
428
|
+
}
|
|
429
|
+
return /* @__PURE__ */ jsxs(Box2, { sx: { mb: 1 }, children: [
|
|
430
|
+
/* @__PURE__ */ jsx(
|
|
431
|
+
FormControlLabel,
|
|
432
|
+
{
|
|
433
|
+
control: /* @__PURE__ */ jsx(
|
|
434
|
+
Switch,
|
|
435
|
+
{
|
|
436
|
+
checked: tempPreferences[category.id] ?? false,
|
|
437
|
+
onChange: (e) => setTempPreferences((prev) => ({
|
|
438
|
+
...prev,
|
|
439
|
+
[category.id]: e.target.checked
|
|
440
|
+
}))
|
|
441
|
+
}
|
|
442
|
+
),
|
|
443
|
+
label: `${category.name} - ${category.description}`
|
|
444
|
+
}
|
|
445
|
+
),
|
|
446
|
+
/* @__PURE__ */ jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
447
|
+
/* @__PURE__ */ jsx("summary", { children: "Ver detalhes" }),
|
|
448
|
+
/* @__PURE__ */ jsx(Box2, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
449
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
450
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
451
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
452
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
453
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Fornecedor" })
|
|
454
|
+
] }) }),
|
|
455
|
+
/* @__PURE__ */ jsx("tbody", { children: mergedFinal.map((d, idx) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
456
|
+
/* @__PURE__ */ jsx("td", { children: d.name }),
|
|
457
|
+
/* @__PURE__ */ jsx("td", { children: d.purpose }),
|
|
458
|
+
/* @__PURE__ */ jsx("td", { children: d.duration }),
|
|
459
|
+
/* @__PURE__ */ jsx("td", { children: d.provider })
|
|
460
|
+
] }, d.name + idx)) })
|
|
461
|
+
] }) })
|
|
462
|
+
] })
|
|
463
|
+
] }, category.id);
|
|
464
|
+
}),
|
|
465
|
+
/* @__PURE__ */ jsx(FormControlLabel, { control: /* @__PURE__ */ jsx(Switch, { checked: true, disabled: true }), label: texts.necessaryAlwaysOn }),
|
|
466
|
+
/* @__PURE__ */ jsxs("details", { style: { marginLeft: 48 }, children: [
|
|
467
|
+
/* @__PURE__ */ jsx("summary", { children: "Ver detalhes" }),
|
|
468
|
+
/* @__PURE__ */ jsx(Box2, { sx: { mt: 1 }, children: /* @__PURE__ */ jsxs("table", { style: { width: "100%", borderCollapse: "collapse" }, children: [
|
|
469
|
+
/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
|
|
470
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Cookie" }),
|
|
471
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Finalidade" }),
|
|
472
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Dura\xE7\xE3o" }),
|
|
473
|
+
/* @__PURE__ */ jsx("th", { style: { textAlign: "left" }, children: "Fornecedor" })
|
|
474
|
+
] }) }),
|
|
475
|
+
/* @__PURE__ */ jsx("tbody", { children: (() => {
|
|
476
|
+
const used = globalThis.__LGPD_USED_INTEGRATIONS__ || [];
|
|
477
|
+
const necessaryCookies = getCookiesInfoForCategory(
|
|
478
|
+
"necessary",
|
|
479
|
+
used
|
|
480
|
+
);
|
|
481
|
+
return necessaryCookies.map((d, idx) => /* @__PURE__ */ jsxs("tr", { children: [
|
|
482
|
+
/* @__PURE__ */ jsx("td", { children: d.name }),
|
|
483
|
+
/* @__PURE__ */ jsx("td", { children: d.purpose || "-" }),
|
|
484
|
+
/* @__PURE__ */ jsx("td", { children: d.duration || "-" }),
|
|
485
|
+
/* @__PURE__ */ jsx("td", { children: d.provider || "-" })
|
|
486
|
+
] }, d.name + idx));
|
|
487
|
+
})() })
|
|
488
|
+
] }) })
|
|
489
|
+
] })
|
|
490
|
+
] })
|
|
491
|
+
] }),
|
|
492
|
+
/* @__PURE__ */ jsxs(DialogActions, { children: [
|
|
493
|
+
/* @__PURE__ */ jsx(Button, { variant: "outlined", onClick: handleCancel, children: texts.close }),
|
|
494
|
+
/* @__PURE__ */ jsx(Button, { variant: "contained", onClick: handleSave, children: texts.save })
|
|
495
|
+
] }),
|
|
496
|
+
!hideBranding && /* @__PURE__ */ jsx(Branding, { variant: "modal" })
|
|
497
|
+
] });
|
|
498
|
+
}
|
|
499
|
+
function ConsentProvider({
|
|
500
|
+
disableDefaultModal = false,
|
|
501
|
+
disableDefaultBanner = false,
|
|
502
|
+
disableDefaultFloatingButton = false,
|
|
503
|
+
PreferencesModalComponent,
|
|
504
|
+
CookieBannerComponent,
|
|
505
|
+
FloatingPreferencesButtonComponent,
|
|
506
|
+
theme,
|
|
507
|
+
hideBranding,
|
|
508
|
+
cookieBannerProps,
|
|
509
|
+
preferencesModalProps,
|
|
510
|
+
floatingPreferencesButtonProps,
|
|
511
|
+
children,
|
|
512
|
+
...coreProps
|
|
513
|
+
}) {
|
|
514
|
+
const modalComponent = disableDefaultModal ? PreferencesModalComponent : PreferencesModalComponent || PreferencesModal;
|
|
515
|
+
const bannerComponent = disableDefaultBanner ? CookieBannerComponent : CookieBannerComponent || CookieBanner;
|
|
516
|
+
const floatingButtonComponent = disableDefaultFloatingButton ? FloatingPreferencesButtonComponent : FloatingPreferencesButtonComponent || FloatingPreferencesButton;
|
|
517
|
+
const mergedCookieBannerProps = {
|
|
518
|
+
...cookieBannerProps,
|
|
519
|
+
hideBranding: cookieBannerProps?.hideBranding ?? hideBranding
|
|
520
|
+
};
|
|
521
|
+
const mergedPreferencesModalProps = {
|
|
522
|
+
...preferencesModalProps,
|
|
523
|
+
hideBranding: preferencesModalProps?.hideBranding ?? hideBranding
|
|
524
|
+
};
|
|
525
|
+
const provider = /* @__PURE__ */ jsx(
|
|
526
|
+
ConsentProvider$1,
|
|
527
|
+
{
|
|
528
|
+
...coreProps,
|
|
529
|
+
hideBranding,
|
|
530
|
+
cookieBannerProps: mergedCookieBannerProps,
|
|
531
|
+
preferencesModalProps: mergedPreferencesModalProps,
|
|
532
|
+
floatingPreferencesButtonProps,
|
|
533
|
+
CookieBannerComponent: bannerComponent,
|
|
534
|
+
PreferencesModalComponent: modalComponent,
|
|
535
|
+
FloatingPreferencesButtonComponent: floatingButtonComponent,
|
|
536
|
+
children
|
|
537
|
+
}
|
|
538
|
+
);
|
|
539
|
+
if (!theme) return provider;
|
|
540
|
+
return /* @__PURE__ */ jsx(ThemeProvider, { theme, children: provider });
|
|
541
|
+
}
|
|
542
|
+
ConsentProvider.displayName = "ConsentProvider(MUI)";
|
|
543
|
+
|
|
544
|
+
export { Branding, ConsentProvider, CookieBanner, FloatingPreferencesButton, PreferencesModal };
|
package/package.json
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@react-lgpd-consent/mui",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Componentes Material-UI prontos para gerenciamento de consentimento LGPD/ANPD",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"lgpd",
|
|
7
|
+
"anpd",
|
|
8
|
+
"consent",
|
|
9
|
+
"cookies",
|
|
10
|
+
"react",
|
|
11
|
+
"typescript",
|
|
12
|
+
"material-ui",
|
|
13
|
+
"mui",
|
|
14
|
+
"privacy",
|
|
15
|
+
"gdpr",
|
|
16
|
+
"acessibilidade",
|
|
17
|
+
"ui-components"
|
|
18
|
+
],
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "Luciano Édipo",
|
|
21
|
+
"email": "luciano.psilva@anpd.gov.br",
|
|
22
|
+
"url": "https://github.com/lucianoedipo"
|
|
23
|
+
},
|
|
24
|
+
"license": "MIT",
|
|
25
|
+
"type": "module",
|
|
26
|
+
"main": "dist/index.cjs",
|
|
27
|
+
"module": "dist/index.js",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"import": "./dist/index.js",
|
|
33
|
+
"require": "./dist/index.cjs"
|
|
34
|
+
},
|
|
35
|
+
"./package.json": "./package.json"
|
|
36
|
+
},
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"files": [
|
|
39
|
+
"dist",
|
|
40
|
+
"README.md",
|
|
41
|
+
"LICENSE"
|
|
42
|
+
],
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
},
|
|
46
|
+
"engines": {
|
|
47
|
+
"node": ">=20.0.0"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"@mui/material": "^7.0.0 || ^6.0.0 || ^5.15.0",
|
|
51
|
+
"@mui/icons-material": "^7.0.0 || ^6.0.0 || ^5.15.0",
|
|
52
|
+
"react": "^18.2.0 || ^19.0.0",
|
|
53
|
+
"react-dom": "^18.2.0 || ^19.0.0"
|
|
54
|
+
},
|
|
55
|
+
"peerDependenciesMeta": {
|
|
56
|
+
"@mui/icons-material": {
|
|
57
|
+
"optional": true
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@react-lgpd-consent/core": "^0.5.0"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"clean": "rimraf dist",
|
|
65
|
+
"build": "cross-env NODE_ENV=production tsup src/index.ts --format esm,cjs --dts --clean",
|
|
66
|
+
"dev": "cross-env NODE_ENV=development tsup src/index.ts --format esm,cjs --dts --watch",
|
|
67
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\" --cache",
|
|
68
|
+
"lint:ci": "eslint \"src/**/*.{ts,tsx}\" --cache --max-warnings=0",
|
|
69
|
+
"format": "prettier --write \"src/**/*.{ts,tsx,json,md}\"",
|
|
70
|
+
"type-check": "tsc --noEmit",
|
|
71
|
+
"test": "jest --config ../../jest.config.mjs"
|
|
72
|
+
}
|
|
73
|
+
}
|