Skip to content

Commit a2f7cf6

Browse files
committed
commit chnages auto dismiss infolabel when move outside the card
1 parent 3a127f7 commit a2f7cf6

4 files changed

Lines changed: 36 additions & 6 deletions

File tree

src/controls/KPIControl/KpiCard.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ export const KPICard: React.FunctionComponent<IKpiCardProps> = (
3131
const { dataCard } = props;
3232
const styles = useKpiStyles();
3333

34+
// State to control InfoLabel popover visibility
35+
const [isInfoLabelOpen, setIsInfoLabelOpen] = React.useState(false);
36+
37+
// Handle card mouse leave to auto-dismiss InfoLabel
38+
const handleCardMouseLeave = React.useCallback(() => {
39+
setIsInfoLabelOpen(false);
40+
}, []);
41+
3442
// Determine if KPI is on track based on goal metric type
3543
const isOnTrack = React.useMemo(
3644
() =>
@@ -97,7 +105,7 @@ export const KPICard: React.FunctionComponent<IKpiCardProps> = (
97105

98106
return (
99107
<>
100-
<Card className={styles.card}>
108+
<Card className={styles.card} onMouseLeave={handleCardMouseLeave}>
101109
{/* Glow blob effect - green for on track, red for exceeds goal */}
102110
<div
103111
className={isOnTrack ? styles.glowBlobSuccess : styles.glowBlobError}
@@ -108,6 +116,13 @@ export const KPICard: React.FunctionComponent<IKpiCardProps> = (
108116
<Stack direction="vertical" gap="2px">
109117
<Stack direction="horizontal" alignItems="center" gap="8px">
110118
<InfoLabel
119+
style={{ zIndex: 99999 }}
120+
infoButton={{
121+
popover: {
122+
open: isInfoLabelOpen,
123+
onOpenChange: (_e, data) => setIsInfoLabelOpen(data.open),
124+
},
125+
}}
111126
info={
112127
<>
113128
<Text size={300} color="neutralSecondary">

src/controls/KPIControl/KpiCardCompact.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ export const KPICardCompact: React.FunctionComponent<IKpiCardProps> = (
2626
const { dataCard } = props;
2727
const styles = useKpiStyles();
2828

29+
// State to control InfoLabel popover visibility
30+
const [isInfoLabelOpen, setIsInfoLabelOpen] = React.useState(false);
31+
32+
// Handle card mouse leave to auto-dismiss InfoLabel
33+
const handleCardMouseLeave = React.useCallback(() => {
34+
setIsInfoLabelOpen(false);
35+
}, []);
36+
2937
// Determine if KPI is on track based on goal metric type
3038
const isOnTrack = React.useMemo(
3139
() =>
@@ -56,7 +64,7 @@ export const KPICardCompact: React.FunctionComponent<IKpiCardProps> = (
5664

5765
return (
5866
<>
59-
<Card className={styles.card} style={{ height: 'fit-content' }}>
67+
<Card className={styles.card} style={{ height: '168px' }} onMouseLeave={handleCardMouseLeave}>
6068
{/* Glow blob effect - green for on track, red for exceeds goal */}
6169
<div
6270
className={isOnTrack ? styles.glowBlobSuccess : styles.glowBlobError}
@@ -67,6 +75,12 @@ export const KPICardCompact: React.FunctionComponent<IKpiCardProps> = (
6775
<Stack direction="vertical" gap="2px">
6876
<Stack direction="horizontal" alignItems="center" gap="8px">
6977
<InfoLabel
78+
infoButton={{
79+
popover: {
80+
open: isInfoLabelOpen,
81+
onOpenChange: (_e, data) => setIsInfoLabelOpen(data.open),
82+
},
83+
}}
7084
info={
7185
<>
7286
<Text size={300} color="neutralSecondary">

src/controls/KPIControl/Kpis.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const mockData: IKpiCardData[] = [
1717
currentValue: 125.0,
1818
goal: 150.0,
1919
totalItems: 200.0,
20-
description: 'Total sales revenue for Q1',
20+
description: 'This is a comprehensive description of the Total Sales Revenue KPI for Q1. This metric tracks all revenue generated from product sales, service contracts, and recurring subscriptions across all business units and geographic regions. The goal is set based on historical performance, market conditions, and strategic growth objectives. Performance is evaluated weekly with detailed breakdowns by product category, sales team, and customer segment. This KPI is critical for quarterly business reviews and investor reporting.',
2121
goalMetric: 2,
2222
},
2323
{

src/controls/KPIControl/useKpiStyles.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ export const useKpiStyles = (): IKpiStyles => {
5353
background: tokens.colorNeutralBackground1,
5454
border: `1px solid ${tokens.colorNeutralStroke1}`,
5555
boxShadow: tokens.shadow8,
56-
overflow: "hidden",
56+
overflow: "visible",
5757
position: "relative",
5858
padding: "0px 15px !important",
5959
transition: "transform 0.25s ease, box-shadow 0.25s ease",
60-
"&:hover": {
61-
transform: "translateY(-3px)",
60+
"&:hover, &:focus-within": {
61+
zIndex: 10,
62+
transform: "translateY(-2px)",
6263
boxShadow: tokens.shadow16, // deeper on hover
6364
},
6465
}),

0 commit comments

Comments
 (0)