# All files / components/Navigation NavigationItems.js

50% Statements 7/14
100% Branches 0/0
0% Functions 0/7
50% Lines 7/14

    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

    5x

    5x

    5x

    5x

    5x

    5x

    5x

     import React from 'react';
    import PropTypes from 'prop-types';
    import styled from 'styled-components';
    import NavigationItem from './NavigationItem';
    import Anchor from '../Anchor';

    export const Container = styled.div.withConfig({ displayName: 'NavigationItemsContainer' })`
      display: flex;
      flex-direction: row;
      justify-content: flex-end;

      background: ${({ theme }) => theme.tab.bg};
      color: ${({ theme }) => theme.tab.fg};
      font-size: ${({ theme }) => theme.tab.fontSize};
      margin-bottom: ${({ theme }) => theme.tab.marginBottom};

      & > * {
        margin: ${({ theme }) => theme.tab.margin};
      }

      & > *:last-of-type {
        margin: 0;
        padding-right: 0;
      }

      & > a {
        color: inherit;
        text-decoration: none;
      }
    `;

    export const linksPropType = PropTypes.arrayOf(PropTypes.shape({
      to: PropTypes.string,
      onClick: PropTypes.func,
      content: PropTypes.node.isRequired,
      exact: PropTypes.bool,
      newTab: PropTypes.bool,
    }));

    const NavigationItems = ({ links, className, id }) => (
      <Container id={id} className={className}>
        {links.map((link) => (
          <Anchor
            key={`${link.content}_${link.to}`}
            to={link.to}
            onClick={link.onClick}
            exact={link.exact}
            newTab={link.newTab}
          >
            <NavigationItem>{link.content}</NavigationItem>
          </Anchor>
        ))}
      </Container>
    );

    NavigationItems.propTypes = {
      /**
       * Links to render in the list.
       */
      links: linksPropType,
      /**
       * Adds a class name to the link container element.
       */
      className: PropTypes.string,
      /**
       * Adds an id to the link container element.
       */
      id: PropTypes.string,
    };
    NavigationItems.defaultProps = {
      links: [],
      className: null,
      id: null,
    };

    NavigationItems.usage = `
    Helper to generate a list of navigation items.

    \`\`\`
    <NavigationItems
      links={[
        { to: '/cat', exact: true, content: 'Cat' },
        { to: '/anotherCat', content: 'Another Cat' },
      ]}
    />
    \`\`\`
    `

    NavigationItems.Item = NavigationItem;
    export default NavigationItems;