react-lgpd-consent 0.4.1 → 0.4.3

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.
@@ -0,0 +1,92 @@
1
+ import { useConsent, useConsentTexts, useDesignTokens, logger } from './chunk-RWT2ORFE.js';
2
+ import CookieOutlined from '@mui/icons-material/CookieOutlined';
3
+ import Fab from '@mui/material/Fab';
4
+ import Tooltip from '@mui/material/Tooltip';
5
+ import { useTheme } from '@mui/material/styles';
6
+ import * as React from 'react';
7
+ import { jsx } from 'react/jsx-runtime';
8
+
9
+ // react-lgpd-consent - Tree-shakeable ESM build
10
+ function useThemeWithFallbacks() {
11
+ const theme = useTheme();
12
+ logger.themeCompatibility(theme);
13
+ return {
14
+ palette: {
15
+ primary: {
16
+ main: theme?.palette?.primary?.main || "#1976d2",
17
+ dark: theme?.palette?.primary?.dark || "#1565c0"
18
+ }
19
+ },
20
+ transitions: {
21
+ duration: {
22
+ shortest: theme?.transitions?.duration?.shortest || 150,
23
+ short: theme?.transitions?.duration?.short || 250
24
+ }
25
+ }
26
+ };
27
+ }
28
+ var FloatingPreferencesButton = React.memo(function FloatingPreferencesButton2({
29
+ position = "bottom-right",
30
+ offset = 24,
31
+ icon = /* @__PURE__ */ jsx(CookieOutlined, {}),
32
+ tooltip,
33
+ FabProps,
34
+ hideWhenConsented = false
35
+ }) {
36
+ const { openPreferences, consented } = useConsent();
37
+ const texts = useConsentTexts();
38
+ const safeTheme = useThemeWithFallbacks();
39
+ const designTokens = useDesignTokens();
40
+ const positionStyles = React.useMemo(() => {
41
+ const styles = {
42
+ position: "fixed",
43
+ zIndex: 1200
44
+ };
45
+ switch (position) {
46
+ case "bottom-left":
47
+ return { ...styles, bottom: offset, left: offset };
48
+ case "bottom-right":
49
+ return { ...styles, bottom: offset, right: offset };
50
+ case "top-left":
51
+ return { ...styles, top: offset, left: offset };
52
+ case "top-right":
53
+ return { ...styles, top: offset, right: offset };
54
+ default:
55
+ return { ...styles, bottom: offset, right: offset };
56
+ }
57
+ }, [position, offset]);
58
+ logger.componentRender("FloatingPreferencesButton", {
59
+ position,
60
+ offset,
61
+ hideWhenConsented,
62
+ consented
63
+ });
64
+ if (hideWhenConsented && consented) {
65
+ logger.debug(
66
+ "FloatingPreferencesButton: Hidden due to hideWhenConsented=true and consented=true"
67
+ );
68
+ return null;
69
+ }
70
+ const tooltipText = tooltip ?? texts.preferencesButton ?? "Gerenciar Prefer\xEAncias de Cookies";
71
+ return /* @__PURE__ */ jsx(Tooltip, { title: tooltipText, placement: "top", children: /* @__PURE__ */ jsx(
72
+ Fab,
73
+ {
74
+ size: "medium",
75
+ color: "primary",
76
+ onClick: openPreferences,
77
+ sx: {
78
+ ...positionStyles,
79
+ backgroundColor: designTokens?.colors?.primary ?? safeTheme.palette.primary.main,
80
+ "&:hover": {
81
+ backgroundColor: designTokens?.colors?.primary ? designTokens?.colors?.primary : safeTheme.palette.primary.dark
82
+ },
83
+ transition: `all ${safeTheme.transitions.duration.short}ms`
84
+ },
85
+ "aria-label": tooltipText,
86
+ ...FabProps,
87
+ children: icon
88
+ }
89
+ ) });
90
+ });
91
+
92
+ export { FloatingPreferencesButton };