-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from ubc-biztech/stats-table
Statistics - Numbers chart
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
interface StatsTableProps { | ||
title: string; | ||
data: Object; | ||
} | ||
|
||
const StatsTable: React.FC<StatsTableProps> = ({ title, data }) => { | ||
const renderData = (data: Object, marginValue: number = 0): JSX.Element[] => { | ||
return Object.entries(data).map(([label, count]) => { | ||
if (typeof count === "number" || typeof count === "string") { | ||
return ( | ||
<> | ||
<div | ||
className="col-span-2" | ||
style={{ marginLeft: `${marginValue}px` }} | ||
> | ||
{label} | ||
</div> | ||
<div className="col-span-1 text-right">{count}</div> | ||
</> | ||
); | ||
} else { | ||
return ( | ||
<> | ||
<div | ||
className="col-span-2" | ||
style={{ marginLeft: `${marginValue}px` }} | ||
> | ||
{label} | ||
</div> | ||
{renderData(count, marginValue + 16)} | ||
</> | ||
); | ||
} | ||
}); | ||
}; | ||
return ( | ||
<div className="bg-dark-slate p-8 w-1/3 rounded-md"> | ||
<h5 className="text-white">{title}</h5> | ||
<br /> | ||
<div className="grid grid-cols-3 gap-2 text-pale-blue"> | ||
{renderData(data)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default StatsTable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters