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

68 lines
1.9 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-11-19 12:44:58 +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() {
2019-12-10 13:30:16 +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
2019-12-10 13:30:16 +00:00
intent={isValid ? Intent.NONE : Intent.DANGER}
2019-12-06 13:16:08 +00:00
type={this.isNumberType() ? "number" : "text"}
input={{
2019-12-10 13:30:16 +00:00
value: propertyValue,
2019-12-06 13:16:08 +00:00
onChange: this.onTextChange,
}}
placeholder={this.props.placeholderText}
2019-12-10 13:30:16 +00:00
meta={{
touched: true,
error: validationMessage,
}}
showError
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-06 13:16:08 +00:00
onTextChange = (event: React.ChangeEvent<HTMLInputElement> | string) => {
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;