2022-09-19 17:12:30 -07:00
|
|
|
|
import { MinusSmallIcon } from '@heroicons/react/20/solid'
|
2022-09-07 18:52:47 -07:00
|
|
|
|
import { DownTriangle, UpTriangle } from './DirectionTriangles'
|
2023-01-23 17:26:14 -08:00
|
|
|
|
import FormatNumericValue from './FormatNumericValue'
|
2022-09-07 18:52:47 -07:00
|
|
|
|
|
2022-10-05 22:11:28 -07:00
|
|
|
|
const Change = ({
|
2022-09-19 17:12:30 -07:00
|
|
|
|
change,
|
2023-02-10 04:55:06 -08:00
|
|
|
|
decimals,
|
2022-12-06 03:58:22 -08:00
|
|
|
|
prefix,
|
2022-09-19 17:12:30 -07:00
|
|
|
|
size,
|
2022-12-06 03:58:22 -08:00
|
|
|
|
suffix,
|
2022-09-19 17:12:30 -07:00
|
|
|
|
}: {
|
|
|
|
|
change: number | typeof NaN
|
2023-02-10 04:55:06 -08:00
|
|
|
|
decimals?: number
|
2022-12-06 03:58:22 -08:00
|
|
|
|
prefix?: string
|
2022-09-19 17:12:30 -07:00
|
|
|
|
size?: 'small'
|
2022-12-06 03:58:22 -08:00
|
|
|
|
suffix?: string
|
2022-09-19 17:12:30 -07:00
|
|
|
|
}) => {
|
2023-06-14 17:43:33 -07:00
|
|
|
|
return !isNaN(change) ? (
|
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
|
|
|
|
) : (
|
2022-09-19 17:12:30 -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
|
2022-09-22 03:46:51 -07:00
|
|
|
|
className={`font-mono font-normal ${
|
2022-10-08 03:22:31 -07:00
|
|
|
|
size === 'small' ? 'text-xs' : 'text-sm'
|
2022-09-19 17:12:30 -07:00
|
|
|
|
} ${
|
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-23 17:26:14 -08:00
|
|
|
|
<FormatNumericValue
|
|
|
|
|
value={isNaN(change) ? '0.00' : Math.abs(change)}
|
2023-02-10 04:55:06 -08:00
|
|
|
|
decimals={decimals ? decimals : 2}
|
2023-01-23 17:26:14 -08:00
|
|
|
|
/>
|
2022-12-06 03:58:22 -08:00
|
|
|
|
{suffix ? suffix : ''}
|
2022-09-07 18:52:47 -07:00
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2023-06-14 17:43:33 -07:00
|
|
|
|
) : (
|
|
|
|
|
<p>–</p>
|
2022-09-07 18:52:47 -07:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-05 22:11:28 -07:00
|
|
|
|
export default Change
|