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
package/dist/index.d.ts
CHANGED
|
@@ -104,6 +104,17 @@ declare class LocalStorage implements AchievementStorage {
|
|
|
104
104
|
clear(): void;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
+
declare class MemoryStorage implements AchievementStorage {
|
|
108
|
+
private metrics;
|
|
109
|
+
private unlockedAchievements;
|
|
110
|
+
constructor();
|
|
111
|
+
getMetrics(): AchievementMetrics;
|
|
112
|
+
setMetrics(metrics: AchievementMetrics): void;
|
|
113
|
+
getUnlockedAchievements(): string[];
|
|
114
|
+
setUnlockedAchievements(achievements: string[]): void;
|
|
115
|
+
clear(): void;
|
|
116
|
+
}
|
|
117
|
+
|
|
107
118
|
interface BadgesButtonProps {
|
|
108
119
|
onClick: () => void;
|
|
109
120
|
position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
@@ -160,6 +171,12 @@ declare const useSimpleAchievements: () => {
|
|
|
160
171
|
* @param value - The metric value
|
|
161
172
|
*/
|
|
162
173
|
track: (metric: string, value: any) => void;
|
|
174
|
+
/**
|
|
175
|
+
* Increment a numeric metric by a specified amount
|
|
176
|
+
* @param metric - The metric name (e.g., 'buttonClicks', 'score')
|
|
177
|
+
* @param amount - The amount to increment by (defaults to 1)
|
|
178
|
+
*/
|
|
179
|
+
increment: (metric: string, amount?: number) => void;
|
|
163
180
|
/**
|
|
164
181
|
* Track multiple metrics at once
|
|
165
182
|
* @param metrics - Object with metric names as keys and values
|
|
@@ -193,88 +210,149 @@ declare const useSimpleAchievements: () => {
|
|
|
193
210
|
declare const defaultStyles: Required<StylesProps>;
|
|
194
211
|
|
|
195
212
|
declare const defaultAchievementIcons: {
|
|
196
|
-
levelUp: string;
|
|
197
|
-
questComplete: string;
|
|
198
|
-
monsterDefeated: string;
|
|
199
|
-
itemCollected: string;
|
|
200
|
-
challengeCompleted: string;
|
|
201
|
-
milestoneReached: string;
|
|
202
|
-
firstStep: string;
|
|
203
|
-
newBeginnings: string;
|
|
204
|
-
breakthrough: string;
|
|
205
|
-
growth: string;
|
|
206
|
-
shared: string;
|
|
207
|
-
liked: string;
|
|
208
|
-
commented: string;
|
|
209
|
-
followed: string;
|
|
210
|
-
invited: string;
|
|
211
|
-
communityMember: string;
|
|
212
|
-
supporter: string;
|
|
213
|
-
connected: string;
|
|
214
|
-
participant: string;
|
|
215
|
-
influencer: string;
|
|
216
|
-
activeDay: string;
|
|
217
|
-
activeWeek: string;
|
|
218
|
-
activeMonth: string;
|
|
219
|
-
earlyBird: string;
|
|
220
|
-
nightOwl: string;
|
|
221
|
-
streak: string;
|
|
222
|
-
dedicated: string;
|
|
223
|
-
punctual: string;
|
|
224
|
-
consistent: string;
|
|
225
|
-
marathon: string;
|
|
226
|
-
artist: string;
|
|
227
|
-
writer: string;
|
|
228
|
-
innovator: string;
|
|
229
|
-
creator: string;
|
|
230
|
-
expert: string;
|
|
231
|
-
master: string;
|
|
232
|
-
pioneer: string;
|
|
233
|
-
performer: string;
|
|
234
|
-
thinker: string;
|
|
235
|
-
explorer: string;
|
|
236
|
-
bronze: string;
|
|
237
|
-
silver: string;
|
|
238
|
-
gold: string;
|
|
239
|
-
diamond: string;
|
|
240
|
-
legendary: string;
|
|
241
|
-
epic: string;
|
|
242
|
-
rare: string;
|
|
243
|
-
common: string;
|
|
244
|
-
special: string;
|
|
245
|
-
hidden: string;
|
|
246
|
-
one: string;
|
|
247
|
-
ten: string;
|
|
248
|
-
hundred: string;
|
|
249
|
-
thousand: string;
|
|
250
|
-
clicked: string;
|
|
251
|
-
used: string;
|
|
252
|
-
found: string;
|
|
253
|
-
built: string;
|
|
254
|
-
solved: string;
|
|
255
|
-
discovered: string;
|
|
256
|
-
unlocked: string;
|
|
257
|
-
upgraded: string;
|
|
258
|
-
repaired: string;
|
|
259
|
-
defended: string;
|
|
260
213
|
default: string;
|
|
261
214
|
loading: string;
|
|
262
215
|
error: string;
|
|
263
216
|
success: string;
|
|
264
|
-
failure: string;
|
|
265
217
|
trophy: string;
|
|
266
218
|
star: string;
|
|
267
|
-
flag: string;
|
|
268
|
-
puzzle: string;
|
|
269
|
-
gem: string;
|
|
270
|
-
crown: string;
|
|
271
|
-
medal: string;
|
|
272
|
-
ribbon: string;
|
|
273
|
-
badge: string;
|
|
274
|
-
shield: string;
|
|
275
219
|
};
|
|
276
220
|
|
|
277
221
|
declare function isSimpleConfig(config: AchievementConfigurationType): config is SimpleAchievementConfig;
|
|
278
222
|
declare function normalizeAchievements(config: AchievementConfigurationType): AchievementConfiguration;
|
|
279
223
|
|
|
280
|
-
|
|
224
|
+
/**
|
|
225
|
+
* Helper interface for cleaner achievement award definitions
|
|
226
|
+
*/
|
|
227
|
+
interface AwardDetails {
|
|
228
|
+
title?: string;
|
|
229
|
+
description?: string;
|
|
230
|
+
icon?: string;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Base class for chainable achievement configuration (Tier 2)
|
|
234
|
+
*/
|
|
235
|
+
declare abstract class Achievement {
|
|
236
|
+
protected metric: string;
|
|
237
|
+
protected award: AwardDetails;
|
|
238
|
+
constructor(metric: string, defaultAward: AwardDetails);
|
|
239
|
+
/**
|
|
240
|
+
* Customize the award details for this achievement
|
|
241
|
+
* @param award - Custom award details
|
|
242
|
+
* @returns This achievement for chaining
|
|
243
|
+
*/
|
|
244
|
+
withAward(award: AwardDetails): Achievement;
|
|
245
|
+
/**
|
|
246
|
+
* Convert this achievement to a SimpleAchievementConfig
|
|
247
|
+
*/
|
|
248
|
+
abstract toConfig(): SimpleAchievementConfig;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Threshold-based achievement (score, level, etc.)
|
|
252
|
+
*/
|
|
253
|
+
declare class ThresholdAchievement extends Achievement {
|
|
254
|
+
private threshold;
|
|
255
|
+
constructor(metric: string, threshold: number, defaultAward: AwardDetails);
|
|
256
|
+
toConfig(): SimpleAchievementConfig;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Boolean achievement (tutorial completion, first login, etc.)
|
|
260
|
+
*/
|
|
261
|
+
declare class BooleanAchievement extends Achievement {
|
|
262
|
+
toConfig(): SimpleAchievementConfig;
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Value-based achievement (character class, difficulty, etc.)
|
|
266
|
+
*/
|
|
267
|
+
declare class ValueAchievement extends Achievement {
|
|
268
|
+
private value;
|
|
269
|
+
constructor(metric: string, value: string, defaultAward: AwardDetails);
|
|
270
|
+
toConfig(): SimpleAchievementConfig;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Complex achievement builder for power users (Tier 3)
|
|
274
|
+
*/
|
|
275
|
+
declare class ComplexAchievementBuilder {
|
|
276
|
+
private id;
|
|
277
|
+
private metric;
|
|
278
|
+
private condition;
|
|
279
|
+
private award;
|
|
280
|
+
/**
|
|
281
|
+
* Set the unique identifier for this achievement
|
|
282
|
+
*/
|
|
283
|
+
withId(id: string): ComplexAchievementBuilder;
|
|
284
|
+
/**
|
|
285
|
+
* Set the metric this achievement tracks
|
|
286
|
+
*/
|
|
287
|
+
withMetric(metric: string): ComplexAchievementBuilder;
|
|
288
|
+
/**
|
|
289
|
+
* Set the condition function that determines if achievement is unlocked
|
|
290
|
+
*/
|
|
291
|
+
withCondition(fn: (value: AchievementMetricValue, state: AchievementState) => boolean): ComplexAchievementBuilder;
|
|
292
|
+
/**
|
|
293
|
+
* Set the award details for this achievement
|
|
294
|
+
*/
|
|
295
|
+
withAward(award: AwardDetails): ComplexAchievementBuilder;
|
|
296
|
+
/**
|
|
297
|
+
* Build the final achievement configuration
|
|
298
|
+
*/
|
|
299
|
+
build(): SimpleAchievementConfig;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Main AchievementBuilder with three-tier API
|
|
303
|
+
* Tier 1: Simple static methods with smart defaults
|
|
304
|
+
* Tier 2: Chainable customization
|
|
305
|
+
* Tier 3: Full builder for complex logic
|
|
306
|
+
*/
|
|
307
|
+
declare class AchievementBuilder {
|
|
308
|
+
/**
|
|
309
|
+
* Create a single score achievement with smart defaults
|
|
310
|
+
* @param threshold - Score threshold to achieve
|
|
311
|
+
* @returns Chainable ThresholdAchievement
|
|
312
|
+
*/
|
|
313
|
+
static createScoreAchievement(threshold: number): ThresholdAchievement;
|
|
314
|
+
/**
|
|
315
|
+
* Create multiple score achievements
|
|
316
|
+
* @param thresholds - Array of thresholds or [threshold, award] tuples
|
|
317
|
+
* @returns Complete SimpleAchievementConfig
|
|
318
|
+
*/
|
|
319
|
+
static createScoreAchievements(thresholds: (number | [number, AwardDetails])[]): SimpleAchievementConfig;
|
|
320
|
+
/**
|
|
321
|
+
* Create a single level achievement with smart defaults
|
|
322
|
+
* @param level - Level threshold to achieve
|
|
323
|
+
* @returns Chainable ThresholdAchievement
|
|
324
|
+
*/
|
|
325
|
+
static createLevelAchievement(level: number): ThresholdAchievement;
|
|
326
|
+
/**
|
|
327
|
+
* Create multiple level achievements
|
|
328
|
+
* @param levels - Array of levels or [level, award] tuples
|
|
329
|
+
* @returns Complete SimpleAchievementConfig
|
|
330
|
+
*/
|
|
331
|
+
static createLevelAchievements(levels: (number | [number, AwardDetails])[]): SimpleAchievementConfig;
|
|
332
|
+
/**
|
|
333
|
+
* Create a boolean achievement with smart defaults
|
|
334
|
+
* @param metric - The metric name (e.g., 'completedTutorial')
|
|
335
|
+
* @returns Chainable BooleanAchievement
|
|
336
|
+
*/
|
|
337
|
+
static createBooleanAchievement(metric: string): BooleanAchievement;
|
|
338
|
+
/**
|
|
339
|
+
* Create a value-based achievement with smart defaults
|
|
340
|
+
* @param metric - The metric name (e.g., 'characterClass')
|
|
341
|
+
* @param value - The value to match (e.g., 'wizard')
|
|
342
|
+
* @returns Chainable ValueAchievement
|
|
343
|
+
*/
|
|
344
|
+
static createValueAchievement(metric: string, value: string): ValueAchievement;
|
|
345
|
+
/**
|
|
346
|
+
* Create a complex achievement builder for power users
|
|
347
|
+
* @returns ComplexAchievementBuilder for full control
|
|
348
|
+
*/
|
|
349
|
+
static create(): ComplexAchievementBuilder;
|
|
350
|
+
/**
|
|
351
|
+
* Combine multiple achievement configurations
|
|
352
|
+
* @param achievements - Array of SimpleAchievementConfig objects or Achievement instances
|
|
353
|
+
* @returns Combined SimpleAchievementConfig
|
|
354
|
+
*/
|
|
355
|
+
static combine(achievements: (SimpleAchievementConfig | Achievement)[]): SimpleAchievementConfig;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export { AchievementBuilder, AchievementCondition, AchievementConfiguration, AchievementConfigurationType, AchievementContext, AchievementContextValue, AchievementDetails, AchievementMetricArrayValue, AchievementMetricValue, AchievementMetrics, AchievementProvider, AchievementProviderProps$1 as AchievementProviderProps, AchievementState, AchievementStorage, AwardDetails, BadgesButton, BadgesModal, ConfettiWrapper, CustomAchievementDetails, InitialAchievementMetrics, LocalStorage, MemoryStorage, SimpleAchievementConfig, SimpleAchievementDetails, StorageType, StylesProps, defaultAchievementIcons, defaultStyles, isSimpleConfig, normalizeAchievements, useAchievements, useSimpleAchievements };
|