Passed
Push — master ( f602d8...7b3414 )
by Huu-Phat
02:55 queued 11s
created

modules/home/components/nav/NavLink.js   A

Complexity

Total Complexity 7
Complexity/F 0

Size

Lines of Code 68
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
eloc 49
mnd 7
bc 7
fnc 0
dl 0
loc 68
ccs 15
cts 15
cp 1
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import React from 'react'
2
import styled from 'styled-components/macro'
3
import PropTypes from 'prop-types'
4
import { EN } from '~/modules/home/consts/langs'
5
import { Translate, withLocalize } from 'react-localize-redux'
6
import useWindowDimensions from '~/modules/core/utils/useWindowDimensions'
7
8 4
const NavLink = ({
9
  lang,
10
  selectedLang,
11
  setSelectedLang,
12
  setActiveLanguage
13
}) => {
14 15
  const { width } = useWindowDimensions()
15 15
  return (
16
    <Container
17
      isSelected={selectedLang === lang}
18
      onClick={() => {
19 1
        setSelectedLang(lang)
20 1
        setActiveLanguage(lang)
21 1
        window.localStorage.setItem('lang', lang)
22
      }}
23
    >
24
      {width < 600 ? (
25
        lang === EN ? (
26
          'en'
27
        ) : (
28
          'vn'
29
        )
30
      ) : lang === EN ? (
31
        <Translate id="english" />
32
      ) : (
33
        <Translate id="vietnamese" />
34
      )}
35
    </Container>
36
  )
37
}
38
39 4
NavLink.propTypes = {
40
  lang: PropTypes.string,
41
  selectedLang: PropTypes.string,
42
  setSelectedLang: PropTypes.func,
43
  setActiveLanguage: PropTypes.func
44
}
45
46
export default withLocalize(NavLink)
47
48
const Container = styled.a`
49
  color: ${props =>
50 15
    props.isSelected
51
      ? props.theme.colors.colorDark
52
      : props.theme.colors.colorLight} !important;
53 15
  cursor: ${props => (props.isSelected ? 'default' : 'pointer')};
54
  text-decoration: ${props =>
55 15
    props.isSelected ? 'underline' : 'none'} !important;
56 15
  border: ${props => (props.isSelected ? 'none' : 'initial')};
57 15
  border-color: ${props => props.theme.colors.colorLight};
58 15
  font-family: ${props => props.theme.font};
59
  font-style: italic;
60 15
  line-height: ${props => props.theme.navHeaderHeight};
61
  transition: color 0.5s;
62
63
  &:hover {
64 15
    color: ${props => props.theme.colors.colorDark};
65
    border: none;
66
  }
67
`
68