react-achievements 3.5.0 → 3.6.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.
Files changed (52) hide show
  1. package/README.md +1127 -27
  2. package/dist/index.d.ts +197 -8
  3. package/dist/index.js +764 -32
  4. package/dist/index.js.map +1 -1
  5. package/dist/types/core/components/BadgesButton.d.ts +18 -3
  6. package/dist/types/core/hooks/useWindowSize.d.ts +16 -0
  7. package/dist/types/core/types.d.ts +2 -6
  8. package/dist/types/core/ui/BuiltInConfetti.d.ts +7 -0
  9. package/dist/types/core/ui/BuiltInModal.d.ts +7 -0
  10. package/dist/types/core/ui/BuiltInNotification.d.ts +7 -0
  11. package/dist/types/core/ui/LegacyWrappers.d.ts +21 -0
  12. package/dist/types/core/ui/interfaces.d.ts +131 -0
  13. package/dist/types/core/ui/legacyDetector.d.ts +40 -0
  14. package/dist/types/core/ui/themes.d.ts +14 -0
  15. package/dist/types/index.d.ts +5 -0
  16. package/dist/types/providers/AchievementProvider.d.ts +14 -2
  17. package/package.json +15 -1
  18. package/dist/assets/defaultIcons.d.ts +0 -81
  19. package/dist/badges.d.ts +0 -8
  20. package/dist/components/Achievement.d.ts +0 -10
  21. package/dist/components/AchievementModal.d.ts +0 -12
  22. package/dist/components/Badge.d.ts +0 -9
  23. package/dist/components/BadgesButton.d.ts +0 -14
  24. package/dist/components/BadgesModal.d.ts +0 -12
  25. package/dist/components/ConfettiWrapper.d.ts +0 -6
  26. package/dist/components/Progress.d.ts +0 -6
  27. package/dist/context/AchievementContext.d.ts +0 -21
  28. package/dist/defaultStyles.d.ts +0 -19
  29. package/dist/hooks/useAchievement.d.ts +0 -8
  30. package/dist/hooks/useAchievementState.d.ts +0 -4
  31. package/dist/index.cjs.js +0 -2428
  32. package/dist/index.esm.js +0 -2403
  33. package/dist/levels.d.ts +0 -7
  34. package/dist/providers/AchievementProvider.d.ts +0 -12
  35. package/dist/redux/achievementSlice.d.ts +0 -30
  36. package/dist/redux/notificationSlice.d.ts +0 -7
  37. package/dist/redux/store.d.ts +0 -15
  38. package/dist/stories/Button.d.ts +0 -28
  39. package/dist/stories/Button.stories.d.ts +0 -23
  40. package/dist/stories/Header.d.ts +0 -13
  41. package/dist/stories/Header.stories.d.ts +0 -18
  42. package/dist/stories/Page.d.ts +0 -3
  43. package/dist/stories/Page.stories.d.ts +0 -12
  44. package/dist/types/core/context/AchievementContext.d.ts +0 -5
  45. package/dist/types/stories/Button.d.ts +0 -16
  46. package/dist/types/stories/Button.stories.d.ts +0 -23
  47. package/dist/types/stories/Header.d.ts +0 -13
  48. package/dist/types/stories/Header.stories.d.ts +0 -18
  49. package/dist/types/stories/Page.d.ts +0 -3
  50. package/dist/types/stories/Page.stories.d.ts +0 -12
  51. package/dist/types.d.ts +0 -37
  52. package/dist/utils/EventEmitter.d.ts +0 -6
@@ -0,0 +1,131 @@
1
+ import React from 'react';
2
+ import { AchievementWithStatus } from '../types';
3
+ /**
4
+ * Notification component interface
5
+ * Displays achievement unlock notifications
6
+ */
7
+ export interface NotificationProps {
8
+ achievement: {
9
+ id: string;
10
+ title: string;
11
+ description: string;
12
+ icon: string;
13
+ };
14
+ onClose?: () => void;
15
+ duration?: number;
16
+ position?: NotificationPosition;
17
+ theme?: string;
18
+ }
19
+ export type NotificationComponent = React.FC<NotificationProps>;
20
+ /**
21
+ * Modal component interface
22
+ * Displays list of achievements (locked/unlocked)
23
+ */
24
+ export interface ModalProps {
25
+ isOpen: boolean;
26
+ onClose: () => void;
27
+ achievements: AchievementWithStatus[];
28
+ icons?: Record<string, string>;
29
+ theme?: string;
30
+ }
31
+ export type ModalComponent = React.FC<ModalProps>;
32
+ /**
33
+ * Confetti component interface
34
+ * Displays celebration animation
35
+ */
36
+ export interface ConfettiProps {
37
+ show: boolean;
38
+ duration?: number;
39
+ particleCount?: number;
40
+ colors?: string[];
41
+ }
42
+ export type ConfettiComponent = React.FC<ConfettiProps>;
43
+ /**
44
+ * Notification positioning options
45
+ */
46
+ export type NotificationPosition = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
47
+ /**
48
+ * Theme configuration interface
49
+ * Defines styling for all UI components
50
+ */
51
+ export interface ThemeConfig {
52
+ name: string;
53
+ notification: {
54
+ background: string;
55
+ textColor: string;
56
+ accentColor: string;
57
+ borderRadius: string;
58
+ boxShadow: string;
59
+ fontSize?: {
60
+ header?: string;
61
+ title?: string;
62
+ description?: string;
63
+ };
64
+ };
65
+ modal: {
66
+ overlayColor: string;
67
+ background: string;
68
+ textColor: string;
69
+ accentColor: string;
70
+ borderRadius: string;
71
+ headerFontSize?: string;
72
+ achievementCardBorderRadius?: string;
73
+ achievementLayout?: 'horizontal' | 'badge';
74
+ };
75
+ confetti: {
76
+ colors: string[];
77
+ particleCount: number;
78
+ shapes?: ('circle' | 'square')[];
79
+ };
80
+ }
81
+ /**
82
+ * UI Configuration for AchievementProvider
83
+ * Allows customization of all UI components
84
+ */
85
+ export interface UIConfig {
86
+ /**
87
+ * Custom notification component
88
+ * If not provided, uses built-in or legacy component based on detection
89
+ */
90
+ NotificationComponent?: NotificationComponent;
91
+ /**
92
+ * Custom modal component
93
+ * If not provided, uses built-in or legacy component based on detection
94
+ */
95
+ ModalComponent?: ModalComponent;
96
+ /**
97
+ * Custom confetti component
98
+ * If not provided, uses built-in or legacy component based on detection
99
+ */
100
+ ConfettiComponent?: ConfettiComponent;
101
+ /**
102
+ * Theme to use (built-in name or registered custom theme name)
103
+ * Built-in themes: 'modern' (default), 'minimal', 'gamified'
104
+ */
105
+ theme?: string;
106
+ /**
107
+ * Direct theme configuration override
108
+ * Takes precedence over theme name
109
+ */
110
+ customTheme?: ThemeConfig;
111
+ /**
112
+ * Notification positioning
113
+ * @default 'top-center'
114
+ */
115
+ notificationPosition?: NotificationPosition;
116
+ /**
117
+ * Enable/disable notifications
118
+ * @default true
119
+ */
120
+ enableNotifications?: boolean;
121
+ /**
122
+ * Enable/disable confetti animations
123
+ * @default true
124
+ */
125
+ enableConfetti?: boolean;
126
+ /**
127
+ * Enable/disable modal
128
+ * @default true
129
+ */
130
+ enableModal?: boolean;
131
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Legacy UI library detection system
3
+ * Attempts to dynamically import external UI libraries
4
+ * Shows deprecation warnings when detected
5
+ */
6
+ export interface LegacyLibraries {
7
+ toast?: any;
8
+ ToastContainer?: any;
9
+ Modal?: any;
10
+ Confetti?: any;
11
+ useWindowSize?: any;
12
+ }
13
+ /**
14
+ * Attempts to dynamically import legacy UI libraries
15
+ * Uses try/catch to gracefully handle missing dependencies
16
+ * Caches result to avoid multiple import attempts
17
+ *
18
+ * @returns Promise resolving to LegacyLibraries object
19
+ */
20
+ export declare function detectLegacyLibraries(): Promise<LegacyLibraries>;
21
+ /**
22
+ * Synchronous check if libraries are already loaded
23
+ * Does not trigger detection if not already attempted
24
+ *
25
+ * @returns Boolean indicating if legacy libraries were detected
26
+ */
27
+ export declare function hasLegacyLibraries(): boolean;
28
+ /**
29
+ * Get cached legacy libraries without re-detection
30
+ * Returns null if detection hasn't been attempted yet
31
+ *
32
+ * @returns Cached LegacyLibraries or null
33
+ */
34
+ export declare function getCachedLegacyLibraries(): LegacyLibraries | null;
35
+ /**
36
+ * Reset detection state (useful for testing)
37
+ *
38
+ * @internal
39
+ */
40
+ export declare function resetDetection(): void;
@@ -0,0 +1,14 @@
1
+ import { ThemeConfig } from './interfaces';
2
+ /**
3
+ * Built-in theme presets
4
+ */
5
+ export declare const builtInThemes: Record<string, ThemeConfig>;
6
+ /**
7
+ * Retrieve a theme by name (internal use only)
8
+ * Only checks built-in themes
9
+ *
10
+ * @param name - Theme name (built-in only)
11
+ * @returns Theme configuration or undefined if not found
12
+ * @internal
13
+ */
14
+ export declare function getTheme(name: string): ThemeConfig | undefined;
@@ -20,3 +20,8 @@ export { AchievementBuilder, type AwardDetails, } from './utils/achievementHelpe
20
20
  export { AchievementError, StorageQuotaError, ImportValidationError, StorageError, ConfigurationError, SyncError, isAchievementError, isRecoverableError } from './core/errors/AchievementErrors';
21
21
  export { exportAchievementData, createConfigHash, type ExportedData } from './core/utils/dataExport';
22
22
  export { importAchievementData, type ImportOptions, type ImportResult } from './core/utils/dataImport';
23
+ export { BuiltInNotification } from './core/ui/BuiltInNotification';
24
+ export { BuiltInModal } from './core/ui/BuiltInModal';
25
+ export { BuiltInConfetti } from './core/ui/BuiltInConfetti';
26
+ export type { NotificationComponent, NotificationProps, ModalComponent, ModalProps, ConfettiComponent, ConfettiProps, NotificationPosition, ThemeConfig, UIConfig, } from './core/types';
27
+ export { useWindowSize } from './core/hooks/useWindowSize';
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
- import { AchievementConfigurationType, AchievementStorage, AsyncAchievementStorage, AchievementMetrics, StorageType, AchievementWithStatus } from '../core/types';
2
+ import { AchievementConfigurationType, AchievementStorage, AsyncAchievementStorage, AchievementMetrics, StorageType, AchievementWithStatus, UIConfig } from '../core/types';
3
3
  import { RestApiStorageConfig } from '../core/storage/RestApiStorage';
4
- import 'react-toastify/dist/ReactToastify.css';
5
4
  import { ImportOptions, ImportResult } from '../core/utils/dataImport';
6
5
  import { AchievementError } from '../core/errors/AchievementErrors';
7
6
  export interface AchievementContextType {
@@ -27,6 +26,19 @@ interface AchievementProviderProps {
27
26
  icons?: Record<string, string>;
28
27
  onError?: (error: AchievementError) => void;
29
28
  restApiConfig?: RestApiStorageConfig;
29
+ /**
30
+ * UI configuration for notifications, modal, and confetti
31
+ * NEW in v3.6.0
32
+ */
33
+ ui?: UIConfig;
34
+ /**
35
+ * Force use of built-in UI components (opt-in for v3.x)
36
+ * Set to true to skip legacy library detection and use built-in UI
37
+ * In v4.0.0, this will become the default behavior
38
+ * NEW in v3.6.0
39
+ * @default false
40
+ */
41
+ useBuiltInUI?: boolean;
30
42
  }
31
43
  export declare const AchievementProvider: React.FC<AchievementProviderProps>;
32
44
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-achievements",
3
- "version": "3.5.0",
3
+ "version": "3.6.1",
4
4
  "description": "Core achievement system for React applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -27,6 +27,20 @@
27
27
  "react-toastify": "^9.1.3",
28
28
  "react-use": "^17.4.0"
29
29
  },
30
+ "peerDependenciesMeta": {
31
+ "react-confetti": {
32
+ "optional": true
33
+ },
34
+ "react-modal": {
35
+ "optional": true
36
+ },
37
+ "react-toastify": {
38
+ "optional": true
39
+ },
40
+ "react-use": {
41
+ "optional": true
42
+ }
43
+ },
30
44
  "devDependencies": {
31
45
  "@babel/core": "^7.22.5",
32
46
  "@babel/preset-env": "^7.22.5",
@@ -1,81 +0,0 @@
1
- export declare const defaultAchievementIcons: {
2
- levelUp: string;
3
- questComplete: string;
4
- monsterDefeated: string;
5
- itemCollected: string;
6
- challengeCompleted: string;
7
- milestoneReached: string;
8
- firstStep: string;
9
- newBeginnings: string;
10
- breakthrough: string;
11
- growth: string;
12
- shared: string;
13
- liked: string;
14
- commented: string;
15
- followed: string;
16
- invited: string;
17
- communityMember: string;
18
- supporter: string;
19
- connected: string;
20
- participant: string;
21
- influencer: string;
22
- activeDay: string;
23
- activeWeek: string;
24
- activeMonth: string;
25
- earlyBird: string;
26
- nightOwl: string;
27
- streak: string;
28
- dedicated: string;
29
- punctual: string;
30
- consistent: string;
31
- marathon: string;
32
- artist: string;
33
- writer: string;
34
- innovator: string;
35
- creator: string;
36
- expert: string;
37
- master: string;
38
- pioneer: string;
39
- performer: string;
40
- thinker: string;
41
- explorer: string;
42
- bronze: string;
43
- silver: string;
44
- gold: string;
45
- diamond: string;
46
- legendary: string;
47
- epic: string;
48
- rare: string;
49
- common: string;
50
- special: string;
51
- hidden: string;
52
- one: string;
53
- ten: string;
54
- hundred: string;
55
- thousand: string;
56
- clicked: string;
57
- used: string;
58
- found: string;
59
- built: string;
60
- solved: string;
61
- discovered: string;
62
- unlocked: string;
63
- upgraded: string;
64
- repaired: string;
65
- defended: string;
66
- default: string;
67
- loading: string;
68
- error: string;
69
- success: string;
70
- failure: string;
71
- trophy: string;
72
- star: string;
73
- flag: string;
74
- puzzle: string;
75
- gem: string;
76
- crown: string;
77
- medal: string;
78
- ribbon: string;
79
- badge: string;
80
- shield: string;
81
- };
package/dist/badges.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export interface BadgeConfig {
2
- id: string;
3
- icon: string;
4
- title: string;
5
- description: string;
6
- }
7
- declare const defaultBadges: BadgeConfig[];
8
- export { defaultBadges };
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- interface AchievementProps {
3
- metric: number;
4
- threshold: number;
5
- onAchieve: () => void;
6
- message: string;
7
- children: React.ReactNode;
8
- }
9
- declare const _default: React.NamedExoticComponent<AchievementProps>;
10
- export default _default;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { AchievementDetails } from '../types';
3
- import { Styles } from '../defaultStyles';
4
- interface AchievementModalProps {
5
- isOpen: boolean;
6
- achievement: AchievementDetails | null;
7
- onClose: () => void;
8
- styles: Styles['achievementModal'];
9
- icons?: Record<string, string>;
10
- }
11
- declare const _default: React.NamedExoticComponent<AchievementModalProps>;
12
- export default _default;
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- interface BadgeProps {
3
- icon: string;
4
- title: string;
5
- description: string;
6
- position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
7
- }
8
- declare const Badge: React.FC<BadgeProps>;
9
- export default Badge;
@@ -1,14 +0,0 @@
1
- import React from 'react';
2
- import { Styles } from '../defaultStyles';
3
- import { AchievementDetails } from '../types';
4
- interface BadgesButtonProps {
5
- onClick: () => void;
6
- position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
7
- styles: Styles['badgesButton'];
8
- unlockedAchievements: AchievementDetails[];
9
- icon?: React.ReactNode;
10
- drawer?: boolean;
11
- customStyles?: React.CSSProperties;
12
- }
13
- declare const _default: React.NamedExoticComponent<BadgesButtonProps>;
14
- export default _default;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import { AchievementDetails } from '../types';
3
- import { Styles } from '../defaultStyles';
4
- interface BadgesModalProps {
5
- isOpen: boolean;
6
- achievements: AchievementDetails[];
7
- onClose: () => void;
8
- styles: Styles['badgesModal'];
9
- icons?: Record<string, string>;
10
- }
11
- declare const _default: React.NamedExoticComponent<BadgesModalProps>;
12
- export default _default;
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- interface ConfettiWrapperProps {
3
- show: boolean;
4
- }
5
- declare const ConfettiWrapper: React.FC<ConfettiWrapperProps>;
6
- export default ConfettiWrapper;
@@ -1,6 +0,0 @@
1
- import React from 'react';
2
- interface ProgressProps {
3
- style?: React.CSSProperties;
4
- }
5
- declare const _default: React.NamedExoticComponent<ProgressProps>;
6
- export default _default;
@@ -1,21 +0,0 @@
1
- import React, { ReactNode } from 'react';
2
- import { Metrics, AchievementConfig, MetricValue } from '../types';
3
- import { Styles } from '../defaultStyles';
4
- interface AchievementContextProps {
5
- metrics: Metrics;
6
- setMetrics: (metrics: Metrics | ((prevMetrics: Metrics) => Metrics)) => void;
7
- unlockedAchievements: string[];
8
- checkAchievements: () => void;
9
- showBadgesModal: () => void;
10
- }
11
- interface AchievementProviderProps {
12
- children: ReactNode;
13
- config: AchievementConfig;
14
- initialState?: Record<string, MetricValue>;
15
- storageKey?: string;
16
- badgesButtonPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
17
- styles?: Partial<Styles>;
18
- }
19
- export declare const AchievementProvider: React.FC<AchievementProviderProps>;
20
- export declare const useAchievement: () => AchievementContextProps;
21
- export {};
@@ -1,19 +0,0 @@
1
- type StyleObject = {
2
- [key: string]: string | number;
3
- };
4
- interface BadgesModalStyles {
5
- overlay: StyleObject;
6
- content: StyleObject;
7
- title: StyleObject;
8
- badgeContainer: StyleObject;
9
- badge: StyleObject;
10
- badgeIcon: StyleObject;
11
- badgeTitle: StyleObject;
12
- button: StyleObject;
13
- }
14
- export interface Styles {
15
- badgesModal: BadgesModalStyles;
16
- badgesButton: StyleObject;
17
- }
18
- export declare const defaultStyles: Styles;
19
- export {};
@@ -1,8 +0,0 @@
1
- export declare const useAchievement: () => {
2
- metrics: import("..").AchievementMetrics;
3
- unlockedAchievements: string[];
4
- notifications: import("..").AchievementDetails[];
5
- config: import("../types").SerializedAchievementConfiguration;
6
- updateMetrics: (newMetrics: import("..").AchievementMetrics | ((prevMetrics: import("..").AchievementMetrics) => import("..").AchievementMetrics)) => void;
7
- resetStorage: () => void;
8
- };
@@ -1,4 +0,0 @@
1
- export declare const useAchievementState: () => {
2
- metrics: import("..").AchievementMetrics;
3
- previouslyAwardedAchievements: string[];
4
- };