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

121 lines
2.8 KiB
TypeScript
Raw Normal View History

import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
import { StyledDynamicInput } from "./StyledControls";
2019-11-25 05:07:27 +00:00
import { InputType } from "widgets/InputWidget";
import CodeEditor from "components/editorComponents/CodeEditor";
import {
EditorModes,
EditorSize,
EditorTheme,
TabBehaviour,
} from "components/editorComponents/CodeEditor/EditorConfig";
2020-01-23 07:53:36 +00:00
export function InputText(props: {
label: string;
value: string;
onChange: (event: React.ChangeEvent<HTMLTextAreaElement> | string) => void;
isValid: boolean;
2020-06-04 13:49:22 +00:00
errorMessage?: string;
2020-06-11 11:03:16 +00:00
evaluatedValue?: any;
2020-06-04 13:49:22 +00:00
expected?: string;
2020-03-16 15:42:39 +00:00
placeholder?: string;
2020-06-04 13:49:22 +00:00
dataTreePath?: string;
additionalAutocomplete?: Record<string, Record<string, unknown>>;
2020-01-23 07:53:36 +00:00
}) {
2020-06-04 13:49:22 +00:00
const {
errorMessage,
expected,
value,
isValid,
onChange,
placeholder,
dataTreePath,
2020-06-11 11:03:16 +00:00
evaluatedValue,
2020-06-04 13:49:22 +00:00
} = props;
2020-01-23 07:53:36 +00:00
return (
<StyledDynamicInput>
<CodeEditor
input={{
value: value,
onChange: onChange,
}}
2020-06-11 11:03:16 +00:00
evaluatedValue={evaluatedValue}
2020-06-04 13:49:22 +00:00
expected={expected}
dataTreePath={dataTreePath}
meta={{
2020-06-04 13:49:22 +00:00
error: isValid ? "" : errorMessage,
touched: true,
}}
theme={EditorTheme.DARK}
mode={EditorModes.TEXT_WITH_BINDING}
tabBehaviour={TabBehaviour.INDENT}
size={EditorSize.EXTENDED}
2020-03-16 15:42:39 +00:00
placeholder={placeholder}
additionalDynamicData={props.additionalAutocomplete}
/>
</StyledDynamicInput>
2020-01-23 07:53:36 +00:00
);
}
class InputTextControl extends BaseControl<InputControlProps> {
render() {
2020-03-16 15:42:39 +00:00
const {
2020-06-04 13:49:22 +00:00
expected,
2020-03-16 15:42:39 +00:00
propertyValue,
isValid,
label,
placeholderText,
2020-06-04 13:49:22 +00:00
dataTreePath,
2020-06-16 07:37:39 +00:00
validationMessage,
defaultValue,
2020-03-16 15:42:39 +00:00
} = this.props;
return (
2020-01-23 07:53:36 +00:00
<InputText
label={label}
value={propertyValue ? propertyValue : defaultValue}
2020-01-23 07:53:36 +00:00
onChange={this.onTextChange}
isValid={isValid}
2020-06-16 07:37:39 +00:00
errorMessage={validationMessage}
2020-06-04 13:49:22 +00:00
expected={expected}
2020-03-16 15:42:39 +00:00
placeholder={placeholderText}
2020-06-04 13:49:22 +00:00
dataTreePath={dataTreePath}
2020-01-23 07:53:36 +00:00
/>
);
}
2019-11-19 12:44:58 +00:00
isNumberType(): boolean {
const { inputType } = this.props;
2019-10-31 05:28:11 +00:00
switch (inputType) {
case "CURRENCY":
case "INTEGER":
case "NUMBER":
case "PHONE_NUMBER":
return true;
default:
return false;
}
}
2019-12-30 07:35:16 +00:00
onTextChange = (event: React.ChangeEvent<HTMLTextAreaElement> | string) => {
2019-12-06 13:16:08 +00:00
let value = event;
if (typeof event !== "string") {
value = event.target.value;
}
2019-11-14 14:26:23 +00:00
this.updateProperty(this.props.propertyName, value);
};
static getControlType() {
return "INPUT_TEXT";
}
}
export interface InputControlProps extends ControlProps {
placeholderText: string;
2019-11-19 12:44:58 +00:00
inputType: InputType;
2020-06-16 07:37:39 +00:00
validationMessage?: string;
isDisabled?: boolean;
defaultValue?: any;
}
export default InputTextControl;