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";
|
2020-07-01 10:01:07 +00:00
|
|
|
import CodeEditor from "components/editorComponents/CodeEditor";
|
|
|
|
|
import {
|
|
|
|
|
EditorModes,
|
|
|
|
|
EditorSize,
|
|
|
|
|
EditorTheme,
|
|
|
|
|
TabBehaviour,
|
|
|
|
|
} from "components/editorComponents/CodeEditor/EditorConfig";
|
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;
|
2020-06-11 11:03:16 +00:00
|
|
|
evaluatedValue?: any;
|
2020-06-04 13:49:22 +00:00
|
|
|
expected?: string;
|
2020-03-16 15:42:39 +00:00
|
|
|
placeholder?: string;
|
2020-06-04 13:49:22 +00:00
|
|
|
dataTreePath?: string;
|
2021-02-16 10:29:08 +00:00
|
|
|
additionalAutocomplete?: Record<string, Record<string, unknown>>;
|
2021-03-15 12:17:56 +00:00
|
|
|
theme?: EditorTheme;
|
2021-04-23 05:43:13 +00:00
|
|
|
hideEvaluatedValue?: boolean;
|
2020-01-23 07:53:36 +00:00
|
|
|
}) {
|
2020-06-04 13:49:22 +00:00
|
|
|
const {
|
|
|
|
|
errorMessage,
|
|
|
|
|
expected,
|
|
|
|
|
value,
|
|
|
|
|
isValid,
|
|
|
|
|
onChange,
|
|
|
|
|
placeholder,
|
|
|
|
|
dataTreePath,
|
2020-06-11 11:03:16 +00:00
|
|
|
evaluatedValue,
|
2021-04-23 05:43:13 +00:00
|
|
|
hideEvaluatedValue,
|
2020-06-04 13:49:22 +00:00
|
|
|
} = props;
|
2021-04-23 05:43:13 +00:00
|
|
|
|
2020-01-23 07:53:36 +00:00
|
|
|
return (
|
2020-02-26 12:44:56 +00:00
|
|
|
<StyledDynamicInput>
|
2020-07-01 10:01:07 +00:00
|
|
|
<CodeEditor
|
2020-02-26 12:44:56 +00:00
|
|
|
input={{
|
|
|
|
|
value: value,
|
|
|
|
|
onChange: onChange,
|
|
|
|
|
}}
|
2020-06-11 11:03:16 +00:00
|
|
|
evaluatedValue={evaluatedValue}
|
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,
|
|
|
|
|
}}
|
2021-03-15 12:17:56 +00:00
|
|
|
theme={props.theme || EditorTheme.LIGHT}
|
2020-07-01 10:01:07 +00:00
|
|
|
mode={EditorModes.TEXT_WITH_BINDING}
|
|
|
|
|
tabBehaviour={TabBehaviour.INDENT}
|
|
|
|
|
size={EditorSize.EXTENDED}
|
2020-03-16 15:42:39 +00:00
|
|
|
placeholder={placeholder}
|
2021-02-16 10:29:08 +00:00
|
|
|
additionalDynamicData={props.additionalAutocomplete}
|
2021-04-23 05:43:13 +00:00
|
|
|
hideEvaluatedValue={hideEvaluatedValue}
|
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
|
|
|
expected,
|
2020-03-16 15:42:39 +00:00
|
|
|
propertyValue,
|
|
|
|
|
isValid,
|
|
|
|
|
label,
|
|
|
|
|
placeholderText,
|
2020-06-04 13:49:22 +00:00
|
|
|
dataTreePath,
|
2020-06-16 07:37:39 +00:00
|
|
|
validationMessage,
|
2021-02-16 10:29:08 +00:00
|
|
|
defaultValue,
|
2021-04-23 05:43:13 +00:00
|
|
|
additionalAutoComplete,
|
|
|
|
|
hideEvaluatedValue,
|
2020-03-16 15:42:39 +00:00
|
|
|
} = this.props;
|
2021-04-23 05:43:13 +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
|
|
|
return (
|
2020-01-23 07:53:36 +00:00
|
|
|
<InputText
|
|
|
|
|
label={label}
|
2021-02-16 10:29:08 +00:00
|
|
|
value={propertyValue ? propertyValue : defaultValue}
|
2020-01-23 07:53:36 +00:00
|
|
|
onChange={this.onTextChange}
|
|
|
|
|
isValid={isValid}
|
2020-06-16 07:37:39 +00:00
|
|
|
errorMessage={validationMessage}
|
2020-06-04 13:49:22 +00:00
|
|
|
expected={expected}
|
|
|
|
|
dataTreePath={dataTreePath}
|
2021-03-15 12:17:56 +00:00
|
|
|
placeholder={placeholderText}
|
|
|
|
|
theme={this.props.theme}
|
2021-04-23 05:43:13 +00:00
|
|
|
additionalAutocomplete={additionalAutoComplete}
|
|
|
|
|
hideEvaluatedValue={hideEvaluatedValue}
|
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;
|
2020-06-16 07:37:39 +00:00
|
|
|
validationMessage?: string;
|
2019-09-19 11:29:24 +00:00
|
|
|
isDisabled?: boolean;
|
2021-02-16 10:29:08 +00:00
|
|
|
defaultValue?: any;
|
2019-09-18 10:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default InputTextControl;
|