-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathPrevNext.js
102 lines (95 loc) · 1.79 KB
/
PrevNext.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
import React from "react";
import styled, { css, cx } from "react-emotion";
import { Link as LinkBase } from "@survivejs/components";
import theme from "../styles/theme";
const Container = styled.div`
display: flex;
flex-wrap: wrap;
margin-bottom: ${theme.space.xl};
`;
const panel = css`
flex-basis: 300px;
flex-grow: 1;
`;
const panelPrev = css`
padding-right: ${theme.space.m};
`;
const panelNext = css`
padding-left: ${theme.space.m};
text-align: right;
`;
const Panel = ({ prev, next, ...props }) => (
<div
className={cx(panel, {
[panelPrev]: prev,
[panelNext]: next,
})}
{...props}
/>
);
const Title = styled.div`
margin-bottom: ${theme.space.xxs};
font-weight: bold;
`;
const link = css`
display: block;
position: relative;
&::before {
font-family: ${theme.font.heading};
position: absolute;
margin-top: 0.15em;
}
`;
const linkPrev = css`
&::before {
content: "←";
left: -1.2em;
}
`;
const linkNext = css`
&::before {
content: "→";
right: -1.2em;
}
`;
const Link = ({ prev, next, ...props }) => (
<LinkBase
className={cx(link, {
[linkPrev]: prev,
[linkNext]: next,
})}
{...props}
/>
);
const PrevNext = ({
next,
nextText,
previous,
previousText,
getTitle = () => {},
}) => {
if (!(next || previous)) {
return null;
}
return (
<Container>
{!!previous && (
<Panel prev>
<Title>{previousText}</Title>
<Link prev to={previous.url}>
{getTitle(previous)}
</Link>
</Panel>
)}
{!!next && (
<Panel next>
<Title>{nextText}</Title>
<Link next to={next.url}>
{getTitle(next)}
</Link>
</Panel>
)}
</Container>
);
};
export default PrevNext;