react-achievements 3.1.0 → 3.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 +320 -225
- package/dist/index.d.ts +152 -74
- package/dist/index.js +328 -110
- package/dist/index.js.map +1 -1
- package/dist/types/core/icons/defaultIcons.d.ts +0 -73
- package/dist/types/hooks/useSimpleAchievements.d.ts +6 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/utils/achievementHelpers.d.ts +135 -0
- package/package.json +7 -2
|
@@ -9,6 +9,12 @@ export declare const useSimpleAchievements: () => {
|
|
|
9
9
|
* @param value - The metric value
|
|
10
10
|
*/
|
|
11
11
|
track: (metric: string, value: any) => void;
|
|
12
|
+
/**
|
|
13
|
+
* Increment a numeric metric by a specified amount
|
|
14
|
+
* @param metric - The metric name (e.g., 'buttonClicks', 'score')
|
|
15
|
+
* @param amount - The amount to increment by (defaults to 1)
|
|
16
|
+
*/
|
|
17
|
+
increment: (metric: string, amount?: number) => void;
|
|
12
18
|
/**
|
|
13
19
|
* Track multiple metrics at once
|
|
14
20
|
* @param metrics - Object with metric names as keys and values
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export type { AchievementMetrics, AchievementConfiguration, AchievementConfigurationType, SimpleAchievementConfig, SimpleAchievementDetails, CustomAchievementDetails, AchievementDetails, AchievementCondition, AchievementMetricValue, AchievementMetricArrayValue, InitialAchievementMetrics, AchievementState, AchievementStorage, AchievementContextValue, StylesProps, AchievementProviderProps, } from './core/types';
|
|
2
2
|
export { LocalStorage } from './core/storage/LocalStorage';
|
|
3
|
+
export { MemoryStorage } from './core/storage/MemoryStorage';
|
|
3
4
|
export { StorageType } from './core/types';
|
|
4
5
|
export { BadgesButton } from './core/components/BadgesButton';
|
|
5
6
|
export { BadgesModal } from './core/components/BadgesModal';
|
|
@@ -10,3 +11,4 @@ export { useSimpleAchievements } from './hooks/useSimpleAchievements';
|
|
|
10
11
|
export { defaultStyles } from './core/styles/defaultStyles';
|
|
11
12
|
export { defaultAchievementIcons } from './core/icons/defaultIcons';
|
|
12
13
|
export { normalizeAchievements, isSimpleConfig } from './core/utils/configNormalizer';
|
|
14
|
+
export { AchievementBuilder, type AwardDetails, } from './utils/achievementHelpers';
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { SimpleAchievementConfig, AchievementMetricValue, AchievementState } from '../core/types';
|
|
2
|
+
/**
|
|
3
|
+
* Helper interface for cleaner achievement award definitions
|
|
4
|
+
*/
|
|
5
|
+
export interface AwardDetails {
|
|
6
|
+
title?: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
icon?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Base class for chainable achievement configuration (Tier 2)
|
|
12
|
+
*/
|
|
13
|
+
declare abstract class Achievement {
|
|
14
|
+
protected metric: string;
|
|
15
|
+
protected award: AwardDetails;
|
|
16
|
+
constructor(metric: string, defaultAward: AwardDetails);
|
|
17
|
+
/**
|
|
18
|
+
* Customize the award details for this achievement
|
|
19
|
+
* @param award - Custom award details
|
|
20
|
+
* @returns This achievement for chaining
|
|
21
|
+
*/
|
|
22
|
+
withAward(award: AwardDetails): Achievement;
|
|
23
|
+
/**
|
|
24
|
+
* Convert this achievement to a SimpleAchievementConfig
|
|
25
|
+
*/
|
|
26
|
+
abstract toConfig(): SimpleAchievementConfig;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Threshold-based achievement (score, level, etc.)
|
|
30
|
+
*/
|
|
31
|
+
declare class ThresholdAchievement extends Achievement {
|
|
32
|
+
private threshold;
|
|
33
|
+
constructor(metric: string, threshold: number, defaultAward: AwardDetails);
|
|
34
|
+
toConfig(): SimpleAchievementConfig;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Boolean achievement (tutorial completion, first login, etc.)
|
|
38
|
+
*/
|
|
39
|
+
declare class BooleanAchievement extends Achievement {
|
|
40
|
+
toConfig(): SimpleAchievementConfig;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Value-based achievement (character class, difficulty, etc.)
|
|
44
|
+
*/
|
|
45
|
+
declare class ValueAchievement extends Achievement {
|
|
46
|
+
private value;
|
|
47
|
+
constructor(metric: string, value: string, defaultAward: AwardDetails);
|
|
48
|
+
toConfig(): SimpleAchievementConfig;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Complex achievement builder for power users (Tier 3)
|
|
52
|
+
*/
|
|
53
|
+
declare class ComplexAchievementBuilder {
|
|
54
|
+
private id;
|
|
55
|
+
private metric;
|
|
56
|
+
private condition;
|
|
57
|
+
private award;
|
|
58
|
+
/**
|
|
59
|
+
* Set the unique identifier for this achievement
|
|
60
|
+
*/
|
|
61
|
+
withId(id: string): ComplexAchievementBuilder;
|
|
62
|
+
/**
|
|
63
|
+
* Set the metric this achievement tracks
|
|
64
|
+
*/
|
|
65
|
+
withMetric(metric: string): ComplexAchievementBuilder;
|
|
66
|
+
/**
|
|
67
|
+
* Set the condition function that determines if achievement is unlocked
|
|
68
|
+
*/
|
|
69
|
+
withCondition(fn: (value: AchievementMetricValue, state: AchievementState) => boolean): ComplexAchievementBuilder;
|
|
70
|
+
/**
|
|
71
|
+
* Set the award details for this achievement
|
|
72
|
+
*/
|
|
73
|
+
withAward(award: AwardDetails): ComplexAchievementBuilder;
|
|
74
|
+
/**
|
|
75
|
+
* Build the final achievement configuration
|
|
76
|
+
*/
|
|
77
|
+
build(): SimpleAchievementConfig;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Main AchievementBuilder with three-tier API
|
|
81
|
+
* Tier 1: Simple static methods with smart defaults
|
|
82
|
+
* Tier 2: Chainable customization
|
|
83
|
+
* Tier 3: Full builder for complex logic
|
|
84
|
+
*/
|
|
85
|
+
export declare class AchievementBuilder {
|
|
86
|
+
/**
|
|
87
|
+
* Create a single score achievement with smart defaults
|
|
88
|
+
* @param threshold - Score threshold to achieve
|
|
89
|
+
* @returns Chainable ThresholdAchievement
|
|
90
|
+
*/
|
|
91
|
+
static createScoreAchievement(threshold: number): ThresholdAchievement;
|
|
92
|
+
/**
|
|
93
|
+
* Create multiple score achievements
|
|
94
|
+
* @param thresholds - Array of thresholds or [threshold, award] tuples
|
|
95
|
+
* @returns Complete SimpleAchievementConfig
|
|
96
|
+
*/
|
|
97
|
+
static createScoreAchievements(thresholds: (number | [number, AwardDetails])[]): SimpleAchievementConfig;
|
|
98
|
+
/**
|
|
99
|
+
* Create a single level achievement with smart defaults
|
|
100
|
+
* @param level - Level threshold to achieve
|
|
101
|
+
* @returns Chainable ThresholdAchievement
|
|
102
|
+
*/
|
|
103
|
+
static createLevelAchievement(level: number): ThresholdAchievement;
|
|
104
|
+
/**
|
|
105
|
+
* Create multiple level achievements
|
|
106
|
+
* @param levels - Array of levels or [level, award] tuples
|
|
107
|
+
* @returns Complete SimpleAchievementConfig
|
|
108
|
+
*/
|
|
109
|
+
static createLevelAchievements(levels: (number | [number, AwardDetails])[]): SimpleAchievementConfig;
|
|
110
|
+
/**
|
|
111
|
+
* Create a boolean achievement with smart defaults
|
|
112
|
+
* @param metric - The metric name (e.g., 'completedTutorial')
|
|
113
|
+
* @returns Chainable BooleanAchievement
|
|
114
|
+
*/
|
|
115
|
+
static createBooleanAchievement(metric: string): BooleanAchievement;
|
|
116
|
+
/**
|
|
117
|
+
* Create a value-based achievement with smart defaults
|
|
118
|
+
* @param metric - The metric name (e.g., 'characterClass')
|
|
119
|
+
* @param value - The value to match (e.g., 'wizard')
|
|
120
|
+
* @returns Chainable ValueAchievement
|
|
121
|
+
*/
|
|
122
|
+
static createValueAchievement(metric: string, value: string): ValueAchievement;
|
|
123
|
+
/**
|
|
124
|
+
* Create a complex achievement builder for power users
|
|
125
|
+
* @returns ComplexAchievementBuilder for full control
|
|
126
|
+
*/
|
|
127
|
+
static create(): ComplexAchievementBuilder;
|
|
128
|
+
/**
|
|
129
|
+
* Combine multiple achievement configurations
|
|
130
|
+
* @param achievements - Array of SimpleAchievementConfig objects or Achievement instances
|
|
131
|
+
* @returns Combined SimpleAchievementConfig
|
|
132
|
+
*/
|
|
133
|
+
static combine(achievements: (SimpleAchievementConfig | Achievement)[]): SimpleAchievementConfig;
|
|
134
|
+
}
|
|
135
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-achievements",
|
|
3
|
-
"version": "3.1
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "Core achievement system for React applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "rollup -c",
|
|
9
|
-
"test": "jest",
|
|
9
|
+
"test": "npm run type-check && jest",
|
|
10
|
+
"test:unit": "jest",
|
|
11
|
+
"type-check": "tsc --noEmit --project tsconfig.test.json",
|
|
12
|
+
"type-check:watch": "tsc --noEmit --watch --project tsconfig.test.json",
|
|
13
|
+
"type-check:src": "tsc --noEmit",
|
|
14
|
+
"type-check:stories": "find stories -name '*.tsx' -o -name '*.ts' | xargs tsc --noEmit --jsx react --esModuleInterop --skipLibCheck",
|
|
10
15
|
"prepare": "npm run build",
|
|
11
16
|
"storybook": "storybook dev -p 6006",
|
|
12
17
|
"build-storybook": "storybook build"
|