-
Notifications
You must be signed in to change notification settings - Fork 367
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move PrimaryLink to own component file
- Loading branch information
1 parent
4256898
commit fcb1c11
Showing
2 changed files
with
90 additions
and
82 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
packages/manager/src/components/PrimaryNav/PrimaryLink.tsx
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,85 @@ | ||
import { BetaChip } from '@linode/ui'; | ||
import * as React from 'react'; | ||
|
||
import { StyledActiveLink, StyledPrimaryLinkBox } from './PrimaryNav.styles'; | ||
import { linkIsActive } from './utils'; | ||
|
||
import type { NavEntity } from './PrimaryNav'; | ||
|
||
export interface PrimaryLink { | ||
activeLinks?: Array<string>; | ||
attr?: { [key: string]: any }; | ||
betaChipClassName?: string; | ||
display: NavEntity; | ||
hide?: boolean; | ||
href: string; | ||
icon?: JSX.Element; | ||
isBeta?: boolean; | ||
onClick?: (e: React.ChangeEvent<any>) => void; | ||
} | ||
|
||
interface PrimaryLinkProps extends PrimaryLink { | ||
closeMenu: () => void; | ||
isBeta?: boolean; | ||
isCollapsed: boolean; | ||
locationPathname: string; | ||
locationSearch: string; | ||
} | ||
|
||
const PrimaryLink = React.memo((props: PrimaryLinkProps) => { | ||
const { | ||
activeLinks, | ||
attr, | ||
betaChipClassName, | ||
closeMenu, | ||
display, | ||
href, | ||
icon, | ||
isBeta, | ||
isCollapsed, | ||
locationPathname, | ||
locationSearch, | ||
onClick, | ||
} = props; | ||
|
||
const isActiveLink = Boolean( | ||
linkIsActive(href, locationSearch, locationPathname, activeLinks) | ||
); | ||
|
||
return ( | ||
<StyledActiveLink | ||
onClick={(e: React.ChangeEvent<any>) => { | ||
closeMenu(); | ||
if (onClick) { | ||
onClick(e); | ||
} | ||
}} | ||
to={href} | ||
{...attr} | ||
aria-current={isActiveLink} | ||
data-testid={`menu-item-${display}`} | ||
isActiveLink={isActiveLink} | ||
> | ||
{icon && ( | ||
<div aria-hidden className="icon"> | ||
{icon} | ||
</div> | ||
)} | ||
<StyledPrimaryLinkBox | ||
className="primaryNavLink" | ||
isCollapsed={isCollapsed} | ||
> | ||
{display} | ||
{isBeta ? ( | ||
<BetaChip | ||
className={`${betaChipClassName ? betaChipClassName : ''}`} | ||
color="primary" | ||
component="span" | ||
/> | ||
) : null} | ||
</StyledPrimaryLinkBox> | ||
</StyledActiveLink> | ||
); | ||
}); | ||
|
||
export default PrimaryLink; |
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