# All files / components/BandwidthProvider BandwidthProvider.js

0% Statements 0/49
0% Branches 0/10
0% Functions 0/4
0% Lines 0/16

    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

     import React from 'react';
    import PropTypes from 'prop-types';
    import { withProps } from 'recompose';
    import DefaultStyleRoot from './styles/StyleRoot';
    import withDragDropContext from './withDragDropContext';
    import DefaultDragLayer from '../DragLayer';
    import ReactDOM from 'react-dom';
    import irisTheme from 'theme/irisTheme';
    import './styles/global'; // injects a global stylesheet

    /**
     * Including this provider at the root of your app will define some global styling,
     * and set up needed contexts for interactions like drag and drop. It also allows
     * you to control the theme programmatically or apply a different theme at a
     * particular level.
     */
    class BandwidthProvider extends React.PureComponent {
      static propTypes = {
        /**
         *  A custom theme; pass one of the themes from `themes/` or pass in your own JSON!
         */
        customTheme: PropTypes.object,
        /**
         * The DOM element to attach the drag layer. By default, attaches it to this component
         */
        dragLayerPortal: PropTypes.object,
        /**
         * Custom StyleRoot component
         */
        StyleRoot: PropTypes.oneOfType([PropTypes.func, PropTypes.symbol]),
        /**
         * Custom drag layer component
         */
        DragLayer: PropTypes.func,
        children: PropTypes.node.isRequired,
      };

      static defaultProps = {
        customTheme: irisTheme,
        dragLayerPortal: null,
        StyleRoot: DefaultStyleRoot,
        DragLayer: DefaultDragLayer,
      };

      render() {
        const {
          StyleRoot,
          DragLayer,
          dragLayerPortal,
          customTheme,
          children,
        } = this.props;
        const styleRootProps = {};
        if (customTheme) styleRootProps.customTheme = customTheme;
        return (
          <StyleRoot className="styleroot" {...styleRootProps}>
            {children}
            {dragLayerPortal ? (
              ReactDOM.createPortal(<DragLayer />, dragLayerPortal)
            ) : (
              <DragLayer />
            )}
          </StyleRoot>
        );
      }
    }

    export default withDragDropContext(BandwidthProvider);