Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrap the logo in a div on the homepage to prevent redirection. (GCOM-1164) #2138

Merged
merged 5 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/calm-bees-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphcommerce/next-ui': patch
---

Wrap the logo in a div on the homepage to prevent redirection.
40 changes: 20 additions & 20 deletions packages/next-ui/LayoutParts/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
SxProps,
Theme,
unstable_composeClasses as composeClasses,
Box,
} from '@mui/material'
import { useRouter } from 'next/router'
import { forwardRef } from 'react'
Expand All @@ -22,25 +23,21 @@ const getLogoUtilityClass = (slot: string) => generateUtilityClass(name, slot)
const useUtilityClasses = ({ classes }: LogoClassProps) =>
composeClasses({ logo: ['logo'], parent: ['parent'] }, getLogoUtilityClass, classes)

/** Creating styled components */
const LogoContainer = styled(NextLink, {
name,
slot: 'parent',
overridesResolver: (_props, styles) => styles.parent,
})(({ theme }) => ({
const commonLogoStyles: SxProps<Theme> = {
height: '100%',
width: 'max-content',
display: 'flex',
alignItems: 'center',
margin: '0 auto',
justifyContent: 'center',
pointerEvents: 'all',
[theme.breakpoints.up('md')]: {
display: 'flex',
margin: 'unset',
justifyContent: 'left',
},
}))
}

const LogoContainer = styled(NextLink, {
name,
slot: 'parent',
overridesResolver: (_props, styles) => styles.parent,
})()

export type LogoProps = {
href?: `/${string}`
Expand All @@ -51,7 +48,6 @@ export type LogoProps = {
export const Logo = forwardRef<HTMLAnchorElement, LogoProps>((props, ref) => {
const { href = '/', image, sx } = props
const router = useRouter()

const classes = useUtilityClasses(props)

const img = (
Expand All @@ -63,13 +59,17 @@ export const Logo = forwardRef<HTMLAnchorElement, LogoProps>((props, ref) => {
/>
)

return router.asPath.split('?')[0] === '/' ? (
<LogoContainer ref={ref} sx={sx} className={classes.parent}>
{img}
</LogoContainer>
) : (
<LogoContainer href={href} ref={ref} sx={sx} className={classes.parent}>
const shouldRedirect = router.asPath.split('?')[0] !== href

return (
<Box
component={shouldRedirect ? LogoContainer : 'div'}
href={shouldRedirect ? href : undefined}
ref={ref}
sx={[...(Array.isArray(sx) ? sx : [sx]), commonLogoStyles]}
className={classes.parent}
>
{img}
</LogoContainer>
</Box>
)
})
Loading