blob: 4af9457a17bc5ba3ef9e1ec23c5a12731bf5de6f [file] [log] [blame]
pineafan54a1e552021-09-03 17:51:18 +01001import React, { Component } from "react";
pineafana5ce9102021-09-02 17:21:31 +01002import Styles from '../styles/navbar.module.css';
3
4class NavBar extends Component {
5 constructor(props) {
6 super(props);
7 this.state = {
pineafan54a1e552021-09-03 17:51:18 +01008 isOpen: false // true
pineafana5ce9102021-09-02 17:21:31 +01009 }
Samuel Shuert604e31d2021-09-02 16:06:20 -050010 this.isTouchDevice = false
pineafan54a1e552021-09-03 17:51:18 +010011 this.hoverSensor = React.createRef();
pineafana5ce9102021-09-02 17:21:31 +010012 }
pineafan54a1e552021-09-03 17:51:18 +010013
Samuel Shuert604e31d2021-09-02 16:06:20 -050014 componentDidMount() {
15 let hasTouchScreen = false;
16 if ("maxTouchPoints" in navigator) {
17 hasTouchScreen = navigator.maxTouchPoints > 0;
18 } else if ("msMaxTouchPoints" in navigator) {
19 hasTouchScreen = navigator.msMaxTouchPoints > 0;
20 } else {
21 const mQ = window.matchMedia && matchMedia("(pointer:coarse)");
22 if (mQ && mQ.media === "(pointer:coarse)") {
23 hasTouchScreen = !!mQ.matches;
24 } else if ("orientation" in window) {
25 hasTouchScreen = true;
26 } else {
27 var UA = navigator.userAgent;
28 hasTouchScreen = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA);
29 }
30 }
31 if (hasTouchScreen) {
32 this.isTouchDevice = true
33 } else {
34 this.isTouchDevice = false
35 }
36 }
37
38 onEnter() {
39 if ( !this.isTouchDevice ) {
40 return this.toggleVertical(this, true)
41 }
42 }
43
44 onLeave() {
45 return this.toggleVertical(this, false)
46 }
47
48 onClick() {
49 if ( this.isTouchDevice ) {
50 return this.toggleVertical(this)
51 }
52 }
pineafana5ce9102021-09-02 17:21:31 +010053
54 toggleVertical(prevState, force=null) {
55 this.setState(prevState => ({
56 isOpen: (force === null) ? !prevState.isOpen : force
57 }));
58 }
59
60 render() {
61 return (
62 <>
pineafan54a1e552021-09-03 17:51:18 +010063 <div ref={this.hoverSensor} className={(Styles.container + " " + (this.state.isOpen ? Styles.containerOpen : null))} onMouseLeave={() => {this.onLeave()}}>
pineafana5ce9102021-09-02 17:21:31 +010064 <div className={Styles.group}>
Samuel Shuert604e31d2021-09-02 16:06:20 -050065 <img className={Styles.headerIcon} src="/Icons/CMP.svg" onMouseEnter={() => {this.onEnter()}} onClick={() => {this.onClick()}}/>
66 <a href="/#"><img className={Styles.icon} src="/Icons/CMP.svg"/></a>
67 <a href="/gps#"><img className={Styles.icon} src="/Icons/GS.svg"/></a>
68 <a href="/rsm#"><img className={Styles.icon} src="/Icons/RM.svg"/></a>
69 <a href="/clicksforms#"><img className={Styles.icon} src="/Icons/CF.svg"/></a>
70 {/* <a href="/castaway#"><img className={Styles.icon} src="/Icons/CA.svg"/></a> */}
Samuel Shuert52f37772021-09-02 12:29:40 -050071 {/* <a href="https://clcks.dev"><img className={Styles.icon} src="/Icons/CL.svg"/></a> */}
pineafana5ce9102021-09-02 17:21:31 +010072 </div>
73 <div className={Styles.group}>
Samuel Shuert604e31d2021-09-02 16:06:20 -050074 <a href="/#"><img className={Styles.icon} src="/Icons/CMP.svg"/></a>
pineafana5ce9102021-09-02 17:21:31 +010075 </div>
76 </div>
77 </>
78 )
79 }
80}
81
82export default NavBar;