@beydesign/storybook 0.0.98 → 0.0.99
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/dist/stories/Credits/CreditsCard.js +2 -3
- package/dist/stories/Credits/CreditsCard.stories.js +2 -1
- package/dist/stories/Credits/types.d.ts +0 -4
- package/dist/stories/Navigation/Sidebar.js +1 -1
- package/dist/stories/Navigation/Sidebar.stories.js +0 -3
- package/dist/utils/common.js +4 -5
- package/package.json +1 -1
|
@@ -41,14 +41,13 @@ const TextWrapper = styled.span `
|
|
|
41
41
|
display: inline-block;
|
|
42
42
|
white-space: nowrap;
|
|
43
43
|
`;
|
|
44
|
-
export const CreditsCard = ({ size = CreditsCardSize.Expanded, className, maxCredits = 1, usedCredits = 0, onUpgradeClick,
|
|
44
|
+
export const CreditsCard = ({ size = CreditsCardSize.Expanded, className, maxCredits = 1, usedCredits = 0, onUpgradeClick, managedAgentsInfoText = 'Managed Agents 1 Min = 100 Credits', speechToVideoInfoText = 'Speech-to-Video 1 Min = 50 Credits', overUsageEnabled = false, overUsedCredits = 0, }) => {
|
|
45
45
|
const isCollapsed = size === CreditsCardSize.Collapsed;
|
|
46
46
|
const creditsLimitReached = usedCredits >= maxCredits;
|
|
47
47
|
const case1 = overUsageEnabled && overUsedCredits > 0; // if over usage is enabled and over used credits are greater than 0
|
|
48
48
|
const case2 = case1 || !creditsLimitReached; // if case 1 is true or credits limit is not reached
|
|
49
49
|
const case3 = !overUsageEnabled && creditsLimitReached; // if over usage is not enabled and credits limit is reached
|
|
50
|
-
const case4 = !overUsageEnabled && !creditsLimitReached; // if over usage is not enabled and credits limit is not reached
|
|
51
50
|
const availableCredits = creditsLimitReached ? 0 : maxCredits - usedCredits;
|
|
52
51
|
const isValid = maxCredits !== undefined && availableCredits !== undefined;
|
|
53
|
-
return (_jsxs(StyledCard, { "$collapsed": isCollapsed, "$size": size, className: className, "$warning": case3, children: [!isCollapsed && isValid && (_jsxs(React.Fragment, { children: [
|
|
52
|
+
return (_jsxs(StyledCard, { "$collapsed": isCollapsed, "$size": size, className: className, "$warning": case3, children: [!isCollapsed && isValid && (_jsxs(React.Fragment, { children: [case2 && (_jsx(CreditRow, { style: { justifyContent: 'end' }, children: _jsx(MainButton, { text: "Upgrade", hierarchy: ButtonHierarchy.TertiaryColor, size: ButtonSize.md, style: { padding: '0' }, onClick: () => onUpgradeClick?.() }) })), _jsxs(CreditRow, { children: [case2 && (_jsxs(Box, { gap: "2px", display: "flex", flexDirection: "row", children: [_jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextS, weight: TypographyWeight.Medium, color: "var(--colors-light-text-text-title)", children: "My Credits:" }) }), _jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextS, weight: TypographyWeight.Medium, color: "var(--colors-light-text-text-title)", children: `${availableCredits}/` }) }), _jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextS, weight: TypographyWeight.Medium, color: "var(--colors-light-text-text-paragraph)", children: `${maxCredits}` }) })] })), case3 && (_jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextS, weight: TypographyWeight.Medium, color: "var(--colors-light-text-text-title)", children: "Credits Limit Reached" }) })), !case2 && (_jsx(MainButton, { text: "Upgrade", hierarchy: ButtonHierarchy.TertiaryColor, size: ButtonSize.md, style: { padding: '0' }, onClick: () => onUpgradeClick?.() }))] }), case1 && (_jsx(CreditRow, { children: _jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextS, weight: TypographyWeight.Medium, color: "var(--colors-light-text-text-title)", children: `Overused: ${overUsedCredits}` }) }) })), _jsx(CreditRow, { children: _jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextXS, weight: TypographyWeight.Regular, color: "var(--colors-light-text-text-subtle)", children: managedAgentsInfoText }) }) }), _jsx(CreditRow, { children: _jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextXS, weight: TypographyWeight.Regular, color: "var(--colors-light-text-text-subtle)", children: speechToVideoInfoText }) }) })] })), isCollapsed && isValid && (_jsxs(Box, { display: "flex", flexDirection: "column", gap: "var(--spacing-tokens-size-in-px-spacing-spacing-md)", alignItems: "center", justifyContent: "center", children: [case2 && (_jsx(CreditRow, { "$collapsed": true, children: _jsxs(Box, { display: "flex", flexDirection: "row", gap: "2px", children: [_jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextM, weight: TypographyWeight.Medium, color: "var(--colors-light-text-text-title)", children: `${formatNumberShort(availableCredits)}/` }) }), _jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextM, weight: TypographyWeight.Medium, color: "var(--colors-light-text-text-paragraph)", children: `${formatNumberShort(maxCredits)}` }) })] }) })), case3 && (_jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextM, weight: TypographyWeight.Medium, color: "var(--colors-light-text-text-title)", textStyle: { textOverflow: 'ellipsis' }, title: "Credits Limit Reached", children: "Cred..." }) })), case1 && (_jsx(TextWrapper, { children: _jsx(Typography, { size: TypographySize.TextS, weight: TypographyWeight.Medium, color: "var(--colors-light-text-text-title)", children: `${formatNumberShort(overUsedCredits)}` }) })), _jsx(Box, { onClick: (e) => e.stopPropagation(), children: _jsx(MainButton, { text: "Upgrade", hierarchy: ButtonHierarchy.TertiaryColor, size: ButtonSize.md, style: { padding: '0' }, onClick: () => onUpgradeClick?.() }) })] }))] }));
|
|
54
53
|
};
|
|
@@ -14,7 +14,8 @@ const meta = {
|
|
|
14
14
|
},
|
|
15
15
|
maxCredits: { control: 'number' },
|
|
16
16
|
usedCredits: { control: 'number' },
|
|
17
|
-
|
|
17
|
+
managedAgentsInfoText: { control: 'text' },
|
|
18
|
+
speechToVideoInfoText: { control: 'text' },
|
|
18
19
|
overUsageEnabled: { control: 'boolean' },
|
|
19
20
|
overUsedCredits: { control: 'number' },
|
|
20
21
|
},
|
|
@@ -28,10 +28,6 @@ export interface CreditsCardProps {
|
|
|
28
28
|
* Function to handle upgrade button click
|
|
29
29
|
*/
|
|
30
30
|
onUpgradeClick?: () => void;
|
|
31
|
-
/**
|
|
32
|
-
* Text explaining credit usage (e.g., "1 Credit = 1 min video")
|
|
33
|
-
*/
|
|
34
|
-
creditInfoText?: string;
|
|
35
31
|
/**
|
|
36
32
|
* Text explaining speech to video usage (e.g., "1 Min = 100 Credits")
|
|
37
33
|
*/
|
|
@@ -111,7 +111,7 @@ export const Sidebar = ({ size = SidebarSize.Expanded, className = '', navSectio
|
|
|
111
111
|
padding: isCollapsed ? '8px' : '0px 12px',
|
|
112
112
|
}, children: _jsx(CreditsCard, { size: isCollapsed
|
|
113
113
|
? CreditsCardSize.Collapsed
|
|
114
|
-
: CreditsCardSize.Expanded, maxCredits: credits.maxCredits, usedCredits: credits.usedCredits,
|
|
114
|
+
: CreditsCardSize.Expanded, maxCredits: credits.maxCredits, usedCredits: credits.usedCredits, managedAgentsInfoText: credits.managedAgentsInfoText, speechToVideoInfoText: credits.speechToVideoInfoText, onUpgradeClick: credits.onUpgradeClick, overUsageEnabled: credits.overUsageEnabled, overUsedCredits: credits.overUsedCredits }) })), bottomNavItems.map((item, index) => (_jsx(NavItemWrapper, { item: item, isCollapsed: isCollapsed }, `bottom-${item.text}-${index}`)))] }) })] }), _jsx(ToggleButtonWrapper, { children: isCollapsed ? (_jsx(MainButton, { text: "Expand", size: ButtonSize.xxs, displayIconMode: ButtonDisplayMode.Only, displayIcon: "CaretRight", onClick: handleToggle, shape: ButtonShape.Circle, hierarchy: ButtonHierarchy.Tertiary, style: {
|
|
115
115
|
boxShadow: '2px 4px 8px 0px #1D142814',
|
|
116
116
|
} })) : (_jsx(MainButton, { size: ButtonSize.xxs, text: "Collapse", hierarchy: ButtonHierarchy.Tertiary, displayIconMode: ButtonDisplayMode.Only, displayIcon: "CaretLeft", onClick: handleToggle, style: {
|
|
117
117
|
boxShadow: '2px 4px 8px 0px #1D142814',
|
|
@@ -121,7 +121,6 @@ export const InBoxContainer = {
|
|
|
121
121
|
}, children: _jsx(Sidebar, { ...args, size: SidebarSize.Expanded, navSections: defaultNavSections.slice(0, 3), bottomNavItems: defaultBottomNavItems, credits: {
|
|
122
122
|
maxCredits: 50,
|
|
123
123
|
usedCredits: 130,
|
|
124
|
-
creditInfoText: '1 Credit = 1 min video',
|
|
125
124
|
overUsageEnabled: true,
|
|
126
125
|
overUsedCredits: 20,
|
|
127
126
|
} }) }), _jsx(Box, { sx: { height: '100dvh', width: 'calc(100dvw)', overflow: 'hidden' }, children: _jsx(Typography, { children: "Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam, quos." }) })] })),
|
|
@@ -134,7 +133,6 @@ export const Expanded = {
|
|
|
134
133
|
credits: {
|
|
135
134
|
maxCredits: 50,
|
|
136
135
|
usedCredits: 10,
|
|
137
|
-
creditInfoText: '1 Credit = 1 min video',
|
|
138
136
|
},
|
|
139
137
|
},
|
|
140
138
|
};
|
|
@@ -146,7 +144,6 @@ export const Collapsed = {
|
|
|
146
144
|
credits: {
|
|
147
145
|
maxCredits: 50,
|
|
148
146
|
usedCredits: 102,
|
|
149
|
-
creditInfoText: '1 Credit = 1 min video',
|
|
150
147
|
overUsageEnabled: true,
|
|
151
148
|
overUsedCredits: 20,
|
|
152
149
|
},
|
package/dist/utils/common.js
CHANGED
|
@@ -10,12 +10,11 @@ export const formatNumberShort = (num) => {
|
|
|
10
10
|
const sign = num < 0 ? '-' : '';
|
|
11
11
|
num = Math.abs(num);
|
|
12
12
|
if (num < 1000)
|
|
13
|
-
return `${sign}${num}`;
|
|
14
|
-
const units = ['', '
|
|
13
|
+
return `${sign}${Math.floor(num)}`;
|
|
14
|
+
const units = ['', 'k', 'm', 'b', 't', 'q'];
|
|
15
15
|
const tier = Math.min(Math.floor(Math.log10(num) / 3), units.length - 1);
|
|
16
16
|
const suffix = units[tier];
|
|
17
17
|
const scale = Math.pow(10, tier * 3);
|
|
18
|
-
const scaled = num / scale;
|
|
19
|
-
|
|
20
|
-
return `${sign}${formatted}${suffix}`;
|
|
18
|
+
const scaled = Math.floor(num / scale);
|
|
19
|
+
return `${sign}${scaled}${suffix}`;
|
|
21
20
|
};
|