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

30 lines
812 B
TypeScript
Raw Normal View History

2022-09-13 23:24:26 -07:00
import React, { FunctionComponent } from 'react'
import { useTranslation } from 'next-i18next'
2022-10-31 11:26:17 -07:00
import { PerpOrderSide } from '@blockworks-foundation/mango-v4'
2022-09-13 23:24:26 -07:00
type SideBadgeProps = {
2022-10-31 11:26:17 -07:00
side: string | PerpOrderSide
2022-09-13 23:24:26 -07:00
}
const SideBadge: FunctionComponent<SideBadgeProps> = ({ side }) => {
const { t } = useTranslation('common')
2023-01-16 19:50:20 -08:00
const isBid =
typeof side === 'string' ? ['buy', 'long'].includes(side) : 'bid' in side
2022-09-13 23:24:26 -07:00
return (
<div
className={`inline-block rounded uppercase ${
2023-01-16 19:50:20 -08:00
isBid
? 'text-th-up md:border md:border-th-up'
: 'text-th-down md:border md:border-th-down'
2022-09-13 23:24:26 -07:00
}
uppercase md:-my-0.5 md:px-1.5 md:py-0.5 md:text-xs`}
2022-09-13 23:24:26 -07:00
>
2023-01-16 19:50:20 -08:00
{typeof side === 'string' ? t(side) : 'bid' in side ? 'Long' : 'Short'}
2022-09-13 23:24:26 -07:00
</div>
)
}
export default SideBadge