Skip to content

Commit f2f2aca

Browse files
committed
feat: some formatting
1 parent 4bd22eb commit f2f2aca

File tree

5 files changed

+470
-65
lines changed

5 files changed

+470
-65
lines changed

src/components/BentoGrid/ComponentCard/ComponentCard.tsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ export const ComponentCard: React.FC<GenericHintProps & {
8787
<MultiPercentageBar
8888
segments={hintState.segments}
8989
className={styles.progressBar}
90-
label={hintState.label}
91-
showPercentage={hintState.showPercentage}
92-
isHealthy={hintState.isHealthy}
9390
showOnlyNonZero={hintState.showOnlyNonZero ?? true}
9491
barWidth={
9592
size === 'small' ? '80%' :
@@ -102,20 +99,50 @@ export const ComponentCard: React.FC<GenericHintProps & {
10299
size === 'medium' ? '600px' :
103100
'none'
104101
}
102+
labelConfig={{
103+
position: 'above',
104+
displayMode: 'primary',
105+
showPercentage: hintState.showPercentage,
106+
showCount: hintState.label?.includes('Roles'),
107+
primaryLabelText: hintState.label,
108+
hideWhenSingleFull: false,
109+
}}
110+
animationConfig={{
111+
enableWave: size !== 'medium',
112+
enableTransitions: size !== 'medium',
113+
duration: size === 'medium' ? 0 : 400,
114+
staggerDelay: size === 'medium' ? 0 : 100,
115+
}}
116+
// Legacy props for backward compatibility
117+
label={hintState.label}
118+
showPercentage={hintState.showPercentage}
119+
isHealthy={hintState.isHealthy}
120+
showSegmentLabels={hintState.label?.includes('Roles')}
121+
minSegmentWidthForLabel={12}
105122
/>
106123

107124
{/* Second progress bar only for large and extra-large cards */}
108125
{(size === 'large' || size === 'extra-large') && secondarySegments && (
109126
<MultiPercentageBar
110127
segments={secondarySegments}
111128
className={styles.progressBar}
112-
label={secondaryLabel}
113-
showPercentage={false}
114-
isHealthy={false}
115129
showOnlyNonZero={true}
116130
barWidth="90%"
117131
barHeight="12px"
118132
barMaxWidth="none"
133+
labelConfig={{
134+
position: 'above',
135+
displayMode: 'primary',
136+
showPercentage: false,
137+
primaryLabelText: secondaryLabel,
138+
hideWhenSingleFull: false,
139+
}}
140+
animationConfig={{
141+
enableWave: true,
142+
enableTransitions: true,
143+
duration: 400,
144+
staggerDelay: 100,
145+
}}
119146
showSegmentLabels={true}
120147
minSegmentWidthForLabel={12}
121148
/>

src/components/BentoGrid/MultiPercentageBar/MultiPercentageBar.module.css

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
}
5656

5757
.label,
58-
.percentage {
58+
.percentage,
59+
.count {
5960
font-size: var(--label-font-size);
6061
font-weight: 400;
6162
color: var(--sapTextColor, #374151);
@@ -68,6 +69,11 @@
6869
font-weight: 700;
6970
}
7071

72+
.count {
73+
opacity: 0.7;
74+
font-size: calc(var(--label-font-size) * 0.9);
75+
}
76+
7177
/* Bar container */
7278
.barContainer {
7379
display: flex;
@@ -198,6 +204,28 @@
198204
}
199205
}
200206

207+
208+
209+
/* No animation class for disabled animations */
210+
.noAnimation {
211+
animation: none !important;
212+
}
213+
214+
.noAnimation .segment {
215+
animation: none !important;
216+
transform: scaleX(1) !important;
217+
}
218+
219+
.noAnimation .segmentLabel {
220+
animation: none !important;
221+
opacity: 1 !important;
222+
transform: translateY(-50%) scale(1) !important;
223+
}
224+
225+
.noAnimation .waveOverlay {
226+
animation: none !important;
227+
}
228+
201229
/* Theme Support */
202230
[data-ui5-theme-root*="dark"] .container,
203231
[data-ui5-theme*="dark"] .container {
@@ -210,3 +238,5 @@
210238
[data-ui5-theme*="dark"] .percentage {
211239
color: #ffffff;
212240
}
241+
242+

src/components/BentoGrid/MultiPercentageBar/MultiPercentageBar.spec.tsx

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe('MultiPercentageBar utilities', () => {
66
percentage: number;
77
color: string;
88
label: string;
9+
count?: number;
910
}
1011

1112
// Helper function to filter non-zero segments (simulating component logic)
@@ -113,4 +114,85 @@ describe('MultiPercentageBar utilities', () => {
113114
expect(result.segments).toBe(0);
114115
});
115116
});
117+
118+
describe('color configuration utilities', () => {
119+
// Helper function to apply color overrides (simulating component logic)
120+
const applyColorOverrides = (
121+
segments: PercentageSegment[],
122+
overrides: Record<string, string>
123+
) => {
124+
return segments.map(segment => ({
125+
...segment,
126+
color: overrides[segment.label] || segment.color,
127+
}));
128+
};
129+
130+
it('applies color overrides correctly', () => {
131+
const segments: PercentageSegment[] = [
132+
{ percentage: 60, color: '#28a745', label: 'Healthy' },
133+
{ percentage: 40, color: '#d22020ff', label: 'Unhealthy' },
134+
];
135+
136+
const overrides = {
137+
'Healthy': '#00ff00',
138+
'Unhealthy': '#ff0000',
139+
};
140+
141+
const result = applyColorOverrides(segments, overrides);
142+
143+
expect(result[0].color).toBe('#00ff00');
144+
expect(result[1].color).toBe('#ff0000');
145+
});
146+
147+
it('keeps original colors when no overrides match', () => {
148+
const segments: PercentageSegment[] = [
149+
{ percentage: 60, color: '#28a745', label: 'Healthy' },
150+
{ percentage: 40, color: '#d22020ff', label: 'Unknown' },
151+
];
152+
153+
const overrides = {
154+
'Different': '#00ff00',
155+
};
156+
157+
const result = applyColorOverrides(segments, overrides);
158+
159+
expect(result[0].color).toBe('#28a745');
160+
expect(result[1].color).toBe('#d22020ff');
161+
});
162+
});
163+
164+
describe('label configuration utilities', () => {
165+
// Helper function to determine if primary label should be hidden
166+
const shouldHidePrimaryLabel = (
167+
segments: PercentageSegment[],
168+
hideWhenSingleFull: boolean
169+
) => {
170+
return hideWhenSingleFull &&
171+
segments.length === 1 &&
172+
segments[0]?.percentage === 100;
173+
};
174+
175+
it('hides primary label when single segment is 100%', () => {
176+
const segments: PercentageSegment[] = [
177+
{ percentage: 100, color: '#28a745', label: 'Complete' },
178+
];
179+
180+
expect(shouldHidePrimaryLabel(segments, true)).toBe(true);
181+
expect(shouldHidePrimaryLabel(segments, false)).toBe(false);
182+
});
183+
184+
it('shows primary label when multiple segments or not 100%', () => {
185+
const multipleSegments: PercentageSegment[] = [
186+
{ percentage: 50, color: '#28a745', label: 'Healthy' },
187+
{ percentage: 50, color: '#d22020ff', label: 'Unhealthy' },
188+
];
189+
190+
const partialSegment: PercentageSegment[] = [
191+
{ percentage: 80, color: '#28a745', label: 'Partial' },
192+
];
193+
194+
expect(shouldHidePrimaryLabel(multipleSegments, true)).toBe(false);
195+
expect(shouldHidePrimaryLabel(partialSegment, true)).toBe(false);
196+
});
197+
});
116198
});

0 commit comments

Comments
 (0)