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

50 lines
1.3 KiB
TypeScript
Raw Normal View History

import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
2019-09-24 12:11:32 +00:00
import { ControlType } from "../constants/PropertyControlConstants";
import { InputType } from "../widgets/InputWidget";
import { ControlWrapper, StyledInputGroup } from "./StyledControls";
class InputTextControl extends BaseControl<InputControlProps> {
render() {
return (
<ControlWrapper>
<label>{this.props.label}</label>
<StyledInputGroup
2019-10-31 05:28:11 +00:00
type={this.isNumberType(this.props.inputType) ? "number" : "text"}
onChange={this.onTextChange}
2019-10-31 05:28:11 +00:00
placeholder={this.props.placeholderText}
defaultValue={this.props.propertyValue}
/>
</ControlWrapper>
);
}
2019-10-31 05:28:11 +00:00
isNumberType(inputType: InputType): boolean {
switch (inputType) {
case "CURRENCY":
case "INTEGER":
case "NUMBER":
case "PHONE_NUMBER":
return true;
default:
return false;
}
}
onTextChange = (event: React.ChangeEvent<HTMLInputElement>) => {
this.updateProperty(this.props.propertyName, event.target.value);
};
getControlType(): ControlType {
return "INPUT_TEXT";
}
}
export interface InputControlProps extends ControlProps {
placeholderText: string;
inputType: InputType;
isDisabled?: boolean;
}
export default InputTextControl;