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

86 lines
2.5 KiB
TypeScript
Raw Normal View History

2022-10-25 21:44:09 -07:00
import { useTranslation } from 'next-i18next'
2023-02-27 23:20:11 -08:00
type Values = string | number
interface TabUnderlineProps<T extends Values> {
activeValue: string
onChange: (x: T) => void
values: T[]
2023-03-11 01:35:13 -08:00
names?: Array<string>
2023-02-27 23:20:11 -08:00
small?: boolean
fillWidth?: boolean
2023-02-27 23:20:11 -08:00
}
const TabUnderline = <T extends Values>({
2022-10-25 21:44:09 -07:00
activeValue,
values,
2023-03-11 01:35:13 -08:00
names,
2022-10-25 21:44:09 -07:00
onChange,
2022-10-26 03:49:05 -07:00
small,
fillWidth = true,
2023-02-27 23:20:11 -08:00
}: TabUnderlineProps<T>) => {
2022-10-26 03:49:05 -07:00
const { t } = useTranslation('common')
2023-03-11 01:35:13 -08:00
2022-10-25 21:44:09 -07:00
return (
2022-12-21 20:19:00 -08:00
<div
className={`relative mb-3 border-b border-th-bkg-3 ${
2023-02-27 23:20:11 -08:00
values.includes('buy' as T) || values.includes('sell' as T)
2022-12-21 20:19:00 -08:00
? 'pb-1 font-display md:pb-2.5'
: 'pb-1 font-bold'
} md:-mt-2.5`}
>
2022-10-25 21:44:09 -07:00
<div
2023-04-19 18:12:45 -07:00
className={`absolute bottom-[-1px] left-0 h-0.5 ${
2022-10-25 21:44:09 -07:00
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={{
maxWidth: !fillWidth ? '176px' : '',
2022-10-25 21:44:09 -07:00
transform: `translateX(${
values.findIndex((v) => v === activeValue) * 100
}%)`,
width: `${100 / values.length}%`,
}}
/>
2023-08-23 21:09:23 -07:00
<nav className="-mb-px flex" aria-label="Tabs">
2022-10-25 21:44:09 -07:00
{values.map((value, i) => (
<button
onClick={() => onChange(value)}
className={`relative flex h-10 w-1/2 ${
fillWidth ? '' : 'max-w-[176px]'
}
2023-08-23 21:09:23 -07:00
cursor-pointer items-center justify-center whitespace-nowrap rounded py-1 focus-visible:text-th-fgd-2 md:h-auto md:rounded-none md:hover:opacity-100 ${
2022-10-26 03:49:05 -07:00
small ? 'text-sm' : 'text-sm lg:text-base'
}
2022-10-25 21:44:09 -07:00
${
activeValue === value
? activeValue === 'buy'
2023-04-19 18:01:31 -07:00
? 'text-th-up'
2022-10-25 21:44:09 -07:00
: activeValue === 'sell'
2023-04-19 18:01:31 -07:00
? 'text-th-down'
: 'text-th-active'
: 'text-th-fgd-4 md:hover:text-th-fgd-3'
2022-10-25 21:44:09 -07:00
}
`}
2023-02-27 23:20:11 -08:00
key={`${value}` + i}
2022-10-25 21:44:09 -07:00
>
2023-08-13 18:30:28 -07:00
<span className="relative">
{names ? names[i] : t(`${value}`)}
{value === 'trade:trigger-order' ? (
2023-09-18 05:55:37 -07:00
<span className="absolute -right-5 -top-2.5 ml-2 rounded bg-th-active px-1 py-0.5 text-xxs font-bold uppercase leading-none text-th-bkg-1">
2023-08-13 18:30:28 -07:00
beta
</span>
) : null}
</span>
2022-10-25 21:44:09 -07:00
</button>
))}
</nav>
</div>
)
}
export default TabUnderline