@oxyhq/bloom 0.29.6 → 0.30.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.
- package/lib/commonjs/activity-heatmap/ActivityHeatmap.js +304 -0
- package/lib/commonjs/activity-heatmap/ActivityHeatmap.js.map +1 -0
- package/lib/commonjs/activity-heatmap/bucketByDay.js +51 -0
- package/lib/commonjs/activity-heatmap/bucketByDay.js.map +1 -0
- package/lib/commonjs/activity-heatmap/index.js +20 -0
- package/lib/commonjs/activity-heatmap/index.js.map +1 -0
- package/lib/commonjs/activity-heatmap/types.js +6 -0
- package/lib/commonjs/activity-heatmap/types.js.map +1 -0
- package/lib/commonjs/avatar-group/AvatarGroupBase.js +42 -18
- package/lib/commonjs/avatar-group/AvatarGroupBase.js.map +1 -1
- package/lib/commonjs/composition-bar/CompositionBar.js +159 -0
- package/lib/commonjs/composition-bar/CompositionBar.js.map +1 -0
- package/lib/commonjs/composition-bar/index.js +13 -0
- package/lib/commonjs/composition-bar/index.js.map +1 -0
- package/lib/commonjs/composition-bar/types.js +6 -0
- package/lib/commonjs/composition-bar/types.js.map +1 -0
- package/lib/commonjs/dot-grid-meter/DotGridMeter.js +69 -0
- package/lib/commonjs/dot-grid-meter/DotGridMeter.js.map +1 -0
- package/lib/commonjs/dot-grid-meter/index.js +13 -0
- package/lib/commonjs/dot-grid-meter/index.js.map +1 -0
- package/lib/commonjs/dot-grid-meter/types.js +6 -0
- package/lib/commonjs/dot-grid-meter/types.js.map +1 -0
- package/lib/commonjs/index.js +59 -12
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +59 -12
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/profile-card/ProfileCard.js +301 -0
- package/lib/commonjs/profile-card/ProfileCard.js.map +1 -0
- package/lib/commonjs/profile-card/index.js +13 -0
- package/lib/commonjs/profile-card/index.js.map +1 -0
- package/lib/commonjs/profile-card/types.js +6 -0
- package/lib/commonjs/profile-card/types.js.map +1 -0
- package/lib/commonjs/stat-bar/StatBar.js +210 -0
- package/lib/commonjs/stat-bar/StatBar.js.map +1 -0
- package/lib/commonjs/stat-bar/index.js +13 -0
- package/lib/commonjs/stat-bar/index.js.map +1 -0
- package/lib/commonjs/stat-bar/types.js +6 -0
- package/lib/commonjs/stat-bar/types.js.map +1 -0
- package/lib/module/activity-heatmap/ActivityHeatmap.js +299 -0
- package/lib/module/activity-heatmap/ActivityHeatmap.js.map +1 -0
- package/lib/module/activity-heatmap/bucketByDay.js +47 -0
- package/lib/module/activity-heatmap/bucketByDay.js.map +1 -0
- package/lib/module/activity-heatmap/index.js +5 -0
- package/lib/module/activity-heatmap/index.js.map +1 -0
- package/lib/module/activity-heatmap/types.js +4 -0
- package/lib/module/activity-heatmap/types.js.map +1 -0
- package/lib/module/avatar-group/AvatarGroupBase.js +42 -18
- package/lib/module/avatar-group/AvatarGroupBase.js.map +1 -1
- package/lib/module/composition-bar/CompositionBar.js +154 -0
- package/lib/module/composition-bar/CompositionBar.js.map +1 -0
- package/lib/module/composition-bar/index.js +4 -0
- package/lib/module/composition-bar/index.js.map +1 -0
- package/lib/module/composition-bar/types.js +4 -0
- package/lib/module/composition-bar/types.js.map +1 -0
- package/lib/module/dot-grid-meter/DotGridMeter.js +64 -0
- package/lib/module/dot-grid-meter/DotGridMeter.js.map +1 -0
- package/lib/module/dot-grid-meter/index.js +4 -0
- package/lib/module/dot-grid-meter/index.js.map +1 -0
- package/lib/module/dot-grid-meter/types.js +4 -0
- package/lib/module/dot-grid-meter/types.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +6 -0
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/profile-card/ProfileCard.js +296 -0
- package/lib/module/profile-card/ProfileCard.js.map +1 -0
- package/lib/module/profile-card/index.js +4 -0
- package/lib/module/profile-card/index.js.map +1 -0
- package/lib/module/profile-card/types.js +4 -0
- package/lib/module/profile-card/types.js.map +1 -0
- package/lib/module/stat-bar/StatBar.js +205 -0
- package/lib/module/stat-bar/StatBar.js.map +1 -0
- package/lib/module/stat-bar/index.js +4 -0
- package/lib/module/stat-bar/index.js.map +1 -0
- package/lib/module/stat-bar/types.js +4 -0
- package/lib/module/stat-bar/types.js.map +1 -0
- package/lib/typescript/commonjs/activity-heatmap/ActivityHeatmap.d.ts +4 -0
- package/lib/typescript/commonjs/activity-heatmap/ActivityHeatmap.d.ts.map +1 -0
- package/lib/typescript/commonjs/activity-heatmap/bucketByDay.d.ts +9 -0
- package/lib/typescript/commonjs/activity-heatmap/bucketByDay.d.ts.map +1 -0
- package/lib/typescript/commonjs/activity-heatmap/index.d.ts +4 -0
- package/lib/typescript/commonjs/activity-heatmap/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/activity-heatmap/types.d.ts +73 -0
- package/lib/typescript/commonjs/activity-heatmap/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/avatar-group/AvatarGroupBase.d.ts.map +1 -1
- package/lib/typescript/commonjs/avatar-group/types.d.ts +15 -1
- package/lib/typescript/commonjs/avatar-group/types.d.ts.map +1 -1
- package/lib/typescript/commonjs/composition-bar/CompositionBar.d.ts +4 -0
- package/lib/typescript/commonjs/composition-bar/CompositionBar.d.ts.map +1 -0
- package/lib/typescript/commonjs/composition-bar/index.d.ts +3 -0
- package/lib/typescript/commonjs/composition-bar/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/composition-bar/types.d.ts +29 -0
- package/lib/typescript/commonjs/composition-bar/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/dot-grid-meter/DotGridMeter.d.ts +4 -0
- package/lib/typescript/commonjs/dot-grid-meter/DotGridMeter.d.ts.map +1 -0
- package/lib/typescript/commonjs/dot-grid-meter/index.d.ts +3 -0
- package/lib/typescript/commonjs/dot-grid-meter/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/dot-grid-meter/types.d.ts +36 -0
- package/lib/typescript/commonjs/dot-grid-meter/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +10 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.web.d.ts +10 -0
- package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/profile-card/ProfileCard.d.ts +4 -0
- package/lib/typescript/commonjs/profile-card/ProfileCard.d.ts.map +1 -0
- package/lib/typescript/commonjs/profile-card/index.d.ts +3 -0
- package/lib/typescript/commonjs/profile-card/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/profile-card/types.d.ts +86 -0
- package/lib/typescript/commonjs/profile-card/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/stat-bar/StatBar.d.ts +4 -0
- package/lib/typescript/commonjs/stat-bar/StatBar.d.ts.map +1 -0
- package/lib/typescript/commonjs/stat-bar/index.d.ts +3 -0
- package/lib/typescript/commonjs/stat-bar/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/stat-bar/types.d.ts +62 -0
- package/lib/typescript/commonjs/stat-bar/types.d.ts.map +1 -0
- package/lib/typescript/module/activity-heatmap/ActivityHeatmap.d.ts +4 -0
- package/lib/typescript/module/activity-heatmap/ActivityHeatmap.d.ts.map +1 -0
- package/lib/typescript/module/activity-heatmap/bucketByDay.d.ts +9 -0
- package/lib/typescript/module/activity-heatmap/bucketByDay.d.ts.map +1 -0
- package/lib/typescript/module/activity-heatmap/index.d.ts +4 -0
- package/lib/typescript/module/activity-heatmap/index.d.ts.map +1 -0
- package/lib/typescript/module/activity-heatmap/types.d.ts +73 -0
- package/lib/typescript/module/activity-heatmap/types.d.ts.map +1 -0
- package/lib/typescript/module/avatar-group/AvatarGroupBase.d.ts.map +1 -1
- package/lib/typescript/module/avatar-group/types.d.ts +15 -1
- package/lib/typescript/module/avatar-group/types.d.ts.map +1 -1
- package/lib/typescript/module/composition-bar/CompositionBar.d.ts +4 -0
- package/lib/typescript/module/composition-bar/CompositionBar.d.ts.map +1 -0
- package/lib/typescript/module/composition-bar/index.d.ts +3 -0
- package/lib/typescript/module/composition-bar/index.d.ts.map +1 -0
- package/lib/typescript/module/composition-bar/types.d.ts +29 -0
- package/lib/typescript/module/composition-bar/types.d.ts.map +1 -0
- package/lib/typescript/module/dot-grid-meter/DotGridMeter.d.ts +4 -0
- package/lib/typescript/module/dot-grid-meter/DotGridMeter.d.ts.map +1 -0
- package/lib/typescript/module/dot-grid-meter/index.d.ts +3 -0
- package/lib/typescript/module/dot-grid-meter/index.d.ts.map +1 -0
- package/lib/typescript/module/dot-grid-meter/types.d.ts +36 -0
- package/lib/typescript/module/dot-grid-meter/types.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +10 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/index.web.d.ts +10 -0
- package/lib/typescript/module/index.web.d.ts.map +1 -1
- package/lib/typescript/module/profile-card/ProfileCard.d.ts +4 -0
- package/lib/typescript/module/profile-card/ProfileCard.d.ts.map +1 -0
- package/lib/typescript/module/profile-card/index.d.ts +3 -0
- package/lib/typescript/module/profile-card/index.d.ts.map +1 -0
- package/lib/typescript/module/profile-card/types.d.ts +86 -0
- package/lib/typescript/module/profile-card/types.d.ts.map +1 -0
- package/lib/typescript/module/stat-bar/StatBar.d.ts +4 -0
- package/lib/typescript/module/stat-bar/StatBar.d.ts.map +1 -0
- package/lib/typescript/module/stat-bar/index.d.ts +3 -0
- package/lib/typescript/module/stat-bar/index.d.ts.map +1 -0
- package/lib/typescript/module/stat-bar/types.d.ts +62 -0
- package/lib/typescript/module/stat-bar/types.d.ts.map +1 -0
- package/package.json +56 -1
- package/src/__tests__/StatWidgets.test.tsx +184 -0
- package/src/__tests__/public-api-contract.test.ts +15 -0
- package/src/activity-heatmap/ActivityHeatmap.stories.tsx +108 -0
- package/src/activity-heatmap/ActivityHeatmap.tsx +289 -0
- package/src/activity-heatmap/bucketByDay.ts +49 -0
- package/src/activity-heatmap/index.ts +3 -0
- package/src/activity-heatmap/types.ts +74 -0
- package/src/avatar-group/AvatarGroup.stories.tsx +14 -0
- package/src/avatar-group/AvatarGroupBase.tsx +39 -18
- package/src/avatar-group/types.ts +15 -1
- package/src/composition-bar/CompositionBar.stories.tsx +70 -0
- package/src/composition-bar/CompositionBar.tsx +161 -0
- package/src/composition-bar/index.ts +2 -0
- package/src/composition-bar/types.ts +30 -0
- package/src/dot-grid-meter/DotGridMeter.stories.tsx +47 -0
- package/src/dot-grid-meter/DotGridMeter.tsx +71 -0
- package/src/dot-grid-meter/index.ts +2 -0
- package/src/dot-grid-meter/types.ts +36 -0
- package/src/index.ts +24 -0
- package/src/index.web.ts +24 -0
- package/src/profile-card/ProfileCard.stories.tsx +210 -0
- package/src/profile-card/ProfileCard.tsx +303 -0
- package/src/profile-card/index.ts +9 -0
- package/src/profile-card/types.ts +86 -0
- package/src/stat-bar/StatBar.stories.tsx +61 -0
- package/src/stat-bar/StatBar.tsx +156 -0
- package/src/stat-bar/index.ts +7 -0
- package/src/stat-bar/types.ts +65 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
4
|
+
|
|
5
|
+
import { ProfileCard } from './index';
|
|
6
|
+
import type { AvatarGroupItem } from '../avatar-group';
|
|
7
|
+
import { BloomThemeProvider } from '../theme';
|
|
8
|
+
import { Star_Filled_Corner0_Rounded as StarIcon } from '../icons/Star';
|
|
9
|
+
|
|
10
|
+
/** Small colored square as a data-URI so stories are self-contained. */
|
|
11
|
+
function token(color: string): string {
|
|
12
|
+
return `data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='40' height='40'><rect width='40' height='40' rx='20' fill='${color}'/></svg>`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const TOP_TOKENS: AvatarGroupItem[] = [
|
|
16
|
+
{ id: 'a', uri: token('gold') },
|
|
17
|
+
{ id: 'b', uri: token('tomato') },
|
|
18
|
+
{ id: 'c', uri: token('mediumseagreen') },
|
|
19
|
+
{ id: 'd', uri: token('royalblue') },
|
|
20
|
+
{ id: 'e', uri: token('orchid') },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const HERO = token('slateblue');
|
|
24
|
+
|
|
25
|
+
function Badge() {
|
|
26
|
+
return (
|
|
27
|
+
<View
|
|
28
|
+
style={{
|
|
29
|
+
width: 18,
|
|
30
|
+
height: 18,
|
|
31
|
+
borderRadius: 9,
|
|
32
|
+
backgroundColor: 'gold',
|
|
33
|
+
borderWidth: 2,
|
|
34
|
+
borderColor: '#111',
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const trophy = <StarIcon size="sm" style={{ color: '#F5B301' }} />;
|
|
41
|
+
|
|
42
|
+
function Gallery() {
|
|
43
|
+
return (
|
|
44
|
+
<View style={{ flexDirection: 'row', flexWrap: 'wrap', gap: 20, maxWidth: 780 }}>
|
|
45
|
+
{/* wallet — dot-grid meter */}
|
|
46
|
+
<ProfileCard
|
|
47
|
+
variant="wallet"
|
|
48
|
+
avatar={{ source: HERO, badge: <Badge />, name: 'Wallet' }}
|
|
49
|
+
value="$167,395"
|
|
50
|
+
subtitle="*5bF5"
|
|
51
|
+
headlineIcon={trophy}
|
|
52
|
+
metric={{ kind: 'dots', label: 'Token diversity', filled: 34, total: 50 }}
|
|
53
|
+
footer={{ label: 'Top tokens', items: TOP_TOKENS }}
|
|
54
|
+
/>
|
|
55
|
+
|
|
56
|
+
{/* wallet — progress + trophy */}
|
|
57
|
+
<ProfileCard
|
|
58
|
+
variant="wallet"
|
|
59
|
+
avatar={{ source: HERO, badge: <Badge />, name: 'Wallet' }}
|
|
60
|
+
value="$167,395"
|
|
61
|
+
subtitle="*5bF5"
|
|
62
|
+
metric={{
|
|
63
|
+
kind: 'progress',
|
|
64
|
+
label: 'TX count 24h',
|
|
65
|
+
value: 192,
|
|
66
|
+
max: 350,
|
|
67
|
+
minLabel: '32',
|
|
68
|
+
maxLabel: '350',
|
|
69
|
+
icon: trophy,
|
|
70
|
+
}}
|
|
71
|
+
footer={{ label: 'Top tokens', items: TOP_TOKENS }}
|
|
72
|
+
/>
|
|
73
|
+
|
|
74
|
+
{/* wallet — split bar % */}
|
|
75
|
+
<ProfileCard
|
|
76
|
+
variant="wallet"
|
|
77
|
+
avatar={{ source: HERO, badge: <Badge />, name: 'Wallet' }}
|
|
78
|
+
value="$167,395"
|
|
79
|
+
subtitle="*5bF5"
|
|
80
|
+
metric={{
|
|
81
|
+
kind: 'split',
|
|
82
|
+
label: 'Net flow 24h',
|
|
83
|
+
percent: 62,
|
|
84
|
+
leftValue: '+$4,210',
|
|
85
|
+
rightValue: '-$2,560',
|
|
86
|
+
}}
|
|
87
|
+
footer={{ label: 'Top tokens', items: TOP_TOKENS }}
|
|
88
|
+
/>
|
|
89
|
+
|
|
90
|
+
{/* social */}
|
|
91
|
+
<ProfileCard
|
|
92
|
+
variant="social"
|
|
93
|
+
avatar={{ source: HERO, badge: <Badge />, name: 'Ada' }}
|
|
94
|
+
value="12,480"
|
|
95
|
+
subtitle="@ada"
|
|
96
|
+
metric={{ kind: 'progress', label: 'Weekly goal', value: 5, max: 7 }}
|
|
97
|
+
footer={{ label: 'Mutuals', items: TOP_TOKENS }}
|
|
98
|
+
/>
|
|
99
|
+
|
|
100
|
+
{/* shopping */}
|
|
101
|
+
<ProfileCard
|
|
102
|
+
variant="shopping"
|
|
103
|
+
avatar={{ source: HERO, name: 'Store' }}
|
|
104
|
+
value="48 orders"
|
|
105
|
+
subtitle="This month"
|
|
106
|
+
metric={{ kind: 'dots', label: 'Categories', filled: 6, total: 12 }}
|
|
107
|
+
footer={{ label: 'Recent buyers', items: TOP_TOKENS }}
|
|
108
|
+
/>
|
|
109
|
+
|
|
110
|
+
{/* stat (default) */}
|
|
111
|
+
<ProfileCard
|
|
112
|
+
variant="stat"
|
|
113
|
+
avatar={{ source: HERO, name: 'Score' }}
|
|
114
|
+
value="820"
|
|
115
|
+
subtitle="Trust score"
|
|
116
|
+
headlineIcon={trophy}
|
|
117
|
+
metric={{
|
|
118
|
+
kind: 'split',
|
|
119
|
+
label: 'Positive vs negative',
|
|
120
|
+
percent: 88,
|
|
121
|
+
leftValue: '880',
|
|
122
|
+
rightValue: '60',
|
|
123
|
+
}}
|
|
124
|
+
/>
|
|
125
|
+
</View>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function WideGallery() {
|
|
130
|
+
return (
|
|
131
|
+
<View style={{ gap: 16, width: 420 }}>
|
|
132
|
+
<ProfileCard
|
|
133
|
+
layout="wide"
|
|
134
|
+
variant="wallet"
|
|
135
|
+
avatar={{ source: HERO, badge: <Badge />, name: 'Wallet' }}
|
|
136
|
+
value="$167,395"
|
|
137
|
+
subtitle="*5bF5"
|
|
138
|
+
headlineIcon={trophy}
|
|
139
|
+
metric={{ kind: 'dots', label: 'Token diversity', filled: 34, total: 50 }}
|
|
140
|
+
footer={{ label: 'Top tokens', items: TOP_TOKENS }}
|
|
141
|
+
/>
|
|
142
|
+
<ProfileCard
|
|
143
|
+
layout="wide"
|
|
144
|
+
variant="social"
|
|
145
|
+
avatar={{ source: HERO, badge: <Badge />, name: 'Ada' }}
|
|
146
|
+
value="12,480"
|
|
147
|
+
subtitle="@ada"
|
|
148
|
+
metric={{
|
|
149
|
+
kind: 'progress',
|
|
150
|
+
label: 'TX count 24h',
|
|
151
|
+
value: 192,
|
|
152
|
+
max: 350,
|
|
153
|
+
minLabel: '32',
|
|
154
|
+
maxLabel: '350',
|
|
155
|
+
icon: trophy,
|
|
156
|
+
}}
|
|
157
|
+
footer={{ label: 'Mutuals', items: TOP_TOKENS }}
|
|
158
|
+
/>
|
|
159
|
+
</View>
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
const meta: Meta<typeof ProfileCard> = {
|
|
164
|
+
title: 'Data Display/ProfileCard',
|
|
165
|
+
component: ProfileCard,
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export default meta;
|
|
169
|
+
|
|
170
|
+
type Story = StoryObj<typeof ProfileCard>;
|
|
171
|
+
|
|
172
|
+
export const WidgetLight: Story = {
|
|
173
|
+
render: () => (
|
|
174
|
+
<BloomThemeProvider mode="light">
|
|
175
|
+
<View style={{ padding: 24 }}>
|
|
176
|
+
<Gallery />
|
|
177
|
+
</View>
|
|
178
|
+
</BloomThemeProvider>
|
|
179
|
+
),
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
export const WidgetDark: Story = {
|
|
183
|
+
render: () => (
|
|
184
|
+
<BloomThemeProvider mode="dark">
|
|
185
|
+
<View style={{ padding: 24, backgroundColor: '#000' }}>
|
|
186
|
+
<Gallery />
|
|
187
|
+
</View>
|
|
188
|
+
</BloomThemeProvider>
|
|
189
|
+
),
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export const WideLight: Story = {
|
|
193
|
+
render: () => (
|
|
194
|
+
<BloomThemeProvider mode="light">
|
|
195
|
+
<View style={{ padding: 24 }}>
|
|
196
|
+
<WideGallery />
|
|
197
|
+
</View>
|
|
198
|
+
</BloomThemeProvider>
|
|
199
|
+
),
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
export const WideDark: Story = {
|
|
203
|
+
render: () => (
|
|
204
|
+
<BloomThemeProvider mode="dark">
|
|
205
|
+
<View style={{ padding: 24, backgroundColor: '#000' }}>
|
|
206
|
+
<WideGallery />
|
|
207
|
+
</View>
|
|
208
|
+
</BloomThemeProvider>
|
|
209
|
+
),
|
|
210
|
+
};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
import React, { memo } from 'react';
|
|
2
|
+
import { View, StyleSheet, type ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import { Card } from '../card';
|
|
5
|
+
import { Avatar } from '../avatar';
|
|
6
|
+
import { AvatarGroup } from '../avatar-group';
|
|
7
|
+
import { DotGridMeter } from '../dot-grid-meter';
|
|
8
|
+
import { StatBar } from '../stat-bar';
|
|
9
|
+
import { Text } from '../typography';
|
|
10
|
+
import { useTheme } from '../theme/use-theme';
|
|
11
|
+
import type { ThemeColors } from '../theme/types';
|
|
12
|
+
import type { AvatarRingConfig } from '../avatar/types';
|
|
13
|
+
import type {
|
|
14
|
+
ProfileCardMetric,
|
|
15
|
+
ProfileCardProps,
|
|
16
|
+
ProfileCardVariant,
|
|
17
|
+
} from './types';
|
|
18
|
+
|
|
19
|
+
const WIDGET_WIDTH = 240;
|
|
20
|
+
const CARD_PADDING = 16;
|
|
21
|
+
const CARD_RADIUS = 24;
|
|
22
|
+
const AVATAR_SIZE = 52;
|
|
23
|
+
const FOOTER_AVATAR_SIZE = 28;
|
|
24
|
+
|
|
25
|
+
interface VariantAccents {
|
|
26
|
+
ring: string;
|
|
27
|
+
fill: string;
|
|
28
|
+
dots: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function variantAccents(variant: ProfileCardVariant, colors: ThemeColors): VariantAccents {
|
|
32
|
+
switch (variant) {
|
|
33
|
+
case 'wallet':
|
|
34
|
+
return { ring: colors.success, fill: colors.primary, dots: colors.success };
|
|
35
|
+
case 'shopping':
|
|
36
|
+
return { ring: colors.info, fill: colors.info, dots: colors.info };
|
|
37
|
+
case 'social':
|
|
38
|
+
return { ring: colors.primary, fill: colors.primary, dots: colors.primary };
|
|
39
|
+
case 'stat':
|
|
40
|
+
default:
|
|
41
|
+
return { ring: colors.primary, fill: colors.primary, dots: colors.primary };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function AvatarWithBadge({
|
|
46
|
+
source,
|
|
47
|
+
name,
|
|
48
|
+
ring,
|
|
49
|
+
badge,
|
|
50
|
+
}: {
|
|
51
|
+
source?: string | null;
|
|
52
|
+
name?: string;
|
|
53
|
+
ring: AvatarRingConfig;
|
|
54
|
+
badge?: React.ReactNode;
|
|
55
|
+
}) {
|
|
56
|
+
return (
|
|
57
|
+
<View style={styles.avatarWrap}>
|
|
58
|
+
<Avatar source={source ?? undefined} name={name} size={AVATAR_SIZE} ring={ring} />
|
|
59
|
+
{badge != null && (
|
|
60
|
+
<View
|
|
61
|
+
style={[
|
|
62
|
+
styles.badge,
|
|
63
|
+
{ width: Math.round(AVATAR_SIZE * 0.34), height: Math.round(AVATAR_SIZE * 0.34) },
|
|
64
|
+
]}
|
|
65
|
+
>
|
|
66
|
+
{badge}
|
|
67
|
+
</View>
|
|
68
|
+
)}
|
|
69
|
+
</View>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function MetricSection({
|
|
74
|
+
metric,
|
|
75
|
+
accents,
|
|
76
|
+
labelColor,
|
|
77
|
+
}: {
|
|
78
|
+
metric: ProfileCardMetric;
|
|
79
|
+
accents: VariantAccents;
|
|
80
|
+
labelColor: string;
|
|
81
|
+
}) {
|
|
82
|
+
switch (metric.kind) {
|
|
83
|
+
case 'dots':
|
|
84
|
+
return (
|
|
85
|
+
<View style={styles.section}>
|
|
86
|
+
{metric.label != null && (
|
|
87
|
+
<Text style={[styles.sectionLabel, { color: labelColor }]} numberOfLines={1}>
|
|
88
|
+
{metric.label}
|
|
89
|
+
</Text>
|
|
90
|
+
)}
|
|
91
|
+
<DotGridMeter
|
|
92
|
+
filled={metric.filled}
|
|
93
|
+
total={metric.total}
|
|
94
|
+
filledColor={metric.filledColor ?? accents.dots}
|
|
95
|
+
/>
|
|
96
|
+
</View>
|
|
97
|
+
);
|
|
98
|
+
case 'progress':
|
|
99
|
+
return (
|
|
100
|
+
<StatBar
|
|
101
|
+
variant="progress"
|
|
102
|
+
label={metric.label}
|
|
103
|
+
value={metric.value}
|
|
104
|
+
max={metric.max}
|
|
105
|
+
minLabel={metric.minLabel}
|
|
106
|
+
maxLabel={metric.maxLabel}
|
|
107
|
+
icon={metric.icon}
|
|
108
|
+
fillColor={metric.fillColor ?? accents.fill}
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
case 'split':
|
|
112
|
+
return (
|
|
113
|
+
<StatBar
|
|
114
|
+
variant="split"
|
|
115
|
+
label={metric.label}
|
|
116
|
+
percent={metric.percent}
|
|
117
|
+
leftValue={metric.leftValue}
|
|
118
|
+
rightValue={metric.rightValue}
|
|
119
|
+
fillColor={metric.fillColor ?? accents.fill}
|
|
120
|
+
/>
|
|
121
|
+
);
|
|
122
|
+
case 'custom':
|
|
123
|
+
default:
|
|
124
|
+
return <>{metric.node}</>;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* A composed profile "widget" card — the Apple-Watch-style stat card. Fully
|
|
130
|
+
* app-agnostic: it takes pre-formatted strings, colors, and `ReactNode` icons
|
|
131
|
+
* (no domain/currency logic). Built on {@link Card}, {@link Avatar} (ring +
|
|
132
|
+
* badge), {@link DotGridMeter}/{@link StatBar}, and a {@link AvatarGroup} row.
|
|
133
|
+
*
|
|
134
|
+
* `variant` only picks sensible accent defaults (ring + metric fill); every
|
|
135
|
+
* accent stays overridable via the individual props.
|
|
136
|
+
*/
|
|
137
|
+
const ProfileCardComponent: React.FC<ProfileCardProps> = ({
|
|
138
|
+
layout = 'widget',
|
|
139
|
+
variant = 'stat',
|
|
140
|
+
avatar,
|
|
141
|
+
value,
|
|
142
|
+
subtitle,
|
|
143
|
+
headlineIcon,
|
|
144
|
+
metric,
|
|
145
|
+
footer,
|
|
146
|
+
onPress,
|
|
147
|
+
style,
|
|
148
|
+
testID,
|
|
149
|
+
}) => {
|
|
150
|
+
const { colors } = useTheme();
|
|
151
|
+
const accents = variantAccents(variant, colors);
|
|
152
|
+
const isWide = layout === 'wide';
|
|
153
|
+
|
|
154
|
+
const ring: AvatarRingConfig = avatar.ring ?? { colors: accents.ring, width: 2, gap: 2 };
|
|
155
|
+
|
|
156
|
+
const surfaceStyle: ViewStyle = {
|
|
157
|
+
width: isWide ? '100%' : WIDGET_WIDTH,
|
|
158
|
+
padding: CARD_PADDING,
|
|
159
|
+
borderRadius: CARD_RADIUS,
|
|
160
|
+
borderCurve: 'continuous',
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
const headline = (
|
|
164
|
+
<>
|
|
165
|
+
<Text style={[styles.value, { color: colors.text }]} numberOfLines={1}>
|
|
166
|
+
{value}
|
|
167
|
+
</Text>
|
|
168
|
+
{subtitle != null && (
|
|
169
|
+
<Text style={[styles.subtitle, { color: colors.textTertiary }]} numberOfLines={1}>
|
|
170
|
+
{subtitle}
|
|
171
|
+
</Text>
|
|
172
|
+
)}
|
|
173
|
+
</>
|
|
174
|
+
);
|
|
175
|
+
|
|
176
|
+
const metricNode =
|
|
177
|
+
metric != null ? (
|
|
178
|
+
<MetricSection metric={metric} accents={accents} labelColor={colors.textTertiary} />
|
|
179
|
+
) : null;
|
|
180
|
+
|
|
181
|
+
const footerNode =
|
|
182
|
+
footer != null ? (
|
|
183
|
+
<View style={styles.section}>
|
|
184
|
+
{footer.label != null && (
|
|
185
|
+
<Text style={[styles.sectionLabel, { color: colors.textTertiary }]} numberOfLines={1}>
|
|
186
|
+
{footer.label}
|
|
187
|
+
</Text>
|
|
188
|
+
)}
|
|
189
|
+
<AvatarGroup
|
|
190
|
+
layout="row"
|
|
191
|
+
items={footer.items}
|
|
192
|
+
size={FOOTER_AVATAR_SIZE}
|
|
193
|
+
max={footer.max ?? 4}
|
|
194
|
+
/>
|
|
195
|
+
</View>
|
|
196
|
+
) : null;
|
|
197
|
+
|
|
198
|
+
return (
|
|
199
|
+
<Card
|
|
200
|
+
variant="filled"
|
|
201
|
+
onPress={onPress}
|
|
202
|
+
style={[surfaceStyle, style]}
|
|
203
|
+
testID={testID}
|
|
204
|
+
>
|
|
205
|
+
<View style={styles.body}>
|
|
206
|
+
{isWide ? (
|
|
207
|
+
<View style={styles.headerRowWide}>
|
|
208
|
+
<AvatarWithBadge
|
|
209
|
+
source={avatar.source}
|
|
210
|
+
name={avatar.name}
|
|
211
|
+
ring={ring}
|
|
212
|
+
badge={avatar.badge}
|
|
213
|
+
/>
|
|
214
|
+
<View style={styles.wideValueRow}>
|
|
215
|
+
<View style={styles.headlineColumn}>{headline}</View>
|
|
216
|
+
{headlineIcon != null && <View style={styles.wideIcon}>{headlineIcon}</View>}
|
|
217
|
+
</View>
|
|
218
|
+
</View>
|
|
219
|
+
) : (
|
|
220
|
+
<View style={styles.headerRow}>
|
|
221
|
+
<AvatarWithBadge
|
|
222
|
+
source={avatar.source}
|
|
223
|
+
name={avatar.name}
|
|
224
|
+
ring={ring}
|
|
225
|
+
badge={avatar.badge}
|
|
226
|
+
/>
|
|
227
|
+
<View style={styles.headlineColumn}>{headline}</View>
|
|
228
|
+
</View>
|
|
229
|
+
)}
|
|
230
|
+
|
|
231
|
+
{metricNode}
|
|
232
|
+
{footerNode}
|
|
233
|
+
</View>
|
|
234
|
+
|
|
235
|
+
{!isWide && headlineIcon != null && <View style={styles.floatingIcon}>{headlineIcon}</View>}
|
|
236
|
+
</Card>
|
|
237
|
+
);
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
const styles = StyleSheet.create({
|
|
241
|
+
body: {
|
|
242
|
+
gap: 16,
|
|
243
|
+
},
|
|
244
|
+
headerRow: {
|
|
245
|
+
flexDirection: 'row',
|
|
246
|
+
alignItems: 'center',
|
|
247
|
+
gap: 12,
|
|
248
|
+
},
|
|
249
|
+
headerRowWide: {
|
|
250
|
+
flexDirection: 'row',
|
|
251
|
+
alignItems: 'center',
|
|
252
|
+
gap: 16,
|
|
253
|
+
},
|
|
254
|
+
headlineColumn: {
|
|
255
|
+
flex: 1,
|
|
256
|
+
minWidth: 0,
|
|
257
|
+
},
|
|
258
|
+
wideValueRow: {
|
|
259
|
+
flex: 1,
|
|
260
|
+
flexDirection: 'row',
|
|
261
|
+
alignItems: 'center',
|
|
262
|
+
gap: 8,
|
|
263
|
+
},
|
|
264
|
+
wideIcon: {
|
|
265
|
+
marginLeft: 8,
|
|
266
|
+
},
|
|
267
|
+
value: {
|
|
268
|
+
fontSize: 26,
|
|
269
|
+
fontWeight: '800',
|
|
270
|
+
letterSpacing: -0.5,
|
|
271
|
+
fontVariant: ['tabular-nums'],
|
|
272
|
+
},
|
|
273
|
+
subtitle: {
|
|
274
|
+
marginTop: 2,
|
|
275
|
+
fontSize: 13,
|
|
276
|
+
fontVariant: ['tabular-nums'],
|
|
277
|
+
},
|
|
278
|
+
section: {
|
|
279
|
+
gap: 8,
|
|
280
|
+
},
|
|
281
|
+
sectionLabel: {
|
|
282
|
+
fontSize: 12,
|
|
283
|
+
fontWeight: '500',
|
|
284
|
+
},
|
|
285
|
+
avatarWrap: {
|
|
286
|
+
position: 'relative',
|
|
287
|
+
},
|
|
288
|
+
badge: {
|
|
289
|
+
position: 'absolute',
|
|
290
|
+
right: -2,
|
|
291
|
+
bottom: -2,
|
|
292
|
+
alignItems: 'center',
|
|
293
|
+
justifyContent: 'center',
|
|
294
|
+
},
|
|
295
|
+
floatingIcon: {
|
|
296
|
+
position: 'absolute',
|
|
297
|
+
top: CARD_PADDING,
|
|
298
|
+
right: CARD_PADDING,
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
export const ProfileCard = memo(ProfileCardComponent);
|
|
303
|
+
ProfileCard.displayName = 'ProfileCard';
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { StyleProp, ViewStyle } from 'react-native';
|
|
3
|
+
|
|
4
|
+
import type { AvatarRingConfig } from '../avatar/types';
|
|
5
|
+
import type { AvatarGroupItem } from '../avatar-group/types';
|
|
6
|
+
|
|
7
|
+
export type ProfileCardLayout = 'widget' | 'wide';
|
|
8
|
+
export type ProfileCardVariant = 'wallet' | 'social' | 'shopping' | 'stat';
|
|
9
|
+
|
|
10
|
+
/** The avatar block of a {@link ProfileCard}. All values are consumer-supplied. */
|
|
11
|
+
export interface ProfileCardAvatar {
|
|
12
|
+
/**
|
|
13
|
+
* Avatar value, routed into {@link Avatar}'s `source` prop — a full URL or a
|
|
14
|
+
* resolver-handled id (e.g. an Oxy file ID).
|
|
15
|
+
*/
|
|
16
|
+
source?: string | null;
|
|
17
|
+
/** Decorative ring. Defaults to a solid ring in the variant accent color. */
|
|
18
|
+
ring?: AvatarRingConfig;
|
|
19
|
+
/** Badge overlay pinned to the avatar's bottom-right (e.g. a small logo). */
|
|
20
|
+
badge?: ReactNode;
|
|
21
|
+
/** Name used for the avatar's initial/placeholder and accessibility. */
|
|
22
|
+
name?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The metric visual rendered below the headline. */
|
|
26
|
+
export type ProfileCardMetric =
|
|
27
|
+
| { kind: 'dots'; label?: string; filled: number; total: number; filledColor?: string }
|
|
28
|
+
| {
|
|
29
|
+
kind: 'progress';
|
|
30
|
+
label: string;
|
|
31
|
+
value: number;
|
|
32
|
+
max: number;
|
|
33
|
+
minLabel?: string;
|
|
34
|
+
maxLabel?: string;
|
|
35
|
+
icon?: ReactNode;
|
|
36
|
+
fillColor?: string;
|
|
37
|
+
}
|
|
38
|
+
| {
|
|
39
|
+
kind: 'split';
|
|
40
|
+
label: string;
|
|
41
|
+
percent: number;
|
|
42
|
+
leftValue: string;
|
|
43
|
+
rightValue: string;
|
|
44
|
+
fillColor?: string;
|
|
45
|
+
}
|
|
46
|
+
| { kind: 'custom'; node: ReactNode };
|
|
47
|
+
|
|
48
|
+
/** The trailing facepile row (e.g. "Top tokens"). */
|
|
49
|
+
export interface ProfileCardFooter {
|
|
50
|
+
/** Small label above the row. */
|
|
51
|
+
label?: string;
|
|
52
|
+
/** Avatars rendered adjacent in a row. */
|
|
53
|
+
items: AvatarGroupItem[];
|
|
54
|
+
/** Maximum avatars before collapsing into `+N`. @default 4 */
|
|
55
|
+
max?: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface ProfileCardProps {
|
|
59
|
+
/**
|
|
60
|
+
* Card shape. `'widget'` is a compact ~square card; `'wide'` is a full-width
|
|
61
|
+
* card. @default 'widget'
|
|
62
|
+
*/
|
|
63
|
+
layout?: ProfileCardLayout;
|
|
64
|
+
/**
|
|
65
|
+
* Selects sensible accent defaults (ring / metric fill). Every accent stays
|
|
66
|
+
* overridable per-element. @default 'stat'
|
|
67
|
+
*/
|
|
68
|
+
variant?: ProfileCardVariant;
|
|
69
|
+
/** Avatar block. */
|
|
70
|
+
avatar: ProfileCardAvatar;
|
|
71
|
+
/** Pre-formatted headline value (e.g. a balance or count). */
|
|
72
|
+
value: string;
|
|
73
|
+
/** Secondary line under the headline. */
|
|
74
|
+
subtitle?: string;
|
|
75
|
+
/** Node floated at the card's top-right (e.g. a trophy or menu icon). */
|
|
76
|
+
headlineIcon?: ReactNode;
|
|
77
|
+
/** Metric visual below the headline. */
|
|
78
|
+
metric?: ProfileCardMetric;
|
|
79
|
+
/** Trailing facepile row. */
|
|
80
|
+
footer?: ProfileCardFooter;
|
|
81
|
+
/** Press handler — makes the whole card pressable. */
|
|
82
|
+
onPress?: () => void;
|
|
83
|
+
/** Container style override (merged over the card surface). */
|
|
84
|
+
style?: StyleProp<ViewStyle>;
|
|
85
|
+
testID?: string;
|
|
86
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
4
|
+
|
|
5
|
+
import { StatBar } from './index';
|
|
6
|
+
import { BloomThemeProvider } from '../theme';
|
|
7
|
+
import { Star_Filled_Corner0_Rounded as StarIcon } from '../icons/Star';
|
|
8
|
+
|
|
9
|
+
function Demo() {
|
|
10
|
+
return (
|
|
11
|
+
<View style={{ gap: 28 }}>
|
|
12
|
+
<StatBar
|
|
13
|
+
variant="progress"
|
|
14
|
+
label="TX count 24h"
|
|
15
|
+
value={192}
|
|
16
|
+
max={350}
|
|
17
|
+
minLabel="32"
|
|
18
|
+
maxLabel="350"
|
|
19
|
+
icon={<StarIcon size="sm" style={{ color: '#F59E0B' }} />}
|
|
20
|
+
/>
|
|
21
|
+
<StatBar
|
|
22
|
+
variant="split"
|
|
23
|
+
label="Net flow 24h"
|
|
24
|
+
percent={62}
|
|
25
|
+
leftValue="+$4,210"
|
|
26
|
+
rightValue="-$2,560"
|
|
27
|
+
leftColor="#10B981"
|
|
28
|
+
rightColor="#EF4444"
|
|
29
|
+
/>
|
|
30
|
+
</View>
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const meta: Meta<typeof StatBar> = {
|
|
35
|
+
title: 'Data Display/StatBar',
|
|
36
|
+
component: StatBar,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export default meta;
|
|
40
|
+
|
|
41
|
+
type Story = StoryObj<typeof StatBar>;
|
|
42
|
+
|
|
43
|
+
export const Light: Story = {
|
|
44
|
+
render: () => (
|
|
45
|
+
<BloomThemeProvider mode="light">
|
|
46
|
+
<View style={{ padding: 24, width: 320 }}>
|
|
47
|
+
<Demo />
|
|
48
|
+
</View>
|
|
49
|
+
</BloomThemeProvider>
|
|
50
|
+
),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const Dark: Story = {
|
|
54
|
+
render: () => (
|
|
55
|
+
<BloomThemeProvider mode="dark">
|
|
56
|
+
<View style={{ padding: 24, width: 320, backgroundColor: '#000' }}>
|
|
57
|
+
<Demo />
|
|
58
|
+
</View>
|
|
59
|
+
</BloomThemeProvider>
|
|
60
|
+
),
|
|
61
|
+
};
|