Add link calculation app
[ccsdk/features.git] / sdnr / wt / odlux / apps / configurationApp / src / components / ifWhenTextInput.tsx
1 /**
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt odlux
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18
19 import { ViewElementBase } from "models/uiModels";
20 import { TextField, InputAdornment, Input, Tooltip, Divider, IconButton, InputBase, Paper, makeStyles, Theme, createStyles, FormControl, InputLabel, FormHelperText } from "@material-ui/core";
21 import * as React from 'react';
22 import { faAdjust } from "@fortawesome/free-solid-svg-icons";
23 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
24 import { InputProps } from "@material-ui/core/Input";
25
26 const useStyles = makeStyles((theme: Theme) =>
27   createStyles({
28     iconDark: {
29       color: '#ff8800'
30     },
31     iconLight: {
32       color: 'orange'
33     },
34     padding: {
35       paddingLeft: 10,
36       paddingRight: 10
37     },
38   }),
39 );
40
41 type IfwhenProps = InputProps & {
42   label: string;
43   element: ViewElementBase;
44   helperText: string;
45   error: boolean;
46   onChangeTooltipVisuability(value: boolean): void;
47 };
48
49 export const IfWhenTextInput = (props: IfwhenProps) => {
50
51   const { element, onChangeTooltipVisuability: toogleTooltip, id, label, helperText: errorText, error, style, ...otherProps } = props;
52   const classes = useStyles();
53
54
55   const ifFeature = element.ifFeature
56     ? (
57         <Tooltip onMouseMove={e => props.onChangeTooltipVisuability(false)} onMouseOut={e => props.onChangeTooltipVisuability(true)} title={element.ifFeature}>
58           <InputAdornment position="start">
59             <FontAwesomeIcon icon={faAdjust} className={classes.iconDark} />
60           </InputAdornment>
61         </Tooltip>
62       )
63     : null;
64
65   const whenFeature = element.when
66     ? (
67         <Tooltip className={classes.padding} onMouseMove={() => props.onChangeTooltipVisuability(false)} onMouseOut={() => props.onChangeTooltipVisuability(true)} title={element.when}>
68           <InputAdornment className={classes.padding} position="end">
69             <FontAwesomeIcon icon={faAdjust} className={classes.iconLight}/>
70           </InputAdornment>
71         </Tooltip>
72       ) 
73     : null;
74
75   return (
76     <FormControl error={error} style={style}>
77       <InputLabel htmlFor={id} >{label}</InputLabel>
78       <Input id={id} endAdornment={<div>{ifFeature}{whenFeature}</div>} {...otherProps}  />
79       <FormHelperText>{errorText}</FormHelperText>
80     </FormControl>
81   );
82 }