Skip to content

Commit 9f0e6c8

Browse files
committed
moving home button into component
1 parent eed4f5a commit 9f0e6c8

File tree

3 files changed

+54
-34
lines changed

3 files changed

+54
-34
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
import { SideNavItem } from '@leafygreen-ui/side-nav';
3+
import Icon from '@leafygreen-ui/icon';
4+
import { css as LeafyCSS, cx } from '@leafygreen-ui/emotion';
5+
import { palette } from '@leafygreen-ui/palette';
6+
import Link from '../Link';
7+
import { baseUrl } from '../../utils/base-url';
8+
import { sideNavItemBasePadding } from './styles/sideNavItem';
9+
import { titleStyle } from './styles/sideNavItem';
10+
11+
const homeLinkStyle = LeafyCSS`
12+
span {
13+
color: ${palette.gray.dark1};
14+
font-weight: 400;
15+
display: flex;
16+
gap: 6px;
17+
align-items: text-bottom;
18+
svg {
19+
height: 17px;
20+
color: ${palette.gray.dark2}
21+
}
22+
}
23+
`;
24+
25+
const DocsHomeButton = () => {
26+
return (
27+
<SideNavItem className={cx(titleStyle, sideNavItemBasePadding, homeLinkStyle)} as={Link} to={baseUrl()}>
28+
<Icon glyph="Home"></Icon>
29+
Docs Home
30+
</SideNavItem>
31+
);
32+
};
33+
34+
export default DocsHomeButton;

src/components/Sidenav/Sidenav.js

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import VersionDropdown from '../VersionDropdown';
1313
import useStickyTopValues from '../../hooks/useStickyTopValues';
1414
import { theme } from '../../theme/docsTheme';
1515
import { formatText } from '../../utils/format-text';
16-
import { baseUrl } from '../../utils/base-url';
1716
import { TocContext } from '../../context/toc-context';
1817
import { VersionContext } from '../../context/version-context';
1918
import useSnootyMetadata from '../../utils/use-snooty-metadata';
@@ -26,7 +25,8 @@ import ProductsList from './ProductsList';
2625
import { SidenavContext } from './sidenav-context';
2726
import SidenavMobileTransition from './SidenavMobileTransition';
2827
import Toctree from './Toctree';
29-
import { sideNavItemBasePadding, sideNavItemFontSize } from './styles/sideNavItem';
28+
import { sideNavItemBasePadding, sideNavItemFontSize, titleStyle } from './styles/sideNavItem';
29+
import DocsHomeButton from './DocsHomeButton';
3030

3131
const SIDENAV_WIDTH = 268;
3232

@@ -76,34 +76,6 @@ const sideNavStyling = ({ hideMobile, isCollapsed }) => LeafyCSS`
7676
7777
`;
7878

79-
const titleStyle = LeafyCSS`
80-
color: ${palette.gray.dark3};
81-
font-size: ${theme.fontSize.small};
82-
font-weight: bold;
83-
line-height: 20px;
84-
text-transform: none;
85-
:hover {
86-
background-color: inherit;
87-
88-
&:after, span:after {
89-
display: none;
90-
}
91-
}
92-
`;
93-
94-
const homeLinkStyle = LeafyCSS`
95-
span {
96-
color: ${palette.gray.dark1};
97-
font-weight: 400;
98-
display: flex;
99-
gap: 6px;
100-
align-items: center;
101-
svg {
102-
color: ${palette.gray.dark2}
103-
}
104-
}
105-
`;
106-
10779
// Prevent content scrolling when the side nav is open on mobile and tablet screen sizes
10880
const disableScroll = (shouldDisableScroll) => css`
10981
body {
@@ -272,10 +244,7 @@ const Sidenav = ({ chapters, guides, page, pageTitle, repoBranches, siteTitle, s
272244
<IATransition back={back} hasIA={!!ia} slug={slug} isMobile={isMobile}>
273245
<NavTopContainer>
274246
<ArtificialPadding />
275-
<SideNavItem className={cx(titleStyle, sideNavItemBasePadding, homeLinkStyle)} as={Link} to={baseUrl()}>
276-
<Icon glyph="Home"></Icon>
277-
Docs Home
278-
</SideNavItem>
247+
<DocsHomeButton />
279248
<Border />
280249
{ia && (
281250
<IA

src/components/Sidenav/styles/sideNavItem.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { css } from '@leafygreen-ui/emotion';
2+
import { palette } from '@leafygreen-ui/palette';
23
import { theme } from '../../../theme/docsTheme';
34

45
export const sideNavItemBasePadding = css`
@@ -31,3 +32,19 @@ export const sideNavItemTOCStyling = ({ level = 1 }) => css`
3132
export const sideNavItemFontSize = css`
3233
font-size: ${theme.fontSize.small};
3334
`;
35+
36+
export const titleStyle = css`
37+
color: ${palette.gray.dark3};
38+
font-size: ${theme.fontSize.small};
39+
font-weight: bold;
40+
line-height: 20px;
41+
text-transform: none;
42+
:hover {
43+
background-color: inherit;
44+
45+
&:after,
46+
span:after {
47+
display: none;
48+
}
49+
}
50+
`;

0 commit comments

Comments
 (0)