-
-
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.
- Loading branch information
1 parent
a62e051
commit 4a8c5ef
Showing
19 changed files
with
7,458 additions
and
2,609 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
Empty file.
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 |
---|---|---|
@@ -1,99 +1,27 @@ | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import clsx from 'clsx'; | ||
import { useRouter } from 'next/router'; | ||
import NextLink from 'next/link'; | ||
import MuiLink from '@mui/material/Link'; | ||
import { styled } from '@mui/material/styles'; | ||
import NextLink from "next/link"; | ||
import { useRouter } from "next/router"; | ||
|
||
// Add support for the sx prop for consistency with the other branches. | ||
const Anchor = styled('a')({}); | ||
|
||
export const NextLinkComposed = React.forwardRef(function NextLinkComposed(props, ref) { | ||
const { to, linkAs, href, replace, scroll, shallow, prefetch, locale, ...other } = props; | ||
|
||
return ( | ||
<NextLink | ||
href={to} | ||
prefetch={prefetch} | ||
as={linkAs} | ||
replace={replace} | ||
scroll={scroll} | ||
shallow={shallow} | ||
passHref | ||
locale={locale} | ||
> | ||
<Anchor ref={ref} {...other} /> | ||
</NextLink> | ||
); | ||
}); | ||
|
||
NextLinkComposed.propTypes = { | ||
href: PropTypes.any, | ||
linkAs: PropTypes.oneOfType([PropTypes.object, PropTypes.string]), | ||
locale: PropTypes.string, | ||
passHref: PropTypes.bool, | ||
prefetch: PropTypes.bool, | ||
replace: PropTypes.bool, | ||
scroll: PropTypes.bool, | ||
shallow: PropTypes.bool, | ||
to: PropTypes.oneOfType([PropTypes.object, PropTypes.string]).isRequired, | ||
}; | ||
|
||
// A styled version of the Next.js Link component: | ||
// https://nextjs.org/docs/api-reference/next/link | ||
const Link = React.forwardRef(function Link(props, ref) { | ||
const { | ||
activeClassName = 'active', | ||
as: linkAs, | ||
className: classNameProps, | ||
export function Link({ | ||
href, | ||
noLinkStyle, | ||
role, // Link don't have roles. | ||
...other | ||
} = props; | ||
|
||
const router = useRouter(); | ||
const pathname = typeof href === 'string' ? href : href.pathname; | ||
const className = clsx(classNameProps, { | ||
[activeClassName]: router.pathname === pathname && activeClassName, | ||
}); | ||
|
||
const isExternal = | ||
typeof href === 'string' && (href.indexOf('http') === 0 || href.indexOf('mailto:') === 0); | ||
|
||
if (isExternal) { | ||
if (noLinkStyle) { | ||
return <Anchor className={className} href={href} ref={ref} {...other} />; | ||
activeClassName, | ||
inactiveClassName, | ||
className, | ||
children, | ||
...rest | ||
}) { | ||
const router = useRouter(); | ||
|
||
let currentClassName = className; | ||
let isActive = router.pathname === href; | ||
if (isActive) { | ||
currentClassName += ` ${activeClassName}`; | ||
} else { | ||
currentClassName += ` ${inactiveClassName}`; | ||
} | ||
|
||
return <MuiLink className={className} href={href} ref={ref} {...other} />; | ||
} | ||
|
||
if (noLinkStyle) { | ||
return <NextLinkComposed className={className} ref={ref} to={href} {...other} />; | ||
} | ||
|
||
return ( | ||
<MuiLink | ||
component={NextLinkComposed} | ||
linkAs={linkAs} | ||
className={className} | ||
ref={ref} | ||
to={href} | ||
{...other} | ||
/> | ||
); | ||
}); | ||
|
||
Link.propTypes = { | ||
activeClassName: PropTypes.string, | ||
as: PropTypes.oneOfType([PropTypes.object, PropTypes.string]), | ||
className: PropTypes.string, | ||
href: PropTypes.any, | ||
linkAs: PropTypes.oneOfType([PropTypes.object, PropTypes.string]), | ||
noLinkStyle: PropTypes.bool, | ||
role: PropTypes.string, | ||
}; | ||
|
||
export default Link; | ||
return ( | ||
<NextLink href={href} {...rest}> | ||
<a className={currentClassName}>{children({ isActive })}</a> | ||
</NextLink> | ||
); | ||
} |
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
Oops, something went wrong.