update from RIFT as of 696b75d2fe9fb046261b08c616f1bcf6c0b54a9b third try
[osm/UI.git] / skyquake / framework / widgets / panel / panel.jsx
1 /*
2  *
3  *   Copyright 2016 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, {Component} from 'react';
19 import 'style/core.css';
20 import './panel.scss';
21 import circleXImage from '../../../node_modules/open-iconic/svg/circle-x.svg';
22 export class Panel extends Component {
23     constructor(props) {
24         super(props)
25     }
26     render() {
27         let self = this;
28         let {children, className, title, ...props} = self.props;
29         let classRoot = className ? ' ' + className : ' ';
30         let hasCorners = this.props['no-corners'];
31         let titleTag = title ? <header className="skyquakePanel-title">{title}</header> : '';
32         let closeButton = (
33             <a onClick={self.props.hasCloseButton}
34               className={"close-btn"}>
35               <img src={circleXImage} title="Close card" />
36               </a>
37         );
38         return (
39             <section className={'skyquakePanel' + classRoot} style={props.style}>
40                 {  self.props.hasCloseButton ? closeButton : null}
41                 { !hasCorners ? <i className="corner-accent top left"></i> : null }
42                 { !hasCorners ? <i className="corner-accent top right"></i> : null }
43                 {titleTag}
44                 <div className="skyquakePanel-wrapper">
45                     <div className={(classRoot ? 'skyquakePanel-body ' + decorateClassNames(classRoot, '-body') : 'skyquakePanel-body')}>
46                             {children}
47                     </div>
48                 </div>
49                 { !hasCorners ? <i className="corner-accent bottom left"></i> : null }
50                 { !hasCorners ? <i className="corner-accent bottom right"></i> : null }
51             </section>
52         )
53     }
54 }
55
56 Panel.defaultProps = {
57
58 }
59
60 export class PanelWrapper extends Component {
61     render() {
62         let wrapperClass = 'skyquakePanelWrapper';
63         let {className, column, style, ...props} = this.props;
64         if(className) {
65             wrapperClass = `${wrapperClass} ${className}`
66         }
67         if(column) {
68             style.flexDirection = 'column';
69         }
70         return (
71         <div className={wrapperClass} style={style} {...props}>
72             {this.props.children}
73         </div>)
74     }
75 }
76 PanelWrapper.defaultProps = {
77     style: {}
78 }
79 export default Panel;
80
81
82 function decorateClassNames(className, addendum) {
83     return className.trim().split(' ').map(function(c) {
84         return c + addendum
85     }).join(' ');
86 }