mango-v4-ui/components/mobile/BottomBar.tsx

169 lines
4.5 KiB
TypeScript
Raw Normal View History

2022-07-18 04:17:56 -07:00
import { ReactNode, useState } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import TradeIcon from '../icons/TradeIcon'
import { useTranslation } from 'next-i18next'
import { IconButton } from '../shared/Button'
import {
2022-09-06 21:36:35 -07:00
ChartBarIcon,
HomeIcon,
Bars3Icon,
XMarkIcon,
2022-07-18 04:17:56 -07:00
ChevronRightIcon,
CurrencyDollarIcon as FeesIcon,
LightBulbIcon,
2022-09-29 21:21:23 -07:00
ArrowsRightLeftIcon,
2022-09-06 21:36:35 -07:00
} from '@heroicons/react/20/solid'
2022-11-19 02:03:39 -08:00
import SolanaTps from '@components/SolanaTps'
2022-07-18 04:17:56 -07:00
const StyledBarItemLabel = ({
children,
...props
}: {
children: ReactNode
}) => (
<div style={{ fontSize: '0.6rem', lineHeight: 1 }} {...props}>
{children}
</div>
)
const BottomBar = () => {
const { t } = useTranslation('common')
const { asPath } = useRouter()
const [showPanel, setShowPanel] = useState(false)
2022-11-19 02:03:39 -08:00
return (
<>
<div className="grid grid-cols-4 grid-rows-1 bg-th-bkg-2 py-2.5">
<Link
href={{
pathname: '/',
}}
className={`${
2022-11-30 19:32:32 -08:00
asPath === '/' ? 'text-th-active' : 'text-th-fgd-3'
2022-11-19 02:03:39 -08:00
} col-span-1 flex cursor-pointer flex-col items-center`}
>
<HomeIcon className="mb-1 h-4 w-4" />
<StyledBarItemLabel>{t('account')}</StyledBarItemLabel>
</Link>
<Link
href={{
pathname: '/swap',
}}
shallow={true}
className={`${
2022-11-30 19:32:32 -08:00
asPath === '/swap' ? 'text-th-active' : 'text-th-fgd-3'
2022-11-19 02:03:39 -08:00
} col-span-1 flex cursor-pointer flex-col items-center`}
>
<ArrowsRightLeftIcon className="mb-1 h-4 w-4" />
<StyledBarItemLabel>{t('swap')}</StyledBarItemLabel>
</Link>
<Link
href="/trade"
shallow={true}
className={`${
2022-11-30 19:32:32 -08:00
asPath === '/trade' ? 'text-th-active' : 'text-th-fgd-3'
2022-11-19 02:03:39 -08:00
} col-span-1 flex cursor-pointer flex-col items-center`}
>
<TradeIcon className="mb-1 h-4 w-4" />
<StyledBarItemLabel>{t('trade')}</StyledBarItemLabel>
</Link>
<a
className={`${
2022-11-30 19:32:32 -08:00
showPanel ? 'text-th-active' : 'text-th-fgd-3'
2022-11-19 02:03:39 -08:00
} col-span-1 flex cursor-pointer flex-col items-center`}
onClick={() => setShowPanel(!showPanel)}
>
<Bars3Icon className="mb-1 h-4 w-4" />
<StyledBarItemLabel>{t('more')}</StyledBarItemLabel>
</a>
</div>
<MoreMenuPanel showPanel={showPanel} setShowPanel={setShowPanel} />
</>
)
2022-07-18 04:17:56 -07:00
}
export default BottomBar
const MoreMenuPanel = ({
showPanel,
setShowPanel,
}: {
showPanel: boolean
setShowPanel: (showPanel: boolean) => void
}) => {
const { t } = useTranslation('common')
return (
<div
2022-09-29 21:21:23 -07:00
className={`fixed bottom-0 z-30 h-96 w-full overflow-hidden rounded-t-3xl bg-th-bkg-2 px-4 transition duration-300 ease-in-out ${
2022-07-18 04:17:56 -07:00
showPanel ? 'translate-y-0' : 'translate-y-full'
}`}
>
2022-11-19 02:03:39 -08:00
<div className="flex justify-between py-4">
<SolanaTps />
2022-07-18 04:17:56 -07:00
<IconButton onClick={() => setShowPanel(false)} hideBg>
2022-09-29 21:21:23 -07:00
<XMarkIcon className="h-6 w-6" />
2022-07-18 04:17:56 -07:00
</IconButton>
</div>
<div
className="border-b border-th-bkg-4"
onClick={() => setShowPanel(false)}
>
2022-09-29 21:21:23 -07:00
<MoreMenuItem
title={t('stats')}
path="/stats"
icon={<ChartBarIcon className="h-5 w-5" />}
/>
2022-07-18 04:17:56 -07:00
<MoreMenuItem
title={t('fees')}
path="/fees"
icon={<FeesIcon className="h-5 w-5" />}
/>
<MoreMenuItem
title={t('learn')}
path="https://docs.mango.markets/"
icon={<LightBulbIcon className="h-5 w-5" />}
isExternal
/>
</div>
</div>
)
}
const MoreMenuItem = ({
title,
path,
icon,
isExternal,
}: {
title: string
path: string
icon: ReactNode
isExternal?: boolean
}) => {
const classNames =
2022-09-29 21:21:23 -07:00
'default-transition flex w-full items-center justify-between border-t border-th-bkg-4 px-2 py-4 text-th-fgd-2 hover:text-th-fgd-1'
2022-07-18 04:17:56 -07:00
return isExternal ? (
<a
className={classNames}
href={path}
target="_blank"
rel="noopener noreferrer"
>
<div className="flex items-center">
{icon}
<span className="ml-1.5">{title}</span>
</div>
<ChevronRightIcon className="h-5 w-5" />
</a>
) : (
2022-11-19 02:03:39 -08:00
<Link href={path} shallow={true} className={classNames}>
2022-10-26 13:01:02 -07:00
<div className="flex items-center">
{icon}
<span className="ml-1.5">{title}</span>
</div>
<ChevronRightIcon className="h-5 w-5" />
2022-11-19 02:03:39 -08:00
</Link>
)
2022-07-18 04:17:56 -07:00
}