import React from 'react'; import './Statistic.scss'; interface StatisticProps { title?: string; value?: number | undefined; prevValue?: number | undefined; currency?: string | undefined; valueClassName?: string; } const Statistic: React.FC = ({ title = '', value, prevValue, currency, valueClassName = '', }) => { const prcntChange = Math.round(((value - prevValue) / prevValue) * 100 * 100) / 100; const positiveChange = prcntChange >= 0; let iconType = 'arrowTop'; let iconBgColor = '#23d160'; if (!positiveChange) { iconType = 'arrowDown'; iconBgColor = '#ff2b2b'; } function numberWithCommas(x: number): string { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); } return (
{title}
{numberWithCommas(value || 0)}
{currency}
{/* */}
{positiveChange && '+'}{prcntChange}%
Previously: {numberWithCommas(prevValue || 0)}
); }; export default Statistic;