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 { Tooltip, TextField } from "@material-ui/core";
20 import { ViewElementString } from "../models/uiModels";
21 import * as React from "react"
22 import { baseProps } from "./baseProps";
23 import { IfWhenTextInput } from "./ifWhenTextInput";
24 import { checkRange, checkPattern } from "./verifyer";
26 type stringEntryProps = baseProps & { isKey: boolean };
28 export const UiElementString = (props: stringEntryProps) => {
30 const [isError, setError] = React.useState(false);
31 const [helperText, setHelperText] = React.useState("");
32 const [isTooltipVisible, setTooltipVisibility] = React.useState(true);
34 const element = props.value as ViewElementString;
36 const verifyValues = (data: string) => {
38 if (data.trim().length > 0) {
40 let errorMessage = "";
41 const result = checkRange(element, data.length);
43 if (result.length > 0)
44 errorMessage += result;
47 const patternResult = checkPattern(element.pattern, data)
49 if (patternResult.error) {
50 errorMessage += patternResult.error;
53 if (errorMessage.length > 0) {
55 setHelperText(errorMessage);
71 <Tooltip title={isTooltipVisible ? element.description || '' : ''}>
72 <IfWhenTextInput element={element} toogleTooltip={(val: boolean) => setTooltipVisibility(val)}
73 spellCheck={false} autoFocus margin="dense"
74 id={element.id} label={props.isKey ? "🔑 " + element.label : element.label} type="text" value={props.inputValue}
75 style={{ width: 485, marginLeft: 20, marginRight: 20 }}
76 onChange={(e: any) => { verifyValues(e.target.value) }}
78 readOnly={props.readOnly}
79 disabled={props.disabled}
80 helperText={helperText}