-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHeader.jsx
90 lines (83 loc) · 2.85 KB
/
Header.jsx
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
import React from "react";
//Redux
import { useSelector, useDispatch } from "react-redux";
import { applyFullscreen } from "../../redux/fullscreen/fullscreenActions";
import { applyTheme } from "../../redux/theme/themeActions";
import { applyTwoColumn } from "../../redux/column/columnMode/columnModeActions";
//Components
import { ControlBtn } from "../ControlBtn/ControlBtn";
//Styles
import "./Header.scss";
//Icons
import maximize from "../../icons/maximize.svg";
import minimize from "../../icons/minimize.svg";
import down from "../../icons/down.svg";
import up from "../../icons/up.svg";
import oneColumnIcon from "../../icons/columns-one.svg";
import twoColumnIcon from "../../icons/columns-two.svg";
//Mobile adaptation
import { isMobileOnly, isBrowser, isTablet } from "react-device-detect";
export const Header = ({ fullscreen }) => {
const dispatch = useDispatch();
//Screen mode (fullscreen)
const changeMode = (fullscreen) => {
dispatch(applyFullscreen(fullscreen));
};
//Dark theme
const darkTheme = useSelector((state) => state.theme.darkTheme);
const changeTheme = (theme) => {
//Smooth theme switching
document.body.classList.add("theme-switch");
dispatch(applyTheme(theme));
setTimeout(() => {
document.body.classList.remove("theme-switch");
}, 500);
};
//Column mode (only on mobile)
const twoColumn = useSelector((state) => state.twoColumn.twoColumn);
const changeColumnMode = () => {
dispatch(applyTwoColumn(!twoColumn));
};
//Classnames
const classNames = `header ${fullscreen ? "fullscreen" : ""} ${
isMobileOnly ? "mobile" : ""
}`;
//Control buttons labels
const modeLabel = fullscreen ? "Minimize" : "Fullscreen";
const themeLabel = darkTheme ? "Dark Theme" : "Light Theme";
const columnModeLabel = twoColumn ? "2 column" : "1 column";
return (
<header className={classNames}>
<p className="header__link" href="">
cr.fetbiko.ru
</p>
<div className="header__controls">
{fullscreen && (
<ControlBtn
label={themeLabel}
icon={darkTheme ? down : up}
reversed={true}
onClick={() => changeTheme(!darkTheme)}
ariaLabel={`${darkTheme ? "disable" : "enable"} dark mode`}
/>
)}
{(isBrowser || isTablet) && (
<ControlBtn
label={modeLabel}
icon={fullscreen ? minimize : maximize}
onClick={() => changeMode(!fullscreen)}
ariaLabel={`${fullscreen ? "disable" : "enable"} fullscreen mode`}
/>
)}
{isMobileOnly && (
<ControlBtn
label={columnModeLabel}
icon={twoColumn ? twoColumnIcon : oneColumnIcon}
onClick={changeColumnMode}
ariaLabel={`${twoColumn ? "disable" : "enable"} two column mode`}
/>
)}
</div>
</header>
);
};