@el7ven/cookie-kit 0.2.15
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 +201 -0
- package/dist/styles/index.css +744 -0
- package/package.json +64 -0
- package/src/core/index.js +232 -0
- package/src/core/index.test.js +90 -0
- package/src/core/version.js +29 -0
- package/src/index.js +67 -0
- package/src/js/CookieConsent.js +618 -0
- package/src/js/components/index.js +1 -0
- package/src/js/index.js +53 -0
- package/src/js/index.test.js +42 -0
- package/src/js/version.js +29 -0
- package/src/react/CookieConsent.tsx +152 -0
- package/src/react/CookieDrawer.tsx +233 -0
- package/src/react/components/index.js +2 -0
- package/src/react/index.js +89 -0
- package/src/react/index.test.js +62 -0
- package/src/react/types.ts +47 -0
- package/src/react/version.js +29 -0
- package/src/vue/CookieConsent.vue +180 -0
- package/src/vue/CookieDrawer.vue +203 -0
- package/src/vue/components/index.js +2 -0
- package/src/vue/composables/useCookieConsent.js +182 -0
- package/src/vue/index.js +58 -0
- package/src/vue/index.test.js +40 -0
- package/src/vue/version.js +29 -0
package/README.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# @el7ven/cookie-consent
|
|
2
|
+
|
|
3
|
+
> Unified cookie consent management for GDPR compliance with React and Vue support
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/@el7ven%2Fcookie-consent)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
A comprehensive, production-ready cookie consent solution that helps websites comply with GDPR and other privacy regulations. Built with modern JavaScript and supports React, Vue, and vanilla JS applications.
|
|
9
|
+
|
|
10
|
+
## ✨ Features
|
|
11
|
+
|
|
12
|
+
- 🚀 **Unified Package** - One dependency for all frameworks
|
|
13
|
+
- 📱 **Framework Agnostic** - Works with React, Vue, and vanilla JS
|
|
14
|
+
- 🔒 **GDPR Compliant** - Privacy-first approach with opt-in consent
|
|
15
|
+
- 🎨 **Customizable UI** - Built-in components or bring your own
|
|
16
|
+
- 📦 **Tree Shakable** - Only bundle what you use
|
|
17
|
+
- 🔄 **Event Driven** - Listen to consent changes in real-time
|
|
18
|
+
- 💾 **Persistent Storage** - Automatic localStorage management
|
|
19
|
+
- 🌍 **Internationalization Ready** - Multi-language support
|
|
20
|
+
|
|
21
|
+
## 📦 Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install @el7ven/cookie-consent@beta
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 🚀 Quick Start
|
|
28
|
+
|
|
29
|
+
### Vanilla JavaScript
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import { createCookieConsent } from '@el7ven/cookie-consent'
|
|
33
|
+
import '@el7ven/cookie-consent/styles'
|
|
34
|
+
|
|
35
|
+
const cookieConsent = await createCookieConsent({
|
|
36
|
+
categories: {
|
|
37
|
+
necessary: { required: true, enabled: true },
|
|
38
|
+
analytics: { required: false, enabled: false },
|
|
39
|
+
marketing: { required: false, enabled: false }
|
|
40
|
+
},
|
|
41
|
+
onConsentChange: (consent) => {
|
|
42
|
+
console.log('Consent updated:', consent)
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Accept all cookies
|
|
47
|
+
cookieConsent.acceptAll()
|
|
48
|
+
|
|
49
|
+
// Check consent
|
|
50
|
+
const consent = cookieConsent.getConsent()
|
|
51
|
+
console.log('Analytics enabled:', consent.categories.analytics.enabled)
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### React
|
|
55
|
+
|
|
56
|
+
```jsx
|
|
57
|
+
import { CookieKitProvider, useCookieKit } from '@el7ven/cookie-consent/react'
|
|
58
|
+
import '@el7ven/cookie-consent/styles'
|
|
59
|
+
|
|
60
|
+
function App() {
|
|
61
|
+
return (
|
|
62
|
+
<CookieKitProvider config={{
|
|
63
|
+
categories: {
|
|
64
|
+
necessary: { required: true, enabled: true },
|
|
65
|
+
analytics: { required: false, enabled: false }
|
|
66
|
+
}
|
|
67
|
+
}}>
|
|
68
|
+
<MyComponent />
|
|
69
|
+
</CookieKitProvider>
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function MyComponent() {
|
|
74
|
+
const { consent, acceptAll, rejectAll } = useCookieKit()
|
|
75
|
+
|
|
76
|
+
return (
|
|
77
|
+
<div>
|
|
78
|
+
<p>Analytics: {consent.categories.analytics.enabled ? 'Enabled' : 'Disabled'}</p>
|
|
79
|
+
<button onClick={acceptAll}>Accept All</button>
|
|
80
|
+
<button onClick={rejectAll}>Reject All</button>
|
|
81
|
+
</div>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Vue
|
|
87
|
+
|
|
88
|
+
```vue
|
|
89
|
+
<template>
|
|
90
|
+
<div>
|
|
91
|
+
<p>Analytics: {{ consent.categories.analytics.enabled ? 'Enabled' : 'Disabled' }}</p>
|
|
92
|
+
<button @click="acceptAll">Accept All</button>
|
|
93
|
+
<button @click="rejectAll">Reject All</button>
|
|
94
|
+
</div>
|
|
95
|
+
</template>
|
|
96
|
+
|
|
97
|
+
<script setup>
|
|
98
|
+
import { useCookieKit } from '@el7ven/cookie-consent/vue'
|
|
99
|
+
import '@el7ven/cookie-consent/styles'
|
|
100
|
+
|
|
101
|
+
const { consent, acceptAll, rejectAll } = useCookieKit({
|
|
102
|
+
categories: {
|
|
103
|
+
necessary: { required: true, enabled: true },
|
|
104
|
+
analytics: { required: false, enabled: false }
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
</script>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 📖 API Reference
|
|
111
|
+
|
|
112
|
+
### Core Methods
|
|
113
|
+
|
|
114
|
+
| Method | Description |
|
|
115
|
+
|--------|-------------|
|
|
116
|
+
| `acceptAll()` | Accept all cookie categories |
|
|
117
|
+
| `rejectAll()` | Reject all non-essential cookies |
|
|
118
|
+
| `acceptSelected(ids)` | Accept specific categories |
|
|
119
|
+
| `clearConsent()` | Clear all consent data |
|
|
120
|
+
| `getConsent()` | Get current consent state |
|
|
121
|
+
| `hasCategoryConsent(category)` | Check consent for specific category |
|
|
122
|
+
|
|
123
|
+
### Events
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
cookieConsent.on('consentChanged', ({ consent }) => {
|
|
127
|
+
// Handle consent changes
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
cookieConsent.on('consentCleared', () => {
|
|
131
|
+
// Handle consent clearing
|
|
132
|
+
})
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### Configuration Options
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
const config = {
|
|
139
|
+
categories: {
|
|
140
|
+
necessary: { required: true, enabled: true },
|
|
141
|
+
analytics: { required: false, enabled: false },
|
|
142
|
+
marketing: { required: false, enabled: false },
|
|
143
|
+
functional: { required: false, enabled: false },
|
|
144
|
+
performance: { required: false, enabled: false },
|
|
145
|
+
social: { required: false, enabled: false }
|
|
146
|
+
},
|
|
147
|
+
storageKey: 'cookie_consent',
|
|
148
|
+
consentExpireDays: 365,
|
|
149
|
+
onConsentChange: (consent) => {},
|
|
150
|
+
onConsentCleared: () => {}
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## 🎨 Customization
|
|
155
|
+
|
|
156
|
+
### CSS Variables
|
|
157
|
+
|
|
158
|
+
```css
|
|
159
|
+
:root {
|
|
160
|
+
--ck-primary: #007bff;
|
|
161
|
+
--ck-secondary: #6c757d;
|
|
162
|
+
--ck-success: #28a745;
|
|
163
|
+
--ck-danger: #dc3545;
|
|
164
|
+
--ck-background: #ffffff;
|
|
165
|
+
--ck-text: #333333;
|
|
166
|
+
--ck-border: #dee2e6;
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Custom Components
|
|
171
|
+
|
|
172
|
+
```javascript
|
|
173
|
+
import { createCookieKit } from '@el7ven/cookie-consent'
|
|
174
|
+
|
|
175
|
+
const cookieKit = createCookieKit(config)
|
|
176
|
+
|
|
177
|
+
// Build your own UI
|
|
178
|
+
const consent = cookieKit.getConsent()
|
|
179
|
+
// Render your custom banner
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## 🌍 Browser Support
|
|
183
|
+
|
|
184
|
+
- Chrome 60+
|
|
185
|
+
- Firefox 55+
|
|
186
|
+
- Safari 12+
|
|
187
|
+
- Edge 79+
|
|
188
|
+
|
|
189
|
+
## 📄 License
|
|
190
|
+
|
|
191
|
+
MIT © [Igor Semionov](https://github.com/El7ven)
|
|
192
|
+
|
|
193
|
+
## 🤝 Contributing
|
|
194
|
+
|
|
195
|
+
Contributions are welcome! Please read our [Contributing Guide](../../CONTRIBUTING.md) for details.
|
|
196
|
+
|
|
197
|
+
## 📞 Support
|
|
198
|
+
|
|
199
|
+
- 📖 [Documentation](https://github.com/El7ven/cookie-kit#readme)
|
|
200
|
+
- 🐛 [Issues](https://github.com/El7ven/cookie-kit/issues)
|
|
201
|
+
- 💬 [Discussions](https://github.com/El7ven/cookie-kit/discussions)
|