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

151 lines
3.4 KiB
TypeScript
Raw Normal View History

import React from "react";
import BaseControl, { ControlProps } from "./BaseControl";
import { ControlType } from "constants/PropertyControlConstants";
feat: Migrate design system components import to design-system repo - I (#15562) * Icon component deleted and changed the imports in refrence places * design system package version changed * import changes * Delete TextInput.tsx * Change imports * Change single named import * Update package * Update package * Delete ScrollIndicator.tsx * Change imports * Icon import completed * Event type added * Changed Button component imports * import change button * Button onclick type fix * Label with Tooltip import changes * Changed breadcrumbs import * EmojiPicker and Emoji Reaction import changes * AppIcon import change * import bug fix * Menu Item import chnages * Icon selector imports changed * Delete LabelWithTooltip.tsx * Change imports across the app * Update package version * Update version number for design-system * Delete Checkbox.tsx * Remove the exports * Add lock file for ds package update * Change imports * default import -> named * Update release version * Make arg type explicit * Updated design-system to latest release * Missing file mysteriously comes back and is updated accordingly * changes design-system package version * Add types to arguments in the onChange for text input * onBlur type fix * Search component in property pane * WDS button changes reverted * package version bumped * conflict fix * Remove Dropdown, change imports * Category import fix * fix: table icon size import * Bump version of design system package * Yarn lock Co-authored-by: Tanvi Bhakta <tanvibhakta@gmail.com>
2022-08-22 05:09:39 +00:00
import { TextInput } from "design-system";
2020-10-27 05:02:32 +00:00
import { Colors } from "constants/Colors";
import styled from "styled-components";
import { InputType } from "components/constants";
import {
Field,
WrappedFieldMetaProps,
WrappedFieldInputProps,
} from "redux-form";
2020-10-27 05:02:32 +00:00
export const StyledInfo = styled.span`
2020-10-27 05:02:32 +00:00
font-weight: normal;
line-height: normal;
color: ${Colors.DOVE_GRAY};
2020-10-27 05:02:32 +00:00
font-size: 12px;
margin-left: 1px;
`;
export function InputText(props: {
label: string;
value: string;
isValid: boolean;
subtitle?: string;
validationMessage?: string;
placeholder?: string;
dataType?: string;
isRequired?: boolean;
name: string;
2020-10-27 05:02:32 +00:00
encrypted?: boolean;
disabled?: boolean;
customStyles?: Record<string, any>;
validator?: (value: string) => { isValid: boolean; message: string };
}) {
const { dataType, disabled, name, placeholder } = props;
return (
<div data-cy={name} style={{ width: "35vw", ...props.customStyles }}>
<Field
component={renderComponent}
datatype={dataType}
disabled={disabled || false}
placeholder={placeholder}
{...props}
asyncControl
/>
</div>
);
}
function renderComponent(
props: {
placeholder: string;
dataType?: InputType;
disabled?: boolean;
validator?: (value: string) => { isValid: boolean; message: string };
} & {
meta: Partial<WrappedFieldMetaProps>;
input: Partial<WrappedFieldInputProps>;
},
) {
return (
<TextInput
dataType={props.dataType}
disabled={props.disabled || false}
name={props.input?.name}
onChange={props.input.onChange}
placeholder={props.placeholder}
value={props.input.value}
{...props.input}
validator={props.validator}
width="100%"
/>
);
}
class InputTextControl extends BaseControl<InputControlProps> {
render() {
const {
configProperty,
dataType,
disabled,
encrypted,
isValid,
label,
placeholderText,
propertyValue,
subtitle,
validationMessage,
validator,
} = this.props;
return (
<InputText
dataType={this.getType(dataType)}
disabled={disabled}
encrypted={encrypted}
isValid={isValid}
label={label}
name={configProperty}
placeholder={placeholderText}
subtitle={subtitle}
validationMessage={validationMessage}
validator={validator}
value={propertyValue}
/>
);
}
isNumberType(): boolean {
const { inputType } = this.props;
switch (inputType) {
case "CURRENCY":
case "INTEGER":
case "NUMBER":
case "PHONE_NUMBER":
return true;
default:
return false;
}
}
getType(dataType: InputType | undefined) {
switch (dataType) {
case "PASSWORD":
return "password";
case "NUMBER":
return "number";
default:
return "text";
}
}
getControlType(): ControlType {
return "INPUT_TEXT";
}
}
export interface InputControlProps extends ControlProps {
placeholderText: string;
inputType?: InputType;
dataType?: InputType;
subtitle?: string;
2020-10-27 05:02:32 +00:00
encrypted?: boolean;
disabled?: boolean;
validator?: (value: string) => { isValid: boolean; message: string };
}
export default InputTextControl;