react-lgpd-consent 0.1.13 → 0.2.1
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 +641 -0
- package/dist/{PreferencesModal-2V2W3262.js → PreferencesModal-4WHKT67T.js} +1 -1
- package/dist/{chunk-XIHO7M77.js → chunk-QCERRRSC.js} +253 -87
- package/dist/index.cjs +442 -116
- package/dist/index.d.cts +195 -14
- package/dist/index.d.ts +195 -14
- package/dist/index.js +150 -3
- package/package.json +105 -100
package/README.md
CHANGED
|
@@ -0,0 +1,641 @@
|
|
|
1
|
+
# react-lgpd-consent 🍪
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/react-lgpd-consent)
|
|
4
|
+
[
|
|
7
|
+
|
|
8
|
+
````tsx
|
|
9
|
+
import { ConsentProvider } from 'react-lgpd-consent'
|
|
10
|
+
|
|
11
|
+
function App() {
|
|
12
|
+
return (
|
|
13
|
+
<ConsentProvider
|
|
14
|
+
// 🛡️ Especificar apenas categorias necessárias (Princípio da Minimização)
|
|
15
|
+
categories={{
|
|
16
|
+
enabledCategories: ['analytics'], // Apenas analytics + necessary
|
|
17
|
+
}}
|
|
18
|
+
|
|
19
|
+
// 🚫 Banner bloqueante para compliance rigorosa (opcional)
|
|
20
|
+
blocking={true}
|
|
21
|
+
|
|
22
|
+
// 📝 Textos específicos para compliance
|
|
23
|
+
texts={{
|
|
24
|
+
bannerMessage: "Utilizamos cookies conforme LGPD...",
|
|
25
|
+
controllerInfo: "Controlador: Empresa XYZ - CNPJ: 00.000.000/0001-00"
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
<YourApp />
|
|
29
|
+
</ConsentProvider>
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
```eact-lgpd-consent?style=for-the-badge)](https://github.com/lucianoedipo/react-lgpd-consent/blob/main/LICENSE)
|
|
33
|
+
[](https://www.typescriptlang.org/)
|
|
34
|
+
[](https://reactjs.org/)
|
|
35
|
+
[](https://mui.com/)
|
|
36
|
+
[](https://bundlephobia.com/package/react-lgpd-consent)
|
|
37
|
+
[](https://www.npmjs.com/package/react-lgpd-consent)
|
|
38
|
+
|
|
39
|
+
[](https://reactjs.org/)
|
|
40
|
+
[](https://mui.com/)
|
|
41
|
+
|
|
42
|
+
> **Biblioteca completa de consentimento de cookies para React e Next.js em conformidade com a LGPD**
|
|
43
|
+
|
|
44
|
+
Solução moderna, acessível e personalizável para gerenciar consentimento de cookies em aplicações React, com suporte completo a SSR, Material-UI e TypeScript.
|
|
45
|
+
|
|
46
|
+
## ✨ Características Principais
|
|
47
|
+
|
|
48
|
+
- 🇧🇷 **Conformidade LGPD + ANPD**: Cookie otimizado conforme Guia Orientativo da ANPD
|
|
49
|
+
- 🍪 **Categorias Configuráveis**: Sistema dinâmico - apenas categorias necessárias ao projeto
|
|
50
|
+
- 🛡️ **Princípio da Minimização**: Cookie contém apenas dados essenciais para compliance
|
|
51
|
+
- 🚀 **Integrações Nativas**: Google Analytics, Tag Manager, UserWay automatizados
|
|
52
|
+
- ⏰ **Auditoria Completa**: Timestamps e rastreabilidade para prestação de contas
|
|
53
|
+
- ⚡ **Client-Side First**: Arquitetura otimizada para SPA com zero-flash
|
|
54
|
+
- 🎨 **Material-UI Integration**: Componentes prontos e customizáveis com MUI
|
|
55
|
+
- ♿ **Acessibilidade**: Navegação por teclado e leitores de tela nativamente suportados
|
|
56
|
+
- 🌐 **Internacionalização**: Textos totalmente customizáveis (padrão pt-BR)
|
|
57
|
+
- 🚀 **TypeScript**: API completamente tipada para melhor DX
|
|
58
|
+
- 📦 **Zero Config**: Funciona out-of-the-box com configurações sensatas
|
|
59
|
+
- 🎯 **Granular Control**: Controle individual por categoria ativa
|
|
60
|
+
- 🚫 **Banner Bloqueante**: Modo opcional para exigir interação antes de continuar
|
|
61
|
+
- 🎨 **Sistema de Temas**: Temas customizáveis para integração visual perfeita
|
|
62
|
+
- ⚡ **Carregamento Automático**: Scripts só executam após consentimento explícito
|
|
63
|
+
- 🔌 **Modal Automático**: Modal de preferências incluído automaticamente com lazy loading
|
|
64
|
+
- 🎛️ **Botão Flutuante**: Componente opcional para acesso fácil às preferências
|
|
65
|
+
|
|
66
|
+
## 🚀 Instalação
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm install react-lgpd-consent
|
|
70
|
+
# ou
|
|
71
|
+
yarn add react-lgpd-consent
|
|
72
|
+
# ou
|
|
73
|
+
pnpm add react-lgpd-consent
|
|
74
|
+
````
|
|
75
|
+
|
|
76
|
+
### Dependências
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm install @mui/material js-cookie
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 🆕 Novidades v0.2.0 - Adequação ANPD Completa
|
|
83
|
+
|
|
84
|
+
### 🍪 Categorias Baseadas no Guia da ANPD
|
|
85
|
+
|
|
86
|
+
A biblioteca agora inclui **6 categorias** baseadas no Guia Orientativo da ANPD:
|
|
87
|
+
|
|
88
|
+
- **`necessary`**: Cookies essenciais (sempre ativos)
|
|
89
|
+
- **`analytics`**: Análise e estatísticas de uso
|
|
90
|
+
- **`functional`**: Funcionalidades extras (preferências, idioma)
|
|
91
|
+
- **`marketing`**: Publicidade e marketing direcionado
|
|
92
|
+
- **`social`**: Integração com redes sociais
|
|
93
|
+
- **`personalization`**: Personalização de conteúdo
|
|
94
|
+
|
|
95
|
+
### 🛡️ Conformidade LGPD Rigorosa (v0.2.1)
|
|
96
|
+
|
|
97
|
+
**Princípio da Minimização**: Cookie contém apenas categorias realmente utilizadas:
|
|
98
|
+
|
|
99
|
+
```tsx
|
|
100
|
+
<ConsentProvider
|
|
101
|
+
categories={{
|
|
102
|
+
enabledCategories: ['analytics'], // Apenas analytics + necessary
|
|
103
|
+
customCategories: [{
|
|
104
|
+
id: 'governo',
|
|
105
|
+
name: 'Integração Governamental',
|
|
106
|
+
description: 'Cookies para sistemas gov.br',
|
|
107
|
+
essential: false
|
|
108
|
+
}]
|
|
109
|
+
}}
|
|
110
|
+
blocking={true} // Banner bloqueia até decisão explícita
|
|
111
|
+
>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Cookie resultante** (apenas dados essenciais):
|
|
115
|
+
|
|
116
|
+
```json
|
|
117
|
+
{
|
|
118
|
+
"version": "1.0",
|
|
119
|
+
"consented": true,
|
|
120
|
+
"preferences": { "necessary": true, "analytics": false, "governo": true },
|
|
121
|
+
"consentDate": "2025-08-12T14:30:00.000Z",
|
|
122
|
+
"lastUpdate": "2025-08-12T14:30:00.000Z",
|
|
123
|
+
"source": "banner"
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
> 📋 **[Guia Completo de Conformidade LGPD](./docs/CONFORMIDADE-LGPD.md)**
|
|
128
|
+
|
|
129
|
+
### 🔧 Categorias Customizadas
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
const customCategories = [
|
|
133
|
+
{
|
|
134
|
+
id: 'governo',
|
|
135
|
+
name: 'Integração Governo',
|
|
136
|
+
description: 'Cookies para integração com sistemas governamentais.',
|
|
137
|
+
essential: false,
|
|
138
|
+
cookies: ['gov_session', 'cpf_hash']
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
id: 'acessibilidade',
|
|
142
|
+
name: 'Acessibilidade',
|
|
143
|
+
description: 'Ferramentas para melhorar acessibilidade.',
|
|
144
|
+
essential: false,
|
|
145
|
+
cookies: ['userway_*', 'voice_*']
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
<ConsentProvider customCategories={customCategories}>
|
|
150
|
+
{/* Sua aplicação */}
|
|
151
|
+
</ConsentProvider>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### 🚀 Integrações Automáticas
|
|
155
|
+
|
|
156
|
+
```tsx
|
|
157
|
+
import {
|
|
158
|
+
ConsentScriptLoader,
|
|
159
|
+
createGoogleAnalyticsIntegration,
|
|
160
|
+
createUserWayIntegration,
|
|
161
|
+
} from 'react-lgpd-consent'
|
|
162
|
+
|
|
163
|
+
const integrations = [
|
|
164
|
+
createGoogleAnalyticsIntegration({
|
|
165
|
+
measurementId: 'GA_MEASUREMENT_ID',
|
|
166
|
+
}),
|
|
167
|
+
createUserWayIntegration({
|
|
168
|
+
accountId: 'USERWAY_ACCOUNT_ID',
|
|
169
|
+
}),
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
function App() {
|
|
173
|
+
return (
|
|
174
|
+
<ConsentProvider>
|
|
175
|
+
{/* Scripts carregam automaticamente quando categoria é aceita */}
|
|
176
|
+
<ConsentScriptLoader integrations={integrations} />
|
|
177
|
+
|
|
178
|
+
<CookieBanner policyLinkUrl="/privacy-policy" />
|
|
179
|
+
</ConsentProvider>
|
|
180
|
+
)
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 📝 Textos ANPD Expandidos
|
|
185
|
+
|
|
186
|
+
```tsx
|
|
187
|
+
<ConsentProvider
|
|
188
|
+
texts={{
|
|
189
|
+
bannerMessage: 'Utilizamos cookies para melhorar sua experiência.',
|
|
190
|
+
// Textos ANPD opcionais
|
|
191
|
+
controllerInfo: 'Controlado por Empresa LTDA (CNPJ: 00.000.000/0001-00)',
|
|
192
|
+
dataTypes: 'Coletamos dados de navegação, preferências e interações.',
|
|
193
|
+
thirdPartySharing: 'Compartilhamos com: Google Analytics, Facebook Pixel',
|
|
194
|
+
userRights: 'Você tem direito a acesso, correção e exclusão dos dados.',
|
|
195
|
+
contactInfo: 'Contato DPO: dpo@empresa.com.br | (11) 9999-9999',
|
|
196
|
+
retentionPeriod: 'Dados armazenados por até 12 meses.',
|
|
197
|
+
lawfulBasis: 'Base legal: consentimento do titular dos dados.',
|
|
198
|
+
transferCountries: 'Dados podem ser transferidos para: EUA, Irlanda.',
|
|
199
|
+
}}
|
|
200
|
+
>
|
|
201
|
+
{/* Os textos são exibidos condicionalmente apenas se definidos */}
|
|
202
|
+
</ConsentProvider>
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## � Exemplo Completo
|
|
206
|
+
|
|
207
|
+
```tsx
|
|
208
|
+
import {
|
|
209
|
+
ConsentProvider,
|
|
210
|
+
CookieBanner,
|
|
211
|
+
FloatingPreferencesButton,
|
|
212
|
+
} from 'react-lgpd-consent'
|
|
213
|
+
|
|
214
|
+
function App() {
|
|
215
|
+
return (
|
|
216
|
+
<ConsentProvider>
|
|
217
|
+
<div>
|
|
218
|
+
<h1>Meu Site</h1>
|
|
219
|
+
<p>Conteúdo do site...</p>
|
|
220
|
+
|
|
221
|
+
{/* Banner de cookies - Modal incluído automaticamente! */}
|
|
222
|
+
<CookieBanner policyLinkUrl="/privacy-policy" blocking={true} />
|
|
223
|
+
|
|
224
|
+
{/* Botão flutuante opcional para acesso às preferências */}
|
|
225
|
+
<FloatingPreferencesButton position="bottom-right" />
|
|
226
|
+
</div>
|
|
227
|
+
</ConsentProvider>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## �📖 Uso Básico
|
|
233
|
+
|
|
234
|
+
### 1. Setup do Provider
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
import { ConsentProvider } from 'react-lgpd-consent'
|
|
238
|
+
|
|
239
|
+
function App() {
|
|
240
|
+
return (
|
|
241
|
+
<ConsentProvider>
|
|
242
|
+
<YourApp />
|
|
243
|
+
</ConsentProvider>
|
|
244
|
+
)
|
|
245
|
+
}
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 2. Banner de Consentimento
|
|
249
|
+
|
|
250
|
+
```tsx
|
|
251
|
+
import { CookieBanner } from 'react-lgpd-consent'
|
|
252
|
+
|
|
253
|
+
function Layout() {
|
|
254
|
+
return (
|
|
255
|
+
<>
|
|
256
|
+
<YourContent />
|
|
257
|
+
<CookieBanner
|
|
258
|
+
policyLinkUrl="/politica-privacidade"
|
|
259
|
+
blocking={true} // Padrão: bloqueia até decisão
|
|
260
|
+
/>
|
|
261
|
+
{/* Modal de preferências incluído automaticamente! */}
|
|
262
|
+
</>
|
|
263
|
+
)
|
|
264
|
+
}
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### 3. Uso do Hook
|
|
268
|
+
|
|
269
|
+
```tsx
|
|
270
|
+
import { useConsent } from 'react-lgpd-consent'
|
|
271
|
+
|
|
272
|
+
function MyComponent() {
|
|
273
|
+
const { consented, preferences, acceptAll, openPreferences } = useConsent()
|
|
274
|
+
|
|
275
|
+
return (
|
|
276
|
+
<div>
|
|
277
|
+
<p>Consentimento: {consented ? 'Dado' : 'Pendente'}</p>
|
|
278
|
+
<button onClick={acceptAll}>Aceitar Todos</button>
|
|
279
|
+
<button onClick={openPreferences}>Gerenciar Preferências</button>
|
|
280
|
+
</div>
|
|
281
|
+
)
|
|
282
|
+
}
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
> ✅ **O modal de preferências é incluído automaticamente pelo ConsentProvider!** Não é mais necessário renderizá-lo manualmente.
|
|
286
|
+
|
|
287
|
+
````
|
|
288
|
+
|
|
289
|
+
### 4. Carregamento Condicional de Scripts
|
|
290
|
+
|
|
291
|
+
```tsx
|
|
292
|
+
import { ConsentGate, loadScript } from 'react-lgpd-consent'
|
|
293
|
+
|
|
294
|
+
function Analytics() {
|
|
295
|
+
return (
|
|
296
|
+
<ConsentGate category="analytics">
|
|
297
|
+
<GoogleAnalytics />
|
|
298
|
+
</ConsentGate>
|
|
299
|
+
)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// Ou carregando scripts que aguardam consentimento
|
|
303
|
+
function MyComponent() {
|
|
304
|
+
const { preferences, consented } = useConsent()
|
|
305
|
+
|
|
306
|
+
useEffect(() => {
|
|
307
|
+
if (consented && preferences.analytics) {
|
|
308
|
+
loadConditionalScript(
|
|
309
|
+
'ga',
|
|
310
|
+
'https://www.googletagmanager.com/gtag/js?id=GA_ID',
|
|
311
|
+
() => preferences.analytics, // Condição que aguarda
|
|
312
|
+
)
|
|
313
|
+
}
|
|
314
|
+
}, [preferences, consented])
|
|
315
|
+
}
|
|
316
|
+
````
|
|
317
|
+
|
|
318
|
+
## 🎨 Customização
|
|
319
|
+
|
|
320
|
+
### Banner Bloqueante vs Não-bloqueante
|
|
321
|
+
|
|
322
|
+
```tsx
|
|
323
|
+
// Banner bloqueante (padrão) - impede interação até decisão
|
|
324
|
+
<CookieBanner blocking={true} />
|
|
325
|
+
|
|
326
|
+
// Banner não-intrusivo - permite navegação
|
|
327
|
+
<CookieBanner blocking={false} />
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Tema Personalizado
|
|
331
|
+
|
|
332
|
+
```tsx
|
|
333
|
+
import { ConsentProvider, defaultConsentTheme } from 'react-lgpd-consent'
|
|
334
|
+
import { createTheme } from '@mui/material/styles'
|
|
335
|
+
|
|
336
|
+
const meuTema = createTheme({
|
|
337
|
+
...defaultConsentTheme,
|
|
338
|
+
palette: {
|
|
339
|
+
...defaultConsentTheme.palette,
|
|
340
|
+
primary: {
|
|
341
|
+
main: '#1976d2', // Sua cor principal
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
<ConsentProvider theme={meuTema}>
|
|
347
|
+
<App />
|
|
348
|
+
</ConsentProvider>
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
### Textos Personalizados
|
|
352
|
+
|
|
353
|
+
```tsx
|
|
354
|
+
<ConsentProvider
|
|
355
|
+
texts={{
|
|
356
|
+
bannerMessage: "Utilizamos cookies para melhorar sua experiência.",
|
|
357
|
+
acceptAll: "Aceitar Todos",
|
|
358
|
+
declineAll: "Recusar Opcionais",
|
|
359
|
+
preferences: "Configurar"
|
|
360
|
+
}}
|
|
361
|
+
>
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### Configuração do Cookie
|
|
365
|
+
|
|
366
|
+
```tsx
|
|
367
|
+
<ConsentProvider
|
|
368
|
+
cookie={{
|
|
369
|
+
name: 'meuSiteConsent',
|
|
370
|
+
maxAgeDays: 180,
|
|
371
|
+
sameSite: 'Strict'
|
|
372
|
+
}}
|
|
373
|
+
>
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Callbacks
|
|
377
|
+
|
|
378
|
+
```tsx
|
|
379
|
+
<ConsentProvider
|
|
380
|
+
onConsentGiven={(state) => {
|
|
381
|
+
console.log('Consentimento dado:', state)
|
|
382
|
+
// Inicializar analytics, etc.
|
|
383
|
+
}}
|
|
384
|
+
onPreferencesSaved={(prefs) => {
|
|
385
|
+
console.log('Preferências salvas:', prefs)
|
|
386
|
+
}}
|
|
387
|
+
>
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
## � Banner Bloqueante
|
|
391
|
+
|
|
392
|
+
Para cenários onde é necessário bloquear o acesso até obter consentimento explícito:
|
|
393
|
+
|
|
394
|
+
```tsx
|
|
395
|
+
<CookieBanner blocking />
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
Com `blocking={true}`, o banner:
|
|
399
|
+
|
|
400
|
+
- Cria um overlay escuro sobre todo o conteúdo
|
|
401
|
+
- Impede interação com o resto da página
|
|
402
|
+
- É útil para casos críticos onde consentimento é obrigatório
|
|
403
|
+
|
|
404
|
+
## 🎨 Sistema de Temas
|
|
405
|
+
|
|
406
|
+
### Tema Personalizado
|
|
407
|
+
|
|
408
|
+
```tsx
|
|
409
|
+
import { createTheme } from '@mui/material/styles'
|
|
410
|
+
|
|
411
|
+
const meuTema = createTheme({
|
|
412
|
+
palette: {
|
|
413
|
+
primary: { main: '#2196f3' },
|
|
414
|
+
secondary: { main: '#f50057' },
|
|
415
|
+
},
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
<ConsentProvider theme={meuTema}>
|
|
419
|
+
<App />
|
|
420
|
+
</ConsentProvider>
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Tema Padrão
|
|
424
|
+
|
|
425
|
+
O tema padrão do react-lgpd-consent está disponível para customização:
|
|
426
|
+
|
|
427
|
+
```tsx
|
|
428
|
+
import { defaultConsentTheme } from 'react-lgpd-consent'
|
|
429
|
+
|
|
430
|
+
const temaCustomizado = createTheme({
|
|
431
|
+
...defaultConsentTheme,
|
|
432
|
+
palette: {
|
|
433
|
+
...defaultConsentTheme.palette,
|
|
434
|
+
primary: { main: '#your-color' },
|
|
435
|
+
},
|
|
436
|
+
})
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
## ⚡ Carregamento Inteligente de Scripts
|
|
440
|
+
|
|
441
|
+
### Função loadScript
|
|
442
|
+
|
|
443
|
+
Scripts aguardam automaticamente o **consentimento finalizado** (banner fechado ou preferências salvas):
|
|
444
|
+
|
|
445
|
+
```tsx
|
|
446
|
+
import { loadScript } from 'react-lgpd-consent'
|
|
447
|
+
|
|
448
|
+
// Carrega script apenas após consentimento para analytics
|
|
449
|
+
await loadScript(
|
|
450
|
+
'gtag',
|
|
451
|
+
'https://www.googletagmanager.com/gtag/js?id=GA_ID',
|
|
452
|
+
'analytics', // Categoria obrigatória
|
|
453
|
+
)
|
|
454
|
+
|
|
455
|
+
// Script geral (sempre carrega após consentimento)
|
|
456
|
+
await loadScript('custom-script', 'https://example.com/script.js')
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
### Comportamento Inteligente
|
|
460
|
+
|
|
461
|
+
- **Aguarda decisão final**: Não executa durante mudanças no modal de preferências
|
|
462
|
+
- **Só executa após salvar**: Scripts só rodam quando o usuário finaliza as preferências
|
|
463
|
+
- **Baseado em categoria**: Respeita as permissões por categoria
|
|
464
|
+
|
|
465
|
+
## 🎨 Personalização Total
|
|
466
|
+
|
|
467
|
+
### Modal de Preferências Customizado
|
|
468
|
+
|
|
469
|
+
Substitua completamente o modal padrão com seu próprio componente:
|
|
470
|
+
|
|
471
|
+
```tsx
|
|
472
|
+
import { ConsentProvider, useConsent } from 'react-lgpd-consent'
|
|
473
|
+
import MeuModalCustomizado from './MeuModalCustomizado'
|
|
474
|
+
|
|
475
|
+
function App() {
|
|
476
|
+
return (
|
|
477
|
+
<ConsentProvider
|
|
478
|
+
PreferencesModalComponent={MeuModalCustomizado}
|
|
479
|
+
preferencesModalProps={{ variant: 'custom' }}
|
|
480
|
+
>
|
|
481
|
+
<MeuApp />
|
|
482
|
+
</ConsentProvider>
|
|
483
|
+
)
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Seu componente customizado
|
|
487
|
+
function MeuModalCustomizado({ variant }) {
|
|
488
|
+
const { isModalOpen, closePreferences, setPreference } = useConsent()
|
|
489
|
+
|
|
490
|
+
return (
|
|
491
|
+
<MyCustomDialog open={isModalOpen} onClose={closePreferences}>
|
|
492
|
+
{/* Seu design personalizado aqui */}
|
|
493
|
+
</MyCustomDialog>
|
|
494
|
+
)
|
|
495
|
+
}
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### Desabilitar Modal Automático
|
|
499
|
+
|
|
500
|
+
Para controle total, desabilite o modal automático:
|
|
501
|
+
|
|
502
|
+
```tsx
|
|
503
|
+
<ConsentProvider disableAutomaticModal>
|
|
504
|
+
<MeuApp />
|
|
505
|
+
{/* Renderize seus componentes customizados onde quiser */}
|
|
506
|
+
<MeuModalTotalmenteCustomizado />
|
|
507
|
+
</ConsentProvider>
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
## �🔧 API Completa
|
|
511
|
+
|
|
512
|
+
### Components
|
|
513
|
+
|
|
514
|
+
| Componente | Descrição | Props Principais |
|
|
515
|
+
| --------------------------- | ------------------------------------------------ | ---------------------------------------------------------------------------------------- |
|
|
516
|
+
| `ConsentProvider` | Provider principal do contexto | `initialState`, `texts`, `theme`, `hideBranding`, `PreferencesModalComponent`, callbacks |
|
|
517
|
+
| `CookieBanner` | Banner de consentimento | `policyLinkUrl`, `blocking`, `hideBranding`, `debug`, pass-through MUI props |
|
|
518
|
+
| `PreferencesModal` | Modal de preferências (incluído automaticamente) | `DialogProps`, `hideBranding` - **Opcional** |
|
|
519
|
+
| `FloatingPreferencesButton` | Botão flutuante para abrir preferências | `position`, `hideWhenConsented`, `tooltip`, `icon`, `FabProps` |
|
|
520
|
+
| `ConsentGate` | Renderização condicional por categoria | `category`, `children` |
|
|
521
|
+
|
|
522
|
+
### Hook `useConsent()`
|
|
523
|
+
|
|
524
|
+
```typescript
|
|
525
|
+
interface ConsentContextValue {
|
|
526
|
+
consented: boolean // usuário já consentiu?
|
|
527
|
+
preferences: ConsentPreferences // preferências atuais
|
|
528
|
+
isModalOpen: boolean // estado do modal de preferências
|
|
529
|
+
acceptAll(): void // aceitar todas as categorias
|
|
530
|
+
rejectAll(): void // recusar opcionais
|
|
531
|
+
setPreference(cat: Category, value: boolean): void // definir categoria específica
|
|
532
|
+
openPreferences(): void // abrir modal de preferências
|
|
533
|
+
closePreferences(): void // fechar modal
|
|
534
|
+
resetConsent(): void // resetar tudo
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
### Hook `useConsentTexts()`
|
|
539
|
+
|
|
540
|
+
```typescript
|
|
541
|
+
// Acesso aos textos contextuais
|
|
542
|
+
const texts = useConsentTexts()
|
|
543
|
+
console.log(texts.banner.title) // "Política de Cookies"
|
|
544
|
+
```
|
|
545
|
+
|
|
546
|
+
### Utilitários
|
|
547
|
+
|
|
548
|
+
- `loadScript(id, src, category?, attrs?)` - Carrega scripts com consentimento inteligente
|
|
549
|
+
- `defaultConsentTheme` - Tema padrão do Material-UI
|
|
550
|
+
- Tipos TypeScript completos exportados## 🌐 SSR / Next.js
|
|
551
|
+
|
|
552
|
+
Para evitar flash de conteúdo em SSR:
|
|
553
|
+
|
|
554
|
+
```tsx
|
|
555
|
+
// pages/_app.tsx (Next.js)
|
|
556
|
+
function MyApp({ Component, pageProps }) {
|
|
557
|
+
return (
|
|
558
|
+
<ConsentProvider
|
|
559
|
+
initialState={{
|
|
560
|
+
consented: false,
|
|
561
|
+
preferences: { analytics: false, marketing: false },
|
|
562
|
+
}}
|
|
563
|
+
>
|
|
564
|
+
<Component {...pageProps} />
|
|
565
|
+
</ConsentProvider>
|
|
566
|
+
)
|
|
567
|
+
}
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
## ♿ Acessibilidade
|
|
571
|
+
|
|
572
|
+
A biblioteca segue as melhores práticas de acessibilidade:
|
|
573
|
+
|
|
574
|
+
- ✅ Navegação por teclado (Tab, Enter, Escape)
|
|
575
|
+
- ✅ Leitores de tela (`aria-labelledby`, `aria-describedby`)
|
|
576
|
+
- ✅ Foco gerenciado automaticamente
|
|
577
|
+
- ✅ Contrastes adequados
|
|
578
|
+
- ✅ Estrutura semântica correta
|
|
579
|
+
|
|
580
|
+
## 📚 Exemplos
|
|
581
|
+
|
|
582
|
+
Confira exemplos completos no repositório:
|
|
583
|
+
|
|
584
|
+
- [Básico com React](./examples/basic)
|
|
585
|
+
- [Next.js com SSR](./examples/nextjs)
|
|
586
|
+
- [Customização avançada](./examples/advanced)
|
|
587
|
+
- [Integração com analytics](./examples/analytics)
|
|
588
|
+
|
|
589
|
+
## 🤝 Contribuição
|
|
590
|
+
|
|
591
|
+
Contribuições são bem-vindas! Por favor:
|
|
592
|
+
|
|
593
|
+
1. Faça fork do projeto
|
|
594
|
+
2. Crie uma branch para sua feature (`git checkout -b feature/AmazingFeature`)
|
|
595
|
+
3. Commit suas mudanças (`git commit -m 'Add some AmazingFeature'`)
|
|
596
|
+
4. Push para a branch (`git push origin feature/AmazingFeature`)
|
|
597
|
+
5. Abra um Pull Request
|
|
598
|
+
|
|
599
|
+
## 📄 Licença
|
|
600
|
+
|
|
601
|
+
Este projeto está licenciado sob a Licença MIT - veja o arquivo [LICENSE](LICENSE) para detalhes.
|
|
602
|
+
|
|
603
|
+
## 🙋♀️ Suporte
|
|
604
|
+
|
|
605
|
+
- 📖 [Documentação](./docs)
|
|
606
|
+
- 🐛 [Issues](https://github.com/lucianoedipo/react-lgpd-consent/issues)
|
|
607
|
+
- 💬 [Discussões](https://github.com/lucianoedipo/react-lgpd-consent/discussions)
|
|
608
|
+
|
|
609
|
+
## 🔮 Roadmap
|
|
610
|
+
|
|
611
|
+
### v0.2.1 - Compliance Avançado (Próxima Release)
|
|
612
|
+
|
|
613
|
+
**Baseado em feedback de uso real em projetos governamentais:**
|
|
614
|
+
|
|
615
|
+
- 📋 **Sistema de Logs de Auditoria**: Rastreamento completo para prestação de contas
|
|
616
|
+
- 📜 **Templates Setoriais**: Textos pré-configurados (governo, saúde, educação)
|
|
617
|
+
- 🎨 **Presets Visuais**: Identidade visual por setor (acessibilidade WCAG AAA)
|
|
618
|
+
- 📊 **Dashboard para DPOs**: Relatórios automáticos de compliance
|
|
619
|
+
- 🔌 **Mais Integrações**: Microsoft Clarity, Hotjar, Intercom, LinkedIn
|
|
620
|
+
|
|
621
|
+
### v0.3.0 - Multi-Regulamentação
|
|
622
|
+
|
|
623
|
+
- 🌍 **Suporte GDPR/CCPA**: Detecção automática por geolocalização
|
|
624
|
+
- 🏗️ **Sistema de Plugins**: Extensões de terceiros
|
|
625
|
+
- 🎭 **Temas Avançados**: Design system tokens
|
|
626
|
+
|
|
627
|
+
### v0.4.0 - Enterprise
|
|
628
|
+
|
|
629
|
+
- 📈 **Analytics Avançadas**: Dashboards completos
|
|
630
|
+
- 🔄 **Sync Multi-Domínio**: Consentimento compartilhado
|
|
631
|
+
- 🛡️ **Segurança Empresarial**: Criptografia, audit logs remotos
|
|
632
|
+
|
|
633
|
+
[📋 Ver plano detalhado v0.2.1](./docs/v0.2.1-PLAN.md)
|
|
634
|
+
|
|
635
|
+
---
|
|
636
|
+
|
|
637
|
+
<div align="center">
|
|
638
|
+
|
|
639
|
+
**Feito com ❤️ para a comunidade React brasileira**
|
|
640
|
+
|
|
641
|
+
</div>
|