You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

170 line
8.1 KiB

  1. import React, { useState } from "react";
  2. import { Link as LinkScroll} from 'react-scroll'
  3. import Link from 'next/link';
  4. const Header = ({sticky,isHome}) => {
  5. isHome = (isHome == null)?true:isHome;
  6. const [menu, setMenu] = React.useState(true)
  7. const toggleNavbar = () => {
  8. setMenu(!menu)
  9. }
  10. React.useEffect(() => {
  11. let elementId = document.getElementById("header");
  12. if(!(sticky||false)){
  13. document.addEventListener("scroll", () => {
  14. if (window.scrollY > 170) {
  15. elementId.classList.add("is-sticky");
  16. } else {
  17. elementId.classList.remove("is-sticky");
  18. }
  19. });
  20. }
  21. else{
  22. elementId.classList.add("is-sticky");
  23. }
  24. window.scrollTo(0, 0);
  25. })
  26. const classOne = menu ? 'collapse navbar-collapse' : 'collapse navbar-collapse show';
  27. const classTwo = menu ? 'navbar-toggler navbar-toggler-right collapsed' : 'navbar-toggler navbar-toggler-right';
  28. return (
  29. <header id="header" className="headroom navbar-color-white navbar-style-four">
  30. <div className="startp-nav">
  31. <div className="container">
  32. <nav className="navbar navbar-expand-md navbar-light">
  33. {
  34. (isHome)
  35. ?(
  36. <LinkScroll href="/#" to="home" spy={true} smooth={true}>
  37. <img src="/images/TBG-Home/Blue.png" width="250px" alt="logo" />
  38. </LinkScroll>
  39. )
  40. :(
  41. <Link href="/">
  42. <a><img src="/images/TBG-Home/Blue.png" width="250px" alt="logo" /></a>
  43. </Link>
  44. )
  45. }
  46. <button
  47. onClick={toggleNavbar}
  48. className={classTwo}
  49. type="button"
  50. data-toggle="collapse"
  51. data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
  52. aria-expanded="false"
  53. aria-label="Toggle navigation"
  54. >
  55. <span className="icon-bar top-bar"></span>
  56. <span className="icon-bar middle-bar"></span>
  57. <span className="icon-bar bottom-bar"></span>
  58. </button>
  59. <div className={classOne} id="navbarSupportedContent">
  60. <ul className="navbar-nav ms-auto">
  61. {
  62. (isHome)
  63. ?(
  64. <>
  65. <li className="nav-item">
  66. <LinkScroll href="/#" to="home" spy={true} smooth={true}>
  67. <a onClick={e => e.preventDefault()} className="nav-link">
  68. Home
  69. </a>
  70. </LinkScroll>
  71. </li>
  72. <li className="nav-item">
  73. <LinkScroll offset={-100} href="/#" to="business_partner" spy={true} smooth={true}>
  74. <a onClick={e => e.preventDefault()} className="nav-link">
  75. Business Partner
  76. </a>
  77. </LinkScroll>
  78. </li>
  79. <li className="nav-item">
  80. <LinkScroll offset={-100} href="/#" to="industri" spy={true} smooth={true}>
  81. <a onClick={e => e.preventDefault()} className="nav-link">
  82. Industri We Serve
  83. </a>
  84. </LinkScroll>
  85. </li>
  86. <li className="nav-item">
  87. <LinkScroll offset={-100} href="/#" to="gallery" spy={true} smooth={true}>
  88. <a onClick={e => e.preventDefault()} className="nav-link">
  89. Gallery
  90. </a>
  91. </LinkScroll>
  92. </li>
  93. <li className="nav-item">
  94. <LinkScroll offset={-100} href="/#" to="subscribe" spy={true} smooth={true}>
  95. <a onClick={e => e.preventDefault()} className="nav-link">
  96. Subscribe
  97. </a>
  98. </LinkScroll>
  99. </li>
  100. </>
  101. )
  102. :(
  103. <>
  104. <li className="nav-item">
  105. <Link href={{
  106. pathname: '/',
  107. query: { s: 'home' },
  108. }}>
  109. Homes
  110. </Link>
  111. </li>
  112. <li className="nav-item">
  113. <Link href={{
  114. pathname: '/',
  115. query: { s: 'business_partner' },
  116. }}>
  117. Business Partner
  118. </Link>
  119. </li>
  120. <li className="nav-item">
  121. <Link href={{
  122. pathname: '/',
  123. query: { s: 'industri' },
  124. }}>
  125. Industri We Serve
  126. </Link>
  127. </li>
  128. <li className="nav-item">
  129. <Link href={{
  130. pathname: '/',
  131. query: { s: 'gallery' },
  132. }}>
  133. Gallery
  134. </Link>
  135. </li>
  136. <li className="nav-item">
  137. <Link href={{
  138. pathname: '/',
  139. query: { s: 'subscribe' },
  140. }}>
  141. Subscribe
  142. </Link>
  143. </li>
  144. </>
  145. )
  146. }
  147. </ul>
  148. </div>
  149. </nav>
  150. </div>
  151. </div>
  152. </header>
  153. );
  154. }
  155. export default Header;