update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / plugins / composer / src / src / components / model / PanelHeader.jsx
1 /*
2  *
3  *   Copyright 2017 RIFT.IO Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  *
17  */
18 import React from 'react';
19 import changeCase from 'change-case'
20 import Button from '../Button'
21 import { CaretRightIcon } from 'react-open-iconic-svg';
22 import { CaretBottomIcon } from 'react-open-iconic-svg';
23
24 import '../../styles/EditDescriptorModelProperties.scss'
25
26 export default function PanelHeader(props) {
27         const {
28                 name, info, action, helpText,
29                 showOpened, onChangeOpenState } = props;
30
31         function onClickOpenClose(e) {
32                 onChangeOpenState();
33         }
34         function onClickAction(e) {
35                 e.preventDefault();
36                 action.invoke();
37         }
38
39         const isExpandCollapseButtonNeeded = !!onChangeOpenState;
40         const isOpened = isExpandCollapseButtonNeeded ? showOpened : true;
41         const actionButton = isOpened && action ?
42                 <Button className="inline-hint" onClick={onClickAction} label={action.title} src={action.icon} />
43                 : null;
44         const expandoButtonStyle = { fill: '#586e75', cursor: 'pointer' };
45         const expandoButton = !isExpandCollapseButtonNeeded ? null : isOpened ?
46                 <CaretBottomIcon style={expandoButtonStyle} onClick={onClickOpenClose} />
47                 : <CaretRightIcon style={expandoButtonStyle} onClick={onClickOpenClose} />;
48         const help = isOpened && helpText ? <span className={'description'} >{helpText}</span> : null;
49         return (
50                 <div>
51                         <h3 className='property-label'>
52                                 {expandoButton}
53                                 <span className={'name'} onClick={onClickOpenClose} style={{cursor: 'pointer'}} >{name}</span>
54                                 <small>
55                                         <span className={'info'}>{info}</span>
56                                 </small>
57                                 {actionButton}
58                         </h3>
59                         <div>{help}</div>
60                 </div>
61         )
62 }
63