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

54 lines
1.4 KiB
TypeScript
Raw Normal View History

import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
2019-11-19 12:44:58 +00:00
import { ControlWrapper, StyledInputGroup } from "./StyledControls";
2019-11-14 09:28:51 +00:00
import { InputType } from "../../widgets/InputWidget";
2019-11-05 05:09:50 +00:00
import { ControlType } from "../../constants/PropertyControlConstants";
2019-11-19 12:44:58 +00:00
import { Intent } from "@blueprintjs/core";
class InputTextControl extends BaseControl<InputControlProps> {
render() {
return (
<ControlWrapper>
<label>{this.props.label}</label>
<StyledInputGroup
2019-11-19 12:44:58 +00:00
intent={this.props.isValid ? Intent.NONE : Intent.DANGER}
type={this.isNumberType() ? "number" : "text"}
onChange={this.onTextChange}
2019-10-31 05:28:11 +00:00
placeholder={this.props.placeholderText}
defaultValue={this.props.propertyValue}
/>
</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;
}
}
onTextChange = (event: React.ChangeEvent<HTMLInputElement>) => {
2019-11-22 13:12:39 +00:00
const value: string = 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;