2020-10-16 07:34:32 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import BaseControl, { ControlProps } from "./BaseControl";
|
|
|
|
|
import { InputType } from "widgets/InputWidget";
|
|
|
|
|
import { ControlType } from "constants/PropertyControlConstants";
|
|
|
|
|
import TextField from "components/editorComponents/form/fields/TextField";
|
|
|
|
|
import FormLabel from "components/editorComponents/FormLabel";
|
|
|
|
|
import styled from "styled-components";
|
|
|
|
|
|
|
|
|
|
const Wrapper = styled.div`
|
|
|
|
|
width: 50vh;
|
|
|
|
|
`;
|
|
|
|
|
|
|
|
|
|
class FixKeyInputControl extends BaseControl<FixedKeyInputControlProps> {
|
|
|
|
|
render() {
|
|
|
|
|
const {
|
|
|
|
|
label,
|
|
|
|
|
placeholderText,
|
|
|
|
|
dataType,
|
|
|
|
|
configProperty,
|
|
|
|
|
isRequired,
|
|
|
|
|
fixedKey,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Wrapper>
|
|
|
|
|
<FormLabel>
|
|
|
|
|
{label} {isRequired && "*"}
|
|
|
|
|
</FormLabel>
|
|
|
|
|
<TextField
|
2020-12-24 04:32:25 +00:00
|
|
|
format={(value) => {
|
2020-10-16 07:34:32 +00:00
|
|
|
// Get the value property
|
|
|
|
|
if (value) {
|
|
|
|
|
return value.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "";
|
|
|
|
|
}}
|
2021-04-28 10:28:39 +00:00
|
|
|
name={configProperty}
|
2020-12-24 04:32:25 +00:00
|
|
|
parse={(value) => {
|
2020-10-16 07:34:32 +00:00
|
|
|
// Store the value in this field as {key: fixedKey, value: <user-input>}
|
|
|
|
|
return {
|
|
|
|
|
key: fixedKey,
|
|
|
|
|
value: value,
|
|
|
|
|
};
|
|
|
|
|
}}
|
2021-04-28 10:28:39 +00:00
|
|
|
placeholder={placeholderText}
|
|
|
|
|
showError
|
|
|
|
|
type={this.getType(dataType)}
|
2020-10-16 07:34:32 +00:00
|
|
|
/>
|
|
|
|
|
</Wrapper>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getType(dataType: InputType | undefined) {
|
|
|
|
|
switch (dataType) {
|
|
|
|
|
case "PASSWORD":
|
|
|
|
|
return "password";
|
|
|
|
|
case "NUMBER":
|
|
|
|
|
return "number";
|
|
|
|
|
default:
|
|
|
|
|
return "text";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getControlType(): ControlType {
|
|
|
|
|
return "FIXED_KEY_INPUT";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface FixedKeyInputControlProps extends ControlProps {
|
|
|
|
|
placeholderText: string;
|
|
|
|
|
inputType?: InputType;
|
|
|
|
|
dataType?: InputType;
|
|
|
|
|
fixedKey: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default FixKeyInputControl;
|