Do more styling work for sidebar

This commit is contained in:
Corbin Crutchley
2020-03-25 16:02:51 -07:00
parent 1156219fb5
commit 554ec01f3a
5 changed files with 32 additions and 16 deletions

View File

@@ -1616,9 +1616,9 @@ Of course, this means that you can send any value as the context. Change the cod
```typescript ```typescript
{ {
$implicit: pigLatinVal, $implicit: pigLatinVal,
original: this.makePiglatin, original: this.makePiglatin,
makePiglatinCasing: 'See? Any value' makePiglatinCasing: 'See? Any value'
} }
``` ```

View File

@@ -3,16 +3,34 @@
.blog-post-layout-container { .blog-post-layout-container {
display: flex; display: flex;
flex-wrap: nowrap; flex-wrap: nowrap;
max-width: 1500px;
margin: 0 auto;
} }
.left-and-right-container { .center-container {
margin: 0 auto;
}
.left-container {
top: 3rem;
overflow: auto;
height: calc(100vh - 10rem);
margin-top: 4rem;
margin-right: 2rem;
min-width: 220px;
}
.right-container {
margin-left: 2rem;
}
.left-container,
.right-container {
width: 1px; width: 1px;
flex-grow: 1; flex-grow: 1;
top: 13rem;
position: sticky; position: sticky;
align-self: flex-start; align-self: flex-start;
overflow: auto; overflow: auto;
height: calc(100vh - 13rem);
// Add 400px to the parent of the blog post, if it matches this, we want to hide the side elements from the browser // Add 400px to the parent of the blog post, if it matches this, we want to hide the side elements from the browser
// This means no left and right containers on mobile // This means no left and right containers on mobile

View File

@@ -13,9 +13,9 @@ export const BlogPostLayout = ({
}: LayoutProps) => { }: LayoutProps) => {
return ( return (
<div className={layoutStyles.blogPostLayoutContainer}> <div className={layoutStyles.blogPostLayoutContainer}>
<div className={layoutStyles.leftAndRightContainer}>{left}</div> <div className={layoutStyles.leftContainer}>{left}</div>
{center} <div className={layoutStyles.centerContainer}>{center}</div>
<div className={layoutStyles.leftAndRightContainer}>{right}</div> <div className={layoutStyles.rightContainer}>{right}</div>
</div> </div>
); );
}; };

View File

@@ -15,8 +15,8 @@ export const useHeadingIntersectionObserver = ({
}: useHeadingIntersectionObserverProp) => { }: useHeadingIntersectionObserverProp) => {
const [previousSection, setPreviousSelection] = React.useState(""); const [previousSection, setPreviousSelection] = React.useState("");
const handleObserver = React.useMemo<IntersectionObserverCallback>(() => { React.useEffect(() => {
return entries => { const handleObserver: IntersectionObserverCallback = entries => {
const highlightFirstActive = () => { const highlightFirstActive = () => {
if (!tocListRef.current) return; if (!tocListRef.current) return;
let firstVisibleLink = tocListRef.current.querySelector( let firstVisibleLink = tocListRef.current.querySelector(
@@ -56,9 +56,7 @@ export const useHeadingIntersectionObserver = ({
highlightFirstActive(); highlightFirstActive();
}); });
}; };
}, [linkRefs, previousSection, tocListRef]);
React.useEffect(() => {
const observer = new IntersectionObserver(handleObserver, { const observer = new IntersectionObserver(handleObserver, {
rootMargin: "0px", rootMargin: "0px",
threshold: 1 threshold: 1
@@ -75,5 +73,5 @@ export const useHeadingIntersectionObserver = ({
}); });
return () => observer.disconnect(); return () => observer.disconnect();
}, [linkRefs, handleObserver, headingsToDisplay]); }, [headingsToDisplay, previousSection, linkRefs, tocListRef]);
}; };

View File

@@ -68,7 +68,7 @@ const BlogPostTemplateChild = (props: BlogPostTemplateProps) => {
<BlogPostLayout <BlogPostLayout
left={<TableOfContents headingsWithId={post.fields.headingsWithId} />} left={<TableOfContents headingsWithId={post.fields.headingsWithId} />}
center={ center={
<div> <>
<header role="banner" className="marginZeroAutoChild"> <header role="banner" className="marginZeroAutoChild">
<PostTitleHeader post={post} /> <PostTitleHeader post={post} />
<PostMetadata post={post} /> <PostMetadata post={post} />
@@ -78,7 +78,7 @@ const BlogPostTemplateChild = (props: BlogPostTemplateProps) => {
data-testid={"post-body-div"} data-testid={"post-body-div"}
dangerouslySetInnerHTML={{ __html: post.html }} dangerouslySetInnerHTML={{ __html: post.html }}
/> />
</div> </>
} }
/> />
<footer role="contentinfo" className="post-lower-area"> <footer role="contentinfo" className="post-lower-area">