2019-09-18 10:19:50 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
2020-02-26 12:44:56 +00:00
|
|
|
import { StyledDynamicInput } from "./StyledControls";
|
2019-11-25 05:07:27 +00:00
|
|
|
import { InputType } from "widgets/InputWidget";
|
2019-12-06 13:16:08 +00:00
|
|
|
import DynamicAutocompleteInput from "components/editorComponents/DynamicAutocompleteInput";
|
2019-09-18 10:19:50 +00:00
|
|
|
|
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;
|
2020-06-04 13:49:22 +00:00
|
|
|
errorMessage?: string;
|
|
|
|
|
expected?: string;
|
2020-03-16 15:42:39 +00:00
|
|
|
placeholder?: string;
|
2020-06-04 13:49:22 +00:00
|
|
|
dataTreePath?: string;
|
2020-01-23 07:53:36 +00:00
|
|
|
}) {
|
2020-06-04 13:49:22 +00:00
|
|
|
const {
|
|
|
|
|
errorMessage,
|
|
|
|
|
expected,
|
|
|
|
|
value,
|
|
|
|
|
isValid,
|
|
|
|
|
onChange,
|
|
|
|
|
placeholder,
|
|
|
|
|
dataTreePath,
|
|
|
|
|
} = props;
|
2020-01-23 07:53:36 +00:00
|
|
|
return (
|
2020-02-26 12:44:56 +00:00
|
|
|
<StyledDynamicInput>
|
|
|
|
|
<DynamicAutocompleteInput
|
|
|
|
|
input={{
|
|
|
|
|
value: value,
|
|
|
|
|
onChange: onChange,
|
|
|
|
|
}}
|
2020-06-04 13:49:22 +00:00
|
|
|
expected={expected}
|
|
|
|
|
dataTreePath={dataTreePath}
|
2020-02-26 12:44:56 +00:00
|
|
|
meta={{
|
2020-06-04 13:49:22 +00:00
|
|
|
error: isValid ? "" : errorMessage,
|
2020-02-26 12:44:56 +00:00
|
|
|
touched: true,
|
|
|
|
|
}}
|
|
|
|
|
theme={"DARK"}
|
|
|
|
|
singleLine={false}
|
2020-03-16 15:42:39 +00:00
|
|
|
placeholder={placeholder}
|
2020-02-26 12:44:56 +00:00
|
|
|
/>
|
|
|
|
|
</StyledDynamicInput>
|
2020-01-23 07:53:36 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-18 10:19:50 +00:00
|
|
|
class InputTextControl extends BaseControl<InputControlProps> {
|
|
|
|
|
render() {
|
2020-03-16 15:42:39 +00:00
|
|
|
const {
|
2020-06-04 13:49:22 +00:00
|
|
|
errorMessage,
|
|
|
|
|
expected,
|
2020-03-16 15:42:39 +00:00
|
|
|
propertyValue,
|
|
|
|
|
isValid,
|
|
|
|
|
label,
|
|
|
|
|
placeholderText,
|
2020-06-04 13:49:22 +00:00
|
|
|
dataTreePath,
|
2020-03-16 15:42:39 +00:00
|
|
|
} = this.props;
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
return (
|
2020-01-23 07:53:36 +00:00
|
|
|
<InputText
|
|
|
|
|
label={label}
|
|
|
|
|
value={propertyValue}
|
|
|
|
|
onChange={this.onTextChange}
|
|
|
|
|
isValid={isValid}
|
2020-06-04 13:49:22 +00:00
|
|
|
errorMessage={errorMessage}
|
|
|
|
|
expected={expected}
|
2020-03-16 15:42:39 +00:00
|
|
|
placeholder={placeholderText}
|
2020-06-04 13:49:22 +00:00
|
|
|
dataTreePath={dataTreePath}
|
2020-01-23 07:53:36 +00:00
|
|
|
/>
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
);
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
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);
|
Property Pane Controls
- Fixes #121, #122, #123, #124, #90, #46, #65, #100, #101, #68, #102
2019-10-24 05:24:45 +00:00
|
|
|
};
|
2019-09-18 10:19:50 +00:00
|
|
|
|
2020-04-14 05:35:16 +00:00
|
|
|
static getControlType() {
|
2019-09-18 10:19:50 +00:00
|
|
|
return "INPUT_TEXT";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface InputControlProps extends ControlProps {
|
|
|
|
|
placeholderText: string;
|
2019-11-19 12:44:58 +00:00
|
|
|
inputType: InputType;
|
2019-09-19 11:29:24 +00:00
|
|
|
isDisabled?: boolean;
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default InputTextControl;
|