# All files / components/Table Table.js

81.82% Statements 9/11
0% Branches 0/4
0% Functions 0/1
81.82% Lines 9/11

    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
    109
    110
    111
    112

    5x
    5x
    5x
    5x
    5x
    5x
    5x
    5x

    5x

     import React from 'react';
    import PropTypes from 'prop-types';
    import { withProps } from 'recompose';

    import Loader from '../Loader';

    import TableStyles from './styles/TableStyles';
    import TableOverlay from './styles/TableOverlay';

    import Cell from './styles/TableCell';
    import Header from './TableHeader';
    import Row from './styles/TableRow';
    import Controls from './TableControls';
    import Simple from './SimpleTable';
    import RowDetails from './TableRowDetails';
    import TableWrap from './TableWrap';
    import TableBody from './styles/TableBody';

    class Table extends React.Component {
      static propTypes = {
        /**
         * Render the rows of the Table within its children.
         */
        children: PropTypes.node.isRequired,
        /**
         * Render headers for the columns with this property.
         */
        headers: PropTypes.node,
        /**
         * Renders a loading spinner over the table body.
         */
        loading: PropTypes.bool,
        /**
         * Adds a class name to the table element.
         */
        className: PropTypes.string,
        /**
         * Adds an id to the table element.
         */
        id: PropTypes.string,
        /**
         * Whether to wrap the passed children in a <Table.Body>. Defaults true.
         */
        wrapBody: PropTypes.bool,
        /**
         * A component to render the table element
         */
        Styles: PropTypes.func,
        /**
         * A component to render any content that overlays the table itself
         */
        Overlay: PropTypes.func,
        /**
         * A component that wraps the whole table as a scroll context
         */
        Wrap: PropTypes.func,
      };

      static defaultProps = {
        loading: false,
        className: null,
        id: null,
        headers: null,
        wrapBody: true,
        Styles: TableStyles,
        Overlay: TableOverlay,
        Wrap: TableWrap,
      };

      render() {
        const {
          children,
          headers,
          loading,
          className,
          id,
          wrapBody,
          Wrap,
          Styles,
          Overlay,
        } = this.props;
        return (
          <Wrap>
            <Styles cellPadding={0} cellSpacing={0} className={className} id={id}>
              <thead>{headers}</thead>
              {wrapBody ? <TableBody>{children}</TableBody> : children}
            </Styles>
            {loading && (
              <Overlay>
                <Loader />
              </Overlay>
            )}
          </Wrap>
        );
      }
    }

    Table.Row = Row;
    Table.Header = Header;
    Table.Cell = Cell;
    Table.Controls = Controls;
    Table.Simple = Simple;
    Table.RowDetails = RowDetails;
    Table.Wrap = TableWrap;
    Table.Body = TableBody;

    Table.Small = withProps({
      Styles: TableStyles.Small,
    })(Table);

    export default Table;