react-achievements 1.3.2 → 1.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/README.md +5 -1
- package/demo/package-lock.json +1046 -55
- package/demo/package.json +1 -1
- package/demo/src/AchievementConfig.ts +37 -0
- package/demo/src/App.jsx +65 -11
- package/demo/src/assets/achievements/explorer.webp +0 -0
- package/demo/src/assets/achievements/seaoned_warrior.webp +0 -0
- package/demo/src/assets/achievements/warrior.webp +0 -0
- package/package.json +1 -1
package/demo/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "demo",
|
|
3
|
-
"private": true,
|
|
4
3
|
"version": "0.0.0",
|
|
5
4
|
"type": "module",
|
|
6
5
|
"scripts": {
|
|
@@ -36,6 +35,7 @@
|
|
|
36
35
|
"eslint-plugin-storybook": "^0.8.0",
|
|
37
36
|
"globals": "^15.9.0",
|
|
38
37
|
"prop-types": "^15.8.1",
|
|
38
|
+
"react-achievements": "^1.3.3",
|
|
39
39
|
"storybook": "^8.2.8",
|
|
40
40
|
"vite": "^5.4.0"
|
|
41
41
|
},
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import explorer from "./assets/achievements/explorer.webp";
|
|
2
|
+
import warrior from "./assets/achievements/warrior.webp";
|
|
3
|
+
import seasoned_warrior from "./assets/achievements/seaoned_warrior.webp";
|
|
4
|
+
|
|
5
|
+
const achievementConfig = {
|
|
6
|
+
level: [
|
|
7
|
+
{
|
|
8
|
+
check: (value: number) => value >= 5,
|
|
9
|
+
data: {
|
|
10
|
+
id: "level_5",
|
|
11
|
+
title: "Novice Adventurer",
|
|
12
|
+
description: "Reached level 5",
|
|
13
|
+
icon: explorer,
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
check: (value: number) => value >= 10,
|
|
18
|
+
data: {
|
|
19
|
+
id: "level_10",
|
|
20
|
+
title: "Warrior",
|
|
21
|
+
description: "Reached level 10",
|
|
22
|
+
icon: warrior,
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
check: (value: number) => value >= 15,
|
|
27
|
+
data: {
|
|
28
|
+
id: "level_15",
|
|
29
|
+
title: "Seasoned Warrior",
|
|
30
|
+
description: "Reached level 15",
|
|
31
|
+
icon: seasoned_warrior,
|
|
32
|
+
},
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export default achievementConfig;
|
package/demo/src/App.jsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
function App() {
|
|
7
|
-
const [count, setCount] = useState(0)
|
|
1
|
+
import reactLogo from "./assets/react.svg";
|
|
2
|
+
import viteLogo from "/vite.svg";
|
|
3
|
+
import "./App.css";
|
|
4
|
+
import { AchievementProvider, useAchievement } from "react-achievements";
|
|
5
|
+
import achievementConfig from "./AchievementConfig";
|
|
8
6
|
|
|
7
|
+
const AppContents = () => {
|
|
8
|
+
const { setMetrics, metrics } = useAchievement();
|
|
9
9
|
return (
|
|
10
10
|
<>
|
|
11
11
|
<div>
|
|
@@ -18,8 +18,17 @@ function App() {
|
|
|
18
18
|
</div>
|
|
19
19
|
<h1>Vite + React</h1>
|
|
20
20
|
<div className="card">
|
|
21
|
-
<button
|
|
22
|
-
|
|
21
|
+
<button
|
|
22
|
+
onClick={() => {
|
|
23
|
+
setMetrics((prevMetrics) => {
|
|
24
|
+
return {
|
|
25
|
+
...prevMetrics,
|
|
26
|
+
level: prevMetrics.level + 1,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
}}
|
|
30
|
+
>
|
|
31
|
+
level is {metrics.level}
|
|
23
32
|
</button>
|
|
24
33
|
<p>
|
|
25
34
|
Edit <code>src/App.jsx</code> and save to test HMR
|
|
@@ -29,7 +38,52 @@ function App() {
|
|
|
29
38
|
Click on the Vite and React logos to learn more
|
|
30
39
|
</p>
|
|
31
40
|
</>
|
|
32
|
-
)
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const initialState = {
|
|
45
|
+
level: 1,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @see node_modules/react-achievements/dist/defaultStyles.d.ts
|
|
50
|
+
*/
|
|
51
|
+
const customStyles = {
|
|
52
|
+
achievementModal: {
|
|
53
|
+
overlay: {
|
|
54
|
+
backgroundColor: "rgba(0, 0, 0, 0.6)",
|
|
55
|
+
},
|
|
56
|
+
content: {
|
|
57
|
+
color: "#000000",
|
|
58
|
+
},
|
|
59
|
+
title: {
|
|
60
|
+
// color: "#ffd700",
|
|
61
|
+
},
|
|
62
|
+
button: {
|
|
63
|
+
// backgroundColor: "#4CAF50",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
badgesModal: {
|
|
67
|
+
content: {
|
|
68
|
+
color: "#000000",
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
badgesButton: {
|
|
72
|
+
// Custom styles for the badges button
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
function App() {
|
|
77
|
+
return (
|
|
78
|
+
<AchievementProvider
|
|
79
|
+
config={achievementConfig}
|
|
80
|
+
initialState={initialState}
|
|
81
|
+
badgesButtonPosition="top-right"
|
|
82
|
+
styles={customStyles}
|
|
83
|
+
>
|
|
84
|
+
<AppContents />
|
|
85
|
+
</AchievementProvider>
|
|
86
|
+
);
|
|
33
87
|
}
|
|
34
88
|
|
|
35
|
-
export default App
|
|
89
|
+
export default App;
|
|
Binary file
|
|
Binary file
|
|
Binary file
|