/
Titles.tsx
102 lines (97 loc) · 2.54 KB
/
Titles.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
import Clock from "components/icons/Clock";
import {
Dispatch,
MutableRefObject,
ReactElement,
SetStateAction,
useEffect,
useRef,
} from "react";
export default function Titles({
isPin,
setIsPin,
type,
}: {
isPin: boolean;
setIsPin: Dispatch<SetStateAction<boolean>>;
type: "presentation" | "playlist" | "album";
}): ReactElement {
const ref = useRef<HTMLDivElement>();
useEffect(() => {
const cachedRef = ref.current,
observer = new IntersectionObserver(
([e]) => {
if (e.intersectionRect.top >= 60) {
setIsPin(true);
} else {
setIsPin(false);
}
},
{
rootMargin: `0px 0px -${window.innerHeight - 60}px 0px`,
}
);
observer.observe(cachedRef as Element);
return function () {
observer.unobserve(cachedRef as Element);
};
});
return (
<div
id="titlesObserver"
className="titles"
ref={ref as MutableRefObject<HTMLDivElement>}
>
<span>#</span>
<span>TITLE</span>
{type === "playlist" ? (
<>
<span className="album">ALBUM</span>
<span className="dataAdded">DATE ADDED</span>
</>
) : null}
<span className="clock">
<Clock />
</span>
<style jsx>{`
.titles {
border-bottom: 1px solid transparent;
box-sizing: content-box;
height: 36px;
margin: ${isPin ? "0 -32px 8px" : "0 -16px 8px"};
padding: ${isPin ? "0 32px" : "0 16px"};
position: sticky;
top: 60px;
z-index: 2;
display: grid;
grid-gap: 16px;
background-color: ${isPin ? "#181818" : "transparent"};
border-bottom: 1px solid #ffffff1a;
grid-template-columns: ${type === "playlist"
? "[index] 48px [first] 6fr [var1] 4fr [var2] 3fr [last] minmax(120px,1fr)"
: type === "album"
? "[index] 48px [first] 6fr [last] minmax(120px,1fr)"
: "[index] 55px [first] 4fr [last] minmax(120px,1fr)"};
}
.titles span {
display: flex;
align-items: center;
font-size: 0.75rem;
color: #b3b3b3;
font-family: sans-serif;
}
.titles span:nth-of-type(1) {
font-size: 16px;
justify-self: center;
margin-left: 16px;
}
.titles span:nth-of-type(2) {
margin-left: 70px;
}
.clock {
justify-content: center;
}
`}</style>
</div>
);
}