-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathintra-page.js
More file actions
106 lines (95 loc) · 2.13 KB
/
Copy pathintra-page.js
File metadata and controls
106 lines (95 loc) · 2.13 KB
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
import React, { useEffect, useState } from "react";
import { Link } from "gatsby";
import styled from "styled-components";
const JoinCommunityWrapper = styled.div`
width: 18rem;
@media screen and (max-width: 750px) {
display: none;
}
@media screen and (min-width: 751px) and (max-width: 1279px) {
display: none;
}
.intra-page {
position: sticky;
top: 17rem;
right: 0rem;
margin-right: 1rem;
margin-top: 17rem;
padding-bottom: 5rem;
padding-right: 2rem;
align-items: left;
justify-content: space-around;
display: flex;
flex-direction: column;
overflow: hidden;
.list {
color: #000000;
}
.active {
font-weight: 5000;
color: #000000;
}
ul {
list-style: none;
top: 3rem;
li {
padding-bottom: 0.5rem;
padding-top: 0.5rem;
}
}
@media only screen and (min-width: 1280px) and (max-width: 1350px) {
padding-right: 0rem;
margin-right: 0rem;
}
@media only screen and (max-width: 950px) {
width: 0;
opacity: 0;
height: 0;
transition: none;
visibility: hidden;
}
}
.learn {
width: 10rem;
}
`;
function IntraPage() {
const [contents, setContents] = useState([]);
useEffect(() => {
const anchors = document.querySelectorAll(".main-content > a");
if (anchors) {
setContents(
Array.from(anchors).map((a) => ({
id: a.id,
link: `#${a.id}`,
text: a.id,
}))
);
}
}, []);
const [intapath, setIntapath] = useState(null);
useEffect(() => {
const path = window.location.pathname;
setIntapath(path);
}, []);
return (
<JoinCommunityWrapper>
<div className="intra-page">
<ul>
{contents.map((x) => (
<li key={x.id} className="list">
<Link
to={`${intapath}${x.link}`}
key={x.id}
activeClassName="active"
>
{x.text}
</Link>
</li>
))}
</ul>
</div>
</JoinCommunityWrapper>
);
}
export default IntraPage;