pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame^] | 1 | import React, { Component } from "react"; |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 2 | import Styles from '../styles/navbar.module.css'; |
| 3 | |
| 4 | class NavBar extends Component { |
| 5 | constructor(props) { |
| 6 | super(props); |
| 7 | this.state = { |
pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame^] | 8 | isOpen: false // true |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 9 | } |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 10 | this.isTouchDevice = false |
pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame^] | 11 | this.hoverSensor = React.createRef(); |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 12 | } |
pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame^] | 13 | |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 14 | 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 | } |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 53 | |
| 54 | toggleVertical(prevState, force=null) { |
| 55 | this.setState(prevState => ({ |
| 56 | isOpen: (force === null) ? !prevState.isOpen : force |
| 57 | })); |
| 58 | } |
| 59 | |
| 60 | render() { |
| 61 | return ( |
| 62 | <> |
pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame^] | 63 | <div ref={this.hoverSensor} className={(Styles.container + " " + (this.state.isOpen ? Styles.containerOpen : null))} onMouseLeave={() => {this.onLeave()}}> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 64 | <div className={Styles.group}> |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 65 | <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 Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 71 | {/* <a href="https://clcks.dev"><img className={Styles.icon} src="/Icons/CL.svg"/></a> */} |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 72 | </div> |
| 73 | <div className={Styles.group}> |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 74 | <a href="/#"><img className={Styles.icon} src="/Icons/CMP.svg"/></a> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 75 | </div> |
| 76 | </div> |
| 77 | </> |
| 78 | ) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | export default NavBar; |