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'; |
Skyler Turner | 16c08d3 | 2021-11-04 20:06:50 +0000 | [diff] [blame] | 3 | import ThemeChangeButton from './ThemeChangeButton'; |
pineafan | df39fd4 | 2021-09-04 16:05:27 +0100 | [diff] [blame] | 4 | |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 5 | |
| 6 | class NavBar extends Component { |
| 7 | constructor(props) { |
| 8 | super(props); |
| 9 | this.state = { |
pineafan | df39fd4 | 2021-09-04 16:05:27 +0100 | [diff] [blame] | 10 | isOpen: 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 | this.isTouchDevice = false |
pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame] | 13 | this.hoverSensor = React.createRef(); |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 14 | } |
pineafan | 54a1e55 | 2021-09-03 17:51:18 +0100 | [diff] [blame] | 15 | |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 16 | componentDidMount() { |
| 17 | let hasTouchScreen = false; |
| 18 | if ("maxTouchPoints" in navigator) { |
| 19 | hasTouchScreen = navigator.maxTouchPoints > 0; |
| 20 | } else if ("msMaxTouchPoints" in navigator) { |
| 21 | hasTouchScreen = navigator.msMaxTouchPoints > 0; |
| 22 | } else { |
| 23 | const mQ = window.matchMedia && matchMedia("(pointer:coarse)"); |
| 24 | if (mQ && mQ.media === "(pointer:coarse)") { |
| 25 | hasTouchScreen = !!mQ.matches; |
| 26 | } else if ("orientation" in window) { |
| 27 | hasTouchScreen = true; |
| 28 | } else { |
| 29 | var UA = navigator.userAgent; |
| 30 | hasTouchScreen = /\b(BlackBerry|webOS|iPhone|IEMobile)\b/i.test(UA) || /\b(Android|Windows Phone|iPad|iPod)\b/i.test(UA); |
| 31 | } |
| 32 | } |
| 33 | if (hasTouchScreen) { |
| 34 | this.isTouchDevice = true |
| 35 | } else { |
| 36 | this.isTouchDevice = false |
| 37 | } |
| 38 | } |
| 39 | |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 40 | onClick() { |
| 41 | if ( this.isTouchDevice ) { |
| 42 | return this.toggleVertical(this) |
| 43 | } |
| 44 | } |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 45 | |
| 46 | toggleVertical(prevState, force=null) { |
| 47 | this.setState(prevState => ({ |
| 48 | isOpen: (force === null) ? !prevState.isOpen : force |
| 49 | })); |
| 50 | } |
| 51 | |
| 52 | render() { |
| 53 | return ( |
| 54 | <> |
pineafan | d494b85 | 2021-09-03 19:49:49 +0100 | [diff] [blame] | 55 | <div ref={this.hoverSensor} className={this.isTouchDevice ? (Styles.container + " " + (this.state.isOpen ? Styles.containerOpen : null)) : Styles.containerDesktop + " " + Styles.container}> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 56 | <div className={Styles.group}> |
pineafan | a841c76 | 2021-11-14 21:21:04 +0000 | [diff] [blame^] | 57 | <img alt="CMP" className={Styles.headerIcon} src="https://assets.clicksminuteper.net/company/logo/normal.svg" onClick={() => {this.onClick()}}/> |
| 58 | <a href="/#"><img alt="Home" className={Styles.icon} src="https://assets.clicksminuteper.net/web/icons/home.svg"/></a> |
| 59 | <a href="/gps#"><img alt="GPS" className={Styles.icon} src="https://assets.clicksminuteper.net/bots/gps/normal.svg"/></a> |
| 60 | <a href="/rsm#"><img alt="RSM" className={Styles.icon} src="https://assets.clicksminuteper.net/bots/rsm/normal.svg"/></a> |
| 61 | <a href="/clicksforms#"><img alt="ClicksForms" className={Styles.icon} src="https://assets.clicksminuteper.net/bots/clicksforms/normal.svg"/></a> |
Samuel Shuert | 604e31d | 2021-09-02 16:06:20 -0500 | [diff] [blame] | 62 | {/* <a href="/castaway#"><img className={Styles.icon} src="/Icons/CA.svg"/></a> */} |
Samuel Shuert | 52f3777 | 2021-09-02 12:29:40 -0500 | [diff] [blame] | 63 | {/* <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] | 64 | </div> |
| 65 | <div className={Styles.group}> |
Skyler Turner | 16c08d3 | 2021-11-04 20:06:50 +0000 | [diff] [blame] | 66 | <ThemeChangeButton/> |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 67 | </div> |
| 68 | </div> |
| 69 | </> |
| 70 | ) |
| 71 | } |
| 72 | } |
| 73 | |
pineafan | a5ce910 | 2021-09-02 17:21:31 +0100 | [diff] [blame] | 74 | export default NavBar; |