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
10 * http://www.apache.org/licenses/LICENSE-2.0
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
16 * ============LICENSE_END==========================================================================
19 import React from 'react';
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';
27 import { ViewElementBoolean } from '../models/uiModels';
28 import { BaseProps } from './baseProps';
30 type BooleanInputProps = BaseProps<boolean>;
32 export const UiElementBoolean = (props: BooleanInputProps) => {
34 const element = props.value as ViewElementBoolean;
36 const value = String(props.inputValue).toLowerCase();
37 const mandatoryError = element.mandatory && value !== 'true' && value !== 'false';
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}
52 id: `select-${element.id}`,
55 <MenuItem value={'true'} aria-label="true">{element.trueValue || 'True'}</MenuItem>
56 <MenuItem value={'false'} aria-label="false">{element.falseValue || 'False'}</MenuItem>
59 <FormHelperText>{mandatoryError ? 'Value is mandatory' : ''}</FormHelperText>