react-lgpd-consent 0.3.3 → 0.3.4
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/CHANGELOG.md +59 -2
- package/QUICKSTART.en.md +245 -0
- package/QUICKSTART.md +596 -0
- package/README.en.md +86 -0
- package/README.md +30 -88
- package/dist/{PreferencesModal-HTTMUZND.js → PreferencesModal-XYBFROAB.js} +1 -1
- package/dist/{chunk-GPLNN3FD.js → chunk-7D2F6JFW.js} +69 -11
- package/dist/index.cjs +71 -10
- package/dist/index.d.cts +25 -3
- package/dist/index.d.ts +25 -3
- package/dist/index.js +1 -1
- package/package.json +33 -17
package/QUICKSTART.md
ADDED
|
@@ -0,0 +1,596 @@
|
|
|
1
|
+
# 🚀 Guia de Início Rápido
|
|
2
|
+
|
|
3
|
+
Este guia fornece tudo o que você precisa para integrar rapidamente a biblioteca `react-lgpd-consent` em seu projeto React.
|
|
4
|
+
|
|
5
|
+
## 📦 Instalação
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install react-lgpd-consent
|
|
9
|
+
# ou
|
|
10
|
+
yarn add react-lgpd-consent
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Dependências Peer
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @mui/material @mui/icons-material @emotion/react @emotion/styled
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 🎯 Uso Básico (30 segundos)
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
import React from 'react'
|
|
23
|
+
import { ConsentProvider } from 'react-lgpd-consent'
|
|
24
|
+
|
|
25
|
+
function App() {
|
|
26
|
+
return (
|
|
27
|
+
<ConsentProvider
|
|
28
|
+
categories={{
|
|
29
|
+
enabledCategories: ['analytics', 'marketing'],
|
|
30
|
+
}}
|
|
31
|
+
>
|
|
32
|
+
<main>
|
|
33
|
+
<h1>Minha Aplicação</h1>
|
|
34
|
+
{/* Seu conteúdo aqui */}
|
|
35
|
+
</main>
|
|
36
|
+
</ConsentProvider>
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
## 🧭 Storybook — quick note
|
|
40
|
+
|
|
41
|
+
This repository ships an interactive Storybook playground used for manual testing and visual exploration of components. Quick commands:
|
|
42
|
+
|
|
43
|
+
- Run locally (development):
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npm run storybook
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- Build static Storybook (for publishing to GitHub Pages):
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm run build-storybook
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Notes:
|
|
56
|
+
- The Storybook preview (`.storybook/preview.tsx`) applies a clean environment between stories (removes consent cookie and performs defensive DOM cleanup). Check that file when creating stories that rely on a clean initial state.
|
|
57
|
+
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default App
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## 📋 Tabela Completa de Props do ConsentProvider
|
|
64
|
+
|
|
65
|
+
| Prop | Tipo | Obrigatória | Padrão | Descrição |
|
|
66
|
+
| ------------------------------------ | ----------------------------------------------------------- | ----------- | ------------------- | ---------------------------------------------- |
|
|
67
|
+
| `categories` | `ProjectCategoriesConfig` | ✅ **Sim** | - | Define as categorias de cookies do projeto |
|
|
68
|
+
| `texts` | `Partial<ConsentTexts>` | ❌ Não | Textos padrão PT-BR | Customiza textos da interface |
|
|
69
|
+
| `theme` | `any` | ❌ Não | Tema padrão | Tema Material-UI para os componentes |
|
|
70
|
+
| `designTokens` | `DesignTokens` | ❌ Não | Tokens padrão | Tokens de design para customização avançada |
|
|
71
|
+
| `blocking` | `boolean` | ❌ Não | `false` | Exibe overlay bloqueando interação até decisão |
|
|
72
|
+
| `blockingStrategy` | `'auto' \| 'provider'` | ❌ Não | `'auto'` | Estratégia de renderização do overlay |
|
|
73
|
+
| `hideBranding` | `boolean` | ❌ Não | `false` | Oculta branding "fornecido por" |
|
|
74
|
+
| `onConsentGiven` | `(state: ConsentState) => void` | ❌ Não | - | Callback na primeira vez que usuário consente |
|
|
75
|
+
| `onPreferencesSaved` | `(prefs: ConsentPreferences) => void` | ❌ Não | - | Callback quando preferências são salvas |
|
|
76
|
+
| `disableDeveloperGuidance` | `boolean` | ❌ Não | `false` | Desativa orientações no console |
|
|
77
|
+
| `disableFloatingPreferencesButton` | `boolean` | ❌ Não | `false` | Desabilita botão flutuante de preferências |
|
|
78
|
+
| `CookieBannerComponent` | `React.ComponentType<CustomCookieBannerProps>` | ❌ Não | Banner padrão | Componente de banner customizado |
|
|
79
|
+
| `PreferencesModalComponent` | `React.ComponentType<CustomPreferencesModalProps>` | ❌ Não | Modal padrão | Componente de modal customizado |
|
|
80
|
+
| `FloatingPreferencesButtonComponent` | `React.ComponentType<CustomFloatingPreferencesButtonProps>` | ❌ Não | Botão padrão | Componente de botão flutuante customizado |
|
|
81
|
+
| `cookieBannerProps` | `object` | ❌ Não | `{}` | Props adicionais para o banner |
|
|
82
|
+
| `preferencesModalProps` | `object` | ❌ Não | `{}` | Props adicionais para o modal |
|
|
83
|
+
| `floatingPreferencesButtonProps` | `object` | ❌ Não | `{}` | Props adicionais para o botão flutuante |
|
|
84
|
+
| `initialState` | `ConsentState` | ❌ Não | - | Estado inicial para hidratação SSR |
|
|
85
|
+
| `cookie` | `Partial<ConsentCookieOptions>` | ❌ Não | Opções padrão | Configurações do cookie de consentimento |
|
|
86
|
+
|
|
87
|
+
## 🎨 Componentes Customizados com TypeScript
|
|
88
|
+
|
|
89
|
+
### Banner Personalizado
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
import React from 'react'
|
|
93
|
+
import { ConsentProvider, type CustomCookieBannerProps } from 'react-lgpd-consent'
|
|
94
|
+
|
|
95
|
+
// Componente de banner customizado
|
|
96
|
+
const MeuBannerCustomizado: React.FC<CustomCookieBannerProps> = ({
|
|
97
|
+
consented,
|
|
98
|
+
acceptAll,
|
|
99
|
+
rejectAll,
|
|
100
|
+
openPreferences,
|
|
101
|
+
texts,
|
|
102
|
+
blocking,
|
|
103
|
+
}) => {
|
|
104
|
+
return (
|
|
105
|
+
<div
|
|
106
|
+
style={{
|
|
107
|
+
position: 'fixed',
|
|
108
|
+
bottom: 0,
|
|
109
|
+
left: 0,
|
|
110
|
+
right: 0,
|
|
111
|
+
backgroundColor: blocking ? 'red' : 'blue',
|
|
112
|
+
color: 'white',
|
|
113
|
+
padding: '1rem',
|
|
114
|
+
zIndex: 1000,
|
|
115
|
+
}}
|
|
116
|
+
>
|
|
117
|
+
<p>{texts.bannerMessage}</p>
|
|
118
|
+
<div style={{ display: 'flex', gap: '1rem', marginTop: '1rem' }}>
|
|
119
|
+
<button onClick={acceptAll}>{texts.acceptAll}</button>
|
|
120
|
+
<button onClick={rejectAll}>{texts.declineAll}</button>
|
|
121
|
+
<button onClick={openPreferences}>{texts.preferences}</button>
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Usando o banner customizado
|
|
128
|
+
function App() {
|
|
129
|
+
return (
|
|
130
|
+
<ConsentProvider
|
|
131
|
+
categories={{ enabledCategories: ['analytics'] }}
|
|
132
|
+
CookieBannerComponent={MeuBannerCustomizado}
|
|
133
|
+
blocking={true}
|
|
134
|
+
>
|
|
135
|
+
<main>Minha App</main>
|
|
136
|
+
</ConsentProvider>
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### Modal de Preferências Personalizado
|
|
142
|
+
|
|
143
|
+
```tsx
|
|
144
|
+
import React from 'react'
|
|
145
|
+
import { ConsentProvider, type CustomPreferencesModalProps } from 'react-lgpd-consent'
|
|
146
|
+
|
|
147
|
+
const MeuModalCustomizado: React.FC<CustomPreferencesModalProps> = ({
|
|
148
|
+
preferences,
|
|
149
|
+
setPreferences,
|
|
150
|
+
closePreferences,
|
|
151
|
+
isModalOpen,
|
|
152
|
+
texts,
|
|
153
|
+
}) => {
|
|
154
|
+
if (!isModalOpen) return null
|
|
155
|
+
|
|
156
|
+
return (
|
|
157
|
+
<div
|
|
158
|
+
style={{
|
|
159
|
+
position: 'fixed',
|
|
160
|
+
top: '50%',
|
|
161
|
+
left: '50%',
|
|
162
|
+
transform: 'translate(-50%, -50%)',
|
|
163
|
+
backgroundColor: 'white',
|
|
164
|
+
border: '2px solid #ccc',
|
|
165
|
+
borderRadius: '8px',
|
|
166
|
+
padding: '2rem',
|
|
167
|
+
zIndex: 2000,
|
|
168
|
+
minWidth: '400px',
|
|
169
|
+
}}
|
|
170
|
+
>
|
|
171
|
+
<h2>{texts.modalTitle}</h2>
|
|
172
|
+
<p>{texts.modalIntro}</p>
|
|
173
|
+
|
|
174
|
+
{/* Lista de categorias */}
|
|
175
|
+
<div style={{ margin: '1rem 0' }}>
|
|
176
|
+
{Object.entries(preferences).map(([category, enabled]) => (
|
|
177
|
+
<label key={category} style={{ display: 'block', marginBottom: '0.5rem' }}>
|
|
178
|
+
<input
|
|
179
|
+
type="checkbox"
|
|
180
|
+
checked={enabled}
|
|
181
|
+
onChange={(e) =>
|
|
182
|
+
setPreferences({
|
|
183
|
+
...preferences,
|
|
184
|
+
[category]: e.target.checked,
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
disabled={category === 'necessary'}
|
|
188
|
+
/>{' '}
|
|
189
|
+
{category === 'necessary' ? texts.necessaryAlwaysOn : `Cookies ${category}`}
|
|
190
|
+
</label>
|
|
191
|
+
))}
|
|
192
|
+
</div>
|
|
193
|
+
|
|
194
|
+
<div style={{ display: 'flex', gap: '1rem', justifyContent: 'flex-end' }}>
|
|
195
|
+
<button onClick={closePreferences}>Cancelar</button>
|
|
196
|
+
<button onClick={closePreferences}>{texts.save}</button>
|
|
197
|
+
</div>
|
|
198
|
+
</div>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function App() {
|
|
203
|
+
return (
|
|
204
|
+
<ConsentProvider
|
|
205
|
+
categories={{ enabledCategories: ['analytics', 'marketing'] }}
|
|
206
|
+
PreferencesModalComponent={MeuModalCustomizado}
|
|
207
|
+
>
|
|
208
|
+
<main>Minha App</main>
|
|
209
|
+
</ConsentProvider>
|
|
210
|
+
)
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## 🎮 Controle Programático
|
|
215
|
+
|
|
216
|
+
### Hook useOpenPreferencesModal (React)
|
|
217
|
+
|
|
218
|
+
```tsx
|
|
219
|
+
import React from 'react'
|
|
220
|
+
import { useOpenPreferencesModal, useConsent } from 'react-lgpd-consent'
|
|
221
|
+
|
|
222
|
+
function MeuComponente() {
|
|
223
|
+
const openPreferences = useOpenPreferencesModal()
|
|
224
|
+
const { preferences, acceptAll, rejectAll } = useConsent()
|
|
225
|
+
|
|
226
|
+
return (
|
|
227
|
+
<div>
|
|
228
|
+
<h3>Status atual: {preferences.analytics ? 'Analytics ativo' : 'Analytics inativo'}</h3>
|
|
229
|
+
|
|
230
|
+
<button onClick={openPreferences}>⚙️ Gerenciar Preferências</button>
|
|
231
|
+
|
|
232
|
+
<button onClick={acceptAll}>✅ Aceitar Todos</button>
|
|
233
|
+
|
|
234
|
+
<button onClick={rejectAll}>❌ Recusar Todos</button>
|
|
235
|
+
</div>
|
|
236
|
+
)
|
|
237
|
+
}
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### window.openPreferencesModal (JavaScript Puro)
|
|
241
|
+
|
|
242
|
+
```html
|
|
243
|
+
<!-- Em templates HTML, emails ou widgets externos -->
|
|
244
|
+
<button onclick="window.openPreferencesModal?.()">Configurar Cookies</button>
|
|
245
|
+
|
|
246
|
+
<script>
|
|
247
|
+
// Ou em JavaScript puro
|
|
248
|
+
function abrirConfiguracoesCookies() {
|
|
249
|
+
if (window.openPreferencesModal) {
|
|
250
|
+
window.openPreferencesModal()
|
|
251
|
+
} else {
|
|
252
|
+
console.warn('Sistema de consentimento não carregado')
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// Verificar se função está disponível
|
|
257
|
+
if (typeof window.openPreferencesModal === 'function') {
|
|
258
|
+
console.log('✅ Sistema de consentimento disponível')
|
|
259
|
+
}
|
|
260
|
+
</script>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## 🐛 Sistema de Debug
|
|
264
|
+
|
|
265
|
+
### Configuração de Debug
|
|
266
|
+
|
|
267
|
+
```tsx
|
|
268
|
+
import { setDebugLogging, LogLevel } from 'react-lgpd-consent'
|
|
269
|
+
|
|
270
|
+
// Ativar todos os logs (desenvolvimento)
|
|
271
|
+
setDebugLogging(true, LogLevel.DEBUG)
|
|
272
|
+
|
|
273
|
+
// Apenas logs importantes (staging)
|
|
274
|
+
setDebugLogging(true, LogLevel.INFO)
|
|
275
|
+
|
|
276
|
+
// Apenas erros (produção)
|
|
277
|
+
setDebugLogging(true, LogLevel.ERROR)
|
|
278
|
+
|
|
279
|
+
// Desativar completamente
|
|
280
|
+
setDebugLogging(false)
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Exemplo de Logs no Console
|
|
284
|
+
|
|
285
|
+
```jsx
|
|
286
|
+
// Em desenvolvimento, você verá logs como:
|
|
287
|
+
// [🍪 LGPD-CONSENT] 🔧 Categorias Ativas (para UI customizada)
|
|
288
|
+
// [🍪 LGPD-CONSENT] ℹ️ User accepted all cookies
|
|
289
|
+
// [🍪 LGPD-CONSENT] 🐛 Category preference changed: analytics = true
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Hook para Debug Runtime
|
|
293
|
+
|
|
294
|
+
```tsx
|
|
295
|
+
import { useConsent } from 'react-lgpd-consent'
|
|
296
|
+
|
|
297
|
+
function DebugPanel() {
|
|
298
|
+
const { preferences, consented } = useConsent()
|
|
299
|
+
|
|
300
|
+
// Apenas mostrar em desenvolvimento
|
|
301
|
+
if (process.env.NODE_ENV !== 'development') return null
|
|
302
|
+
|
|
303
|
+
return (
|
|
304
|
+
<div
|
|
305
|
+
style={{
|
|
306
|
+
position: 'fixed',
|
|
307
|
+
top: 0,
|
|
308
|
+
right: 0,
|
|
309
|
+
background: 'rgba(0,0,0,0.8)',
|
|
310
|
+
color: 'white',
|
|
311
|
+
padding: '1rem',
|
|
312
|
+
fontSize: '12px',
|
|
313
|
+
fontFamily: 'monospace',
|
|
314
|
+
}}
|
|
315
|
+
>
|
|
316
|
+
<h4>🍪 Debug LGPD</h4>
|
|
317
|
+
<p>Consentimento: {consented ? '✅' : '❌'}</p>
|
|
318
|
+
<pre>{JSON.stringify(preferences, null, 2)}</pre>
|
|
319
|
+
</div>
|
|
320
|
+
)
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
## 🎨 Integração com Material-UI ThemeProvider
|
|
325
|
+
|
|
326
|
+
### Configuração Completa
|
|
327
|
+
|
|
328
|
+
```tsx
|
|
329
|
+
import React from 'react'
|
|
330
|
+
import { ThemeProvider, createTheme } from '@mui/material/styles'
|
|
331
|
+
import CssBaseline from '@mui/material/CssBaseline'
|
|
332
|
+
import { ConsentProvider } from 'react-lgpd-consent'
|
|
333
|
+
|
|
334
|
+
// Seu tema personalizado
|
|
335
|
+
const meuTema = createTheme({
|
|
336
|
+
palette: {
|
|
337
|
+
primary: {
|
|
338
|
+
main: '#1976d2',
|
|
339
|
+
},
|
|
340
|
+
secondary: {
|
|
341
|
+
main: '#dc004e',
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
typography: {
|
|
345
|
+
fontFamily: '"Roboto", "Helvetica", "Arial", sans-serif',
|
|
346
|
+
},
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
// Tema específico para componentes de consentimento (opcional)
|
|
350
|
+
const temaConsentimento = createTheme({
|
|
351
|
+
...meuTema,
|
|
352
|
+
components: {
|
|
353
|
+
MuiPaper: {
|
|
354
|
+
styleOverrides: {
|
|
355
|
+
root: {
|
|
356
|
+
borderRadius: 12,
|
|
357
|
+
},
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
MuiButton: {
|
|
361
|
+
styleOverrides: {
|
|
362
|
+
root: {
|
|
363
|
+
textTransform: 'none',
|
|
364
|
+
fontWeight: 600,
|
|
365
|
+
},
|
|
366
|
+
},
|
|
367
|
+
},
|
|
368
|
+
},
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
function App() {
|
|
372
|
+
return (
|
|
373
|
+
<ThemeProvider theme={meuTema}>
|
|
374
|
+
<CssBaseline />
|
|
375
|
+
<ConsentProvider
|
|
376
|
+
categories={{
|
|
377
|
+
enabledCategories: ['analytics', 'marketing', 'advertising'],
|
|
378
|
+
}}
|
|
379
|
+
theme={temaConsentimento} // Tema específico para consentimento
|
|
380
|
+
texts={{
|
|
381
|
+
bannerMessage: 'Utilizamos cookies para personalizar sua experiência.',
|
|
382
|
+
acceptAll: 'Aceitar Todos',
|
|
383
|
+
declineAll: 'Apenas Necessários',
|
|
384
|
+
preferences: 'Personalizar',
|
|
385
|
+
}}
|
|
386
|
+
onConsentGiven={(state) => {
|
|
387
|
+
console.log('✅ Consentimento dado:', state.preferences)
|
|
388
|
+
}}
|
|
389
|
+
>
|
|
390
|
+
<main>
|
|
391
|
+
<h1>Minha Aplicação com Material-UI</h1>
|
|
392
|
+
{/* Seus componentes aqui */}
|
|
393
|
+
</main>
|
|
394
|
+
</ConsentProvider>
|
|
395
|
+
</ThemeProvider>
|
|
396
|
+
)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export default App
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
## 🔧 Configurações Avançadas
|
|
403
|
+
|
|
404
|
+
### Personalização de Design Tokens
|
|
405
|
+
|
|
406
|
+
```tsx
|
|
407
|
+
import { ConsentProvider, type DesignTokens } from 'react-lgpd-consent'
|
|
408
|
+
|
|
409
|
+
const meusTokens: DesignTokens = {
|
|
410
|
+
colors: {
|
|
411
|
+
primary: '#6366f1',
|
|
412
|
+
secondary: '#f59e0b',
|
|
413
|
+
background: '#ffffff',
|
|
414
|
+
text: '#1f2937',
|
|
415
|
+
border: '#e5e7eb',
|
|
416
|
+
},
|
|
417
|
+
layout: {
|
|
418
|
+
borderRadius: '12px',
|
|
419
|
+
spacing: '1rem',
|
|
420
|
+
backdrop: 'rgba(0, 0, 0, 0.6)', // ou false para transparente
|
|
421
|
+
},
|
|
422
|
+
typography: {
|
|
423
|
+
fontFamily: '"Inter", system-ui, sans-serif',
|
|
424
|
+
fontSize: '14px',
|
|
425
|
+
fontWeight: '500',
|
|
426
|
+
},
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function App() {
|
|
430
|
+
return (
|
|
431
|
+
<ConsentProvider
|
|
432
|
+
categories={{ enabledCategories: ['analytics'] }}
|
|
433
|
+
designTokens={meusTokens}
|
|
434
|
+
blocking={true}
|
|
435
|
+
blockingStrategy="provider"
|
|
436
|
+
>
|
|
437
|
+
<main>Minha App</main>
|
|
438
|
+
</ConsentProvider>
|
|
439
|
+
)
|
|
440
|
+
}
|
|
441
|
+
```
|
|
442
|
+
|
|
443
|
+
### Configuração de Cookie Personalizada
|
|
444
|
+
|
|
445
|
+
```tsx
|
|
446
|
+
import { ConsentProvider } from 'react-lgpd-consent'
|
|
447
|
+
|
|
448
|
+
function App() {
|
|
449
|
+
return (
|
|
450
|
+
<ConsentProvider
|
|
451
|
+
categories={{ enabledCategories: ['analytics'] }}
|
|
452
|
+
cookie={{
|
|
453
|
+
name: 'meu_app_consent', // Nome customizado
|
|
454
|
+
maxAge: 365 * 24 * 60 * 60, // 1 ano em segundos
|
|
455
|
+
domain: '.meudominio.com.br', // Cookie compartilhado entre subdomínios
|
|
456
|
+
secure: true, // Apenas HTTPS
|
|
457
|
+
sameSite: 'Lax', // Política SameSite
|
|
458
|
+
}}
|
|
459
|
+
>
|
|
460
|
+
<main>Minha App</main>
|
|
461
|
+
</ConsentProvider>
|
|
462
|
+
)
|
|
463
|
+
}
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
## 🚀 Casos de Uso Comuns
|
|
467
|
+
|
|
468
|
+
### 1. E-commerce com Analytics + Marketing
|
|
469
|
+
|
|
470
|
+
```tsx
|
|
471
|
+
<ConsentProvider
|
|
472
|
+
categories={{
|
|
473
|
+
enabledCategories: ['analytics', 'marketing', 'advertising'],
|
|
474
|
+
}}
|
|
475
|
+
texts={{
|
|
476
|
+
bannerMessage:
|
|
477
|
+
'Usamos cookies para melhorar sua experiência de compra e exibir ofertas personalizadas.',
|
|
478
|
+
acceptAll: 'Aceitar e continuar',
|
|
479
|
+
declineAll: 'Apenas essenciais',
|
|
480
|
+
}}
|
|
481
|
+
onConsentGiven={(state) => {
|
|
482
|
+
// Inicializar ferramentas baseado no consentimento
|
|
483
|
+
if (state.preferences.analytics) {
|
|
484
|
+
// gtag('config', 'GA_MEASUREMENT_ID')
|
|
485
|
+
}
|
|
486
|
+
if (state.preferences.marketing) {
|
|
487
|
+
// fbq('init', 'FACEBOOK_PIXEL_ID')
|
|
488
|
+
}
|
|
489
|
+
}}
|
|
490
|
+
>
|
|
491
|
+
{/* Sua loja */}
|
|
492
|
+
</ConsentProvider>
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
### 2. Blog/Site Institucional Simples
|
|
496
|
+
|
|
497
|
+
```tsx
|
|
498
|
+
<ConsentProvider
|
|
499
|
+
categories={{
|
|
500
|
+
enabledCategories: ['analytics'],
|
|
501
|
+
}}
|
|
502
|
+
disableFloatingPreferencesButton={false}
|
|
503
|
+
hideBranding={true}
|
|
504
|
+
>
|
|
505
|
+
{/* Seu conteúdo */}
|
|
506
|
+
</ConsentProvider>
|
|
507
|
+
```
|
|
508
|
+
|
|
509
|
+
### 3. Aplicação Corporativa com Controle Rigoroso
|
|
510
|
+
|
|
511
|
+
```tsx
|
|
512
|
+
<ConsentProvider
|
|
513
|
+
categories={{
|
|
514
|
+
enabledCategories: ['analytics', 'functional'],
|
|
515
|
+
}}
|
|
516
|
+
blocking={true}
|
|
517
|
+
blockingStrategy="provider"
|
|
518
|
+
disableDeveloperGuidance={false}
|
|
519
|
+
onPreferencesSaved={(prefs) => {
|
|
520
|
+
// Log de auditoria
|
|
521
|
+
console.log('Audit: User preferences updated', prefs)
|
|
522
|
+
}}
|
|
523
|
+
>
|
|
524
|
+
{/* Sua app corporativa */}
|
|
525
|
+
</ConsentProvider>
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
## 🆘 Solução de Problemas Comuns
|
|
529
|
+
|
|
530
|
+
### "ConsentProvider must be used within ConsentProvider"
|
|
531
|
+
|
|
532
|
+
```tsx
|
|
533
|
+
// ❌ Errado - hook usado fora do provider
|
|
534
|
+
function MeuComponente() {
|
|
535
|
+
const { preferences } = useConsent() // Erro!
|
|
536
|
+
return <div>...</div>
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
function App() {
|
|
540
|
+
return (
|
|
541
|
+
<div>
|
|
542
|
+
<MeuComponente /> {/* useConsent usado aqui falhará */}
|
|
543
|
+
<ConsentProvider categories={{ enabledCategories: ['analytics'] }}>
|
|
544
|
+
<main>App</main>
|
|
545
|
+
</ConsentProvider>
|
|
546
|
+
</div>
|
|
547
|
+
)
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
// ✅ Correto - hook usado dentro do provider
|
|
551
|
+
function App() {
|
|
552
|
+
return (
|
|
553
|
+
<ConsentProvider categories={{ enabledCategories: ['analytics'] }}>
|
|
554
|
+
<div>
|
|
555
|
+
<MeuComponente /> {/* Agora funciona */}
|
|
556
|
+
<main>App</main>
|
|
557
|
+
</div>
|
|
558
|
+
</ConsentProvider>
|
|
559
|
+
)
|
|
560
|
+
}
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
### Banner não aparece
|
|
564
|
+
|
|
565
|
+
1. Verificar se não há consentimento salvo no cookie:
|
|
566
|
+
|
|
567
|
+
```js
|
|
568
|
+
// Limpar cookie para teste
|
|
569
|
+
document.cookie = 'cookieConsent=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'
|
|
570
|
+
```
|
|
571
|
+
|
|
572
|
+
2. Verificar se `hideBranding` e outras configs estão corretas
|
|
573
|
+
3. Conferir se o `z-index` não está sendo sobrescrito por outros elementos
|
|
574
|
+
|
|
575
|
+
### TypeScript - tipos não encontrados
|
|
576
|
+
|
|
577
|
+
```ts
|
|
578
|
+
// Se você tiver problemas com tipos, adicione ao tsconfig.json:
|
|
579
|
+
{
|
|
580
|
+
"compilerOptions": {
|
|
581
|
+
"moduleResolution": "bundler", // ou "node"
|
|
582
|
+
"skipLibCheck": true
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
```
|
|
586
|
+
|
|
587
|
+
## 📚 Próximos Passos
|
|
588
|
+
|
|
589
|
+
- 📖 [Documentação Completa da API](./API.md)
|
|
590
|
+
- 🏗️ [Guia de Conformidade LGPD](./CONFORMIDADE.md)
|
|
591
|
+
- 🔌 [Integrações Nativas](./INTEGRACOES.md)
|
|
592
|
+
- 🧪 [Executar o Exemplo](./example/)
|
|
593
|
+
|
|
594
|
+
---
|
|
595
|
+
|
|
596
|
+
💡 **Dica**: Use `setDebugLogging(true, LogLevel.DEBUG)` durante o desenvolvimento para ver logs detalhados do comportamento da biblioteca.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<h1>react-lgpd-consent 🍪</h1>
|
|
3
|
+
<p><strong>A React library for cookie consent management compliant with Brazil's LGPD.</strong></p>
|
|
4
|
+
|
|
5
|
+
<div>
|
|
6
|
+
<a href="https://www.npmjs.com/package/react-lgpd-consent"><img src="https://img.shields.io/npm/v/react-lgpd-consent?style=for-the-badge&logo=npm&color=cb3837&logoColor=white" alt="NPM Version"></a>
|
|
7
|
+
<a href="https://www.npmjs.com/package/react-lgpd-consent"><img src="https://img.shields.io/npm/dm/react-lgpd-consent?style=for-the-badge&logo=npm&color=ff6b35&logoColor=white" alt="Downloads"></a>
|
|
8
|
+
<a href="https://github.com/lucianoedipo/react-lgpd-consent/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/react-lgpd-consent?style=for-the-badge&color=green&logoColor=white" alt="License"></a>
|
|
9
|
+
<a href="https://lucianoedipo.github.io/react-lgpd-consent/storybook/"><img src="https://img.shields.io/badge/Storybook-Playground-ff4785?style=for-the-badge&logo=storybook&logoColor=white" alt="Storybook"></a>
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<div>
|
|
13
|
+
<a href="https://www.typescriptlang.org/"><img src="https://img.shields.io/badge/TypeScript-Ready-3178c6?style=for-the-badge&logo=typescript&logoColor=white" alt="TypeScript Ready"></a>
|
|
14
|
+
<a href="https://reactjs.org/"><img src="https://img.shields.io/badge/React-18+-61dafb?style=for-the-badge&logo=react&logoColor=white" alt="React 18+"></a>
|
|
15
|
+
<a href="https://nextjs.org/"><img src="https://img.shields.io/badge/Next.js-Compatible-000000?style=for-the-badge&logo=next.js&logoColor=white" alt="Next.js Compatible"></a>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<br />
|
|
19
|
+
|
|
20
|
+
<p>
|
|
21
|
+
<a href="#installation"><strong>Installation</strong></a> •
|
|
22
|
+
<a href="#basic-usage"><strong>Basic Usage</strong></a> •
|
|
23
|
+
<a href="./QUICKSTART.md"><strong>📚 Quickstart</strong></a> •
|
|
24
|
+
<a href="#documentation"><strong>Documentation</strong></a> •
|
|
25
|
+
<a href="#contributing"><strong>Contributing</strong></a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<a href="./QUICKSTART.en.md"><img src="https://img.shields.io/badge/Quickstart-Get%20Started-blue?style=for-the-badge&logo=book" alt="Quickstart"></a>
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
<p align="center"><strong>Start here:</strong> follow the <a href="./QUICKSTART.en.md">Quickstart guide (QUICKSTART.en.md)</a> for step-by-step setup, TypeScript examples, props summary and MUI integration — recommended for new users.</p>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## 🚀 Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install react-lgpd-consent @mui/material @emotion/react @emotion/styled js-cookie
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Peer dependencies:** `react`, `react-dom`, `@mui/material` and `js-cookie`.
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## 📖 Basic Usage
|
|
48
|
+
|
|
49
|
+
Wrap your app with `ConsentProvider` (minimal example):
|
|
50
|
+
|
|
51
|
+
```tsx
|
|
52
|
+
import { ConsentProvider } from 'react-lgpd-consent'
|
|
53
|
+
|
|
54
|
+
export default function App() {
|
|
55
|
+
return (
|
|
56
|
+
<ConsentProvider categories={{ enabledCategories: ['analytics'] }}>
|
|
57
|
+
<YourApp />
|
|
58
|
+
</ConsentProvider>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- For full guides, TypeScript examples, props table and integrations see:
|
|
64
|
+
-
|
|
65
|
+
- **[QUICKSTART.en.md](./QUICKSTART.en.md)** (recommended)
|
|
66
|
+
- **[Docs / API](./API.md)**
|
|
67
|
+
- **[LGPD Compliance](./CONFORMIDADE.md)**
|
|
68
|
+
- **[Integrations](./INTEGRACOES.md)**
|
|
69
|
+
|
|
70
|
+
### 🎨 Interactive Documentation (GitHub Pages)
|
|
71
|
+
- **[📖 Storybook - Interactive Playground](https://lucianoedipo.github.io/react-lgpd-consent/storybook/)**: Explore and test all components live with interactive controls.
|
|
72
|
+
- **[⚙️ TypeDoc - API Reference](https://lucianoedipo.github.io/react-lgpd-consent/docs/)**: Automatically generated complete API documentation.
|
|
73
|
+
- **[🏠 Documentation Portal](https://lucianoedipo.github.io/react-lgpd-consent/)**: Home page that navigates between all docs sites.
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 🤝 Contributing
|
|
78
|
+
|
|
79
|
+
1. Open an Issue for bugs or feature requests.
|
|
80
|
+
2. Follow `DEVELOPMENT.md` to submit a PR.
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## 📄 License
|
|
85
|
+
|
|
86
|
+
MIT — see the `LICENSE` file.
|