mango-v4-ui/components/shared/Change.tsx

53 lines
1.2 KiB
TypeScript
Raw Normal View History

import { MinusSmallIcon } from '@heroicons/react/20/solid'
2023-01-06 01:30:29 -08:00
import { formatDecimal } from 'utils/numbers'
2022-09-07 18:52:47 -07:00
import { DownTriangle, UpTriangle } from './DirectionTriangles'
2022-10-05 22:11:28 -07:00
const Change = ({
change,
2022-12-06 03:58:22 -08:00
prefix,
size,
2022-12-06 03:58:22 -08:00
suffix,
}: {
change: number | typeof NaN
2022-12-06 03:58:22 -08:00
prefix?: string
size?: 'small'
2022-12-06 03:58:22 -08:00
suffix?: string
}) => {
2022-09-07 18:52:47 -07:00
return (
2022-09-07 19:49:12 -07:00
<div className="flex items-center space-x-1.5">
{change > 0 ? (
2022-09-20 23:13:14 -07:00
<div className="mt-[1px]">
<UpTriangle size={size} />
</div>
2022-09-07 19:49:12 -07:00
) : change < 0 ? (
2022-09-20 23:13:14 -07:00
<div className="mt-[1px]">
<DownTriangle size={size} />
</div>
2022-09-07 19:49:12 -07:00
) : (
<MinusSmallIcon
className={`-mr-1 ${
size === 'small' ? 'h-4 w-4' : 'h-6 w-6'
} text-th-fgd-4`}
/>
2022-09-07 19:49:12 -07:00
)}
2022-09-07 18:52:47 -07:00
<p
className={`font-mono font-normal ${
2022-10-08 03:22:31 -07:00
size === 'small' ? 'text-xs' : 'text-sm'
} ${
2022-09-07 18:52:47 -07:00
change > 0
2022-11-30 19:32:32 -08:00
? 'text-th-up'
2022-09-07 18:52:47 -07:00
: change < 0
2022-11-30 19:32:32 -08:00
? 'text-th-down'
2022-09-07 18:52:47 -07:00
: 'text-th-fgd-4'
}`}
>
2022-12-06 03:58:22 -08:00
{prefix ? prefix : ''}
2023-01-06 01:30:29 -08:00
{isNaN(change) ? '0.00' : formatDecimal(Math.abs(change), 2)}
2022-12-06 03:58:22 -08:00
{suffix ? suffix : ''}
2022-09-07 18:52:47 -07:00
</p>
</div>
)
}
2022-10-05 22:11:28 -07:00
export default Change