forked from badges/shields
-
Notifications
You must be signed in to change notification settings - Fork 1
/
category-headings.js
80 lines (69 loc) · 1.52 KB
/
category-headings.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
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
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import { Link } from 'gatsby'
import { H3 } from './common'
export function CategoryHeading({ category: { id, name } }) {
return (
<Link to={`/category/${id}`}>
<H3 id={id}>{name}</H3>
</Link>
)
}
CategoryHeading.propTypes = {
category: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
}).isRequired,
}
export function CategoryHeadings({ categories }) {
return (
<div>
{categories.map(category => (
<CategoryHeading category={category} key={category.id} />
))}
</div>
)
}
CategoryHeadings.propTypes = {
categories: PropTypes.arrayOf(CategoryHeading.propTypes.category).isRequired,
}
const StyledNav = styled.nav`
ul {
display: flex;
min-width: 50%;
max-width: 500px;
margin: 0 auto 20px;
padding-inline-start: 0;
flex-wrap: wrap;
justify-content: center;
list-style-type: none;
}
@media screen and (max-width: 768px) {
ul {
display: none;
}
}
li {
margin: 4px 10px;
}
.active {
font-weight: 900;
}
`
export function CategoryNav({ categories }) {
return (
<StyledNav>
<ul>
{categories.map(({ id, name }) => (
<li key={id}>
<Link to={`/category/${id}`}>{name}</Link>
</li>
))}
</ul>
</StyledNav>
)
}
CategoryNav.propTypes = {
categories: PropTypes.arrayOf(CategoryHeading.propTypes.category).isRequired,
}