Advertisement
dfghgfhplkjbv

src/components/Header/Header.js

Mar 5th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import PropTypes from 'prop-types'
  3. import classNames from 'classnames'
  4. import { Link } from 'gatsby'
  5. import Search from 'src/components/Search'
  6. import styles from './Header.module.scss'
  7. import logo from 'src/img/theheroes_logo.svg'
  8. import SideBar from 'src/components/Sidebar'
  9. import { formatMessage } from 'src/translations'
  10. import { isOnline, removeListeners, getLink } from 'src/utils'
  11. import withLocale from 'src/components/withLocale'
  12.  
  13. const isPartiallyActive = ({ isPartiallyCurrent }) => {
  14. return isPartiallyCurrent ? { className: classNames(styles.logo, styles.active) } : null
  15. }
  16.  
  17. const PartialNavLink = (props) => <Link getProps={isPartiallyActive} {...props} />
  18.  
  19. class Header extends Component {
  20. state = { isOnline: true, lang: 'ru', url: '' }
  21.  
  22. componentDidMount() {
  23. isOnline(this)
  24. }
  25.  
  26. componentWillUnmount() {
  27. removeListeners(this)
  28. }
  29.  
  30. render() {
  31. const { className, style, full, locale, changeLocale } = this.props
  32.  
  33. const news = formatMessage(locale, 'news')
  34. const interviews = formatMessage(locale, 'interview')
  35. const videos = formatMessage(locale, 'video')
  36. const podcasts = formatMessage(locale, 'podcasts')
  37.  
  38. const onlineLinks = (
  39. <>
  40. <li>
  41. <PartialNavLink to={getLink(locale, 'videos')}>{videos}</PartialNavLink>
  42. </li>
  43. <li>
  44. <PartialNavLink to={getLink(locale, 'podcasts')}>{podcasts}</PartialNavLink>
  45. </li>
  46. </>
  47. )
  48.  
  49. const offineLinks = (
  50. <>
  51. <li className={styles.offlineMode}>
  52. <PartialNavLink to="/videos">{videos}</PartialNavLink>
  53. </li>
  54. <li className={styles.offlineMode}>
  55. <PartialNavLink to="/podcasts">{podcasts}</PartialNavLink>
  56. </li>
  57. </>
  58. )
  59.  
  60. return (
  61. <div className={classNames(styles.wrap, { [styles.full]: full })}>
  62. <div className={styles.sidebar}>
  63. <SideBar locale={locale || this.props.locale} />
  64. </div>
  65. <header id="header" className={classNames(className, styles.root)}>
  66. <Link to={getLink(locale)} className={styles.logo}>
  67. <img src={logo} alt="logo" />
  68. <figure>BETA</figure>
  69. </Link>
  70. <nav className={styles.nav}>
  71. <ul>
  72. <li>
  73. <PartialNavLink to={getLink(locale, 'news')}>{news}</PartialNavLink>
  74. </li>
  75. <li>
  76. <PartialNavLink to={getLink(locale, 'interviews')}>{interviews}</PartialNavLink>
  77. </li>
  78. {this.state.isOnline && locale !== 'en' ? onlineLinks : offineLinks}
  79. </ul>
  80. </nav>
  81.  
  82. <nav className={styles.controls}>
  83. <ul className={styles.languages}>
  84. <li>
  85. <button className={styles.changeLanguage} onClick={changeLocale}>
  86. <span className={styles.lang}>{this.props.locale === 'en' ? 'ru' : 'en'}</span>
  87. </button>
  88. </li>
  89. </ul>
  90. <div className={styles.search}>
  91. <Search locale={locale || this.props.locale} />
  92. </div>
  93. </nav>
  94. </header>
  95. </div>
  96. )
  97. }
  98. }
  99.  
  100. Header.propTypes = {
  101. className: PropTypes.string,
  102. style: PropTypes.object,
  103. full: PropTypes.bool,
  104. locale: PropTypes.string.isRequired,
  105. }
  106.  
  107. export default withLocale(Header)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement