PromucFlow_constructor/app/client/src/components/formControls/InputTextControl.tsx

140 lines
3.0 KiB
TypeScript
Raw Normal View History

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";
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";
export const StyledInfo = styled.span`
2020-10-27 05:02:32 +00:00
font-weight: normal;
line-height: normal;
color: ${Colors.DOVE_GRAY};
2020-10-27 05:02:32 +00:00
font-size: 12px;
margin-left: 1px;
`;
export function InputText(props: {
label: string;
value: string;
isValid: boolean;
subtitle?: string;
validationMessage?: string;
placeholder?: string;
dataType?: string;
isRequired?: boolean;
name: string;
2020-10-27 05:02:32 +00:00
encrypted?: boolean;
disabled?: boolean;
}) {
const {
name,
placeholder,
dataType,
label,
isRequired,
disabled,
subtitle,
encrypted,
} = props;
return (
<div data-cy={name} style={{ width: "50vh" }}>
<FormLabel>
2020-10-27 05:02:32 +00:00
{label} {isRequired && "*"}{" "}
{encrypted && (
2020-10-27 05:02:32 +00:00
<>
<FormIcons.LOCK_ICON height={12} keepColors width={12} />
2020-10-27 05:02:32 +00:00
<StyledInfo>Encrypted</StyledInfo>
</>
)}
{subtitle && (
<>
<br />
<StyledInfo>{subtitle}</StyledInfo>
</>
)}
</FormLabel>
<TextField
disabled={disabled || false}
name={name}
placeholder={placeholder}
showError
type={dataType}
/>
</div>
);
}
class InputTextControl extends BaseControl<InputControlProps> {
render() {
const {
validationMessage,
propertyValue,
isValid,
label,
placeholderText,
dataType,
configProperty,
disabled,
subtitle,
} = this.props;
return (
<InputText
dataType={this.getType(dataType)}
disabled={disabled}
encrypted={this.props.encrypted}
isValid={isValid}
label={label}
name={configProperty}
placeholder={placeholderText}
subtitle={subtitle}
validationMessage={validationMessage}
value={propertyValue}
/>
);
}
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;
subtitle?: string;
2020-10-27 05:02:32 +00:00
encrypted?: boolean;
disabled?: boolean;
}
export default InputTextControl;