react-achievements 3.5.0 → 3.6.0

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 +310 -20
  2. package/dist/index.d.ts +196 -2
  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 +1 -0
  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/levels.d.ts DELETED
@@ -1,7 +0,0 @@
1
- export interface LevelConfig {
2
- level: number;
3
- threshold: number;
4
- badgeId: string;
5
- }
6
- declare const defaultLevels: LevelConfig[];
7
- export { defaultLevels };
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import 'react-toastify/dist/ReactToastify.css';
3
- import { AchievementProviderProps, AchievementMetrics } from '../types';
4
- export interface AchievementContextType {
5
- updateMetrics: (newMetrics: AchievementMetrics | ((prevMetrics: AchievementMetrics) => AchievementMetrics)) => void;
6
- unlockedAchievements: string[];
7
- resetStorage: () => void;
8
- }
9
- export declare const AchievementContext: React.Context<AchievementContextType | undefined>;
10
- export declare const useAchievementContext: () => AchievementContextType;
11
- declare const AchievementProvider: React.FC<AchievementProviderProps>;
12
- export { AchievementProvider };
@@ -1,30 +0,0 @@
1
- import { PayloadAction } from '@reduxjs/toolkit';
2
- import { InitialAchievementMetrics, AchievementMetrics, SerializedAchievementConfiguration } from '../types';
3
- export interface AchievementState {
4
- config: SerializedAchievementConfiguration;
5
- metrics: AchievementMetrics;
6
- unlockedAchievements: string[];
7
- previouslyAwardedAchievements: string[];
8
- storageKey: string | null;
9
- }
10
- export declare const achievementSlice: import("@reduxjs/toolkit").Slice<AchievementState, {
11
- initialize: (state: import("immer/dist/internal").WritableDraft<AchievementState>, action: PayloadAction<{
12
- config: SerializedAchievementConfiguration;
13
- initialState?: InitialAchievementMetrics & {
14
- previouslyAwardedAchievements?: string[];
15
- };
16
- storageKey: string;
17
- }>) => void;
18
- setMetrics: (state: import("immer/dist/internal").WritableDraft<AchievementState>, action: PayloadAction<AchievementMetrics>) => void;
19
- markAchievementAsAwarded: (state: import("immer/dist/internal").WritableDraft<AchievementState>, action: PayloadAction<string>) => void;
20
- resetAchievements: (state: import("immer/dist/internal").WritableDraft<AchievementState>) => void;
21
- }, "achievements">;
22
- export declare const initialize: import("@reduxjs/toolkit").ActionCreatorWithPayload<{
23
- config: SerializedAchievementConfiguration;
24
- initialState?: InitialAchievementMetrics & {
25
- previouslyAwardedAchievements?: string[];
26
- };
27
- storageKey: string;
28
- }, "achievements/initialize">, setMetrics: import("@reduxjs/toolkit").ActionCreatorWithPayload<AchievementMetrics, "achievements/setMetrics">, resetAchievements: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"achievements/resetAchievements">, markAchievementAsAwarded: import("@reduxjs/toolkit").ActionCreatorWithPayload<string, "achievements/markAchievementAsAwarded">;
29
- declare const _default: import("@reduxjs/toolkit").Reducer<AchievementState>;
30
- export default _default;
@@ -1,7 +0,0 @@
1
- import { AchievementDetails } from '../types';
2
- export interface NotificationState {
3
- notifications: AchievementDetails[];
4
- }
5
- export declare const addNotification: import("@reduxjs/toolkit").ActionCreatorWithPayload<AchievementDetails, "notifications/addNotification">, clearNotifications: import("@reduxjs/toolkit").ActionCreatorWithoutPayload<"notifications/clearNotifications">;
6
- declare const _default: import("@reduxjs/toolkit").Reducer<NotificationState>;
7
- export default _default;
@@ -1,15 +0,0 @@
1
- import { AchievementState } from './achievementSlice';
2
- import { NotificationState } from './notificationSlice';
3
- export interface RootState {
4
- achievements: AchievementState;
5
- notifications: NotificationState;
6
- }
7
- declare const store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<{
8
- achievements: AchievementState;
9
- notifications: NotificationState;
10
- }, import("@reduxjs/toolkit").AnyAction, [import("@reduxjs/toolkit").ThunkMiddleware<{
11
- achievements: AchievementState;
12
- notifications: NotificationState;
13
- }, import("@reduxjs/toolkit").AnyAction>]>;
14
- export type AppDispatch = typeof store.dispatch;
15
- export default store;
@@ -1,28 +0,0 @@
1
- import React from 'react';
2
- import './button.css';
3
- export interface ButtonProps {
4
- /**
5
- * Is this the principal call to action on the page?
6
- */
7
- primary?: boolean;
8
- /**
9
- * What background color to use
10
- */
11
- backgroundColor?: string;
12
- /**
13
- * How large should the button be?
14
- */
15
- size?: 'small' | 'medium' | 'large';
16
- /**
17
- * Button contents
18
- */
19
- label: string;
20
- /**
21
- * Optional click handler
22
- */
23
- onClick?: () => void;
24
- }
25
- /**
26
- * Primary UI component for user interaction
27
- */
28
- export declare const Button: ({ primary, size, backgroundColor, label, ...props }: ButtonProps) => React.JSX.Element;
@@ -1,23 +0,0 @@
1
- import type { StoryObj } from '@storybook/react';
2
- declare const meta: {
3
- title: string;
4
- component: ({ primary, size, backgroundColor, label, ...props }: import("./Button").ButtonProps) => import("react").JSX.Element;
5
- parameters: {
6
- layout: string;
7
- };
8
- tags: string[];
9
- argTypes: {
10
- backgroundColor: {
11
- control: "color";
12
- };
13
- };
14
- args: {
15
- onClick: import("@vitest/spy").Mock<[], void>;
16
- };
17
- };
18
- export default meta;
19
- type Story = StoryObj<typeof meta>;
20
- export declare const Primary: Story;
21
- export declare const Secondary: Story;
22
- export declare const Large: Story;
23
- export declare const Small: Story;
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- import './header.css';
3
- type User = {
4
- name: string;
5
- };
6
- export interface HeaderProps {
7
- user?: User;
8
- onLogin?: () => void;
9
- onLogout?: () => void;
10
- onCreateAccount?: () => void;
11
- }
12
- export declare const Header: ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => React.JSX.Element;
13
- export {};
@@ -1,18 +0,0 @@
1
- import type { StoryObj } from '@storybook/react';
2
- declare const meta: {
3
- title: string;
4
- component: ({ user, onLogin, onLogout, onCreateAccount }: import("./Header").HeaderProps) => import("react").JSX.Element;
5
- tags: string[];
6
- parameters: {
7
- layout: string;
8
- };
9
- args: {
10
- onLogin: import("@vitest/spy").Mock<[], void>;
11
- onLogout: import("@vitest/spy").Mock<[], void>;
12
- onCreateAccount: import("@vitest/spy").Mock<[], void>;
13
- };
14
- };
15
- export default meta;
16
- type Story = StoryObj<typeof meta>;
17
- export declare const LoggedIn: Story;
18
- export declare const LoggedOut: Story;
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- import './page.css';
3
- export declare const Page: React.FC;
@@ -1,12 +0,0 @@
1
- import type { StoryObj } from '@storybook/react';
2
- declare const meta: {
3
- title: string;
4
- component: import("react").FC<{}>;
5
- parameters: {
6
- layout: string;
7
- };
8
- };
9
- export default meta;
10
- type Story = StoryObj<typeof meta>;
11
- export declare const LoggedOut: Story;
12
- export declare const LoggedIn: Story;
@@ -1,5 +0,0 @@
1
- import React from 'react';
2
- import 'react-toastify/dist/ReactToastify.css';
3
- import { AchievementContextValue, AchievementProviderProps } from '../types';
4
- export declare const useAchievementContext: () => AchievementContextValue;
5
- export declare const AchievementProvider: React.FC<AchievementProviderProps>;
@@ -1,16 +0,0 @@
1
- import React from 'react';
2
- import './button.css';
3
- export interface ButtonProps {
4
- /** Is this the principal call to action on the page? */
5
- primary?: boolean;
6
- /** What background color to use */
7
- backgroundColor?: string;
8
- /** How large should the button be? */
9
- size?: 'small' | 'medium' | 'large';
10
- /** Button contents */
11
- label: string;
12
- /** Optional click handler */
13
- onClick?: () => void;
14
- }
15
- /** Primary UI component for user interaction */
16
- export declare const Button: ({ primary, size, backgroundColor, label, ...props }: ButtonProps) => React.JSX.Element;
@@ -1,23 +0,0 @@
1
- import type { StoryObj } from '@storybook/react';
2
- declare const meta: {
3
- title: string;
4
- component: ({ primary, size, backgroundColor, label, ...props }: import("./Button").ButtonProps) => import("react").JSX.Element;
5
- parameters: {
6
- layout: string;
7
- };
8
- tags: string[];
9
- argTypes: {
10
- backgroundColor: {
11
- control: "color";
12
- };
13
- };
14
- args: {
15
- onClick: import("@vitest/spy").Mock<(...args: any[]) => any>;
16
- };
17
- };
18
- export default meta;
19
- type Story = StoryObj<typeof meta>;
20
- export declare const Primary: Story;
21
- export declare const Secondary: Story;
22
- export declare const Large: Story;
23
- export declare const Small: Story;
@@ -1,13 +0,0 @@
1
- import React from 'react';
2
- import './header.css';
3
- type User = {
4
- name: string;
5
- };
6
- export interface HeaderProps {
7
- user?: User;
8
- onLogin?: () => void;
9
- onLogout?: () => void;
10
- onCreateAccount?: () => void;
11
- }
12
- export declare const Header: ({ user, onLogin, onLogout, onCreateAccount }: HeaderProps) => React.JSX.Element;
13
- export {};
@@ -1,18 +0,0 @@
1
- import type { StoryObj } from '@storybook/react';
2
- declare const meta: {
3
- title: string;
4
- component: ({ user, onLogin, onLogout, onCreateAccount }: import("./Header").HeaderProps) => import("react").JSX.Element;
5
- tags: string[];
6
- parameters: {
7
- layout: string;
8
- };
9
- args: {
10
- onLogin: import("@vitest/spy").Mock<(...args: any[]) => any>;
11
- onLogout: import("@vitest/spy").Mock<(...args: any[]) => any>;
12
- onCreateAccount: import("@vitest/spy").Mock<(...args: any[]) => any>;
13
- };
14
- };
15
- export default meta;
16
- type Story = StoryObj<typeof meta>;
17
- export declare const LoggedIn: Story;
18
- export declare const LoggedOut: Story;
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- import './page.css';
3
- export declare const Page: React.FC;
@@ -1,12 +0,0 @@
1
- import type { StoryObj } from '@storybook/react';
2
- declare const meta: {
3
- title: string;
4
- component: import("react").FC<{}>;
5
- parameters: {
6
- layout: string;
7
- };
8
- };
9
- export default meta;
10
- type Story = StoryObj<typeof meta>;
11
- export declare const LoggedOut: Story;
12
- export declare const LoggedIn: Story;
package/dist/types.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import { Styles } from "./defaultStyles";
2
- export type AchievementMetricValue = number | string | boolean | Date;
3
- export interface AchievementDetails {
4
- achievementId: string;
5
- achievementTitle: string;
6
- achievementDescription: string;
7
- achievementIconKey?: string;
8
- }
9
- export type AchievementIconRecord = Record<string, string>;
10
- export interface AchievementConfiguration {
11
- [metricName: string]: Array<AchievementUnlockCondition<AchievementMetricValue>>;
12
- }
13
- export type InitialAchievementMetrics = Record<string, AchievementMetricValue | AchievementMetricValue[] | undefined>;
14
- export type AchievementMetrics = Record<string, AchievementMetricValue[]>;
15
- export interface AchievementProviderProps {
16
- children: React.ReactNode;
17
- config: AchievementConfiguration;
18
- initialState?: InitialAchievementMetrics & {
19
- previouslyAwardedAchievements?: string[];
20
- };
21
- storageKey?: string;
22
- badgesButtonPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
23
- styles?: Partial<Styles>;
24
- icons?: Record<string, string>;
25
- }
26
- export interface AchievementUnlockCondition<T extends AchievementMetricValue> {
27
- isConditionMet: (value: T) => boolean;
28
- achievementDetails: AchievementDetails;
29
- }
30
- export interface SerializedAchievementUnlockCondition {
31
- achievementDetails: AchievementDetails;
32
- conditionType: 'number' | 'string' | 'boolean' | 'date';
33
- conditionValue: any;
34
- }
35
- export interface SerializedAchievementConfiguration {
36
- [metricName: string]: SerializedAchievementUnlockCondition[];
37
- }
@@ -1,6 +0,0 @@
1
- import EventEmitter from 'eventemitter3';
2
- interface EventTypes {
3
- checkAchievements: (payload: Record<string, any>) => void;
4
- }
5
- declare const reactAchievementsEventEmitter: EventEmitter<EventTypes, any>;
6
- export { reactAchievementsEventEmitter };