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

208 lines
5.7 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 { useTranslation } from 'next-i18next'
import { IconButton } from '../shared/Button'
import {
2022-09-06 21:36:35 -07:00
ChartBarIcon,
Bars3Icon,
XMarkIcon,
2022-07-18 04:17:56 -07:00
ChevronRightIcon,
LightBulbIcon,
2022-09-29 21:21:23 -07:00
ArrowsRightLeftIcon,
2022-12-06 19:07:07 -08:00
CurrencyDollarIcon,
Cog8ToothIcon,
BuildingLibraryIcon,
2022-12-18 17:59:31 -08:00
ArrowTrendingUpIcon,
2023-01-10 18:46:18 -08:00
MagnifyingGlassIcon,
2023-01-26 16:05:50 -08:00
BanknotesIcon,
PlusCircleIcon,
2023-05-22 05:41:27 -07:00
ArchiveBoxArrowDownIcon,
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'
2023-03-15 01:35:29 -07:00
import LeaderboardIcon from '@components/icons/LeaderboardIcon'
2022-07-18 04:17:56 -07:00
const StyledBarItemLabel = ({
children,
...props
}: {
children: ReactNode
}) => (
<div style={{ fontSize: '0.6rem', lineHeight: 1 }} {...props}>
{children}
</div>
)
2023-01-22 01:54:07 -08:00
const BottomBarLink = ({
children,
isActive,
pathName,
}: {
children: ReactNode
isActive: boolean
pathName: string
}) => {
return (
<Link
href={{
pathname: pathName,
}}
className={`${
isActive ? 'text-th-active' : 'text-th-fgd-2'
} col-span-1 flex flex-col items-center justify-center`}
shallow={true}
>
{children}
</Link>
)
}
2022-07-18 04:17:56 -07:00
const BottomBar = () => {
const { t } = useTranslation('common')
const { asPath } = useRouter()
const [showPanel, setShowPanel] = useState(false)
2022-11-19 02:03:39 -08:00
return (
<>
2023-01-22 01:54:07 -08:00
<div className="grid h-12 grid-cols-5 grid-rows-1 bg-th-bkg-3 shadow-bottomBar">
<BottomBarLink isActive={asPath === '/'} pathName="/">
2022-12-06 19:07:07 -08:00
<CurrencyDollarIcon className="mb-1 h-4 w-4" />
2022-11-19 02:03:39 -08:00
<StyledBarItemLabel>{t('account')}</StyledBarItemLabel>
2023-01-22 01:54:07 -08:00
</BottomBarLink>
<BottomBarLink isActive={asPath === '/swap'} pathName="/swap">
2022-11-19 02:03:39 -08:00
<ArrowsRightLeftIcon className="mb-1 h-4 w-4" />
<StyledBarItemLabel>{t('swap')}</StyledBarItemLabel>
2023-01-22 01:54:07 -08:00
</BottomBarLink>
<BottomBarLink isActive={asPath === '/trade'} pathName="/trade">
2022-12-18 17:59:31 -08:00
<ArrowTrendingUpIcon className="mb-1 h-4 w-4" />
2022-11-19 02:03:39 -08:00
<StyledBarItemLabel>{t('trade')}</StyledBarItemLabel>
2023-01-22 01:54:07 -08:00
</BottomBarLink>
2023-01-26 16:05:50 -08:00
<BottomBarLink isActive={asPath === '/borrow'} pathName="/borrow">
<BanknotesIcon className="mb-1 h-4 w-4" />
<StyledBarItemLabel>{t('borrow')}</StyledBarItemLabel>
2023-01-22 01:54:07 -08:00
</BottomBarLink>
<button
2022-11-19 02:03:39 -08:00
className={`${
2023-01-22 01:54:07 -08:00
showPanel ? 'text-th-active' : 'text-th-fgd-2'
} col-span-1 flex cursor-pointer flex-col items-center justify-center`}
2022-11-19 02:03:39 -08:00
onClick={() => setShowPanel(!showPanel)}
>
<Bars3Icon className="mb-1 h-4 w-4" />
<StyledBarItemLabel>{t('more')}</StyledBarItemLabel>
2023-01-22 01:54:07 -08:00
</button>
2022-11-19 02:03:39 -08:00
</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
}) => {
2023-01-10 18:46:18 -08:00
const { t } = useTranslation(['common', 'search'])
2022-07-18 04:17:56 -07:00
return (
<div
2023-04-11 03:33:58 -07:00
className={`fixed bottom-0 z-30 h-[calc(100%-32px)] 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>
2023-04-11 03:33:58 -07:00
<XMarkIcon className="h-6 w-6 text-th-fgd-3" />
2022-07-18 04:17:56 -07:00
</IconButton>
</div>
<div
className="border-b border-th-bkg-4"
onClick={() => setShowPanel(false)}
>
2023-01-26 16:05:50 -08:00
<MoreMenuItem
title={t('settings')}
path="/settings"
icon={<Cog8ToothIcon className="h-5 w-5" />}
/>
2022-09-29 21:21:23 -07:00
<MoreMenuItem
title={t('stats')}
path="/stats"
icon={<ChartBarIcon className="h-5 w-5" />}
/>
2023-03-15 01:35:29 -07:00
<MoreMenuItem
title={t('leaderboard')}
path="/leaderboard"
icon={<LeaderboardIcon className="h-5 w-5" />}
/>
2023-01-10 18:46:18 -08:00
<MoreMenuItem
title={t('search:search-accounts')}
path="/search"
icon={<MagnifyingGlassIcon className="h-5 w-5" />}
/>
<MoreMenuItem
title={t('common:list-token')}
2023-05-28 22:43:01 -07:00
path="/governance/list-token"
icon={<PlusCircleIcon className="h-5 w-5" />}
/>
<MoreMenuItem
title={t('common:vote')}
path="/governance/vote"
2023-05-22 05:41:27 -07:00
icon={<ArchiveBoxArrowDownIcon className="h-5 w-5" />}
/>
2022-07-18 04:17:56 -07:00
<MoreMenuItem
title={t('learn')}
path="https://docs.mango.markets/"
icon={<LightBulbIcon className="h-5 w-5" />}
isExternal
/>
2022-12-06 19:07:07 -08:00
<MoreMenuItem
title={t('governance')}
path="https://dao.mango.markets/"
icon={<BuildingLibraryIcon className="h-5 w-5" />}
isExternal
/>
2022-07-18 04:17:56 -07:00
</div>
</div>
)
}
const MoreMenuItem = ({
title,
path,
icon,
isExternal,
}: {
title: string
path: string
icon: ReactNode
isExternal?: boolean
}) => {
const classNames =
2023-04-19 18:12:45 -07:00
'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"
>
2023-03-15 01:35:29 -07:00
<div className="flex items-center space-x-3">
2022-07-18 04:17:56 -07:00
{icon}
2023-03-15 01:35:29 -07:00
<span>{title}</span>
2022-07-18 04:17:56 -07:00
</div>
<ChevronRightIcon className="h-5 w-5" />
</a>
) : (
2022-11-19 02:03:39 -08:00
<Link href={path} shallow={true} className={classNames}>
2023-03-15 01:35:29 -07:00
<div className="flex items-center space-x-3">
2022-10-26 13:01:02 -07:00
{icon}
2023-03-15 01:35:29 -07:00
<span>{title}</span>
2022-10-26 13:01:02 -07:00
</div>
<ChevronRightIcon className="h-5 w-5" />
2022-11-19 02:03:39 -08:00
</Link>
)
2022-07-18 04:17:56 -07:00
}