Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vidvidvid committed Nov 28, 2024
1 parent 956861e commit 4a5efbd
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/ui/app/_components/points_comp/FlatMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React, { useMemo } from 'react';

interface IFlatMap {
colorData?: string[];
rewardsData?: number[];
}
const FlatMap = ({
rewardsData = [10, 30, 30, 15, 5],
colorData = ['#3bff89ff', '#f3fa96', '#F19A3E', '#FF3864', '#C567F1']
}: IFlatMap) => {
const totalSum: number = rewardsData.reduce((acc, curr) => acc + curr, 0);
function calculatePercentages(numbers: number[], total: number): number[] {
return numbers.map(
(number: number) => +((number / total) * 100).toFixed(1) || 0
);
}
const percentVals = useMemo(() => {
return calculatePercentages(rewardsData, totalSum);
}, [rewardsData, totalSum]);

return (
<div
className={`w-full bg-grayUnselect rounded-xl overflow-hidden flex h-3`}
>
{percentVals.map((vals: number, idx: number) => (
<span
className={` h-3`}
key={idx}
style={{ backgroundColor: `${colorData[idx]}`, width: `${vals}%` }}
>
{' '}
</span>
))}
</div>
);
};

export default FlatMap;

0 comments on commit 4a5efbd

Please sign in to comment.