pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 1 | import { Component } from "react"; |
| 2 | import Styles from '../styles/navbar.module.css'; |
| 3 | |
| 4 | class NavBar extends Component { |
| 5 | constructor(props) { |
| 6 | super(props); |
| 7 | this.state = { |
| 8 | isOpen: false |
| 9 | } |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame^] | 10 | this.isTouchDevice = false |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 11 | } |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame^] | 12 | |
| 13 | componentDidMount() { |
| 14 | let hasTouchScreen = false; |
| 15 | if ("maxTouchPoints" in navigator) { |
| 16 | hasTouchScreen = navigator.maxTouchPoints > 0; |
| 17 | } else if ("msMaxTouchPoints" in navigator) { |
| 18 | hasTouchScreen = navigator.msMaxTouchPoints > 0; |
| 19 | } else { |
| 20 | const mQ = window.matchMedia && matchMedia("(pointer:coarse)"); |
| 21 | if (mQ && mQ.media === "(pointer:coarse)") { |
| 22 | hasTouchScreen = !!mQ.matches; |
| 23 | } else if ("orientation" in window) { |
| 24 | hasTouchScreen = true; |
| 25 | } else { |
| 26 | var UA = navigator.userAgent; |
| 27 | hasTouchScreen = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA); |
| 28 | } |
| 29 | } |
| 30 | if (hasTouchScreen) { |
| 31 | this.isTouchDevice = true |
| 32 | } else { |
| 33 | this.isTouchDevice = false |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | onEnter() { |
| 38 | if ( !this.isTouchDevice ) { |
| 39 | return this.toggleVertical(this, true) |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | onLeave() { |
| 44 | return this.toggleVertical(this, false) |
| 45 | } |
| 46 | |
| 47 | onClick() { |
| 48 | if ( this.isTouchDevice ) { |
| 49 | return this.toggleVertical(this) |
| 50 | } |
| 51 | } |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 52 | |
| 53 | toggleVertical(prevState, force=null) { |
| 54 | this.setState(prevState => ({ |
| 55 | isOpen: (force === null) ? !prevState.isOpen : force |
| 56 | })); |
| 57 | } |
| 58 | |
| 59 | render() { |
| 60 | return ( |
| 61 | <> |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame^] | 62 | <div className={Styles.container + " " + (this.state.isOpen ? Styles.containerOpen : null)} onMouseLeave={() => {this.onLeave()}}> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 63 | <div className={Styles.group}> |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame^] | 64 | <img className={Styles.headerIcon} src="/Icons/CMP.svg" onMouseEnter={() => {this.onEnter()}} onClick={() => {this.onClick()}}/> |
| 65 | <a href="/#"><img className={Styles.icon} src="/Icons/CMP.svg"/></a> |
| 66 | <a href="/gps#"><img className={Styles.icon} src="/Icons/GS.svg"/></a> |
| 67 | <a href="/rsm#"><img className={Styles.icon} src="/Icons/RM.svg"/></a> |
| 68 | <a href="/clicksforms#"><img className={Styles.icon} src="/Icons/CF.svg"/></a> |
| 69 | {/* <a href="/castaway#"><img className={Styles.icon} src="/Icons/CA.svg"/></a> */} |
Samuel Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 70 | {/* <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] | 71 | </div> |
| 72 | <div className={Styles.group}> |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame^] | 73 | <a href="/#"><img className={Styles.icon} src="/Icons/CMP.svg"/></a> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 74 | </div> |
| 75 | </div> |
| 76 | </> |
| 77 | ) |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | export default NavBar; |