-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prev/next button in docs page to navigate previous and next pag…
…e respectively (#71) * fix(link): made the logo link to home route * feat(buttons): added prev and next button in guides docs * fix(name): changed button names from prev/next to doc names * fix(line): removed the unnecessary line of code * style: refactored the links and icon issue and fixed display issue in light mode * fix(favicon): addded favicon, removed prev/next icon, fixed guides docs layout --------- Co-authored-by: Sagar Bera <contact.sagarbera@gmail.com>
- Loading branch information
1 parent
fcb6dad
commit 06c4d31
Showing
6 changed files
with
105 additions
and
5 deletions.
There are no files selected for viewing
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,81 @@ | ||
import type { FolderStructure } from '@/types/client/FileSystem'; | ||
import { ChevronLeftIcon, ChevronRightIcon } from '@heroicons/react/20/solid'; | ||
import { useRouter } from 'next/router'; | ||
import type { FC } from 'react'; | ||
|
||
interface NavigationButtonProps { | ||
menu: FolderStructure; | ||
activeLink: string; | ||
} | ||
|
||
const NavigationButton: FC<NavigationButtonProps> = ({ menu }) => { | ||
const router = useRouter(); | ||
|
||
const links = Object.entries(menu) | ||
.sort((a, b) => | ||
a[0] === 'starting-contribution' | ||
? -1 | ||
: b[0] === 'starting-contribution' | ||
? 1 | ||
: 0 | ||
) | ||
.flatMap(([folderName, folder]) => | ||
folderName === 'starting-contribution' | ||
? [ | ||
folder.find((item) => item.name === 'welcome'), | ||
...folder.filter((item) => item.name !== 'welcome'), | ||
] | ||
: folder | ||
) | ||
.flatMap((item) => item?.link); | ||
|
||
let currentRoute = ''; | ||
if (Array.isArray(router.query.guide)) { | ||
currentRoute = router.query.guide.join('/'); | ||
} | ||
const route = links.findIndex((link) => link?.endsWith(currentRoute)); | ||
const prevRoute = | ||
route > 0 && links[route - 1]?.split('/').pop()?.split('-').join(' '); | ||
const nextRoute = | ||
route < links.length - 1 && | ||
links[route + 1]?.split('/').pop()?.split('-').join(' '); | ||
|
||
const handlePrevClick = () => { | ||
if (route === 0) return; | ||
router.push(`${links[route - 1]}`); | ||
}; | ||
|
||
const handleNextClick = () => { | ||
if (route === links.length - 1) return; | ||
router.push(`${links[route + 1]}`); | ||
}; | ||
|
||
return ( | ||
<div className={`mt-16 flex w-full items-center justify-between`}> | ||
<div className=""> | ||
{prevRoute && ( | ||
<button | ||
onClick={handlePrevClick} | ||
className={`flex items-center gap-1 font-semibold capitalize text-skin-base transition-all duration-300 ease-in-out hover:text-accent`} | ||
> | ||
<ChevronLeftIcon className="h-4 w-4 " /> | ||
{prevRoute} | ||
</button> | ||
)} | ||
</div> | ||
<div className=""> | ||
{nextRoute && ( | ||
<button | ||
onClick={handleNextClick} | ||
className={`flex items-center gap-1 font-medium capitalize text-skin-base transition-all duration-300 ease-in-out hover:text-accent`} | ||
> | ||
{nextRoute} | ||
<ChevronRightIcon className="h-4 w-4 " /> | ||
</button> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default NavigationButton; |
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
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
06c4d31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
gitopener-vercel-app – ./
gitopener-vercel-app-git-opener-team.vercel.app
gitopener-vercel-app-git-main-git-opener-team.vercel.app
gitopener.vercel.app