mango-ui-v3/components/DayHighLow.tsx

41 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-08-15 06:31:59 -07:00
import { formatUsdValue } from '../utils'
import { MarketDataLoader } from './MarketDetails'
import { useTranslation } from 'next-i18next'
2021-08-13 14:30:39 -07:00
const DayHighLow = ({ high, low, latest }) => {
const { t } = useTranslation('common')
2021-08-13 14:30:39 -07:00
let rangePercent = 0
2021-08-14 03:26:54 -07:00
if (high) {
2021-08-13 14:30:39 -07:00
rangePercent =
((parseFloat(latest) - parseFloat(low)) * 100) /
(parseFloat(high) - parseFloat(low))
2021-08-13 14:30:39 -07:00
}
return (
<div className="flex items-center justify-between md:block md:pr-6">
2021-11-30 04:00:42 -08:00
<div className="text-left xl:text-center text-th-fgd-3 tiny-text pb-0.5">
{t('daily-range')}
2021-08-16 06:31:25 -07:00
</div>
<div className="flex items-center font-semibold">
<div className="pr-2 text-th-fgd-1 md:text-xs">
{low ? formatUsdValue(low) : <MarketDataLoader />}
2021-08-13 14:30:39 -07:00
</div>
<div className="h-1.5 flex rounded bg-th-bkg-3 w-16 sm:w-20">
<div
style={{
2021-08-13 14:30:39 -07:00
width: `${rangePercent}%`,
}}
className="flex rounded bg-th-primary"
></div>
</div>
<div className="pl-2 text-th-fgd-1 md:text-xs">
{high ? formatUsdValue(high) : <MarketDataLoader />}
2021-08-13 14:30:39 -07:00
</div>
</div>
</div>
)
}
export default DayHighLow