Skip to content

Commit 9678e11

Browse files
committed
commit changes improve card layout and labels
1 parent 67ecbc6 commit 9678e11

6 files changed

Lines changed: 46 additions & 33 deletions

File tree

707 KB
Loading

docs/documentation/docs/controls/KPIControl.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ npm install @pnp/spfx-controls-react
2020

2121
## Example of KPIControl
2222

23-
![KPIControl Example](../assets/KPIControl.png)
23+
![KPIControl Example](../assets/KPIControl3.png)
2424

2525
## Basic Usage
2626

src/controls/KPIControl/KpiCard.tsx

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

34-
const isGreen = React.useMemo(
34+
// Determine if KPI is on track based on goal metric type
35+
const isOnTrack = React.useMemo(
3536
() =>
3637
dataCard.goalMetric === EGoalMetric.LOWER_IS_BETTER
37-
? dataCard.currentValue <= dataCard.goal
38-
: dataCard.currentValue >= dataCard.goal,
39-
[dataCard.currentValue, dataCard.goal],
38+
? dataCard.currentValue <= dataCard.goal // Lower is better: on track when current <= goal
39+
: dataCard.currentValue >= dataCard.goal, // Higher is better: on track when current >= goal
40+
[dataCard.currentValue, dataCard.goal, dataCard.goalMetric],
4041
);
42+
4143
const progressColor = React.useMemo(
42-
() => (isGreen ? 'success' : 'error'),
43-
[isGreen],
44+
() => (isOnTrack ? 'success' : 'error'),
45+
[isOnTrack],
4446
);
4547
const goal = React.useMemo(
4648
() => dataCard.goal.toLocaleString(),
@@ -50,13 +52,6 @@ export const KPICard: React.FunctionComponent<IKpiCardProps> = (
5052
() => (dataCard.currentValue / dataCard.totalItems) * 100,
5153
[dataCard.currentValue, dataCard.totalItems],
5254
);
53-
const isOnTrack = React.useMemo(
54-
() =>
55-
dataCard.goalMetric === EGoalMetric.LOWER_IS_BETTER
56-
? dataCard.currentValue <= dataCard.goal
57-
: dataCard.currentValue >= dataCard.goal,
58-
[dataCard.currentValue, dataCard.goal],
59-
);
6055

6156
// Success / Danger foregrounds (icon + badge text + bar fill)
6257
const accentFg = React.useMemo(
@@ -110,20 +105,33 @@ export const KPICard: React.FunctionComponent<IKpiCardProps> = (
110105
<Stack gap="m" padding="m">
111106
<CardHeader
112107
header={
113-
<Stack direction="horizontal" alignItems="center" gap="8px">
114-
<InfoLabel
115-
info={
116-
<>
117-
<Text size={300} color="neutralSecondary">
118-
{dataCard.description || strings.KPINoDescription}
119-
</Text>
120-
</>
121-
}
108+
<Stack direction="vertical" gap="2px">
109+
<Stack direction="horizontal" alignItems="center" gap="8px">
110+
<InfoLabel
111+
info={
112+
<>
113+
<Text size={300} color="neutralSecondary">
114+
{dataCard.description || strings.KPINoDescription}
115+
</Text>
116+
</>
117+
}
118+
>
119+
<Text weight="bold" size={300}>
120+
{dataCard.title?.toUpperCase() || strings.KPIDEfaultTitle}
121+
</Text>
122+
</InfoLabel>
123+
</Stack>
124+
<Text
125+
size={200}
126+
style={{
127+
color: tokens.colorNeutralForeground3,
128+
fontStyle: 'italic',
129+
}}
122130
>
123-
<Text weight="bold" size={300}>
124-
{dataCard.title?.toUpperCase() || strings.KPIDEfaultTitle}
125-
</Text>
126-
</InfoLabel>
131+
{dataCard.goalMetric === EGoalMetric.LOWER_IS_BETTER
132+
? strings.KPILowerIsBetter
133+
: strings.KPIHigherIsBetter}
134+
</Text>
127135
</Stack>
128136
}
129137
action={

src/loc/en-us.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,11 @@ CalendarControlFullDaylabel: "Full Day",
475475
KPICurrentValueAsPercent: "Current value as % of total items",
476476
KPIDEfaultTitle: "KPI Card",
477477
KPIError: "error",
478-
KPIExceedGoal: "Exceeds Goal",
479-
KPIExceedsGoalTreshhold: "Exceeds goal threshold",
478+
KPIExceedGoal: "Off Track",
479+
KPIExceedsGoalTreshhold: "Not meeting goal threshold",
480480
KPIGoal: "Goal",
481+
KPIHigherIsBetter: "Higher is better",
482+
KPILowerIsBetter: "Lower is better",
481483
KPIMaxAllowedThreshold: "Maximum allowed threshold",
482484
KPINoDescription: " 'No description provided for this KPI card.'",
483485
KPIOnTrack: "On Track",

src/loc/mystrings.d.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ declare interface IControlStrings {
66
KPIError: string;
77
KPIExceedsGoalTreshhold: string;
88
KPIGoal: string;
9+
KPIHigherIsBetter: string;
10+
KPILowerIsBetter: string;
911
KPIMaxAllowedThreshold: string;
1012
KPINoDescription: string;
1113
KPIProgressGoal: string;
@@ -15,6 +17,7 @@ declare interface IControlStrings {
1517
KPICurrentValueAsPercent: string;
1618
KPIExceedGoal: string;
1719
KPIOnTrack: string;
20+
KPIPercentOfTotal: string;
1821

1922
CalendarControlDayOfWeekSunday: string;
2023
CalendarControlDayOfWeekMonday: string;
@@ -480,8 +483,6 @@ worldMapLocationPluralLabel: string;
480483
worldMapLoadintText: string;
481484
worldMapResetMap: string;
482485
worldMapFlag: string;
483-
}
484-
485486

486487
L_RelativeDateTime_AFewSecondsFuture: string;
487488
L_RelativeDateTime_AFewSeconds: string;

src/loc/pt-pt.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ define([], () => {
66
KPICurrentValueAsPercent: "Valor atual em % do total de itens",
77
KPIDEfaultTitle: "Cartão KPI",
88
KPIError: "ERRO",
9-
KPIExceedGoal: "Excede a Meta",
10-
KPIExceedsGoalTreshhold: "Excede o limite da meta",
9+
KPIExceedGoal: "Fora do Objetivo",
10+
KPIExceedsGoalTreshhold: "Não está a atingir o limite da meta",
1111
KPIGoal: "Meta",
12+
KPIHigherIsBetter: "Quanto maior, melhor",
13+
KPILowerIsBetter: "Quanto menor, melhor",
1214
KPIMaxAllowedThreshold: "Limite máximo permitido",
1315
KPINoDescription: "Nenhuma descrição fornecida para este cartão KPI.",
1416
KPIOnTrack: "No Caminho",

0 commit comments

Comments
 (0)