react-achievements 1.3.7 → 2.0.3
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 +181 -146
- package/coverage/clover.xml +1 -1
- package/coverage/lcov-report/src/context/AchievementContext.tsx.html +6 -6
- package/coverage/lcov-report/src/context/index.html +1 -1
- package/coverage/lcov-report/src/index.ts.html +1 -1
- package/coverage/lcov.info +1 -1
- package/dist/assets/defaultIcons.d.ts +81 -0
- package/dist/components/AchievementModal.d.ts +3 -2
- package/dist/components/BadgesButton.d.ts +6 -1
- package/dist/components/BadgesModal.d.ts +3 -2
- package/dist/hooks/useAchievement.d.ts +8 -0
- package/dist/index.cjs.js +2100 -103
- package/dist/index.d.ts +5 -3
- package/dist/index.esm.js +2097 -120
- package/dist/providers/AchievementProvider.d.ts +11 -0
- package/dist/redux/achievementSlice.d.ts +25 -0
- package/dist/redux/notificationSlice.d.ts +7 -0
- package/dist/redux/store.d.ts +15 -0
- package/dist/types.d.ts +22 -13
- package/package.json +26 -18
- package/src/assets/defaultIcons.ts +100 -0
- package/src/components/AchievementModal.tsx +37 -8
- package/src/components/BadgesButton.tsx +33 -7
- package/src/components/BadgesModal.tsx +23 -9
- package/src/hooks/useAchievement.ts +20 -0
- package/src/index.ts +11 -7
- package/src/providers/AchievementProvider.tsx +185 -0
- package/src/redux/achievementSlice.ts +71 -0
- package/src/redux/notificationSlice.ts +26 -0
- package/src/redux/store.ts +20 -0
- package/src/types.ts +24 -13
- package/demo/src/stories/Button.jsx +0 -50
- package/demo/src/stories/Button.stories.js +0 -48
- package/demo/src/stories/Configure.mdx +0 -364
- package/demo/src/stories/Header.jsx +0 -59
- package/demo/src/stories/Header.stories.js +0 -28
- package/demo/src/stories/Page.jsx +0 -69
- package/demo/src/stories/Page.stories.js +0 -28
- package/demo/src/stories/assets/accessibility.png +0 -0
- package/demo/src/stories/assets/accessibility.svg +0 -1
- package/demo/src/stories/assets/addon-library.png +0 -0
- package/demo/src/stories/assets/assets.png +0 -0
- package/demo/src/stories/assets/avif-test-image.avif +0 -0
- package/demo/src/stories/assets/context.png +0 -0
- package/demo/src/stories/assets/discord.svg +0 -1
- package/demo/src/stories/assets/docs.png +0 -0
- package/demo/src/stories/assets/figma-plugin.png +0 -0
- package/demo/src/stories/assets/github.svg +0 -1
- package/demo/src/stories/assets/share.png +0 -0
- package/demo/src/stories/assets/styling.png +0 -0
- package/demo/src/stories/assets/testing.png +0 -0
- package/demo/src/stories/assets/theming.png +0 -0
- package/demo/src/stories/assets/tutorials.svg +0 -1
- package/demo/src/stories/assets/youtube.svg +0 -1
- package/demo/src/stories/button.css +0 -30
- package/demo/src/stories/header.css +0 -32
- package/demo/src/stories/page.css +0 -69
- package/dist/stories/Button.d.ts +0 -28
- package/dist/stories/Button.stories.d.ts +0 -23
- package/dist/stories/Header.d.ts +0 -13
- package/dist/stories/Header.stories.d.ts +0 -18
- package/dist/stories/Page.d.ts +0 -3
- package/dist/stories/Page.stories.d.ts +0 -12
- package/src/context/AchievementContext.tsx +0 -185
- package/src/stories/Button.stories.ts +0 -52
- package/src/stories/Button.tsx +0 -48
- package/src/stories/Configure.mdx +0 -364
- package/src/stories/Header.stories.ts +0 -33
- package/src/stories/Header.tsx +0 -56
- package/src/stories/Page.stories.ts +0 -32
- package/src/stories/Page.tsx +0 -73
- package/src/stories/assets/accessibility.png +0 -0
- package/src/stories/assets/accessibility.svg +0 -1
- package/src/stories/assets/addon-library.png +0 -0
- package/src/stories/assets/assets.png +0 -0
- package/src/stories/assets/avif-test-image.avif +0 -0
- package/src/stories/assets/context.png +0 -0
- package/src/stories/assets/discord.svg +0 -1
- package/src/stories/assets/docs.png +0 -0
- package/src/stories/assets/figma-plugin.png +0 -0
- package/src/stories/assets/github.svg +0 -1
- package/src/stories/assets/share.png +0 -0
- package/src/stories/assets/styling.png +0 -0
- package/src/stories/assets/testing.png +0 -0
- package/src/stories/assets/theming.png +0 -0
- package/src/stories/assets/tutorials.svg +0 -1
- package/src/stories/assets/youtube.svg +0 -1
- package/src/stories/button.css +0 -30
- package/src/stories/header.css +0 -32
- package/src/stories/page.css +0 -69
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
.storybook-page {
|
|
2
|
-
font-family: 'Nunito Sans', 'Helvetica Neue', Helvetica, Arial, sans-serif;
|
|
3
|
-
font-size: 14px;
|
|
4
|
-
line-height: 24px;
|
|
5
|
-
padding: 48px 20px;
|
|
6
|
-
margin: 0 auto;
|
|
7
|
-
max-width: 600px;
|
|
8
|
-
color: #333;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
.storybook-page h2 {
|
|
12
|
-
font-weight: 700;
|
|
13
|
-
font-size: 32px;
|
|
14
|
-
line-height: 1;
|
|
15
|
-
margin: 0 0 4px;
|
|
16
|
-
display: inline-block;
|
|
17
|
-
vertical-align: top;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
.storybook-page p {
|
|
21
|
-
margin: 1em 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.storybook-page a {
|
|
25
|
-
text-decoration: none;
|
|
26
|
-
color: #1ea7fd;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
.storybook-page ul {
|
|
30
|
-
padding-left: 30px;
|
|
31
|
-
margin: 1em 0;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.storybook-page li {
|
|
35
|
-
margin-bottom: 8px;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
.storybook-page .tip {
|
|
39
|
-
display: inline-block;
|
|
40
|
-
border-radius: 1em;
|
|
41
|
-
font-size: 11px;
|
|
42
|
-
line-height: 12px;
|
|
43
|
-
font-weight: 700;
|
|
44
|
-
background: #e7fdd8;
|
|
45
|
-
color: #66bf3c;
|
|
46
|
-
padding: 4px 12px;
|
|
47
|
-
margin-right: 10px;
|
|
48
|
-
vertical-align: top;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.storybook-page .tip-wrapper {
|
|
52
|
-
font-size: 13px;
|
|
53
|
-
line-height: 20px;
|
|
54
|
-
margin-top: 40px;
|
|
55
|
-
margin-bottom: 40px;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.storybook-page .tip-wrapper svg {
|
|
59
|
-
display: inline-block;
|
|
60
|
-
height: 12px;
|
|
61
|
-
width: 12px;
|
|
62
|
-
margin-right: 4px;
|
|
63
|
-
vertical-align: top;
|
|
64
|
-
margin-top: 3px;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
.storybook-page .tip-wrapper svg path {
|
|
68
|
-
fill: #1ea7fd;
|
|
69
|
-
}
|
package/dist/stories/Button.d.ts
DELETED
|
@@ -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;
|
package/dist/stories/Header.d.ts
DELETED
|
@@ -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;
|
package/dist/stories/Page.d.ts
DELETED
|
@@ -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,185 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext, useState, useEffect, useCallback, ReactNode } from 'react';
|
|
2
|
-
import { Metrics, AchievementConfig, AchievementData, MetricValue } from '../types';
|
|
3
|
-
import { defaultStyles, Styles } from '../defaultStyles';
|
|
4
|
-
import AchievementModal from '../components/AchievementModal';
|
|
5
|
-
import BadgesModal from '../components/BadgesModal';
|
|
6
|
-
import BadgesButton from '../components/BadgesButton';
|
|
7
|
-
import ConfettiWrapper from '../components/ConfettiWrapper';
|
|
8
|
-
|
|
9
|
-
interface AchievementContextProps {
|
|
10
|
-
metrics: Metrics;
|
|
11
|
-
setMetrics: (metrics: Metrics | ((prevMetrics: Metrics) => Metrics)) => void;
|
|
12
|
-
unlockedAchievements: string[];
|
|
13
|
-
checkAchievements: () => void;
|
|
14
|
-
showBadgesModal: () => void;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
interface AchievementProviderProps {
|
|
18
|
-
children: ReactNode;
|
|
19
|
-
config: AchievementConfig;
|
|
20
|
-
initialState?: Record<string, MetricValue>;
|
|
21
|
-
storageKey?: string;
|
|
22
|
-
badgesButtonPosition?: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
23
|
-
styles?: Partial<Styles>;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const AchievementContext = createContext<AchievementContextProps | undefined>(undefined);
|
|
27
|
-
|
|
28
|
-
export const AchievementProvider: React.FC<AchievementProviderProps> = ({
|
|
29
|
-
children,
|
|
30
|
-
config,
|
|
31
|
-
initialState = {},
|
|
32
|
-
storageKey = 'react-achievements',
|
|
33
|
-
badgesButtonPosition = 'top-right',
|
|
34
|
-
styles = {},
|
|
35
|
-
}) => {
|
|
36
|
-
const mergedStyles = React.useMemo(() => mergeDeep(defaultStyles, styles), [styles]);
|
|
37
|
-
|
|
38
|
-
const [metrics, setMetrics] = useState<Metrics>(() => {
|
|
39
|
-
const savedMetrics = localStorage.getItem(`${storageKey}-metrics`);
|
|
40
|
-
return savedMetrics ? JSON.parse(savedMetrics) : initialState;
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const [unlockedAchievements, setUnlockedAchievements] = useState<string[]>(() => {
|
|
44
|
-
const saved = localStorage.getItem(`${storageKey}-unlocked-achievements`);
|
|
45
|
-
return saved ? JSON.parse(saved) : [];
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const [newlyUnlockedAchievements, setNewlyUnlockedAchievements] = useState<string[]>(() => {
|
|
49
|
-
const saved = localStorage.getItem(`${storageKey}-newly-unlocked-achievements`);
|
|
50
|
-
return saved ? JSON.parse(saved) : [];
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const [achievementQueue, setAchievementQueue] = useState<AchievementData[]>([]);
|
|
54
|
-
const [currentAchievement, setCurrentAchievement] = useState<AchievementData | null>(null);
|
|
55
|
-
const [showBadges, setShowBadges] = useState(false);
|
|
56
|
-
const [showConfetti, setShowConfetti] = useState(false);
|
|
57
|
-
|
|
58
|
-
const checkAchievements = useCallback(() => {
|
|
59
|
-
const newAchievements: AchievementData[] = [];
|
|
60
|
-
|
|
61
|
-
Object.entries(config).forEach(([metricKey, conditions]) => {
|
|
62
|
-
const metricValue = metrics[metricKey];
|
|
63
|
-
conditions.forEach(condition => {
|
|
64
|
-
if (condition.check(metricValue) && !unlockedAchievements.includes(condition.data.id)) {
|
|
65
|
-
newAchievements.push(condition.data);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
if (newAchievements.length > 0) {
|
|
71
|
-
const newlyUnlockedIds = newAchievements.map(a => a.id);
|
|
72
|
-
setUnlockedAchievements(prev => {
|
|
73
|
-
const updated = [...prev, ...newlyUnlockedIds];
|
|
74
|
-
localStorage.setItem(`${storageKey}-unlocked-achievements`, JSON.stringify(updated));
|
|
75
|
-
return updated;
|
|
76
|
-
});
|
|
77
|
-
setNewlyUnlockedAchievements(prev => {
|
|
78
|
-
const updated = [...prev, ...newlyUnlockedIds];
|
|
79
|
-
localStorage.setItem(`${storageKey}-newly-unlocked-achievements`, JSON.stringify(updated));
|
|
80
|
-
return updated;
|
|
81
|
-
});
|
|
82
|
-
setAchievementQueue(prevQueue => [...prevQueue, ...newAchievements]);
|
|
83
|
-
setShowConfetti(true);
|
|
84
|
-
}
|
|
85
|
-
}, [config, metrics, unlockedAchievements, storageKey]);
|
|
86
|
-
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
checkAchievements();
|
|
89
|
-
}, [metrics, checkAchievements]);
|
|
90
|
-
|
|
91
|
-
useEffect(() => {
|
|
92
|
-
if (achievementQueue.length > 0 && !currentAchievement) {
|
|
93
|
-
const nextAchievement = achievementQueue[0];
|
|
94
|
-
setCurrentAchievement(nextAchievement);
|
|
95
|
-
setAchievementQueue(prevQueue => prevQueue.slice(1));
|
|
96
|
-
|
|
97
|
-
setNewlyUnlockedAchievements(prev => {
|
|
98
|
-
const updated = prev.filter(id => id !== nextAchievement.id);
|
|
99
|
-
localStorage.setItem(`${storageKey}-newly-unlocked-achievements`, JSON.stringify(updated));
|
|
100
|
-
return updated;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}, [achievementQueue, currentAchievement, storageKey]);
|
|
104
|
-
|
|
105
|
-
const showBadgesModal = () => setShowBadges(true);
|
|
106
|
-
|
|
107
|
-
const getAchievements = (achievedIds: string[]) => {
|
|
108
|
-
return Object.values(config).flatMap(conditions =>
|
|
109
|
-
conditions.filter(c => achievedIds.includes(c.data.id)).map(c => c.data)
|
|
110
|
-
);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const contextValue: AchievementContextProps = {
|
|
114
|
-
metrics,
|
|
115
|
-
setMetrics: (newMetrics) => {
|
|
116
|
-
setMetrics(prevMetrics => {
|
|
117
|
-
const updatedMetrics = typeof newMetrics === 'function' ? newMetrics(prevMetrics) : newMetrics;
|
|
118
|
-
localStorage.setItem(`${storageKey}-metrics`, JSON.stringify(updatedMetrics));
|
|
119
|
-
return updatedMetrics;
|
|
120
|
-
});
|
|
121
|
-
},
|
|
122
|
-
unlockedAchievements,
|
|
123
|
-
checkAchievements,
|
|
124
|
-
showBadgesModal
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
<AchievementContext.Provider value={contextValue}>
|
|
129
|
-
{children}
|
|
130
|
-
<AchievementModal
|
|
131
|
-
isOpen={!!currentAchievement}
|
|
132
|
-
achievement={currentAchievement}
|
|
133
|
-
onClose={() => {
|
|
134
|
-
setCurrentAchievement(null);
|
|
135
|
-
if (achievementQueue.length === 0 && newlyUnlockedAchievements.length === 0) {
|
|
136
|
-
setShowConfetti(false);
|
|
137
|
-
}
|
|
138
|
-
}}
|
|
139
|
-
styles={mergedStyles.achievementModal}
|
|
140
|
-
/>
|
|
141
|
-
<BadgesModal
|
|
142
|
-
isOpen={showBadges}
|
|
143
|
-
achievements={getAchievements(unlockedAchievements)}
|
|
144
|
-
onClose={() => setShowBadges(false)}
|
|
145
|
-
styles={mergedStyles.badgesModal}
|
|
146
|
-
/>
|
|
147
|
-
<BadgesButton
|
|
148
|
-
onClick={showBadgesModal}
|
|
149
|
-
position={badgesButtonPosition}
|
|
150
|
-
styles={mergedStyles.badgesButton}
|
|
151
|
-
/>
|
|
152
|
-
<ConfettiWrapper show={showConfetti || achievementQueue.length > 0} />
|
|
153
|
-
</AchievementContext.Provider>
|
|
154
|
-
);
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
export const useAchievement = () => {
|
|
158
|
-
const context = useContext(AchievementContext);
|
|
159
|
-
if (context === undefined) {
|
|
160
|
-
throw new Error('useAchievement must be used within an AchievementProvider');
|
|
161
|
-
}
|
|
162
|
-
return context;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
// Helper function to deep merge objects
|
|
166
|
-
function mergeDeep(target: any, source: any) {
|
|
167
|
-
const output = Object.assign({}, target);
|
|
168
|
-
if (isObject(target) && isObject(source)) {
|
|
169
|
-
Object.keys(source).forEach(key => {
|
|
170
|
-
if (isObject(source[key])) {
|
|
171
|
-
if (!(key in target))
|
|
172
|
-
Object.assign(output, { [key]: source[key] });
|
|
173
|
-
else
|
|
174
|
-
output[key] = mergeDeep(target[key], source[key]);
|
|
175
|
-
} else {
|
|
176
|
-
Object.assign(output, { [key]: source[key] });
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
return output;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function isObject(item: any) {
|
|
184
|
-
return (item && typeof item === 'object' && !Array.isArray(item));
|
|
185
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
2
|
-
import { fn } from '@storybook/test';
|
|
3
|
-
import { Button } from './Button';
|
|
4
|
-
|
|
5
|
-
// More on how to set up stories at: https://storybook.js.org/docs/writing-stories#default-export
|
|
6
|
-
const meta = {
|
|
7
|
-
title: 'Example/Button',
|
|
8
|
-
component: Button,
|
|
9
|
-
parameters: {
|
|
10
|
-
// Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
|
|
11
|
-
layout: 'centered',
|
|
12
|
-
},
|
|
13
|
-
// This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
|
|
14
|
-
tags: ['autodocs'],
|
|
15
|
-
// More on argTypes: https://storybook.js.org/docs/api/argtypes
|
|
16
|
-
argTypes: {
|
|
17
|
-
backgroundColor: { control: 'color' },
|
|
18
|
-
},
|
|
19
|
-
// Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
|
|
20
|
-
args: { onClick: fn() },
|
|
21
|
-
} satisfies Meta<typeof Button>;
|
|
22
|
-
|
|
23
|
-
export default meta;
|
|
24
|
-
type Story = StoryObj<typeof meta>;
|
|
25
|
-
|
|
26
|
-
// More on writing stories with args: https://storybook.js.org/docs/writing-stories/args
|
|
27
|
-
export const Primary: Story = {
|
|
28
|
-
args: {
|
|
29
|
-
primary: true,
|
|
30
|
-
label: 'Button',
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const Secondary: Story = {
|
|
35
|
-
args: {
|
|
36
|
-
label: 'Button',
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export const Large: Story = {
|
|
41
|
-
args: {
|
|
42
|
-
size: 'large',
|
|
43
|
-
label: 'Button',
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export const Small: Story = {
|
|
48
|
-
args: {
|
|
49
|
-
size: 'small',
|
|
50
|
-
label: 'Button',
|
|
51
|
-
},
|
|
52
|
-
};
|
package/src/stories/Button.tsx
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import './button.css';
|
|
3
|
-
|
|
4
|
-
export interface ButtonProps {
|
|
5
|
-
/**
|
|
6
|
-
* Is this the principal call to action on the page?
|
|
7
|
-
*/
|
|
8
|
-
primary?: boolean;
|
|
9
|
-
/**
|
|
10
|
-
* What background color to use
|
|
11
|
-
*/
|
|
12
|
-
backgroundColor?: string;
|
|
13
|
-
/**
|
|
14
|
-
* How large should the button be?
|
|
15
|
-
*/
|
|
16
|
-
size?: 'small' | 'medium' | 'large';
|
|
17
|
-
/**
|
|
18
|
-
* Button contents
|
|
19
|
-
*/
|
|
20
|
-
label: string;
|
|
21
|
-
/**
|
|
22
|
-
* Optional click handler
|
|
23
|
-
*/
|
|
24
|
-
onClick?: () => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Primary UI component for user interaction
|
|
29
|
-
*/
|
|
30
|
-
export const Button = ({
|
|
31
|
-
primary = false,
|
|
32
|
-
size = 'medium',
|
|
33
|
-
backgroundColor,
|
|
34
|
-
label,
|
|
35
|
-
...props
|
|
36
|
-
}: ButtonProps) => {
|
|
37
|
-
const mode = primary ? 'storybook-button--primary' : 'storybook-button--secondary';
|
|
38
|
-
return (
|
|
39
|
-
<button
|
|
40
|
-
type="button"
|
|
41
|
-
className={['storybook-button', `storybook-button--${size}`, mode].join(' ')}
|
|
42
|
-
style={{ backgroundColor }}
|
|
43
|
-
{...props}
|
|
44
|
-
>
|
|
45
|
-
{label}
|
|
46
|
-
</button>
|
|
47
|
-
);
|
|
48
|
-
};
|