react-achievements 3.0.0 → 3.0.2

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.
Files changed (2) hide show
  1. package/README.md +130 -3
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,6 +2,104 @@
2
2
 
3
3
  A flexible and extensible achievement system for React applications. This package provides the foundation for implementing achievements in React applications with support for multiple state management solutions including Redux, Zustand, and Context API. Check the `stories/examples` directory for implementation examples with different state management solutions.
4
4
 
5
+ <p align="center">
6
+ <img src="https://media4.giphy.com/media/v1.Y2lkPTc5MGI3NjExbnMxdHVqanZvbGR6czJqOTdpejZqc3F3NXh6a2FiM3lmdnB0d3VoOSZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw/LYXAZelQMeeYpzbgtT/giphy.gif" alt="React Achievements Demo" width="600" />
7
+ </p>
8
+
9
+ ## Installation
10
+
11
+ ```bash
12
+ npm install react-achievements react react-dom react-confetti react-modal react-toastify react-use
13
+ ```
14
+
15
+ Note: React and React DOM should be version 16.8.0 or higher. If you already have some of these packages installed, npm will skip them automatically.
16
+
17
+ ## Quick Start
18
+
19
+ Here's a complete working example that shows automatic notifications and achievement tracking:
20
+
21
+ ```tsx
22
+ import React, { useState } from 'react';
23
+ import {
24
+ AchievementProvider,
25
+ useAchievements,
26
+ BadgesButton,
27
+ BadgesModal
28
+ } from 'react-achievements';
29
+
30
+ // Define a simple achievement
31
+ const achievementConfig = {
32
+ score: [{
33
+ isConditionMet: (value: number) => value >= 100,
34
+ achievementDetails: {
35
+ achievementId: 'score_100',
36
+ achievementTitle: 'Century!',
37
+ achievementDescription: 'Score 100 points',
38
+ achievementIconKey: 'trophy'
39
+ }
40
+ }]
41
+ };
42
+
43
+ // Demo component with all essential features
44
+ const DemoComponent = () => {
45
+ const [isModalOpen, setIsModalOpen] = useState(false);
46
+ const { update, achievements, reset } = useAchievements();
47
+
48
+ return (
49
+ <div>
50
+ <h1>Achievement Demo</h1>
51
+
52
+ {/* Button to trigger achievement */}
53
+ <button onClick={() => update({ score: 100 })}>
54
+ Score 100 points
55
+ </button>
56
+
57
+ {/* Reset button */}
58
+ <button onClick={reset}>
59
+ Reset Achievements
60
+ </button>
61
+
62
+ {/* Shows unlocked achievements count */}
63
+ <p>Unlocked: {achievements.unlocked.length}</p>
64
+
65
+ {/* Floating badges button */}
66
+ <BadgesButton
67
+ position="bottom-right"
68
+ onClick={() => setIsModalOpen(true)}
69
+ unlockedAchievements={achievements.unlocked}
70
+ />
71
+
72
+ {/* Achievement history modal */}
73
+ <BadgesModal
74
+ isOpen={isModalOpen}
75
+ onClose={() => setIsModalOpen(false)}
76
+ achievements={achievements.unlocked}
77
+ />
78
+ </div>
79
+ );
80
+ };
81
+
82
+ // Root component with provider
83
+ const App = () => {
84
+ return (
85
+ <AchievementProvider
86
+ achievements={achievementConfig}
87
+ storage="local"
88
+ >
89
+ <DemoComponent />
90
+ </AchievementProvider>
91
+ );
92
+ };
93
+
94
+ export default App;
95
+ ```
96
+
97
+ When you click "Score 100 points":
98
+ 1. A toast notification appears
99
+ 2. Confetti animation plays
100
+ 3. The achievement is stored and visible in the badges modal
101
+ 4. The badges button updates to show the new count
102
+
5
103
  ## State Management Options
6
104
 
7
105
  This package includes example implementations for different state management solutions in the `stories/examples` directory:
@@ -22,12 +120,41 @@ See the [examples directory](./stories/examples) for detailed implementations an
22
120
  - Confetti animations
23
121
  - TypeScript support
24
122
 
25
- ## Installation
123
+ ## Achievement Notifications & History
26
124
 
27
- ```bash
28
- npm install react-achievements
125
+ The package provides two ways to display achievements to users:
126
+
127
+ ### Automatic Notifications
128
+ When an achievement is unlocked, the system automatically:
129
+ - Shows a toast notification in the top-right corner with the achievement details
130
+ - Plays a confetti animation to celebrate the achievement
131
+
132
+ These notifications appear immediately when achievements are unlocked and require no additional setup.
133
+
134
+ ### Achievement History
135
+ To allow users to view their achievement history, the package provides two essential components:
136
+
137
+ 1. `BadgesButton`: A floating button that shows the number of unlocked achievements
138
+ ```tsx
139
+ <BadgesButton
140
+ position="bottom-right" // or "top-right", "top-left", "bottom-left"
141
+ onClick={() => setIsModalOpen(true)}
142
+ unlockedAchievements={achievements.unlocked}
143
+ />
29
144
  ```
30
145
 
146
+ 2. `BadgesModal`: A modal dialog that displays all unlocked achievements with their details
147
+ ```tsx
148
+ <BadgesModal
149
+ isOpen={isModalOpen}
150
+ onClose={() => setIsModalOpen(false)}
151
+ achievements={achievements.unlocked}
152
+ icons={customIcons} // Optional custom icons
153
+ />
154
+ ```
155
+
156
+ These components are the recommended way to give users access to their achievement history. While you could build custom UI using the `useAchievements` hook data, these components provide a polished, ready-to-use interface for achievement history.
157
+
31
158
  ## Basic Usage
32
159
 
33
160
  ```tsx
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-achievements",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Core achievement system for React applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",