File size: 1,284 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import React, { Component, createContext } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { createClassNames } from '../core/utils';

const cx = createClassNames('Panel');

export const { Consumer: PanelConsumer, Provider: PanelProvider } =
  createContext(function setCanRefine() {});

class Panel extends Component {
  static propTypes = {
    children: PropTypes.node.isRequired,
    className: PropTypes.string,
    header: PropTypes.node,
    footer: PropTypes.node,
  };

  static defaultProps = {
    className: '',
    header: null,
    footer: null,
  };

  state = {
    canRefine: true,
  };

  setCanRefine = (nextCanRefine) => {
    this.setState({ canRefine: nextCanRefine });
  };

  render() {
    const { children, className, header, footer } = this.props;
    const { canRefine } = this.state;

    return (
      <div
        className={classNames(cx('', !canRefine && '-noRefinement'), className)}
      >
        {header && <div className={cx('header')}>{header}</div>}

        <div className={cx('body')}>
          <PanelProvider value={this.setCanRefine}>{children}</PanelProvider>
        </div>

        {footer && <div className={cx('footer')}>{footer}</div>}
      </div>
    );
  }
}

export default Panel;