This repository was archived by the owner on Apr 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Sidebar improvement #294
Merged
Merged
Sidebar improvement #294
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import { Flex, FlexProps, Icon, LinkBox, Image } from '@chakra-ui/react' | |
| import { dataAttr } from '@chakra-ui/utils' | ||
| import { usePathname } from 'next/navigation' | ||
| import React from 'react' | ||
| import Link from 'next/link' | ||
| import LinkOverlay from '../elements/LinkElements/LinkOverlay' | ||
| import { useTranslations } from 'next-intl' | ||
|
|
||
|
|
@@ -20,46 +21,57 @@ export const SidebarItem = (props: SidebarItemProps) => { | |
|
|
||
| const pathname = usePathname() | ||
| const isActiveRoute = pathname?.endsWith(item.route) | ||
| const isExternalLink = item.route.startsWith('http') | ||
|
|
||
| const renderLinkContent = () => ( | ||
| <Flex | ||
| h="40px" | ||
| align="center" | ||
| pl={{ base: 5, lg: '15' }} | ||
| cursor="pointer" | ||
| data-active={dataAttr(isActiveRoute)} | ||
| color="grayText" | ||
| fontWeight="medium" | ||
| _hover={{ | ||
| bg: 'divider', | ||
| color: 'dimmedText', | ||
| }} | ||
| _active={{ | ||
| bg: 'hoverBg', | ||
| color: 'brandText', | ||
| }} | ||
| transition="all .2s ease" | ||
| position="relative" | ||
| gap="2" | ||
| > | ||
| {typeof item.icon === 'string' ? ( | ||
| <Image src={item.icon} boxSize="6" alt="icon" /> | ||
| ) : ( | ||
| <Icon as={item.icon} boxSize="6" /> | ||
| )} | ||
| {t(item.label)} | ||
| {isActiveRoute && ( | ||
| <NavIndicator position="absolute" right="0" bg="transparent" /> | ||
| )} | ||
| </Flex> | ||
| ) | ||
|
|
||
| return ( | ||
| <LinkBox {...rest}> | ||
| <LinkOverlay href={item.route} target={item.target} onClick={onClose}> | ||
| <Flex | ||
| h="40px" | ||
| align="center" | ||
| pl={{ base: 5, lg: '15' }} | ||
| cursor="pointer" | ||
| data-active={dataAttr(isActiveRoute)} | ||
| color="grayText" | ||
| fontWeight="medium" | ||
| _hover={{ | ||
| bg: 'divider', | ||
| color: 'dimmedText', | ||
| }} | ||
| _active={{ | ||
| bg: 'hoverBg', | ||
| color: 'brandText', | ||
| }} | ||
| transition="all .2s ease" | ||
| role="group" | ||
| display="flex" | ||
| gap="2" | ||
| {isExternalLink ? ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then instead of the condition here, we can do this: What do you think? |
||
| <Link | ||
| href={item.route} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| onClick={onClose} | ||
| > | ||
| {typeof item.icon === 'string' ? ( | ||
| <Image src={item.icon} boxSize="6" alt="icon" /> | ||
| ) : ( | ||
| <Icon as={item.icon} boxSize="6" /> | ||
| )} | ||
| {t(item.label)} | ||
| <NavIndicator | ||
| display="none" | ||
| _groupActive={{ | ||
| display: 'inherit', | ||
| }} | ||
| ml="auto" | ||
| /> | ||
| </Flex> | ||
| </LinkOverlay> | ||
| {renderLinkContent()} | ||
| </Link> | ||
| ) : ( | ||
| <LinkOverlay href={item.route} target={item.target} onClick={onClose}> | ||
| {renderLinkContent()} | ||
| </LinkOverlay> | ||
| )} | ||
| </LinkBox> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Since internal links can also start with 'https', I think this will be a better way to check for external links: