2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 import React from 'react';
27 import FontAwesome from 'react-fontawesome';
28 import ReactDOM from 'react-dom';
30 class SlidePanel extends React.Component {
33 direction: React.PropTypes.string.isRequired,
34 className: React.PropTypes.string,
35 title: React.PropTypes.string,
36 isOpen: React.PropTypes.bool
39 static defaultProps = {
46 isOpen: this.props.isOpen,
47 direction: this.props.direction,
53 this.setSliderPosition();
56 componentDidUpdate() {
57 this.setSliderPosition();
62 let {children, className} = this.props;
63 let {isOpen} = this.state;
66 <div className={ `slide-panel ${className}`}>
67 {this.renderHeader(isOpen)}
69 className={'slide-panel-content ' + (isOpen ? 'opened' : 'closed')}>{children}</div>
74 renderHeader(isOpen) {
75 let {direction: initialDirection, title} = this.props;
76 let {direction: currentDirection} = this.state;
78 let iconName = currentDirection ===
80 ? 'angle-double-right collapse-double-icon'
81 : 'angle-double-left collapse-double-icon';
83 let awestyle = {padding: '5px'};
85 if (!isOpen && initialDirection === 'right') {
86 awestyle.marginLeft = '-1px';
89 <div className='slide-panel-header'>
90 { initialDirection === 'left' &&
91 <span className='slide-panel-header-title'>{title}</span>}
95 onClick={this.handleClick}
96 className='pull-right'
99 { initialDirection === 'right' &&
100 <span className='slide-panel-header-title'>{title}</span>}
105 handleClick = () => {
107 isOpen: !this.state.isOpen,
108 direction: this.state.direction === 'left' ? 'right' : 'left'
112 setSliderPosition = () => {
114 let el = ReactDOM.findDOMNode(this);
117 let {direction: initialDirection} = this.props;
118 let arrowIconSize = Math.floor(ReactDOM.findDOMNode(this.refs.arrowIcon)
119 .getBoundingClientRect().width) * 2;
120 if (!this.state.isOpen) {
121 if (this.props.direction === 'left') {
122 style.left = arrowIconSize - el.getBoundingClientRect().width + 'px';
124 if (initialDirection === 'right') {
125 style.right = arrowIconSize - el.getBoundingClientRect().width + 'px';
129 if (initialDirection === 'left') {
133 if (this.props.direction === 'right') {
141 export default SlidePanel;