summaryrefslogtreecommitdiff
path: root/opendc-web/opendc-web-ui/src/components/app/sidebars/Sidebar.js
blob: f7368f54f9403927b9fbbbd574e924969bb2e507 (plain)
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
import PropTypes from 'prop-types'
import classNames from 'classnames'
import React from 'react'
import './Sidebar.sass'

class Sidebar extends React.Component {
    static propTypes = {
        isRight: PropTypes.bool.isRequired,
        collapsible: PropTypes.bool,
    }

    static defaultProps = {
        collapsible: true,
    }

    state = {
        collapsed: false,
    }

    render() {
        const collapseButton = (
            <div
                className={classNames('sidebar-collapse-button', {
                    'sidebar-collapse-button-right': this.props.isRight,
                })}
                onClick={() => this.setState({ collapsed: !this.state.collapsed })}
            >
                {(this.state.collapsed && this.props.isRight) || (!this.state.collapsed && !this.props.isRight) ? (
                    <span className="fa fa-angle-left" title={this.props.isRight ? 'Expand' : 'Collapse'} />
                ) : (
                    <span className="fa fa-angle-right" title={this.props.isRight ? 'Collapse' : 'Expand'} />
                )}
            </div>
        )

        if (this.state.collapsed) {
            return collapseButton
        }
        return (
            <div
                className={classNames('sidebar p-3 h-100', {
                    'sidebar-right': this.props.isRight,
                })}
                onWheel={(e) => e.stopPropagation()}
            >
                {this.props.children}
                {this.props.collapsible && collapseButton}
            </div>
        )
    }
}

export default Sidebar