react-achievements 3.7.0 → 3.9.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/README.md CHANGED
@@ -8,369 +8,127 @@
8
8
 
9
9
  [![npm version](https://img.shields.io/npm/v/react-achievements.svg)](https://www.npmjs.com/package/react-achievements) [![License](https://img.shields.io/badge/license-Dual%20(MIT%20%2B%20Commercial)-blue.svg)](./LICENSE) [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
10
10
 
11
- ## Why React Achievements?
11
+ ## Installation
12
+
13
+ ```bash
14
+ npm install react-achievements
15
+ ```
12
16
 
13
- - **🎯 Simple API** - 90% less configuration than traditional achievement systems
14
- - **🎨 Built-in UI** - Beautiful notifications & modals with zero external dependencies
15
- - **⚡ 5-Minute Setup** - From installation to first achievement unlock
16
- - **💾 5 Storage Options** - LocalStorage, Memory, IndexedDB, REST API, Offline Queue
17
- - **🎭 3 Themes** - Modern, Minimal, Gamified - or create your own
18
- - **📦 Type-Safe** - Full TypeScript support with comprehensive types
17
+ **Requirements:** React 17.0+, Node.js 16+
19
18
 
20
19
  ---
21
20
 
22
- ## Get Started in 5 Minutes
21
+ ## Usage
23
22
 
24
- ### 1. Install
23
+ React Achievements supports two tracking patterns:
25
24
 
26
- ```bash
27
- npm install react-achievements
28
- ```
25
+ ### Pattern 1: Event-Based Tracking
29
26
 
30
- ### 2. Configure Achievements (Simple API)
27
+ Track achievements using semantic events. Perfect for complex applications or multi-framework projects.
31
28
 
32
29
  ```tsx
33
- import {
34
- AchievementProvider,
35
- useSimpleAchievements,
36
- BadgesButtonWithModal
37
- } from 'react-achievements';
30
+ // achievementEngine.ts
31
+ import { AchievementEngine } from 'react-achievements';
38
32
 
39
- // Define achievements - notice how simple this is!
40
33
  const achievements = {
41
34
  score: {
42
35
  100: { title: 'Century!', description: 'Score 100 points', icon: '🏆' },
43
- 500: { title: 'High Scorer!', description: 'Score 500 points', icon: '⭐' },
44
- },
45
- completedTutorial: {
46
- true: { title: 'Tutorial Master', description: 'Complete the tutorial', icon: '📚' }
47
36
  }
48
37
  };
49
38
 
50
- function Game() {
51
- const { track, unlocked } = useSimpleAchievements();
39
+ const eventMapping = {
40
+ 'userScored': (data) => ({ score: data.points }),
41
+ };
52
42
 
53
- return (
54
- <div>
55
- {/* Track achievements with one line */}
56
- <button onClick={() => track('score', 100)}>Score Points</button>
57
- <button onClick={() => track('completedTutorial', true)}>Complete Tutorial</button>
43
+ export const engine = new AchievementEngine({
44
+ achievements,
45
+ eventMapping,
46
+ storage: 'local'
47
+ });
48
+ ```
58
49
 
59
- {/* Built-in UI - no state management needed! */}
60
- <BadgesButtonWithModal unlockedAchievements={unlocked} />
61
- </div>
62
- );
63
- }
50
+ ```tsx
51
+ // App.tsx
52
+ import { AchievementProvider } from 'react-achievements';
53
+ import { engine } from './achievementEngine';
64
54
 
65
55
  function App() {
66
56
  return (
67
- <AchievementProvider achievements={achievements} useBuiltInUI={true}>
57
+ <AchievementProvider engine={engine} useBuiltInUI={true}>
68
58
  <Game />
69
59
  </AchievementProvider>
70
60
  );
71
61
  }
72
62
  ```
73
63
 
74
- ### 3. See It Work
75
-
76
- When users click "Score Points":
77
- 1. ✨ Beautiful notification appears: "🏆 Century! - Score 100 points"
78
- 2. 🎉 Confetti animation plays
79
- 3. 💾 Achievement saved to localStorage
80
- 4. 🏅 Badge button updates with count
81
-
82
- **That's it!** You now have a fully functional achievement system.
83
-
84
- ➡️ **[Full Quick Start Guide](https://dave-b-b.github.io/react-achievements/docs/getting-started/quick-start)** - Step-by-step with all details
85
-
86
- ---
87
-
88
- ## Key Features
89
-
90
- ### 🎯 Simple API - 90% Less Configuration
91
-
92
- Traditional achievement systems require verbose configuration. Not anymore:
93
-
94
- ```tsx
95
- // ❌ Before (Complex API) - 15+ lines per achievement
96
- const achievements = {
97
- score: [{
98
- isConditionMet: (value) => value >= 100,
99
- achievementDetails: {
100
- achievementId: 'score_100',
101
- achievementTitle: 'Century!',
102
- achievementDescription: 'Score 100 points',
103
- achievementIconKey: 'trophy'
104
- }
105
- }]
106
- };
107
-
108
- // ✅ After (Simple API) - 1 line per achievement!
109
- const achievements = {
110
- score: {
111
- 100: { title: 'Century!', description: 'Score 100 points', icon: '🏆' }
112
- }
113
- };
114
- ```
115
-
116
- ➡️ **[Simple API Guide](https://dave-b-b.github.io/react-achievements/docs/guides/simple-api)**
117
-
118
- ### 🎨 Built-in UI Components
119
-
120
- Zero external dependencies, three beautiful themes:
121
-
122
- ```tsx
123
- <AchievementProvider
124
- achievements={achievements}
125
- useBuiltInUI={true}
126
- ui={{
127
- theme: 'modern', // 'modern' | 'minimal' | 'gamified'
128
- notificationPosition: 'top-right'
129
- }}
130
- >
131
- <YourApp />
132
- </AchievementProvider>
133
- ```
134
-
135
- **Includes:**
136
- - 🔔 Notifications with smooth animations
137
- - 🎊 Confetti celebrations
138
- - 🏆 Achievement modal with locked/unlocked states
139
- - 🎨 Customizable themes or inject your own components
140
-
141
- ➡️ **[UI & Theming Guide](https://dave-b-b.github.io/react-achievements/docs/guides/theming)**
142
-
143
- ### 💾 Flexible Storage - Choose What Fits
144
-
145
- | Storage | Capacity | Use Case |
146
- |---------|----------|----------|
147
- | **LocalStorage** | 5-10MB | Simple browser apps (default) |
148
- | **IndexedDB** | 50MB+ | Large datasets, PWAs |
149
- | **REST API** | Unlimited | Multi-device sync, cloud backup |
150
- | **Offline Queue** | Unlimited | Offline-first apps |
151
- | **Memory** | Unlimited | Testing, prototypes |
152
-
153
64
  ```tsx
154
- // Change storage with one prop
155
- import { StorageType } from 'react-achievements';
156
-
157
- <AchievementProvider
158
- achievements={achievements}
159
- storage={StorageType.IndexedDB}
160
- >
161
- <YourApp />
162
- </AchievementProvider>
163
- ```
164
-
165
- ➡️ **[Storage Options Guide](https://dave-b-b.github.io/react-achievements/docs/guides/storage-options)**
166
-
167
- ### 📦 TypeScript Support
65
+ // Game.tsx
66
+ import { useAchievementEngine } from 'react-achievements';
168
67
 
169
- Full type safety out of the box:
170
-
171
- ```tsx
172
- import type { AchievementMetrics, AchievementWithStatus } from 'react-achievements';
173
-
174
- const metrics: AchievementMetrics = { score: 100, level: 5 };
68
+ function Game() {
69
+ const engine = useAchievementEngine();
70
+
71
+ return (
72
+ <button onClick={() => engine.emit('userScored', { points: 100 })}>
73
+ Score Points
74
+ </button>
75
+ );
76
+ }
175
77
  ```
176
78
 
177
- ➡️ **[Complete API Reference](https://dave-b-b.github.io/react-achievements/docs/api)**
79
+ ➡️ **[Event-Based Tracking Guide](https://dave-b-b.github.io/react-achievements/docs/guides/event-based-tracking)**
178
80
 
179
81
  ---
180
82
 
181
- ## Common Use Cases
83
+ ### Pattern 2: Direct Track Updates
182
84
 
183
- ### Tracking User Progress
184
-
185
- ```tsx
186
- const { track, increment } = useSimpleAchievements();
187
-
188
- // Track specific values
189
- track('score', 500);
190
- track('level', 10);
191
- track('completedTutorial', true);
192
-
193
- // Increment counters
194
- increment('buttonClicks'); // +1
195
- increment('points', 50); // +50
196
- ```
197
-
198
- ### Complex Achievements (Multiple Conditions)
85
+ Update metrics directly in your React components. Perfect for simple applications or quick prototypes.
199
86
 
200
87
  ```tsx
88
+ // achievements.ts
201
89
  const achievements = {
202
- perfectGame: {
203
- custom: {
204
- title: 'Perfect Game',
205
- description: 'Score 1000+ with 100% accuracy',
206
- icon: '💎',
207
- condition: (metrics) => metrics.score >= 1000 && metrics.accuracy === 100
208
- }
90
+ score: {
91
+ 100: { title: 'Century!', description: 'Score 100 points', icon: '🏆' },
209
92
  }
210
93
  };
211
94
  ```
212
95
 
213
- ### Export/Import for Backups
214
-
215
96
  ```tsx
216
- const { exportData, importData } = useAchievements();
217
-
218
- // Backup to file
219
- const backup = exportData();
220
- localStorage.setItem('backup', backup);
97
+ // App.tsx
98
+ import { AchievementProvider } from 'react-achievements';
221
99
 
222
- // Restore from backup
223
- const result = importData(backup, { strategy: 'merge' });
100
+ function App() {
101
+ return (
102
+ <AchievementProvider achievements={achievements} useBuiltInUI={true}>
103
+ <Game />
104
+ </AchievementProvider>
105
+ );
106
+ }
224
107
  ```
225
108
 
226
- ### Show Locked & Unlocked Achievements
227
-
228
109
  ```tsx
229
- const { getAllAchievements } = useSimpleAchievements();
230
-
231
- <BadgesModal
232
- isOpen={modalOpen}
233
- onClose={() => setModalOpen(false)}
234
- showAllAchievements={true}
235
- allAchievements={getAllAchievements()}
236
- showUnlockConditions={true} // Show hints for locked achievements
237
- />
238
- ```
239
-
240
- ➡️ **[More Patterns & Recipes](https://dave-b-b.github.io/react-achievements/docs/recipes/common-patterns)**
241
-
242
- ---
243
-
244
- ## Installation
245
-
246
- ```bash
247
- npm install react-achievements
248
- ```
110
+ // Game.tsx
111
+ import { useSimpleAchievements, BadgesButtonWithModal } from 'react-achievements';
249
112
 
250
- **Requirements:**
251
- - React 16.8+ (hooks support)
252
- - Node.js 16+
253
- - TypeScript 4.5+ (optional but recommended)
254
-
255
- **Note about Legacy Dependencies:**
256
-
257
- As of v3.6.0, React Achievements includes a built-in UI system with **zero external dependencies** when using `useBuiltInUI={true}`. The legacy external UI dependencies (`react-toastify`, `react-modal`, `react-confetti`, `react-use`) are now optional and will be fully deprecated in v4.0.0.
113
+ function Game() {
114
+ const { track, unlocked } = useSimpleAchievements();
258
115
 
259
- ```bash
260
- # Only if using legacy external UI (deprecated in v4.0.0)
261
- npm install react-toastify react-modal react-confetti react-use
116
+ return (
117
+ <div>
118
+ <button onClick={() => track('score', 100)}>Score Points</button>
119
+ <BadgesButtonWithModal unlockedAchievements={unlocked} />
120
+ </div>
121
+ );
122
+ }
262
123
  ```
263
124
 
264
- ➡️ **[Installation Guide](https://dave-b-b.github.io/react-achievements/docs/getting-started/installation)** - Full setup with troubleshooting
125
+ ➡️ **[Direct Updates Guide](https://dave-b-b.github.io/react-achievements/docs/guides/direct-updates)**
265
126
 
266
127
  ---
267
128
 
268
129
  ## Documentation
269
130
 
270
- ### Getting Started
271
- - 📦 **[Installation](https://dave-b-b.github.io/react-achievements/docs/getting-started/installation)** - Setup and troubleshooting
272
- - 🚀 **[Quick Start](https://dave-b-b.github.io/react-achievements/docs/getting-started/quick-start)** - Build your first achievement system
273
- - 📖 **[Simple API Guide](https://dave-b-b.github.io/react-achievements/docs/guides/simple-api)** - Recommended configuration approach
274
-
275
- ### Guides
276
- - 🎨 **[Theming & Built-in UI](https://dave-b-b.github.io/react-achievements/docs/guides/theming)** - Customize UI appearance
277
- - 🏗️ **[Builder API](https://dave-b-b.github.io/react-achievements/docs/guides/builder-api)** - Three-tier builder system for complex achievements
278
- - 💾 **[Storage Options](https://dave-b-b.github.io/react-achievements/docs/guides/storage-options)** - Choose the right storage backend
279
- - 🔧 **[Error Handling](https://dave-b-b.github.io/react-achievements/docs/guides/error-handling)** - Handle errors gracefully
280
- - 📤 **[Data Portability](https://dave-b-b.github.io/react-achievements/docs/guides/data-portability)** - Export/import achievements, cloud storage integration
281
- - 🎨 **[Styling](https://dave-b-b.github.io/react-achievements/docs/guides/styling)** - Custom styling patterns
282
-
283
- ### Recipes & Examples
284
- - 🍳 **[Common Patterns](https://dave-b-b.github.io/react-achievements/docs/recipes/common-patterns)** - Ready-to-use code examples
285
- - 📱 **[State Management](https://dave-b-b.github.io/react-achievements/docs/recipes/state-management)** - Redux, Zustand, Context examples
286
-
287
- ### API Reference
288
- - 📚 **[Complete API Docs](https://dave-b-b.github.io/react-achievements/docs/api)** - Full TypeScript API reference
289
- - 🪝 **[Hooks](https://dave-b-b.github.io/react-achievements/docs/api/functions/useSimpleAchievements)** - useSimpleAchievements, useAchievements
290
- - 🧱 **[Components](https://dave-b-b.github.io/react-achievements/docs/api/variables/BadgesButton)** - BadgesButton, BadgesModal, etc.
291
-
292
- ### Advanced
293
- - 🔌 **[Custom Storage](https://dave-b-b.github.io/react-achievements/docs/advanced/custom-storage)** - Implement your own storage backend
294
- - 🏗️ **[Complex API](https://dave-b-b.github.io/react-achievements/docs/advanced/complex-api)** - For power users needing full control
295
-
296
- ---
297
-
298
- ## Version & Updates
299
-
300
- **Current Version:** 3.7.0
301
-
302
- ### Recent Highlights
303
-
304
- **v3.6.0** - Built-in UI System
305
- - Zero external dependencies with built-in notifications, modals, confetti
306
- - 3 professional themes (modern, minimal, gamified)
307
- - Component injection for custom UI
308
- - Legacy external UI dependencies now optional
309
-
310
- **v3.5.0** - Show All Achievements
311
- - Display locked and unlocked achievements
312
- - Unlock condition hints for user guidance
313
- - Enhanced BadgesModal component
314
-
315
- **v3.4.0** - Async Storage
316
- - IndexedDB support (50MB+ capacity)
317
- - REST API storage for cloud sync
318
- - Offline Queue for offline-first apps
319
- - Optimistic updates and eager loading
320
-
321
- **v3.3.0** - Error Handling & Data Portability
322
- - Type-safe error classes with recovery guidance
323
- - Export/import for backups and cross-device transfer
324
- - AWS S3 and Azure Blob Storage integration
325
-
326
- ➡️ **[Full Changelog](https://github.com/dave-b-b/react-achievements/releases)**
327
-
328
- ---
329
-
330
- ## Examples & Feature Explanation
331
-
332
- ### Feature Explanation
333
- - 🎮 **[Interactive Storybook](https://dave-b-b.github.io/react-achievements/)** - Explore all components and features
334
- - 🌐 **[Documentation Site](https://dave-b-b.github.io/react-achievements/docs/)** - Comprehensive guides and API docs
335
-
336
- ### Example Implementations
337
- Explore complete working implementations in the `stories/examples/` directory:
338
-
339
- - **[Redux Example](./stories/examples/redux/)** - Integration with Redux Toolkit
340
- - **[Zustand Example](./stories/examples/zustand/)** - Integration with Zustand
341
- - **[Context Example](./stories/examples/context/)** - Pure React Context implementation
342
-
343
- Each example includes complete working code you can copy and adapt for your project.
344
-
345
- ---
346
-
347
- ## Contributing
348
-
349
- We welcome contributions! React Achievements is built with:
350
- - ✅ 154+ comprehensive tests with full coverage
351
- - ✅ Pre-commit hooks (TypeScript + Jest)
352
- - ✅ TypeScript-first development
353
- - ✅ Storybook for component development
354
-
355
- ### Quick Contribution Steps
356
-
357
- 1. Fork the repository
358
- 2. Install dependencies: `npm install`
359
- 3. Install git hooks: `npm run install-hooks`
360
- 4. Make your changes
361
- 5. Ensure tests pass: `npm test`
362
- 6. Open a Pull Request
363
-
364
- ➡️ **[Contributing Guide](./CONTRIBUTING.md)** - Detailed contribution guidelines
365
-
366
- ### Development Commands
367
-
368
- ```bash
369
- npm run build # Build the library
370
- npm test # Run TypeScript checks + tests
371
- npm run storybook # Start Storybook on port 6006
372
- npm run type-check # TypeScript type checking
373
- ```
131
+ 📚 **[Full Documentation](https://dave-b-b.github.io/react-achievements/)** - Complete guides, API reference, and examples
374
132
 
375
133
  ---
376
134
 
@@ -378,36 +136,11 @@ npm run type-check # TypeScript type checking
378
136
 
379
137
  React Achievements is **dual-licensed**:
380
138
 
381
- ### Free for Non-Commercial Use (MIT License)
139
+ - **Free for Non-Commercial Use** (MIT License) - Personal projects, education, non-profits, open source
140
+ - **Commercial License Required** - Businesses, SaaS, commercial apps, enterprise
382
141
 
383
- Personal projects
384
- ✅ Educational institutions
385
- ✅ Non-profit organizations (501(c)(3) or equivalent)
386
- ✅ Open source projects (OSI-approved license)
387
- ✅ Evaluation, development, and testing
388
-
389
- ### Commercial License Required
390
-
391
- 💼 Businesses using the library in revenue-generating products or services
392
- 💼 SaaS applications, commercial websites, paid mobile apps
393
- 💼 Enterprise software and internal business applications
394
- 💼 Freelancers or contractors building paid projects for clients
395
-
396
- **[Get Your Commercial License via GitHub Sponsors →](https://github.com/sponsors/dave-b-b)**
397
-
398
- #### Pricing Tiers:
399
- - **Indie Developer** ($20/month) - Small businesses, freelancers, startups under $100K revenue
400
- - **Professional** ($50/month) - Growing companies under $1M revenue, priority support
401
- - **Enterprise** ($100/month) - Large companies, unlimited revenue
402
-
403
- ➡️ **[License Details](./LICENSE)** | **[Commercial License Terms](./COMMERCIAL-LICENSE.md)**
404
-
405
- For custom licensing or questions: **reactachievements@gmail.com**
142
+ **[Get Commercial License →](https://github.com/sponsors/dave-b-b)** | **[License Details](./LICENSE)** | **[Commercial Terms](./COMMERCIAL-LICENSE.md)**
406
143
 
407
144
  ---
408
145
 
409
- **Built with ❤️ by [Dave B](https://github.com/dave-b-b)**
410
-
411
- **Questions?** [Open an issue](https://github.com/dave-b-b/react-achievements/issues) | [Join discussions](https://github.com/dave-b-b/react-achievements/discussions) | [⭐ Star on GitHub](https://github.com/dave-b-b/react-achievements)
412
-
413
- **Commercial Users**: Support development via [GitHub Sponsors](https://github.com/sponsors/dave-b-b)
146
+ **Built with ❤️ by [Dave B](https://github.com/dave-b-b)** | [📚 Documentation](https://dave-b-b.github.io/react-achievements/) | [⭐ Star on GitHub](https://github.com/dave-b-b/react-achievements)