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';
20 import { ViewElementNumber } from "../models/uiModels";
21 import { Tooltip, InputAdornment } from "@mui/material";
22 import { BaseProps } from "./baseProps";
23 import { IfWhenTextInput } from "./ifWhenTextInput";
24 import { checkRange } from "../utilities/verifyer";
26 type numberInputProps = BaseProps<number>;
28 export const UiElementNumber = (props: numberInputProps) => {
31 const [error, setError] = React.useState(false);
32 const [helperText, setHelperText] = React.useState("");
33 const [isTooltipVisible, setTooltipVisibility] = React.useState(true);
35 const element = props.value as ViewElementNumber;
37 const verifyValue = (data: string) => {
38 const num = Number(data);
40 const result = checkRange(element, num);
41 if (result.length > 0) {
43 setHelperText(result);
50 setHelperText("Input is not a number.");
56 <Tooltip disableInteractive title={isTooltipVisible ? element.description || '' : ''}>
57 <IfWhenTextInput element={element} onChangeTooltipVisibility={setTooltipVisibility}
58 spellCheck={false} autoFocus margin="dense"
59 id={element.id} label={element.label} type="text" value={props.inputValue}
60 style={{ width: 485, marginLeft: 20, marginRight: 20 }}
61 onChange={(e) => { verifyValue(e.target.value) }}
63 readOnly={props.readOnly}
64 disabled={props.disabled}
65 helperText={helperText}
66 startAdornment={element.units != null ? <InputAdornment position="start">{element.units}</InputAdornment> : undefined}