# All files / components/Navigation/styles NavigationItem.js

50% Statements 3/6
0% Branches 0/6
0% Functions 0/3
50% Lines 3/6

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108

    5x

    5x

    5x

     import PropTypes from 'prop-types';
    import styled, { css } from 'styled-components';
    import get from 'extensions/themeGet';
    import NavigationItemList from './NavigationItemList';
    import NavigationItemListStack from './NavigationItemListStack';
    import NavigationBar from './NavigationBar';

    const NavigationItem = styled.div.withConfig({ displayName: 'NavigationItem' })`
      border: 0;
      padding: ${get('spacing.large')} 0 ${get('spacing.large')} 0;
      line-height: 1;
      opacity: 1;
      transition: all 0.2s ease;
      position: relative;
      cursor: pointer;
      color: inherit;
      font-size: 1em;
      font-weight: 200;

      &::before {
        content: '';
        background: ${get('colors.primary.dark')};
        width: 104%;
        height: ${props => (props.active ? '5px' : 0)};
        display: block;
        position: absolute;
        bottom: 0;
        top: auto;
        left: 50%;
        transform: translateX(-50%);
        transition: height 0.2s ease, opacity 0.2s ease;
      }

      &:hover::before {
        opacity: 0.5;
        height: 5px;
      }

      /* items that are children of a dark and sub nav have different colors */

      ${NavigationBar.Dark} &, ${NavigationBar.Sub} & {
        &::before {
          background: ${get('colors.primary.default')};
        }

        /* hover state must be repeated for specificity */

        &:hover::before {
          opacity: 0.5;
          height: 5px;
        }
      }

      /* sub nav items use a color for active state as well */

      ${NavigationBar.Sub} & {
        color: ${props =>
          props.active ? get('colors.primary.default')(props) : 'inherit'};
      }

      /* make items smaller when they're inside a small list */

      ${NavigationItemList.Small} & {
        padding: ${get('spacing.large')} 0 0 0;
        margin-bottom: 10px;
        font-size: 0.8em;

        &::before {
          height: ${props => (props.active ? '5px' : 0)};
          top: calc(100% + 10px);
          bottom: auto;
        }

        &:hover::before {
          opacity: 0.5;
          height: 5px;
        }
      }

      /*
        when items are in a stack, but not part of the first list in the stack,
        they get squished down a bit on the top.
      */

      ${NavigationItemListStack} > ${NavigationItemList}:not(:first-child) :not(:only-child) & {
        padding-top: ${get('spacing.medium')};
      }
    `;

    NavigationItem.propTypes = {
      /**
       * Adds a class name to the element.
       */
      className: PropTypes.string,

      /**
       * Adds an id to the element.
       */
      id: PropTypes.string,
    };

    NavigationItem.defaultProps = {
      className: null,
      id: null,
    };

    export default NavigationItem;