-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathpage-top.tsx
67 lines (56 loc) · 1.41 KB
/
page-top.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
import React, { FC, useEffect, useRef } from "react";
import styled from "styled-components";
import { Icon } from "@/components/sprites";
import { useObservable } from "@/state";
import { THEME_COLORS } from "@/style";
// Icons
import ChevronUpIconSvg from "@/images/icons/chevron-up.svg";
export interface PageTopProps {
readonly onTopScroll: () => void;
}
export const PageTop: FC<PageTopProps> = ({ onTopScroll }) => {
const ref = useRef<HTMLButtonElement>(null);
const showButton$ = useObservable((state) => {
return state.common.yScrollPosition > 72;
});
useEffect(() => {
const subscription = showButton$.subscribe((showButton) => {
ref.current?.classList.toggle("show", showButton);
});
return () => {
subscription.unsubscribe();
};
}, [showButton$]);
return (
<JumpToTop ref={ref} onClick={onTopScroll}>
<Icon {...ChevronUpIconSvg} />
</JumpToTop>
);
};
const JumpToTop = styled.button`
display: none;
position: fixed;
right: 24px;
bottom: 24px;
z-index: 20;
border-radius: 12px;
padding: 6px 4px 2px;
width: 42px;
height: 42px;
background-color: ${THEME_COLORS.text};
opacity: 0.6;
transition: opacity 0.2s ease-in-out;
&.show {
display: initial;
}
&:hover {
opacity: 1;
}
svg {
width: 30px;
height: 30px;
}
@media only screen and (min-width: 1600px) {
right: calc(((100vw - 1320px) / 2) - 100px);
}
`;