Create wt-odlux directory
[ccsdk/features.git] / sdnr / wt-odlux / odlux / apps / configurationApp / src / components / uiElementBoolean.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 React from 'react';
20
21 import MenuItem from '@mui/material/MenuItem';
22 import FormHelperText from '@mui/material/FormHelperText';
23 import Select from '@mui/material/Select';
24 import FormControl from '@mui/material/FormControl';
25 import InputLabel from '@mui/material/InputLabel';
26
27 import { ViewElementBoolean } from '../models/uiModels';
28 import { BaseProps } from './baseProps';
29
30 type BooleanInputProps = BaseProps<boolean>;
31
32 export const UiElementBoolean = (props: BooleanInputProps) => {
33
34   const element = props.value as ViewElementBoolean;
35
36   const value = String(props.inputValue).toLowerCase();
37   const mandatoryError = element.mandatory && value !== 'true' && value !== 'false';
38     
39   return (!props.readOnly || element.id != null
40     ? (<FormControl variant="standard" style={{ width: 485, marginLeft: 20, marginRight: 20 }}>
41             <InputLabel htmlFor={`select-${element.id}`} >{element.label}</InputLabel>
42             <Select variant="standard"
43                 aria-label={element.label + '-selection'}
44                 required={!!element.mandatory}
45                 error={mandatoryError}
46                 onChange={(e) => { props.onChange(e.target.value === 'true'); }}
47                 readOnly={props.readOnly}
48                 disabled={props.disabled}
49                 value={value}
50                 inputProps={{
51                   name: element.id,
52                   id: `select-${element.id}`,
53                 }}
54             >
55                 <MenuItem value={'true'} aria-label="true">{element.trueValue || 'True'}</MenuItem>
56                 <MenuItem value={'false'} aria-label="false">{element.falseValue || 'False'}</MenuItem>
57
58             </Select>
59             <FormHelperText>{mandatoryError ? 'Value is mandatory' : ''}</FormHelperText>
60         </FormControl>)
61     : null
62   );
63 };