1 import React from 'react';
2 import FontAwesome from 'react-fontawesome';
3 import ReactDOM from 'react-dom';
5 class SlidePanel extends React.Component {
8 direction: React.PropTypes.string.isRequired,
9 className: React.PropTypes.string,
10 title: React.PropTypes.string,
11 isOpen: React.PropTypes.bool
14 static defaultProps = {
21 isOpen: this.props.isOpen,
22 direction: this.props.direction,
28 this.setSliderPosition();
31 componentDidUpdate() {
32 this.setSliderPosition();
37 let {children, className} = this.props;
38 let {isOpen} = this.state;
41 <div className={ `slide-panel ${className}`}>
42 {this.renderHeader(isOpen)}
43 <div className={'slide-panel-content ' + (isOpen ? 'opened' : 'closed')}>{children}</div>
48 renderHeader(isOpen) {
49 let {direction: initialDirection, title} = this.props;
50 let {direction: currentDirection} = this.state;
52 let iconName = currentDirection === 'right' ? 'angle-double-right collapse-double-icon' : 'angle-double-left collapse-double-icon';
54 let awestyle = {padding: '5px'};
56 if (!isOpen && initialDirection === 'right') {
57 awestyle.marginLeft = '-1px';
60 <div className='slide-panel-header'>
61 { initialDirection === 'left' && <span className='slide-panel-header-title'>{title}</span>}
65 onClick={this.handleClick}
66 className='pull-right'
69 { initialDirection === 'right' && <span className='slide-panel-header-title'>{title}</span>}
76 isOpen: !this.state.isOpen,
77 direction: this.state.direction === 'left' ? 'right' : 'left'
81 setSliderPosition = () => {
83 let el = ReactDOM.findDOMNode(this);
86 let {direction: initialDirection} = this.props;
87 let arrowIconSize = Math.floor(ReactDOM.findDOMNode(this.refs.arrowIcon).getBoundingClientRect().width) * 2;
88 if (!this.state.isOpen) {
89 if (this.props.direction === 'left') {
90 style.left = arrowIconSize - el.getBoundingClientRect().width + 'px';
92 if (initialDirection === 'right') {
93 style.right = arrowIconSize - el.getBoundingClientRect().width + 'px';
97 if (initialDirection === 'left') {
101 if (this.props.direction === 'right') {
109 export default SlidePanel;