Skip to content

Commit

Permalink
feat(menu): Add prop to make logo absolute url (#114)
Browse files Browse the repository at this point in the history
* feat(menu): Add prop to make logo absolute url

* feat(menu): Check home link for logo url
  • Loading branch information
hachiojidev authored Jan 6, 2021
1 parent 851de1b commit 778a50e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
24 changes: 19 additions & 5 deletions src/widgets/Menu/Logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface Props {
isPushed: boolean;
isDark: boolean;
togglePush: () => void;
href: string;
}

const StyledLink = styled(Link)`
Expand All @@ -30,7 +31,15 @@ const StyledLink = styled(Link)`
}
`;

const Logo: React.FC<Props> = ({ isPushed, togglePush, isDark }) => {
const Logo: React.FC<Props> = ({ isPushed, togglePush, isDark, href }) => {
const isAbsoluteUrl = href.startsWith("http");
const innerLogo = (
<>
<LogoIcon className="mobile-icon" />
<LogoWithText className="desktop-icon" isDark={isDark} />
</>
);

return (
<Flex>
<MenuButton aria-label="Toggle menu" onClick={togglePush} mr="24px">
Expand All @@ -40,10 +49,15 @@ const Logo: React.FC<Props> = ({ isPushed, togglePush, isDark }) => {
<HamburgerIcon width="24px" color="textSubtle" />
)}
</MenuButton>
<StyledLink to="/" aria-label="Pancake home page">
<LogoIcon className="mobile-icon" />
<LogoWithText className="desktop-icon" isDark={isDark} />
</StyledLink>
{isAbsoluteUrl ? (
<StyledLink as="a" href={href} aria-label="Pancake home page">
{innerLogo}
</StyledLink>
) : (
<StyledLink to={href} aria-label="Pancake home page">
{innerLogo}
</StyledLink>
)}
</Flex>
);
};
Expand Down
10 changes: 9 additions & 1 deletion src/widgets/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,18 @@ const Menu: React.FC<NavProps> = ({
};
}, []);

// Find the home link if provided
const homeLink = links.find((link) => link.label === "Home");

return (
<Wrapper>
<StyledNav showMenu={showMenu}>
<Logo isPushed={isPushed} togglePush={() => setIsPushed((prevState: boolean) => !prevState)} isDark={isDark} />
<Logo
isPushed={isPushed}
togglePush={() => setIsPushed((prevState: boolean) => !prevState)}
isDark={isDark}
href={homeLink?.href ?? "/"}
/>
<UserBlock account={account} login={login} logout={logout} />
</StyledNav>
<BodyWrapper>
Expand Down

0 comments on commit 778a50e

Please sign in to comment.