SDN-R add updated odlux
[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 = { element: ViewElementBase, id: any, label: any, style: any, helperText: string, error: boolean, toogleTooltip(value: boolean): void, [x: string]: any };
42
43 export const IfWhenTextInput = (props: ifwhenProps) => {
44
45     const { element, toogleTooltip, id, label, helperText: errorText, error, style, ...otherProps } = props;
46     const classes = useStyles();
47
48
49     const ifFeature = element.ifFeature ? <Tooltip onMouseMove={e => props.toogleTooltip(false)} onMouseOut={e => props.toogleTooltip(true)} title={element.ifFeature}><InputAdornment position="start"><FontAwesomeIcon icon={faAdjust} className={classes.iconDark}></FontAwesomeIcon></InputAdornment></Tooltip> : null;
50     const whenFeature = element.when ? (<Tooltip className={classes.padding} onMouseMove={e => props.toogleTooltip(false)} onMouseOut={e => props.toogleTooltip(true)} title={element.when}>
51         <InputAdornment className={classes.padding} position="end"><FontAwesomeIcon icon={faAdjust} className={classes.iconLight}></FontAwesomeIcon></InputAdornment></Tooltip>) : null;
52
53     return (
54         <FormControl error={error} style={style}>
55             <InputLabel htmlFor={id} >{label}</InputLabel>
56             <Input  {...otherProps} id={id} endAdornment={<div>{ifFeature}{whenFeature}</div>} />
57             <FormHelperText>{errorText}</FormHelperText>
58         </FormControl>
59
60     );
61 }