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
package/dist/index.d.ts CHANGED
@@ -1,5 +1,135 @@
1
1
  import React$1 from 'react';
2
2
 
3
+ /**
4
+ * Notification component interface
5
+ * Displays achievement unlock notifications
6
+ */
7
+ 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
+ type NotificationComponent = React$1.FC<NotificationProps>;
20
+ /**
21
+ * Modal component interface
22
+ * Displays list of achievements (locked/unlocked)
23
+ */
24
+ interface ModalProps {
25
+ isOpen: boolean;
26
+ onClose: () => void;
27
+ achievements: AchievementWithStatus[];
28
+ icons?: Record<string, string>;
29
+ theme?: string;
30
+ }
31
+ type ModalComponent = React$1.FC<ModalProps>;
32
+ /**
33
+ * Confetti component interface
34
+ * Displays celebration animation
35
+ */
36
+ interface ConfettiProps {
37
+ show: boolean;
38
+ duration?: number;
39
+ particleCount?: number;
40
+ colors?: string[];
41
+ }
42
+ type ConfettiComponent = React$1.FC<ConfettiProps>;
43
+ /**
44
+ * Notification positioning options
45
+ */
46
+ 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
+ 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
+ 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
+ }
132
+
3
133
  type AchievementMetricValue = number | string | boolean | Date | null | undefined;
4
134
  type AchievementMetricArrayValue = AchievementMetricValue | AchievementMetricValue[];
5
135
  interface AchievementMetrics {
@@ -16,12 +146,7 @@ interface AchievementWithStatus extends AchievementDetails {
16
146
  }
17
147
  interface AchievementCondition {
18
148
  isConditionMet: (value: AchievementMetricArrayValue, state: AchievementState) => boolean;
19
- achievementDetails: {
20
- achievementId: string;
21
- achievementTitle: string;
22
- achievementDescription: string;
23
- achievementIconKey: string;
24
- };
149
+ achievementDetails: AchievementDetails | AchievementWithStatus;
25
150
  }
26
151
  interface AchievementConfiguration {
27
152
  [key: string]: AchievementCondition[];
@@ -326,9 +451,25 @@ declare class OfflineQueueStorage implements AsyncAchievementStorage {
326
451
 
327
452
  interface BadgesButtonProps {
328
453
  onClick: () => void;
329
- position: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
454
+ /**
455
+ * Position for fixed placement mode
456
+ * Only used when placement='fixed'
457
+ */
458
+ position?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
459
+ /**
460
+ * Placement mode
461
+ * - 'fixed': Traditional floating button with fixed positioning
462
+ * - 'inline': Regular component that can be placed in drawers, nav bars, etc.
463
+ * @default 'fixed'
464
+ */
465
+ placement?: 'fixed' | 'inline';
330
466
  styles?: React$1.CSSProperties;
331
467
  unlockedAchievements: AchievementDetails[];
468
+ /**
469
+ * Theme name for styling (matches notification/modal theme)
470
+ * @default 'modern'
471
+ */
472
+ theme?: string;
332
473
  }
333
474
  declare const BadgesButton: React$1.FC<BadgesButtonProps>;
334
475
 
@@ -422,6 +563,19 @@ interface AchievementProviderProps {
422
563
  icons?: Record<string, string>;
423
564
  onError?: (error: AchievementError) => void;
424
565
  restApiConfig?: RestApiStorageConfig;
566
+ /**
567
+ * UI configuration for notifications, modal, and confetti
568
+ * NEW in v3.6.0
569
+ */
570
+ ui?: UIConfig;
571
+ /**
572
+ * Force use of built-in UI components (opt-in for v3.x)
573
+ * Set to true to skip legacy library detection and use built-in UI
574
+ * In v4.0.0, this will become the default behavior
575
+ * NEW in v3.6.0
576
+ * @default false
577
+ */
578
+ useBuiltInUI?: boolean;
425
579
  }
426
580
  declare const AchievementProvider: React$1.FC<AchievementProviderProps>;
427
581
 
@@ -673,4 +827,39 @@ declare function exportAchievementData(metrics: AchievementMetrics, unlocked: st
673
827
  */
674
828
  declare function createConfigHash(config: any): string;
675
829
 
676
- export { AchievementBuilder, AchievementCondition, AchievementConfiguration, AchievementConfigurationType, AchievementContext, AchievementContextValue, AchievementDetails, AchievementError, AchievementMetricArrayValue, AchievementMetricValue, AchievementMetrics, AchievementProvider, AchievementProviderProps$1 as AchievementProviderProps, AchievementState, AchievementStorage, AchievementWithStatus, AnyAchievementStorage, AsyncAchievementStorage, AsyncStorageAdapter, AwardDetails, BadgesButton, BadgesModal, ConfettiWrapper, ConfigurationError, CustomAchievementDetails, ExportedData, ImportOptions, ImportResult, ImportValidationError, IndexedDBStorage, InitialAchievementMetrics, LocalStorage, MemoryStorage, OfflineQueueStorage, RestApiStorage, RestApiStorageConfig, SimpleAchievementConfig, SimpleAchievementDetails, StorageError, StorageQuotaError, StorageType, StylesProps, SyncError, createConfigHash, defaultAchievementIcons, defaultStyles, exportAchievementData, importAchievementData, isAchievementError, isAsyncStorage, isRecoverableError, isSimpleConfig, normalizeAchievements, useAchievements, useSimpleAchievements };
830
+ /**
831
+ * Built-in notification component
832
+ * Modern, theme-aware achievement notification with smooth animations
833
+ */
834
+ declare const BuiltInNotification: React$1.FC<NotificationProps>;
835
+
836
+ /**
837
+ * Built-in modal component
838
+ * Modern, theme-aware achievement modal with smooth animations
839
+ */
840
+ declare const BuiltInModal: React$1.FC<ModalProps>;
841
+
842
+ /**
843
+ * Built-in confetti component
844
+ * Lightweight CSS-based confetti animation
845
+ */
846
+ declare const BuiltInConfetti: React$1.FC<ConfettiProps>;
847
+
848
+ /**
849
+ * Hook to track window dimensions
850
+ * Replacement for react-use's useWindowSize
851
+ *
852
+ * @returns Object with width and height properties
853
+ *
854
+ * @example
855
+ * ```tsx
856
+ * const { width, height } = useWindowSize();
857
+ * console.log(`Window size: ${width}x${height}`);
858
+ * ```
859
+ */
860
+ declare function useWindowSize(): {
861
+ width: number;
862
+ height: number;
863
+ };
864
+
865
+ export { AchievementBuilder, AchievementCondition, AchievementConfiguration, AchievementConfigurationType, AchievementContext, AchievementContextValue, AchievementDetails, AchievementError, AchievementMetricArrayValue, AchievementMetricValue, AchievementMetrics, AchievementProvider, AchievementProviderProps$1 as AchievementProviderProps, AchievementState, AchievementStorage, AchievementWithStatus, AnyAchievementStorage, AsyncAchievementStorage, AsyncStorageAdapter, AwardDetails, BadgesButton, BadgesModal, BuiltInConfetti, BuiltInModal, BuiltInNotification, ConfettiComponent, ConfettiProps, ConfettiWrapper, ConfigurationError, CustomAchievementDetails, ExportedData, ImportOptions, ImportResult, ImportValidationError, IndexedDBStorage, InitialAchievementMetrics, LocalStorage, MemoryStorage, ModalComponent, ModalProps, NotificationComponent, NotificationPosition, NotificationProps, OfflineQueueStorage, RestApiStorage, RestApiStorageConfig, SimpleAchievementConfig, SimpleAchievementDetails, StorageError, StorageQuotaError, StorageType, StylesProps, SyncError, ThemeConfig, UIConfig, createConfigHash, defaultAchievementIcons, defaultStyles, exportAchievementData, importAchievementData, isAchievementError, isAsyncStorage, isRecoverableError, isSimpleConfig, normalizeAchievements, useAchievements, useSimpleAchievements, useWindowSize };