11# KPIControl
22
3- A React component for displaying Key Performance Indicator (KPI) cards in a responsive grid layout. Each card visualizes progress toward a goal with visual indicators, progress bars, and status badges.
3+ A React component for displaying Key Performance Indicator (KPI) cards in a responsive grid layout. Each card visualizes progress toward a goal with visual indicators, progress bars, and status badges. Two card variants are available: a full-featured card and a compact version.
44
55## Table of Contents
66
77- [ Installation] ( #installation )
88- [ Basic Usage] ( #basic-usage )
9+ - [ Card Variants] ( #card-variants )
910- [ Properties] ( #properties )
1011- [ Data Structure] ( #data-structure )
1112- [ Goal Metrics] ( #goal-metrics )
@@ -20,7 +21,7 @@ npm install @pnp/spfx-controls-react
2021
2122## Example of KPIControl
2223
23- ![ KPIControl Example] ( ../assets/KPIControl3 .png )
24+ ![ KPIControl Example] ( ../assets/KPIControl .png )
2425
2526## Basic Usage
2627
@@ -35,7 +36,13 @@ const MyKPIComponent: React.FC = () => {
3536};
3637```
3738
38- ## Using Individual KPI Cards
39+ ## Card Variants
40+
41+ The KPIControl offers two card variants to suit different use cases:
42+
43+ ### KPICard (Full Version)
44+
45+ The full KPICard displays comprehensive information including footer metrics (Goal, Total Items, % of Total) and a status badge.
3946
4047``` tsx
4148import * as React from ' react' ;
@@ -59,15 +66,71 @@ const MyKPICard: React.FC = () => {
5966};
6067```
6168
69+ ### KPICardCompact (Compact Version)
70+
71+ The compact version displays only essential information: title, goal metric indicator, current value, goal, and progress bar. Ideal for dashboards with limited space or when displaying many KPIs.
72+
73+ ``` tsx
74+ import * as React from ' react' ;
75+ import { KPICardCompact } from ' @pnp/spfx-controls-react/lib/KPIControl' ;
76+ import { IKpiCardData , EGoalMetric } from ' @pnp/spfx-controls-react/lib/KPIControl' ;
77+
78+ const MyCompactKPICard: React .FC = () => {
79+ const kpiData: IKpiCardData = {
80+ identifier: ' sales-kpi' ,
81+ title: ' Sales Revenue' ,
82+ currentValue: 125000 ,
83+ goal: 150000 ,
84+ totalItems: 200000 ,
85+ description: ' Total sales revenue for Q1' ,
86+ goalMetric: EGoalMetric .HIGHER_IS_BETTER ,
87+ };
88+
89+ return (
90+ <KPICardCompact dataCard = { kpiData } />
91+ );
92+ };
93+ ```
94+
95+ ### Comparison
96+
97+ | Feature | KPICard | KPICardCompact |
98+ | ---------| ---------| ----------------|
99+ | Title | ✅ | ✅ |
100+ | Goal Metric Indicator | ✅ | ✅ |
101+ | Current Value / Goal | ✅ | ✅ |
102+ | Progress Bar | ✅ | ✅ |
103+ | Progress Percentage | ✅ | ✅ |
104+ | Footer Metrics (Goal, Total Items, % of Total) | ✅ | ❌ |
105+ | Status Badge (On Track / Off Track) | ✅ | ❌ |
106+ | Glow Effect | ✅ | ✅ |
107+ | Info Tooltip | ✅ | ✅ |
108+
62109## Properties
63110
64111### Kpis Component Properties
65112
66113| Property | Type | Required | Default | Description |
67114| ----------| ------| ----------| ---------| -------------|
68115| ` skeletonCount ` | ` number ` | No | ` 3 ` | Number of skeleton cards to display while loading |
116+ | ` compact ` | ` boolean ` | No | ` false ` | When ` true ` , renders compact KPI cards instead of full cards |
117+
118+ #### Using the compact prop
119+
120+ ``` tsx
121+ import * as React from ' react' ;
122+ import { Kpis } from ' @pnp/spfx-controls-react/lib/KPIControl' ;
123+
124+ // Full cards (default)
125+ const FullKpis: React .FC = () => <Kpis />;
126+
127+ // Compact cards
128+ const CompactKpis: React .FC = () => <Kpis compact />;
129+ ```
130+
131+ ### KPICard & KPICardCompact Component Properties
69132
70- ### KPICard Component Properties
133+ Both card variants share the same props interface:
71134
72135| Property | Type | Required | Default | Description |
73136| ----------| ------| ----------| ---------| -------------|
@@ -235,3 +298,91 @@ const salesKpi: IKpiCardData = {
235298 goalMetric: EGoalMetric .HIGHER_IS_BETTER ,
236299};
237300```
301+
302+ ### Using Compact Cards in a Dashboard
303+
304+ ``` tsx
305+ import * as React from ' react' ;
306+ import { KPICardCompact } from ' @pnp/spfx-controls-react/lib/KPIControl' ;
307+ import { IKpiCardData , EGoalMetric } from ' @pnp/spfx-controls-react/lib/KPIControl' ;
308+
309+ const kpis: IKpiCardData [] = [
310+ {
311+ identifier: ' kpi-1' ,
312+ title: ' Sales Revenue' ,
313+ currentValue: 125000 ,
314+ goal: 150000 ,
315+ totalItems: 200000 ,
316+ description: ' Total sales revenue for Q1' ,
317+ goalMetric: EGoalMetric .HIGHER_IS_BETTER ,
318+ },
319+ {
320+ identifier: ' kpi-2' ,
321+ title: ' Customer Satisfaction' ,
322+ currentValue: 87 ,
323+ goal: 90 ,
324+ totalItems: 100 ,
325+ description: ' Customer satisfaction score' ,
326+ goalMetric: EGoalMetric .HIGHER_IS_BETTER ,
327+ },
328+ {
329+ identifier: ' kpi-3' ,
330+ title: ' Response Time' ,
331+ currentValue: 1.5 ,
332+ goal: 2 ,
333+ totalItems: 5 ,
334+ description: ' Average response time in hours' ,
335+ goalMetric: EGoalMetric .LOWER_IS_BETTER ,
336+ },
337+ ];
338+
339+ const MyCompactKPIs: React .FC = () => {
340+ return (
341+ <div style = { { display: ' grid' , gridTemplateColumns: ' repeat(auto-fill, minmax(280px, 1fr))' , gap: ' 16px' }} >
342+ { kpis .map ((kpi ) => (
343+ <KPICardCompact key = { kpi .identifier } dataCard = { kpi } />
344+ ))}
345+ </div >
346+ );
347+ };
348+ ```
349+
350+ ### Mixing Full and Compact Cards
351+
352+ You can use both card types in the same dashboard for different purposes:
353+
354+ ``` tsx
355+ import * as React from ' react' ;
356+ import { KPICard , KPICardCompact } from ' @pnp/spfx-controls-react/lib/KPIControl' ;
357+ import { IKpiCardData , EGoalMetric } from ' @pnp/spfx-controls-react/lib/KPIControl' ;
358+
359+ const primaryKpi: IKpiCardData = {
360+ identifier: ' primary-kpi' ,
361+ title: ' Revenue' ,
362+ currentValue: 125000 ,
363+ goal: 150000 ,
364+ totalItems: 200000 ,
365+ description: ' Primary KPI with full details' ,
366+ goalMetric: EGoalMetric .HIGHER_IS_BETTER ,
367+ };
368+
369+ const secondaryKpis: IKpiCardData [] = [
370+ // ... secondary KPIs
371+ ];
372+
373+ const MixedDashboard: React .FC = () => {
374+ return (
375+ <div >
376+ { /* Primary KPI with full details */ }
377+ <KPICard dataCard = { primaryKpi } />
378+
379+ { /* Secondary KPIs in compact format */ }
380+ <div style = { { display: ' grid' , gridTemplateColumns: ' repeat(3, 1fr)' , gap: ' 16px' , marginTop: ' 16px' }} >
381+ { secondaryKpis .map ((kpi ) => (
382+ <KPICardCompact key = { kpi .identifier } dataCard = { kpi } />
383+ ))}
384+ </div >
385+ </div >
386+ );
387+ };
388+ ```
0 commit comments