# All files / components/SidebarList SidebarList.js

0% Statements 0/59
0% Branches 0/10
0% Functions 0/8
0% Lines 0/20

    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

     import React from 'react';
    import PropTypes from 'prop-types';
    import styled from 'styled-components';
    import SidebarListShowMore from './styles/SidebarListShowMore';
    import SidebarListItem from './SidebarListItem';
    import SidebarListContainer from './styles/SidebarListContainer';

    /**
     * Lays out items vertically in a sidebar. Does not handle scrolling.
     * Use [SidebarList.Item](/#!/SidebarListItem) as the child elements.
     *
     * You can show selected state by either passing an `active` prop to the correct item
     * or linking your list to your router so that each item is a unique route. If you go that direction,
     * you can wrap the items with `<Route/>` components from React Router, and have them utilize RR's
     * built-in route matching logic to determine rendering appearance.
     */
    class SidebarList extends React.PureComponent {
      static propTypes = {
        /**
         * List items.
         */
        children: PropTypes.node.isRequired,
        /**
         * Indicates whether the list should show that it has a next page.
         */
        hasNextPage: PropTypes.bool,
        /**
         * Indicates whether the list should show that it has a previous page.
         */
        hasPreviousPage: PropTypes.bool,
        /**
         * Called when the button to load the next page is clicked.
         */
        onNextPageClicked: PropTypes.func,
        /**
         * Called when the button to load the previous page is clicked.
         */
        onPreviousPageClicked: PropTypes.func,
        /**
         * Adds a class name to the containing list element.
         */
        className: PropTypes.string,
        /**
         * Adds an id to the containing list element.
         */
        id: PropTypes.string,
        /**
         * A compoennt to render the container around the list
         */
        Container: PropTypes.func,
        /**
         * A container that renders a clickable 'show more' area
         */
        ShowMore: PropTypes.func,
      };

      static defaultProps = {
        hasNextPage: false,
        hasPreviousPage: false,
        onNextPageClicked: () => null,
        onPreviousPageClicked: () => null,
        className: null,
        id: null,
        Container: SidebarListContainer,
        ShowMore: SidebarListShowMore,
      };

      renderPrevious = () => {
        const { hasPreviousPage, onPreviousPageClicked, ShowMore } = this.props;
        if (hasPreviousPage) {
          return <ShowMore onClick={onPreviousPageClicked}>Show Previous</ShowMore>;
        }

        return null;
      };

      renderNext = () => {
        const { hasNextPage, onNextPageClicked, ShowMore } = this.props;
        if (hasNextPage) {
          return <ShowMore onClick={onNextPageClicked}>Show Next</ShowMore>;
        }

        return null;
      };

      render() {
        const { Container, children, ...rest } = this.props;
        return (
          <Container {...rest}>
            {this.renderPrevious()}
            {children}
            {this.renderNext()}
          </Container>
        );
      }
    }

    SidebarList.Item = SidebarListItem;
    export default SidebarList;