Header Component

import React from 'react';
import './header.scss';
import utility from '../utility';

class Header extends React.Component{
  constructor(props){
    super(props);
    this.state = {};
  }

  async fetchAPI(){
    let url = '/api';
    try{
      let res = await fetch(url);
      return await res.json();
    }catch(error){
      console.log(error);
    }
  }

  mobielMenu = () => {
    var x = document.getElementById("myTopnav");
    if (x.className === "topnav") {
      x.className += " responsive";
    } else {
      x.className = "topnav";
    }
  }
    
  async componentDidMount(){
    this.setState(await this.fetchAPI());
    document.title = this.state.siteTitle;
    utility.clock();
    const options = {weekday: 'long', year: 'numeric', month: 'long', day: 'numeric'};
    document.getElementById('date').innerHTML = (new Date()).toLocaleDateString('en-US', options);
  }

  render(){
    return(
      <div className="header">
        <section id="header">
          <div className="top-menu-outer">
            <div className="top-menu region"><span id="date"></span><span id="kh-clock" className="time">time</span></div>
          </div>
          <div className="title-outer">
            <h1 className="site-title region">
              <span><a href="/" >{this.state.siteTitle}</a></span>
              <img className="news" alt="" src={'/images/newspaper.png'} />
              <span><img alt="" className="tvlive" src={'/images/livetv.png'}/></span>
            </h1>
          </div>
        </section>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"></link>
        <div className="main-menu-outer">
          <nav className='main-menu region'>
            <div className="topnav" id="myTopnav">
              <a id="house" href="/" className="active"><img alt="" src="/images/house.png" /></a>
              <a href="#news">News</a>
              <a href="#contact">Contact</a>
              <a href="#about">About</a>
              <a href="/admin">Login</a>
              <a onClick={(e) => {e.preventDefault()}} className="icon" onClick={()=>this.mobielMenu()}>
                <i className="fa fa-bars"></i>
              </a>
            </div>
          </nav>
        </div>
      </div>
    );
  }
}

export default Header;
*{
  padding:0;
  margin:0;
  box-sizing: border-box;
}
body{
  font:14px Vidaloka;
}
a{
  color:#e20000;
  text-decoration: none;
}
a:hover{
  opacity:.7;
}
.region{
  max-width: 1100px;
  margin:0 auto;
}
#header{
  background:#e20000;
  color:white;
 .top-menu-outer{
    padding:5px 0;
    border-bottom: 5px solid black;
  }
  .top-menu{
    display: grid;
    grid-template-columns: auto auto;
    text-align:left;
    align-items: center;
    .time{
      text-align: right;
    }
  }
  .title-outer{
    background: #3d3d3d;
    padding: 10px 0;
  }
  .site-title{
    display: grid;
    grid-template-columns:auto auto auto;
    text-align:left;
    align-items: center;
    font:55px/1.75 PirataOne;
    text-shadow:0px 0px 0 rgb(231,231,231), 
    1px 1px 0 rgb(216,216,216), 
    2px 2px 0 rgb(202,202,202), 
    3px 3px 0 rgb(187,187,187), 
    4px 4px 0 rgb(173,173,173), 
    5px 5px 0 rgb(158,158,158), 
    6px 6px 0 rgb(144,144,144), 
    7px 7px 6px rgba(0,0,0,0.6), 
    7px 7px 1px rgba(0,0,0,0.5), 
    0px 0px 6px rgba(0,0,0,.2);

    a{
      color:white;
    }
    img{
      width: 150px;
    }
    .tvlive{
      float: right;
    }
    .news{
      margin: 0 auto;
      width:120px;
    }
  }
  
}

.main-menu-outer{
  background: black;
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 999;
}
.topnav {
  background-color:transparent;
  overflow: hidden;
  a {
    float: left;
    display: block;
    color: #f2f2f2;
    text-align: center;
    padding: 12px 16px;
    text-decoration: none;
    font: 16px/1.5 Oswald, Bayon;
  }
  #house{
    padding-top:0;
    padding-bottom:10px;
    img{
      width: 40px;
      position: relative;
      top:5px;
    }
  }
  a:hover {
    background-color:rgb(34, 34, 34);
  }
  a.active {
    background-color: rgb(46, 46, 46);
    color: white;
  }
  .icon {
    display: none;
  }
}

@media only screen and (max-width:600px){
  #header{
    .top-menu{
      padding: 0 10px;
      grid-template-columns: 100%;
      span, .time{
        text-align:center;
      }
    }
    .site-title{
      grid-template-columns:100%;
      text-align:center;
      .tvlive{
        float: none;
      }
      .news{
        margin: 10px auto;
      }
    }
  }
}

@media screen and (max-width: 600px) {
  .topnav{
    a:not(:first-child) {
      display: none;
    }
    a.icon {
      float: right;
      display: block;
    }
  }
}

@media screen and (max-width: 600px) {
  .topnav.responsive {
    position: relative;
    a.icon {
      position: absolute;
      right: 0;
      top: 0;
    }
    a {
      float: none;
      display: block;
      text-align: left;
    }
  }
}
class Utility{
    
  clock(){
    var period = 'AM';
    var today = new Date();
    var h = today.getHours();
    if(h>12){
      h = h-12;
      period = 'PM';
    }
    var m = today.getMinutes();
    var s = today.getSeconds();
    
    m = utility.checkTime(m);
    s = utility.checkTime(s);
  
    document.getElementById('kh-clock').innerHTML = h + " : " + m + " : " + s+' '+period;
    setTimeout(utility.clock, 500);
  }
  
  checkTime(i) {
    if (i < 10){i = "0" + i};  
    return i;
  }

}//end class

const utility = new Utility();

export default utility;

GitHub: "https://github.com/Sokhavuth/emultimedia
Heroku: https://khmerweb-emultimedia.herokuapp.com/

Comments

Popular posts from this blog