changed the header and license
[aai/sparky-fe.git] / src / generic-components / titledContainer / TitledContainer.jsx
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 import React, {Component, PropTypes} from 'react';
22 import Button from 'react-bootstrap/lib/Button';
23
24 import i18n from 'utils/i18n/i18n';
25
26 const ICON_CLASS_MAXIMIZE = 'fa fa-chevron-down fa-lg';
27 const ICON_CLASS_MINIMIZE = 'fa fa-chevron-up fa-lg';
28
29 export default class TitledContainer extends Component {
30
31   static propType = {
32     title: PropTypes.string
33   };
34
35   static defaultProps = {
36     title: 'Some Title'
37   };
38
39   constructor(props) {
40     super(props);
41     this.state = {isToggleOn: true};
42
43     this.handleClick = this.handleClick.bind(this);
44   }
45
46   handleClick() {
47     this.setState(prevState => ({
48       isToggleOn: !prevState.isToggleOn
49     }));
50   }
51
52   render() {
53     let {title, children} = this.props;
54     let contentsClass = this.state.isToggleOn ? 'contents' : 'hidden';
55     let className = this.state.isToggleOn
56       ? ICON_CLASS_MINIMIZE
57       : ICON_CLASS_MAXIMIZE;
58     return (
59       <div className='dep-titled-container'>
60         <div className='header'>
61           <span className='header-title'>{i18n(title)}</span>
62           <Button type='submit' className='toggle-visibility-button'
63                   onClick={this.handleClick}>
64             <i className={className} aria-hidden='true'/>
65           </Button>
66         </div>
67         <div className={contentsClass}>
68           {children}
69         </div>
70       </div>
71     );
72   }
73 }