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

74 lines
2.2 KiB
TypeScript
Raw Normal View History

2022-08-10 04:17:10 -07:00
import { useTranslation } from 'next-i18next'
2023-02-27 23:20:11 -08:00
type Values = string
interface TabButtonsProps<T extends Values> {
activeValue: T
onChange: (x: T) => void
values: [T, number][]
2022-09-14 23:06:23 -07:00
showBorders?: boolean
rounded?: boolean
fillWidth?: boolean
2022-08-10 04:17:10 -07:00
}
2023-02-27 23:20:11 -08:00
const TabButtons = <T extends Values>({
2022-08-10 04:17:10 -07:00
activeValue,
values,
onChange,
2022-09-14 23:06:23 -07:00
showBorders = false,
rounded = false,
fillWidth = false,
2023-02-27 23:20:11 -08:00
}: TabButtonsProps<T>) => {
2023-01-26 04:12:03 -08:00
const { t } = useTranslation(['common', 'swap', 'token', 'trade', 'borrow'])
2022-08-10 04:17:10 -07:00
return (
<div className="flex w-full bg-th-bkg-1 text-th-fgd-4">
{values.map(([label, count], i) => (
2023-02-27 23:20:11 -08:00
<div className={fillWidth ? 'flex-1' : ''} key={`${label}` + i}>
2022-08-10 04:17:10 -07:00
<button
2023-08-23 15:17:04 -07:00
className={`flex h-12 w-full items-center justify-center px-4 font-normal focus-visible:bg-th-bkg-2 focus-visible:text-th-fgd-1 md:px-6 ${
2022-09-16 03:49:10 -07:00
rounded ? 'rounded-md' : 'rounded-none'
2022-11-14 02:18:38 -08:00
} ${
showBorders
2022-12-20 19:48:06 -08:00
? fillWidth && i === values.length - 1
? 'border-r-0'
: 'border-r border-th-bkg-3'
2022-11-14 02:18:38 -08:00
: ''
} ${
label === activeValue
2022-12-21 20:19:00 -08:00
? label === 'buy'
? 'bg-th-up-dark font-display text-th-fgd-1'
: label === 'sell'
? 'bg-th-down-dark font-display text-th-fgd-1'
2023-08-23 15:17:04 -07:00
: 'bg-th-bkg-3 text-th-active'
2023-04-19 18:01:31 -07:00
: 'hover:cursor-pointer hover:text-th-fgd-2'
2022-09-14 23:06:23 -07:00
}`}
key={`${label}${i}`}
onClick={() => onChange(label)}
2022-08-10 04:17:10 -07:00
>
2022-12-21 20:19:00 -08:00
<span
className={`${
label === 'buy' || label === 'sell'
? 'font-display'
: 'font-medium'
2023-02-01 17:21:24 -08:00
} whitespace-nowrap`}
2022-12-21 20:19:00 -08:00
>
{t(label)}
</span>
2022-09-29 21:21:23 -07:00
{count ? (
<div
className={`ml-1.5 rounded ${
2023-08-23 15:17:04 -07:00
label === activeValue ? 'bg-th-bkg-1' : 'bg-th-bkg-3'
2022-10-02 22:42:28 -07:00
} px-1.5 font-mono text-xxs text-th-fgd-2`}
2022-09-29 21:21:23 -07:00
>
{count}
</div>
) : null}
2022-08-10 04:17:10 -07:00
</button>
</div>
))}
</div>
)
}
export default TabButtons