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

85 lines
2.2 KiB
TypeScript
Raw Normal View History

import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
2019-12-06 13:16:08 +00:00
import { ControlWrapper, StyledDynamicInput } from "./StyledControls";
2019-11-25 05:07:27 +00:00
import { InputType } from "widgets/InputWidget";
import { ControlType } from "constants/PropertyControlConstants";
2019-12-30 07:35:16 +00:00
// import { Intent } from "@blueprintjs/core";
2019-12-06 13:16:08 +00:00
import DynamicAutocompleteInput from "components/editorComponents/DynamicAutocompleteInput";
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;
validationMessage?: string;
}) {
const { validationMessage, value, isValid, label, onChange } = props;
return (
<ControlWrapper>
<label>{label}</label>
<StyledDynamicInput>
<DynamicAutocompleteInput
input={{
value: value,
onChange: onChange,
}}
meta={{
error: isValid ? "" : validationMessage,
touched: true,
}}
theme={"DARK"}
2020-02-21 07:57:28 +00:00
singleLine={false}
2020-01-23 07:53:36 +00:00
/>
</StyledDynamicInput>
</ControlWrapper>
);
}
class InputTextControl extends BaseControl<InputControlProps> {
render() {
2020-01-02 13:36:35 +00:00
const { validationMessage, propertyValue, isValid, label } = this.props;
return (
2020-01-23 07:53:36 +00:00
<InputText
label={label}
value={propertyValue}
onChange={this.onTextChange}
isValid={isValid}
validationMessage={validationMessage}
/>
);
}
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);
};
getControlType(): ControlType {
return "INPUT_TEXT";
}
}
export interface InputControlProps extends ControlProps {
placeholderText: string;
2019-11-19 12:44:58 +00:00
inputType: InputType;
isDisabled?: boolean;
}
export default InputTextControl;