Skip to content

Commit 6145347

Browse files
committed
CHARTS-81: Refactor story and improve naming.
1 parent 2aaf7f4 commit 6145347

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

projects/js-packages/charts/src/components/leaderboard-chart/stories/index.stories.tsx

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
smallDataset,
77
largeValues,
88
negativeGrowth,
9-
salesByProduct,
9+
dataWithImageColor,
1010
} from './sample-data';
1111
import type { Meta, StoryObj } from '@storybook/react';
1212

@@ -379,18 +379,38 @@ export const NumberFormatting: Story = {
379379
},
380380
};
381381

382+
const CustomLabelComponent = ( { label, imageColor, style = {} } ) => (
383+
<div
384+
style={ {
385+
display: 'flex',
386+
alignItems: 'center',
387+
gap: '8px',
388+
...style,
389+
} }
390+
>
391+
<img
392+
src={ `data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='50' height='50'><rect width='50' height='50' fill='${ encodeURIComponent(
393+
imageColor
394+
) }'/></svg>` }
395+
alt="icon"
396+
style={ {
397+
width: '28px',
398+
height: '28px',
399+
verticalAlign: 'middle',
400+
borderRadius: '4px',
401+
} }
402+
/>
403+
<span style={ { fontSize: '13px' } }>{ label }</span>
404+
</div>
405+
);
406+
382407
export const CustomLabel: Story = {
383408
args: {
384-
data: smallDataset.map( entry => ( {
409+
data: dataWithImageColor.map( entry => ( {
385410
...entry,
386-
label: (
387-
<span style={ { fontSize: '24px', padding: '8px 16px', color: '#EEEEEE' } }>
388-
{ entry.label }
389-
</span>
390-
),
411+
label: <CustomLabelComponent label={ entry.label } imageColor={ entry.imageColor } />,
391412
} ) ),
392413
withComparison: false,
393-
withOverlayLabel: true,
394414
loading: false,
395415
},
396416
};
@@ -457,31 +477,16 @@ export const WooCommerceTheme: Story = {
457477
],
458478
};
459479

460-
export const WooAnalyticsSalesByProduct: Story = {
480+
export const OverlayLabelWithImage: Story = {
461481
args: {
462-
data: salesByProduct.map( entry => ( {
482+
data: dataWithImageColor.map( entry => ( {
463483
...entry,
464484
label: (
465-
<div
466-
style={ {
467-
display: 'flex',
468-
alignItems: 'center',
469-
gap: '8px',
470-
padding: '6px',
471-
} }
472-
>
473-
<img
474-
src={ `data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='50' height='50'><rect width='50' height='50' fill='${ entry.imageColor }'/></svg>` }
475-
alt="icon"
476-
style={ {
477-
width: '28px',
478-
height: '28px',
479-
verticalAlign: 'middle',
480-
borderRadius: '4px',
481-
} }
482-
/>
483-
<span style={ { fontSize: '13px' } }>{ entry.label }</span>
484-
</div>
485+
<CustomLabelComponent
486+
label={ entry.label }
487+
imageColor={ entry.imageColor }
488+
style={ { padding: '6px' } }
489+
/>
485490
),
486491
} ) ),
487492
primaryColor: '#C8CFF6',

projects/js-packages/charts/src/components/leaderboard-chart/stories/sample-data.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export const negativeGrowth: LeaderboardEntry[] = [
120120
},
121121
];
122122

123-
export const salesByProduct: ( LeaderboardEntry & { imageColor: string } )[] = [
123+
export const dataWithImageColor: ( LeaderboardEntry & { imageColor: string } )[] = [
124124
{
125125
id: 'direct',
126126
label: 'Direct',
@@ -129,7 +129,7 @@ export const salesByProduct: ( LeaderboardEntry & { imageColor: string } )[] = [
129129
currentShare: 100,
130130
previousShare: 80,
131131
delta: 25,
132-
imageColor: '%23007aff',
132+
imageColor: '#007aff',
133133
},
134134
{
135135
id: 'social',
@@ -139,7 +139,7 @@ export const salesByProduct: ( LeaderboardEntry & { imageColor: string } )[] = [
139139
currentShare: 30,
140140
previousShare: 76,
141141
delta: -7.9,
142-
imageColor: '%23ffc0cb',
142+
imageColor: '#ffc0cb',
143143
},
144144
{
145145
id: 'referral',
@@ -149,6 +149,6 @@ export const salesByProduct: ( LeaderboardEntry & { imageColor: string } )[] = [
149149
currentShare: 10,
150150
previousShare: 16,
151151
delta: -7.9,
152-
imageColor: '%2300ff00',
152+
imageColor: '#00ff00',
153153
},
154154
];

0 commit comments

Comments
 (0)