generated from defi-wonderland/web3-nextjs-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feat/responsiveness
- Loading branch information
Showing
7 changed files
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { usePathname } from 'next/navigation'; | ||
import { Link, Typography, styled } from '@mui/material'; | ||
import { useTranslation } from 'next-i18next'; | ||
import Image from 'next/image'; | ||
|
||
import { useData, useCustomTheme } from '~/hooks'; | ||
import SmallArrowDark from '~/assets/icons/smallArrowDark.svg'; | ||
import SmallArrowLight from '~/assets/icons/smallArrowLight.svg'; | ||
|
||
interface BreadcrumbProps { | ||
isChain: boolean; | ||
} | ||
|
||
export const Breadcrumb = ({ isChain }: BreadcrumbProps) => { | ||
const pathname = usePathname(); | ||
const { chainData } = useData(); | ||
const { theme } = useCustomTheme(); | ||
const { t } = useTranslation(); | ||
|
||
const pathNames = pathname ? pathname.split('/').filter((path) => path) : []; | ||
|
||
const breadcrumbItems = pathNames.map((path, index) => { | ||
const isLast = index === pathNames.length - 1; | ||
const displayName = isChain && isLast ? chainData?.metadata?.chainName || path : path; | ||
const href = `/${pathNames.slice(0, index + 1).join('/')}`; | ||
|
||
return { | ||
key: index, | ||
isLast, | ||
displayName, | ||
href, | ||
}; | ||
}); | ||
|
||
return ( | ||
<BreadcrumbNav aria-label='breadcrumb'> | ||
<BreadcrumbLink href='/'>{t('HOME.home')}</BreadcrumbLink> | ||
|
||
{breadcrumbItems.map(({ key, isLast, displayName, href }) => ( | ||
<BreadcrumbItem key={key}> | ||
<ArrowIcon src={theme === 'dark' ? SmallArrowDark : SmallArrowLight} alt='arrow' /> | ||
{isLast ? ( | ||
<BreadcrumbCurrent aria-current='page'>{displayName}</BreadcrumbCurrent> | ||
) : ( | ||
<BreadcrumbLink href={href}>{displayName}</BreadcrumbLink> | ||
)} | ||
</BreadcrumbItem> | ||
))} | ||
</BreadcrumbNav> | ||
); | ||
}; | ||
|
||
const BreadcrumbNav = styled('nav')({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
}); | ||
|
||
const BreadcrumbLink = styled(Link)(() => { | ||
const { currentTheme } = useCustomTheme(); | ||
return { | ||
display: 'flex', | ||
alignItems: 'center', | ||
color: currentTheme.textPrimary, | ||
textDecoration: 'none', | ||
fontSize: '0.875rem', | ||
lineHeight: '1.25rem', | ||
}; | ||
}); | ||
|
||
const BreadcrumbItem = styled('span')({ | ||
display: 'flex', | ||
alignItems: 'center', | ||
}); | ||
|
||
const ArrowIcon = styled(Image)({ | ||
width: '1.25rem', | ||
}); | ||
|
||
const BreadcrumbCurrent = styled(Typography)(() => { | ||
const { currentTheme } = useCustomTheme(); | ||
return { | ||
fontSize: '0.875rem', | ||
color: currentTheme.textSecondary, | ||
lineHeight: '1.25rem', | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters