Open History to see the last commit
1import * as React from 'react';
2import { SidebarNavLink } from './SidebarNavLink';
3import cn from 'classnames';
4export const SidebarPost = ({
5 isMobile,
6 route,
7 level = 1,
8 onClick,
9 ...props
10}) => {
11 const selectedRef = React.useRef(null);
12 const ref = route.selected ? selectedRef : null;
13 React.useEffect(() => {
14 if (ref && ref.current && !isMobile) {
15 const content = document.querySelector('.sidebar-content'); // 32 is the top and bottom margin for `.link`
16β
17 const height = ref.current.offsetTop - 32;
18β
19 if (content) {
20 content.scrollTop = height - content.offsetHeight / 2;
21 }
22 }
23 }, [ref, isMobile]);
24 return <div ref={ref} className={cn('link', `level-${level}`)}>
25 <SidebarNavLink route={route} scrollSelectedIntoView={props.scrollSelectedIntoView} categorySelected={props.categorySelected} level={level} onClick={onClick} />
26 <style jsx>{`
27 .link {
28 margin: 12px 0;
29 display: flex;
30 align-items: center;
31 }
32β
33 .link:first-child {
34 margin-top: 0;
35 }
36 .link:last-child {
37 margin-bottom: 0;
38 }
39 @media screen and (max-width: 950px) {
40 .link {
41 margin: 24px 0;
42 }
43 }
44 `}</style>
45 </div>;
46};