2020-04-28 06:52:53 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
|
|
|
|
import { InputType } from "widgets/InputWidget";
|
|
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
|
|
|
|
import TextField from "components/editorComponents/form/fields/TextField";
|
2020-08-05 08:02:24 +00:00
|
|
|
import FormLabel from "components/editorComponents/FormLabel";
|
2020-10-27 05:02:32 +00:00
|
|
|
import { FormIcons } from "icons/FormIcons";
|
|
|
|
|
import { Colors } from "constants/Colors";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
2021-02-26 06:58:47 +00:00
|
|
|
export const StyledInfo = styled.span`
|
2020-10-27 05:02:32 +00:00
|
|
|
font-weight: normal;
|
|
|
|
|
line-height: normal;
|
2021-02-26 06:58:47 +00:00
|
|
|
color: ${Colors.DOVE_GRAY};
|
2020-10-27 05:02:32 +00:00
|
|
|
font-size: 12px;
|
|
|
|
|
margin-left: 1px;
|
|
|
|
|
`;
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
export function InputText(props: {
|
|
|
|
|
label: string;
|
|
|
|
|
value: string;
|
|
|
|
|
isValid: boolean;
|
2021-02-26 06:58:47 +00:00
|
|
|
subtitle?: string;
|
2020-04-28 06:52:53 +00:00
|
|
|
validationMessage?: string;
|
|
|
|
|
placeholder?: string;
|
|
|
|
|
dataType?: string;
|
|
|
|
|
isRequired?: boolean;
|
|
|
|
|
name: string;
|
2020-10-27 05:02:32 +00:00
|
|
|
encrypted?: boolean;
|
2021-02-26 06:58:47 +00:00
|
|
|
disabled?: boolean;
|
2020-04-28 06:52:53 +00:00
|
|
|
}) {
|
2021-02-26 06:58:47 +00:00
|
|
|
const {
|
|
|
|
|
name,
|
|
|
|
|
placeholder,
|
|
|
|
|
dataType,
|
|
|
|
|
label,
|
|
|
|
|
isRequired,
|
|
|
|
|
disabled,
|
|
|
|
|
subtitle,
|
|
|
|
|
encrypted,
|
|
|
|
|
} = props;
|
2020-04-28 06:52:53 +00:00
|
|
|
|
|
|
|
|
return (
|
2021-04-28 10:28:39 +00:00
|
|
|
<div data-cy={name} style={{ width: "50vh" }}>
|
2020-08-05 08:02:24 +00:00
|
|
|
<FormLabel>
|
2020-10-27 05:02:32 +00:00
|
|
|
{label} {isRequired && "*"}{" "}
|
2021-02-26 06:58:47 +00:00
|
|
|
{encrypted && (
|
2020-10-27 05:02:32 +00:00
|
|
|
<>
|
2021-04-28 10:28:39 +00:00
|
|
|
<FormIcons.LOCK_ICON height={12} keepColors width={12} />
|
2020-10-27 05:02:32 +00:00
|
|
|
<StyledInfo>Encrypted</StyledInfo>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2021-02-26 06:58:47 +00:00
|
|
|
{subtitle && (
|
|
|
|
|
<>
|
|
|
|
|
<br />
|
|
|
|
|
<StyledInfo>{subtitle}</StyledInfo>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2020-08-05 08:02:24 +00:00
|
|
|
</FormLabel>
|
2020-04-28 06:52:53 +00:00
|
|
|
<TextField
|
2021-04-28 10:28:39 +00:00
|
|
|
disabled={disabled || false}
|
2020-04-28 06:52:53 +00:00
|
|
|
name={name}
|
|
|
|
|
placeholder={placeholder}
|
|
|
|
|
showError
|
2021-04-28 10:28:39 +00:00
|
|
|
type={dataType}
|
2020-04-28 06:52:53 +00:00
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class InputTextControl extends BaseControl<InputControlProps> {
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
validationMessage,
|
|
|
|
|
propertyValue,
|
|
|
|
|
isValid,
|
|
|
|
|
label,
|
|
|
|
|
placeholderText,
|
|
|
|
|
dataType,
|
|
|
|
|
configProperty,
|
2021-02-26 06:58:47 +00:00
|
|
|
disabled,
|
|
|
|
|
subtitle,
|
2020-04-28 06:52:53 +00:00
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<InputText
|
|
|
|
|
dataType={this.getType(dataType)}
|
2021-02-26 06:58:47 +00:00
|
|
|
disabled={disabled}
|
2021-04-28 10:28:39 +00:00
|
|
|
encrypted={this.props.encrypted}
|
|
|
|
|
isValid={isValid}
|
|
|
|
|
label={label}
|
|
|
|
|
name={configProperty}
|
|
|
|
|
placeholder={placeholderText}
|
2021-02-26 06:58:47 +00:00
|
|
|
subtitle={subtitle}
|
2021-04-28 10:28:39 +00:00
|
|
|
validationMessage={validationMessage}
|
|
|
|
|
value={propertyValue}
|
2020-04-28 06:52:53 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isNumberType(): boolean {
|
|
|
|
|
const { inputType } = this.props;
|
|
|
|
|
switch (inputType) {
|
|
|
|
|
case "CURRENCY":
|
|
|
|
|
case "INTEGER":
|
|
|
|
|
case "NUMBER":
|
|
|
|
|
case "PHONE_NUMBER":
|
|
|
|
|
return true;
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getType(dataType: InputType | undefined) {
|
|
|
|
|
switch (dataType) {
|
|
|
|
|
case "PASSWORD":
|
|
|
|
|
return "password";
|
|
|
|
|
case "NUMBER":
|
|
|
|
|
return "number";
|
|
|
|
|
default:
|
|
|
|
|
return "text";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getControlType(): ControlType {
|
|
|
|
|
return "INPUT_TEXT";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InputControlProps extends ControlProps {
|
|
|
|
|
placeholderText: string;
|
|
|
|
|
inputType?: InputType;
|
|
|
|
|
dataType?: InputType;
|
2021-02-26 06:58:47 +00:00
|
|
|
subtitle?: string;
|
2020-10-27 05:02:32 +00:00
|
|
|
encrypted?: boolean;
|
2021-02-26 06:58:47 +00:00
|
|
|
disabled?: boolean;
|
2020-04-28 06:52:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default InputTextControl;
|