Initial coomit for AAI-UI(sparky-fe)
[aai/sparky-fe.git] / src / generic-components / toggleButtonGroup / ToggleButtonGroup.jsx
1 /*
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
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
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
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=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 import React, {Component, PropTypes} from 'react';
27 import {connect} from 'react-redux';
28
29 import ButtonGroup from 'react-bootstrap/lib/ButtonGroup.js';
30 import Button from 'react-bootstrap/lib/Button.js';
31
32 import ToggleButtonGroupActions from 'generic-components/toggleButtonGroup/ToggleButtonGroupActions.js';
33
34 let mapActionToProps = (dispatch) => {
35                 return {
36                                 onButtonToggle: (buttonName) => {
37                                                 dispatch(ToggleButtonGroupActions.onToggle({button: buttonName}));
38                                 }
39                 };
40 };
41
42 let mapStateToProps = ({toggleButtonGroupData}) => {
43                 
44                 let {selectedButton} = toggleButtonGroupData;
45                 
46                 return {
47                                 selectedButton
48                 };
49 };
50
51 class ToggleButtonGroup extends Component {
52                 
53                 static propTypes = {
54                                 buttonDefinitions: PropTypes.object.isRequired
55                 };
56                 
57                 onButtonSelect(buttonName) {
58                                 this.props.onButtonToggle(buttonName);
59                 }
60                 
61                 render() {
62                                 let {selectedButton, buttonDefinitions} = this.props;
63                                 let buttonListElements = [];
64                                 Object.keys(buttonDefinitions).map(function (item) {
65                                                 buttonListElements.push(
66                                                                 <Button id={item} active={selectedButton === item ? true : false}
67                                                                         onClick={() => this.onButtonSelect(item)}>
68                                                                                 <i className={buttonDefinitions[item]} aria-hidden='true'></i>
69                                                                 </Button>
70                                                 );
71                                 }.bind(this));
72                                 
73                                 return (
74                                                 <ButtonGroup bsClass='btn-group displayOptionButtons'>
75                                                                 {buttonListElements}
76                                                 </ButtonGroup>
77                                 );
78                 }
79 }
80 export default connect(mapStateToProps, mapActionToProps)(ToggleButtonGroup);