-
-
Notifications
You must be signed in to change notification settings - Fork 767
/
Copy pathblog-article-navigation.tsx
132 lines (118 loc) · 3.2 KB
/
blog-article-navigation.tsx
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { graphql } from "gatsby";
import React, { FC } from "react";
import styled from "styled-components";
import { ScrollContainer } from "@/components/article-elements";
import { IconContainer, Link } from "@/components/misc";
import { Icon } from "@/components/sprites";
import { BlogArticleNavigationFragment } from "@/graphql-types";
import { FONT_FAMILY_HEADING, THEME_COLORS } from "@/style";
// Icons
import Grid2IconSvg from "@/images/icons/grid-2.svg";
import {
NavigationItem,
NavigationLink,
NavigationList,
NavigationTitle,
} from "./article-navigation-elements";
export interface BlogArticleNavigationProps {
readonly data: BlogArticleNavigationFragment;
readonly selectedPath: string;
}
export const BlogArticleNavigation: FC<BlogArticleNavigationProps> = ({
data,
selectedPath,
}) => {
const posts: Post[] =
data.latestPosts.posts.map((post) => ({
slug: post.fields?.slug ?? "",
title: post.frontmatter?.title ?? "",
})) ?? [];
return (
<>
<Header>
<BackButton to="/blog">
Overview
<IconContainer $size={14}>
<Icon {...Grid2IconSvg} />
</IconContainer>
</BackButton>
</Header>
<ScrollContainer>
<NavigationTitle>Latest Blog Posts</NavigationTitle>
<NavigationList>
{posts.map(({ slug, title }) => {
return (
<NavigationItem key={slug} active={selectedPath === slug}>
<NavigationLink to={slug}>{title}</NavigationLink>
</NavigationItem>
);
})}
</NavigationList>
</ScrollContainer>
</>
);
};
interface Post {
readonly slug: string;
readonly title: string;
}
export const BlogArticleNavigationGraphQLFragment = graphql`
fragment BlogArticleNavigation on Query {
latestPosts: allMdx(
limit: 10
filter: { frontmatter: { path: { regex: "//blog(/.*)?/" } } }
sort: { order: DESC, fields: [frontmatter___date] }
) {
posts: nodes {
fields {
slug
}
frontmatter {
title
}
}
}
}
`;
const BackButton = styled(Link)`
display: flex;
flex: 0 0 auto;
flex-direction: row;
align-items: center;
box-sizing: border-box;
border: 2px solid ${THEME_COLORS.primaryButtonBorder};
border-radius: var(--button-border-radius);
width: 100%;
height: 38px;
padding-right: 10px;
padding-left: 10px;
font-family: ${FONT_FAMILY_HEADING};
font-size: 0.875rem;
font-weight: 500;
color: ${THEME_COLORS.primaryButtonText};
background-color: ${THEME_COLORS.primaryButton};
transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
> ${IconContainer} {
margin-left: auto;
padding-left: 6px;
> svg {
fill: ${THEME_COLORS.primaryButtonText};
}
}
:hover {
color: ${THEME_COLORS.primaryButtonHoverText};
background-color: ${THEME_COLORS.primaryButtonHover};
> ${IconContainer} > svg {
fill: ${THEME_COLORS.primaryButtonHoverText};
}
}
`;
const Header = styled.div`
display: flex;
align-items: center;
justify-content: space-between;
margin: 6px 14px 20px 14px;
@media only screen and (min-width: 1070px) {
margin: 0 0 20px 0;
}
`;