/
PageLink.js
122 lines (111 loc) · 3.04 KB
/
PageLink.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
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
import PropTypes from 'prop-types';
import React from 'react';
import Link from 'gatsby-link';
import typography from '../utils/typography';
import CategoryIcon from './CategoryIcon';
import format from 'date-fns/format';
import parse from 'date-fns/parse';
import glamorous from 'glamorous';
import star from '../svg/star.svgi';
import flame from '../svg/flame.svgi';
import Icon from './Icon';
import { css } from 'glamor';
import { sansFontStack, serifFontStack } from '../utils/typography';
export const TrendingIcon = () => <Icon color="#E55934" icon={flame} />;
export const FavoriteIcon = () => <Icon color="#D7AF70" icon={star} />;
const ListItem = glamorous.li({
marginBottom: typography.rhythm(1 / 2),
listStyle: 'none',
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
});
const PageWrapper = glamorous.div({
maxWidth: '50vw',
'@media all and (max-width: 700px)': {
maxWidth: '100vw',
},
display: 'flex',
alignItems: 'centglamor.er',
});
const linkClass = css({
boxShadow: 'none',
fontSize: '16px',
fontFamily: sansFontStack,
textDecoration: 'none',
});
const PageDescription = glamorous.p({
fontFamily: serifFontStack,
// fontStyle: 'italic',
fontSize: '16px',
margin: 0,
color: 'rgba(100,100,100, 0.7)',
});
const DateContainer = glamorous.span({
fontFamily: serifFontStack,
whiteSpace: 'nowrap',
fontSize: '18px',
color: 'rgba(100,100,100, 0.7)',
});
const TitleRow = glamorous.div({
display: 'flex',
alignItems: 'center',
'> *': {
marginRight: '10px',
},
});
class PageLink extends React.Component {
render() {
let {
page,
showCategory,
showDate,
showDescription,
titleFn,
showPopular,
showTrending,
} = this.props;
const _title = titleFn(page);
return (
<ListItem>
<PageWrapper>
<div>
<TitleRow>
<Link className={linkClass} to={page.path}>
{_title}
</Link>
{showTrending && page.data.isTrending ? <TrendingIcon /> : null}
{showPopular && page.data.isPopular ? <FavoriteIcon /> : null}
</TitleRow>
{showDescription ? (
<PageDescription>{page.data.description}</PageDescription>
) : null}
{showCategory ? (
<CategoryIcon category={page.data.category} />
) : null}
</div>
</PageWrapper>
{showDate ? (
<DateContainer className="no-mobile">
{format(parse(page.data.date), 'MMM Do YYYY')}
</DateContainer>
) : null}
</ListItem>
);
}
}
PageLink.propTypes = {
page: PropTypes.object.isRequired,
showDate: PropTypes.bool.isRequired,
showCategory: PropTypes.bool.isRequired,
showDescription: PropTypes.bool.isRequired,
showPopular: PropTypes.bool.isRequired,
showTrending: PropTypes.bool.isRequired,
titleFn: PropTypes.func.isRequired,
};
PageLink.defaultProps = {
showCategory: true,
showDate: true,
showDescription: true,
};
export default PageLink;