modules/home/components/nav/NavItem.js   A
last analyzed

Complexity

Total Complexity 3
Complexity/F 0

Size

Lines of Code 62
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 3
eloc 37
mnd 3
bc 3
fnc 0
dl 0
loc 62
ccs 7
cts 8
cp 0.875
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
1
import React from 'react'
2
import PropTypes from 'prop-types'
3
import styled from 'styled-components/macro'
4
import { Translate } from 'react-localize-redux'
5
6 3
const NavItem = ({
7
  page: { Icon, name, url },
8
  isSelected,
9
  isMobile,
10
  setSelectedPage
11
}) => {
12 27
  return isSelected ? (
13
    <SelectedContainer>
14
      {isMobile ? Icon : <Translate id={name} />}
15
    </SelectedContainer>
16
  ) : (
17
    <Container
18
      data-test-id="nav-link"
19
      href={url}
20
      onClick={() => {
21 1
        setSelectedPage(name)
22
      }}
23
    >
24
      {isMobile ? Icon : <Translate id={name} />}
25
    </Container>
26
  )
27
}
28
29 3
NavItem.propTypes = {
30
  page: PropTypes.shape({
31
    url: PropTypes.string,
32
    name: PropTypes.string,
33
    Icon: PropTypes.element
34
  }),
35
  isMobile: PropTypes.bool,
36
  isSelected: PropTypes.bool,
37
  setSelectedPage: PropTypes.func
38
}
39
40
export default NavItem
41
42
const Container = styled.a`
43 25
  line-height: ${props => props.theme.navContentMinHeight};
44 25
  font-size: ${props => props.theme.fontSizes.XL};
45
  transition: color 0.5s;
46
47
  &:hover {
48 25
    color: ${props => props.theme.colors.colorDarken};
49
    border: none;
50
  }
51
52
  @media screen and (max-width: 768px) {
53
    line-height: 2;
54
    border-bottom: none;
55
    font-size: 13px;
56
  }
57
`
58
const SelectedContainer = styled(Container)`
59
  color: ${props => props.theme.colors.colorDarken} !important;
60
  border: none;
61
`
62