Upgrade to react 16
[aai/sparky-fe.git] / src / generic-components / InlineMessage / InlineMessage.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} from 'react';
22 import { PropTypes } from 'prop-types';
23 import FontAwesome from 'react-fontawesome';
24 import InlineMessageConstatns from './InlineMessageConstants';
25
26 import Alert from 'react-bootstrap/lib/Alert';
27
28 export default class InlineMessage extends Component {
29
30   static propType = {
31     level: PropTypes.string,
32     messageTxt: PropTypes.string
33   };
34
35   static defaultProps = {
36     level: '',
37     messageTxt: ''
38   };
39
40   render() {
41     let {level, messageTxt} = this.props;
42     let fontawesomeClassName;
43     //Select the font based on the severity level
44     switch (level) {
45       case 'success':
46         fontawesomeClassName = InlineMessageConstatns.SUCCESS_CLASSNAME;
47         break;
48       case 'warning':
49         fontawesomeClassName = InlineMessageConstatns.WARNING_CLASSNAME;
50         break;
51       case 'danger':
52         fontawesomeClassName = InlineMessageConstatns.DANGER_CLASSNAME;
53         break;
54       default:
55         fontawesomeClassName = InlineMessageConstatns.DEFAULT_CLASSNAME;
56         break;
57
58     }
59
60     if (messageTxt && messageTxt.length > 0) {
61       return (
62         <Alert bsStyle={level}
63                className={InlineMessageConstatns.ALERT_PANEL_CLASSNAME}>
64           <div className={InlineMessageConstatns.NOTIFICATION_PANEL_CLASSNAME}>
65             <div className={InlineMessageConstatns.ICON_PANEL_CLASSNAME}>
66               <FontAwesome className={fontawesomeClassName}
67                            name={fontawesomeClassName}/>
68             </div>
69             <div className={InlineMessageConstatns.MESSAGE_PANEL_CLASSNAME}>
70               {messageTxt}
71             </div>
72           </div>
73         </Alert>
74       );
75     } else {
76       return false;
77     }
78
79   }
80 }