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

64 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-10-25 21:44:09 -07:00
import { useTranslation } from 'next-i18next'
const TabUnderline = ({
activeValue,
values,
onChange,
2022-10-26 03:49:05 -07:00
small,
2022-10-25 21:44:09 -07:00
}: {
activeValue: string
onChange: (x: any) => void
values: string[]
2022-10-26 03:49:05 -07:00
small?: boolean
2022-10-25 21:44:09 -07:00
}) => {
2022-10-26 03:49:05 -07:00
const { t } = useTranslation('common')
2022-10-25 21:44:09 -07:00
return (
<div
className={`relative mb-3 pb-1 md:-mt-2.5 md:border-b md:border-th-bkg-3`}
>
<div
className={`default-transition absolute bottom-[-1px] left-0 h-0.5 ${
activeValue === 'buy'
2022-11-30 19:32:32 -08:00
? 'bg-th-up'
2022-10-25 21:44:09 -07:00
: activeValue === 'sell'
2022-11-30 19:32:32 -08:00
? 'bg-th-down'
: 'bg-th-active'
2022-10-25 21:44:09 -07:00
}`}
style={{
2022-11-14 02:18:38 -08:00
// maxWidth: '176px',
2022-10-25 21:44:09 -07:00
transform: `translateX(${
values.findIndex((v) => v === activeValue) * 100
}%)`,
width: `${100 / values.length}%`,
}}
/>
<nav className="-mb-px flex space-x-2" aria-label="Tabs">
{values.map((value, i) => (
<button
onClick={() => onChange(value)}
className={`default-transition relative flex h-10 w-1/2
2022-10-26 03:49:05 -07:00
cursor-pointer items-center justify-center whitespace-nowrap rounded py-1 font-bold md:h-auto md:rounded-none md:hover:opacity-100 ${
small ? 'text-sm' : 'text-sm lg:text-base'
}
2022-10-25 21:44:09 -07:00
${
activeValue === value
? activeValue === 'buy'
2022-11-30 19:32:32 -08:00
? 'text-th-up'
2022-10-25 21:44:09 -07:00
: activeValue === 'sell'
2022-11-30 19:32:32 -08:00
? 'text-th-down'
: 'text-th-active'
2022-10-25 21:44:09 -07:00
: 'text-th-fgd-4 hover:text-th-fgd-3'
}
`}
key={value + i}
>
{t(value)}
</button>
))}
</nav>
</div>
)
}
export default TabUnderline