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

65 lines
1.7 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";
class InputTextControl extends BaseControl<InputControlProps> {
render() {
2020-01-02 13:36:35 +00:00
const { validationMessage, propertyValue, isValid, label } = this.props;
return (
<ControlWrapper>
2019-12-10 13:30:16 +00:00
<label>{label}</label>
2019-12-06 13:16:08 +00:00
<StyledDynamicInput>
<DynamicAutocompleteInput
input={{
2019-12-10 13:30:16 +00:00
value: propertyValue,
2019-12-06 13:16:08 +00:00
onChange: this.onTextChange,
}}
2020-01-02 13:36:35 +00:00
meta={{
error: isValid ? "" : validationMessage,
touched: true,
}}
2019-12-30 07:35:16 +00:00
theme={"DARK"}
2019-12-06 13:16:08 +00:00
/>
</StyledDynamicInput>
</ControlWrapper>
);
}
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;