import styles from './styles.module.scss'; import type {PercentChangePillProps} from './types'; /** * @since 4.0.0 */ const getPercentageChange = (previousValue: number, currentValue: number) => { if (previousValue === 0) { return currentValue === 0 ? 0 : 100; } const value = currentValue - previousValue / Math.abs(previousValue) * 100; if (value !== 100) { return value.toFixed(1); } return value; } const IconArrowUp = () => ( ); const IconArrowDown = () => ( ) const IconArrowRight = () => ( ) /** * @since 4.0.0 */ const PercentChangePill = ({value, comparison}: PercentChangePillProps) => { const change = getPercentageChange(comparison, value); const [color, backgroundColor, symbol] = change === 0 ? ['#060c1a', '#f2f2f2', ] : Number(change) > 0 ? ['#2d802f', '#f2fff3', ] : ['#e35f45', '#fff4f2', ]; return (
{symbol} {change}%
); }; export default PercentChangePill;