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